Fix for hosted mode with XHR-based iframe selection script.
Includes fix for issue 3717.
Review: http://gwt-code-reviews.appspot.com/33840
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5517 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html b/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
index 5e1e983..4aa4edd 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
@@ -4,11 +4,21 @@
var $doc = $wnd.document;
var $moduleName, $moduleBase
,$stats = $wnd.__gwtStatsEvent ? function(a) {return $wnd.__gwtStatsEvent(a);} : null;
+
+// The module to be loaded can be specified either through the url query
+// parameter (as done by the legacy HostedModeTemplate.js), or by specifying
+// window.name (as done by IFrameTemplate.js). When the former approach
+// is removed, we can drop the window.location.search part of this logic.
+var moduleFuncName = window.location.search.substring(1);
+if (!moduleFuncName || !$wnd[moduleFuncName]) {
+ moduleFuncName = window.name;
+}
+
+var moduleFunc = $wnd[moduleFuncName];
+var moduleName = moduleFunc ? moduleFunc.moduleName : "unknown";
+
// Lightweight metrics
if ($stats) {
- var moduleFuncName = location.search.substr(1);
- var moduleFunc = $wnd[moduleFuncName];
- var moduleName = moduleFunc ? moduleFunc.moduleName : "unknown";
$stats({moduleName:moduleName,subSystem:'startup',evtGroup:'moduleStartup',millis:(new Date()).getTime(),type:'moduleEvalStart'});
}
@@ -241,13 +251,5 @@
}
}
-// The module to be loaded can be specified either through the url query
-// parameter (as done by the legacy HostedModeTemplate.js), or by specifying
-// window.__gwt_module (as done by IFrameTemplate.js). When the former approach
-// is removed, we can drop the 'query' part of this logic.
-query = window.location.search.substring(1);
-if (query && $wnd[query]) setTimeout($wnd[query].onScriptLoad, 1);
-
-var module = window.__gwt_module;
-if (module && $wnd[module]) setTimeout($wnd[module].onScriptLoad, 1);
+setTimeout($wnd[moduleFuncName].onScriptLoad, 1);
--></script></body></html>
diff --git a/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js b/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
index c4362b1..3697006 100644
--- a/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
+++ b/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
@@ -309,6 +309,9 @@
type: 'moduleRequested'
});
+ // to avoid http://support.microsoft.com/kb/927917 only mutate closed containers - therefore we create a closed container which can be mutated within xhr.onreadystatechange
+ document.write("<div id='__MODULE_NAME__.container' style='position:absolute; width:0; height:0; border:none'></div>");
+
// Fetch the contents via XHR.
var xhr = newXhr();
xhr.open('GET', base + initialHtml);
@@ -322,14 +325,14 @@
scriptFrame.id = '__MODULE_NAME__';
scriptFrame.style.cssText = 'position:absolute; width:0; height:0; border:none';
scriptFrame.tabIndex = -1;
- document.body.appendChild(scriptFrame);
+ document.getElementById("__MODULE_NAME__.container").appendChild(scriptFrame);
- // Expose the module function via an expando on the iframe's window.
+ // Expose the module function via the iframe's window.name property
// (this is needed for the compiled script to call back into
// onScriptLoad()).
var win = scriptFrame.contentWindow;
if (isHostedMode()) {
- win.__gwt_module = '__MODULE_FUNC__';
+ win.name = '__MODULE_FUNC__';
}
// Inject the fetched script into the script frame.