Revision: 8723
Author: [email protected]
Date: Tue Sep  7 12:33:00 2010
Log: Rolling back due load test failures.

*** Original change description ***
Add Late Loading support to xsiframe linker
Review at http://gwt-code-reviews.appspot.com/807801

http://code.google.com/p/google-web-toolkit/source/detail?r=8723

Modified:
/trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/computeScriptBase.js
 /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.js
 /trunk/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js

=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/computeScriptBase.js Fri Sep 3 10:10:06 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/computeScriptBase.js Tue Sep 7 09:26:43 2010
@@ -24,39 +24,24 @@
  * on each side.
  */
 function computeScriptBase() {
-  // First, check if the meta properties give the baseUrl
+  var thisScript
+  ,markerId = "__gwt_marker___MODULE_NAME__"
+  ,markerScript;
+
   if (metaProps['baseUrl']) {
     base = metaProps['baseUrl'];
     return;
   }

-  // The baseUrl will be similar to the URL for this script's URL
-  var thisScript;
-
-  // By default, this script looks like something/moduleName.nocache.js
-  // so look for a script tag that looks like that
-  var scriptTags = $doc.getElementsByTagName('script');
-  for (var i = 0; i < scriptTags.length; ++i) {
-    if (scriptTags[i].src.indexOf('__MODULE_NAME__.nocache.js') != -1) {
-      thisScript = scriptTags[i];
-    }
-  }
-
- // If the user renamed their script tag, we'll use a fancier method to find
-  // it. Note that this will not work in the Late Loading case due to the
-  // document.write call.
-  if (!thisScript) {
- // Put in a marker script element which should be the first script tag after - // the tag we're looking for. To find it, we start at the marker and walk
-    // backwards until we find a script.
-    var markerId = "__gwt_marker___MODULE_NAME__";
-    var markerScript;
-    $doc.write('<script id="' + markerId + '"></script>');
-    markerScript = $doc.getElementById(markerId);
-    thisScript = markerScript && markerScript.previousSibling;
-    while (thisScript && thisScript.tagName != 'SCRIPT') {
-      thisScript = thisScript.previousSibling;
-    }
+  $doc.write('<script id="' + markerId + '"></script>');
+  markerScript = $doc.getElementById(markerId);
+
+ // Our script element is assumed to be the closest previous script element
+  // to the marker, so start at the marker and walk backwards until we find
+  // a script.
+  thisScript = markerScript && markerScript.previousSibling;
+  while (thisScript && thisScript.tagName != 'SCRIPT') {
+    thisScript = thisScript.previousSibling;
   }

   // Gets the part of a url up to and including the 'path' portion.
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.js Fri Sep 3 10:10:06 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.js Tue Sep 7 09:26:43 2010
@@ -333,20 +333,13 @@

 doBrowserSpecificFixes();

+// DevMode currently only supports iframe based linkers
+var query = parent.location.search;
 if (!findPluginXPCOM()) {
-  var embed = document.createElement('embed');
-  embed.id = 'pluginEmbed';
-  embed.type = 'application/x-gwt-hosted-mode';
-  embed.width = '10';
-  embed.height = '20';
-
-  var obj = document.createElement('object');
-  obj.id = 'pluginObject';
-  obj.CLASSID = 'CLSID:1D6156B6-002B-49E7-B5CA-C138FB843B4E';
-
-  var dochead = doc.getElementsByTagName('head')[0];
-  dochead.append(embed);
-  dochead.append(obj);
+ document.write('<embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10" height="10">');
+  document.write('</embed>');
+ document.write('<object id="pluginObject" CLASSID="CLSID:1D6156B6-002B-49E7-B5CA-C138FB843B4E">');
+  document.write('</object>');
 }

setTimeout(function() { $wnd[$moduleName].onScriptInstalled(gwtOnLoad) }, 1);
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js Fri Sep 3 10:10:06 2010 +++ /trunk/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeTemplate.js Tue Sep 7 09:26:43 2010
@@ -56,20 +56,24 @@

   ; // end of global vars

-  sendStats('bootstrap', 'begin');
+  $stats && $stats({
+    moduleName: '__MODULE_NAME__',
+    sessionId: $sessionId,
+    subSystem: 'startup',
+    evtGroup: 'bootstrap',
+    millis:(new Date()).getTime(),
+    type: 'begin',
+  });
+
+  // ------------------ TRUE GLOBALS ------------------
+
+ // Maps to synchronize the loading of styles and scripts; resources are loaded + // only once, even when multiple modules depend on them. This API must not
+  // change across GWT versions.
+  if (!$wnd.__gwt_stylesLoaded) { $wnd.__gwt_stylesLoaded = {}; }
+  if (!$wnd.__gwt_scriptsLoaded) { $wnd.__gwt_scriptsLoaded = {}; }

   // --------------- INTERNAL FUNCTIONS ---------------
-
-  function sendStats(evtGroupString, typeString) {
-    $stats && $stats({
-      moduleName: '__MODULE_NAME__',
-      sessionId: $sessionId,
-      subSystem: 'startup',
-      evtGroup: evtGroupString,
-      millis:(new Date()).getTime(),
-      type: typeString,
-    });
-  }

   function isHostedMode() {
     var result = false;
@@ -144,53 +148,6 @@
     // It should have installed its code immediately after being added.
     docbody.removeChild(script);
   }
-
- // Setup code so that maybeCreateFrame() is called once the body is loaded
-  function setupWaitForBodyLoad() {
-    function isBodyLoaded() {
-      return (/loaded|complete/.test($doc.readyState));
-    }
-
-    if (isBodyLoaded()) {
- // If this script is being added to an already loaded page, then just set
-      // the variable to true.
-      bodyDone = true;
- // maybeCreateFrame will not do anything since we know the compiled script - // has not yet been downloaded, so we don't need to call it here like we
-      // do when bodyDone becomes true after a callback or timer.
-    }
-
- // If the page is not already loaded, setup some listeners and timers to
-    // detect when it is done.
-    var onBodyDoneTimerId;
-    function onBodyDone() {
-      if (!bodyDone) {
-        bodyDone = true;
-        maybeCreateFrame();
-
-        if ($doc.removeEventListener) {
-          $doc.removeEventListener("DOMContentLoaded", onBodyDone, false);
-        }
-        if (onBodyDoneTimerId) {
-          clearInterval(onBodyDoneTimerId);
-        }
-      }
-    }
-
-    // For everyone that supports DOMContentLoaded.
-    if ($doc.addEventListener) {
-      $doc.addEventListener("DOMContentLoaded", function() {
-        onBodyDone();
-      }, false);
-    }
-
-    // Fallback. If onBodyDone() gets fired twice, it's not a big deal.
-    var onBodyDoneTimerId = setInterval(function() {
-      if (isBodyLoaded()) {
-        onBodyDone();
-      }
-    }, 50);
-  }

   __PROCESS_METAS__
   __COMPUTE_SCRIPT_BASE__
@@ -270,13 +227,20 @@
     }
gwtOnLoadFunc(onLoadErrorFunc, '__MODULE_NAME__', base, softPermutationId);
     // Record when the module EntryPoints return.
-    sendStats('moduleStartup', 'end');
+    $stats && $stats({
+      moduleName: '__MODULE_NAME__',
+      sessionId: $sessionId,
+      subSystem: 'startup',
+      evtGroup: 'moduleStartup',
+      millis:(new Date()).getTime(),
+      type: 'end',
+    });
   }

   // Install code pulled in via runAsync
   //
   __MODULE_FUNC__.installCode = installCode;
