Reviewers: zundel,

Description:
Clean up the CrossSiteIFrameLoadingStrategy class, removing some dead
code,
adding comments to clarify what is going on, and making it throw an
error
which is more explicit about what triggered the error


Please review this at http://gwt-code-reviews.appspot.com/1413801/

Affected files:
  M user/src/com/google/gwt/core/client/CodeDownloadException.java
M user/src/com/google/gwt/core/client/impl/CrossSiteIframeLoadingStrategy.java


Index: user/src/com/google/gwt/core/client/CodeDownloadException.java
===================================================================
--- user/src/com/google/gwt/core/client/CodeDownloadException.java (revision 9972) +++ user/src/com/google/gwt/core/client/CodeDownloadException.java (working copy)
@@ -27,10 +27,10 @@
    * need to be down loaded.
    */
   public enum Reason {
-    /**
-     * Generic code for terminating the download.
-     */
-    TERMINATED
+    ONERROR,
+    ONLOAD,
+    READYSTATELOADED,
+    READYSTATECOMPLETE,
   }

   private final Reason reason;
Index: user/src/com/google/gwt/core/client/impl/CrossSiteIframeLoadingStrategy.java
===================================================================
--- user/src/com/google/gwt/core/client/impl/CrossSiteIframeLoadingStrategy.java (revision 9972) +++ user/src/com/google/gwt/core/client/impl/CrossSiteIframeLoadingStrategy.java (working copy)
@@ -25,14 +25,6 @@
 /**
  * Load runAsync code using a script tag. Intended for use with the
  * {@link com.google.gwt.core.linker.CrossSiteIframeLinker}.
- *
- * <p>
- * The linker wraps its selection script code with a function refered to by
- * <code>__gwtModuleFunction</code>. On that function is a property
- * <code>installCode</code> that can be invoked to eval more code in a scope - * nested somewhere within that function. The loaded script for fragment 123 is
- * expected to invoke <code>__gwtModuleFunction.runAsyncCallback123</code>
- * as the final thing it does.
  */
 public class CrossSiteIframeLoadingStrategy implements LoadingStrategy {
   /**
@@ -58,10 +50,19 @@
     }-*/;
   }

-  private static final RuntimeException LoadTerminated =
-      new CodeDownloadException("Code download terminated",
-                                CodeDownloadException.Reason.TERMINATED);
-
+  private static final RuntimeException LoadTerminatedError =
+      new CodeDownloadException("Code download terminated - onError",
+                                CodeDownloadException.Reason.ONERROR);
+  private static final RuntimeException LoadTerminatedLoaded =
+    new CodeDownloadException("Code download terminated - onLoad",
+                              CodeDownloadException.Reason.ONLOAD);
+  private static final RuntimeException LoadTerminatedReadyComplete =
+    new CodeDownloadException("Code download terminated - onReadyComplete",
+ CodeDownloadException.Reason.READYSTATECOMPLETE);
+  private static final RuntimeException LoadTerminatedReadyLoaded =
+    new CodeDownloadException("Code download terminated - onReadyLoaded",
+ CodeDownloadException.Reason.READYSTATELOADED);
+
   /**
    * Clear callbacks on script objects. This is important on IE 6 and 7 to
* prevent a memory leak. If the callbacks aren't cleared, there is a cyclical
@@ -71,13 +72,6 @@
   private static native void clearCallbacks(JavaScriptObject script) /*-{
     var nop = new Function('');
     script.onerror = script.onload = script.onreadystatechange = nop;
-  }-*/;
-
-  /**
-   * Clear the success callback for fragment <code>fragment</code>.
-   */
-  private static native void clearOnSuccess(int fragment) /*-{
-    delete __gwtModuleFunction['runAsyncCallback'+fragment];
   }-*/;

   private static native JavaScriptObject createScriptTag(String url) /*-{
@@ -97,13 +91,18 @@
       LoadTerminatedHandler loadFinishedHandler) /*-{
      return function(exception) {
        if (tag.parentNode == null) {
-         // onSuccess or onFailure must have already been called.
+         // This function must have already been called.
          return;
        }
        var head = document.getElementsByTagName('head').item(0);
- @com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::clearOnSuccess(*)(fragment); @com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::clearCallbacks(*)(tag);
        head.removeChild(tag);
+       // It seems unintuitive to call the error function every time, but
+       // it appears that AsyncFragmentLoader::fragmentHasLoaded (which is
+       // called by each fragment) will set the fragmentLoading variable to
+       // -1 when the code in this fragment executes, so this
+ // loadTerminated call will fail the (fragmentLoading == fragment) check
+       // and will immediately exit, so no errors are actually fired.
        function callLoadTerminated() {
loadfinishedhandl...@com.google.gwt.core.client.impl.AsyncFragmentLoader.LoadTerminatedHandler::loadTerminated(*)(exception);
        }
@@ -113,17 +112,20 @@

   private static native void setOnTerminated(JavaScriptObject script,
       JavaScriptObject callback) /*-{
- var exception = @com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::LoadTerminated;
     script.onerror = function() {
-      callback(exception);
+ callback(@com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::LoadTerminatedError);
     }
     script.onload = function() {
-      callback(exception);
+ callback(@com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::LoadTerminatedError);
     }
     script.onreadystatechange = function () {
- if (script.readyState == 'loaded' || script.readyState == 'complete') {
+      if (script.readyState == 'loaded') {
         script.onreadystatechange = function () { }
-        callback(exception);
+ callback(@com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::LoadTerminatedReadyLoaded);
+      }
+      if (script.readyState == 'complete') {
+        script.onreadystatechange = function () { }
+ callback(@com.google.gwt.core.client.impl.CrossSiteIframeLoadingStrategy::LoadTerminatedReadyComplete);
       }
     }
   }-*/;


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

Reply via email to