* This is the real implementation of <code>getModulePrefix</code> for this
* linker. The other versions forward to this one.
*/
private String getModulePrefix(LinkerContext context, String strongName,
boolean supportRunAsync) {
DefaultTextOutput out = new DefaultTextOutput(context.isOutputCompact());
out.print("<html>");
out.newlineOpt();
// Setup the well-known variables.
out.print("<head><script>");
out.newlineOpt();
out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
out.newlineOpt();
out.print("var $wnd = parent;");
out.newlineOpt();
out.print("var $doc = $wnd.document;");
out.newlineOpt();
out.print("var $moduleName, $moduleBase;");
out.newlineOpt();
out.print("var $strongName = '" + strongName + "';");
out.newlineOpt();
if (supportRunAsync) {
out.print("function __gwtStartLoadingFragment(frag) {");
out.indentIn();
out.newlineOpt();
out.print(" return $moduleBase + '" + getFragmentSubdir()
+ "/' + $strongName + '/' + frag + '" + FRAGMENT_EXTENSION + "';");
out.indentOut();
out.newlineOpt();
out.print("};");
out.newlineOpt();
out.print("function __gwtInstallCode(code) {");
/*
* Use a script tag on all platforms, for simplicity. It would be cleaner
* to use window.eval, but at the time of writing that only reliably works
* on Firefox. It would also be cleaner to use window.execScript on
* platforms that support it (IE and Chrome). However, trying this causes
* IE 6 (and possibly others) to emit "error 80020101", apparently due to
* something objectionable in the compiler's output JavaScript.
*/
out.indentIn();
out.newlineOpt();
out.print("var head = document.getElementsByTagName('head').item(0);");
out.newlineOpt();
out.print("var script = document.createElement('script');");
out.newlineOpt();
out.print("script.type = 'text/javascript';");
out.newlineOpt();
out.print("script.text = code;");
out.newlineOpt();
out.print("head.appendChild(script);");
out.indentOut();
out.newlineOpt();
out.print("};");
out.newlineOpt();
}
out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {return $wnd.__gwtStatsEvent(a);} : null,");
out.newlineOpt();
out.print("$sessionId = $wnd.__gwtStatsSessionId ? $wnd.__gwtStatsSessionId : null;");
out.newlineOpt();
out.print("$stats && $stats({moduleName:'" + context.getModuleName()
+ "',sessionId:$sessionId"
+ ",subSystem:'startup',evtGroup:'moduleStartup'"
+ ",millis:(new Date()).getTime(),type:'moduleEvalStart'});");
out.newlineOpt();
out.print("</script></head>");
out.newlineOpt();
out.print("<body>");
out.newlineOpt();
// Begin a script block inside the body. It's commented out so that the
// browser won't mistake strings containing "<script>" for actual script.
out.print("<script><!--");
out.newline();
return out.toString();
}