-
+
   // --------------- STRAIGHT-LINE CODE ---------------

   // do it early for compile/browse rebasing
@@ -285,7 +249,14 @@

   // --------------- WINDOW ONLOAD HOOK ---------------

-  sendStats('bootstrap', 'selectingPermutation');
+  $stats && $stats({
+    moduleName:'__MODULE_NAME__',
+    sessionId: $sessionId,
+    subSystem:'startup',
+    evtGroup: 'bootstrap',
+    millis:(new Date()).getTime(),
+    type: 'selectingPermutation'
+  });

   var strongName;
   if (!isHostedMode()) {
@@ -303,19 +274,84 @@
       return;
     }
   }
-
-  setupWaitForBodyLoad();
-
-  sendStats('bootstrap', 'end');
-  sendStats('moduleStartup', 'moduleRequested');
-
+
+  var onBodyDoneTimerId;
+  function onBodyDone() {
+    if (!bodyDone) {
+      bodyDone = true;
+// __MODULE_STYLES_BEGIN__
+ // Style resources are injected here to prevent operation aborted errors on ie
+// __MODULE_STYLES_END__
+      maybeCreateFrame();
+
+      if ($doc.removeEventListener) {
+        $doc.removeEventListener("DOMContentLoaded", onBodyDone, false);
+      }
+      if (onBodyDoneTimerId) {
+        clearInterval(onBodyDoneTimerId);
+      }
+    }
+  }
+
+  // For everyone that supports DOMContentLoaded.
+  if ($doc.addEventListener) {
+    $doc.addEventListener("DOMContentLoaded", function() {
+      onBodyDone();
+    }, false);
+  }
+
+  // Fallback. If onBodyDone() gets fired twice, it's not a big deal.
+  var onBodyDoneTimerId = setInterval(function() {
+    if (/loaded|complete/.test($doc.readyState)) {
+      onBodyDone();
+    }
+  }, 50);
+
+  $stats && $stats({
+    moduleName:'__MODULE_NAME__',
+    sessionId: $sessionId,
+    subSystem:'startup',
+    evtGroup: 'bootstrap',
+    millis:(new Date()).getTime(),
+    type: 'end'
+  });
+
+  $stats && $stats({
+    moduleName:'__MODULE_NAME__',
+    sessionId: $sessionId,
+    subSystem:'startup',
+    evtGroup: 'loadExternalRefs',
+    millis:(new Date()).getTime(),
+    type: 'begin'
+  });
+
+// __MODULE_SCRIPTS_BEGIN__
+  // Script resources are injected here
+// __MODULE_SCRIPTS_END__
+ // This is a bit ugly, but serves a purpose. We need to ensure that the stats + // script runs before the compiled script. If they are both doc.write()n in
+  // sequence, that should be the effect. Except on IE it turns out that a
+ // script injected via doc.write() can execute immediately! Adding 'defer'
+  // attributes to both seemed to fix this, but caused startup problems for
+  // some apps. The final solution was simply to inject the compiled script
+ // from *within* the stats script, guaranteeing order at the expense of near
+  // total inscrutability :(
+  var compiledScriptWrite = '';
   if (!isHostedMode()) {
-    var script = document.createElement('script');
-    script.src = base + strongName + '.cache.js;'
-    $doc.getElementsByTagName('head')[0].appendChild(script);
-  } else {
-       maybeCreateFrame();
-  }
+ compiledScriptWrite = 'document.write("<script src=\\"' + base + strongName + '.cache.js\\"></scr" + "ipt>");';
+  }
+
+  $doc.write('<scr' + 'ipt><!-' + '-\n'
+    + 'window.__gwtStatsEvent && window.__gwtStatsEvent({'
+ + 'moduleName:"__MODULE_NAME__", sessionId:window.__gwtStatsSessionId, subSystem:"startup",'
+    + 'evtGroup: "loadExternalRefs", millis:(new Date()).getTime(),'
+    + 'type: "end"});'
+    + 'window.__gwtStatsEvent && window.__gwtStatsEvent({'
+ + 'moduleName:"__MODULE_NAME__", sessionId:window.__gwtStatsSessionId, subSystem:"startup",'
+    + 'evtGroup: "moduleStartup", millis:(new Date()).getTime(),'
+    + 'type: "moduleRequested"});'
+    + compiledScriptWrite
+    + '\n-' + '-></scr' + 'ipt>');
 }

 __MODULE_FUNC__();

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to