Bug 1241085 - part 1: improve inLoadURI support, r=mconley draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 28 Apr 2016 18:31:42 +0100
changeset 364223 dea0a728eec67a7c78ac57ce34e83f7d554136fa
parent 363908 de5ab3fd7c7e5772cc323a6d998a3a94143c23b1
child 364224 a877f7c81abff9626096895c7ed02714e6575246
push id17388
push usergijskruitbosch@gmail.com
push dateFri, 06 May 2016 08:12:53 +0000
reviewersmconley
bugs1241085
milestone49.0a1
Bug 1241085 - part 1: improve inLoadURI support, r=mconley MozReview-Commit-ID: 8jTbktXGOA1
toolkit/content/browser-child.js
toolkit/content/widgets/browser.xml
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -272,29 +272,40 @@ var WebNavigation =  {
         this.reload(message.data.flags);
         break;
       case "WebNavigation:Stop":
         this.stop(message.data.flags);
         break;
     }
   },
 
+  _wrapURIChangeCall(fn) {
+    this._inLoadURI = true;
+    try {
+      fn();
+    } finally {
+      this._inLoadURI = false;
+      WebProgressListener.sendLoadCallResult();
+    }
+  },
+
   goBack: function() {
     if (this.webNavigation.canGoBack) {
-      this.webNavigation.goBack();
+      this._wrapURIChangeCall(() => this.webNavigation.goBack());
     }
   },
 
   goForward: function() {
-    if (this.webNavigation.canGoForward)
-      this.webNavigation.goForward();
+    if (this.webNavigation.canGoForward) {
+      this._wrapURIChangeCall(() => this.webNavigation.goForward());
+    }
   },
 
   gotoIndex: function(index) {
-    this.webNavigation.gotoIndex(index);
+    this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(index));
   },
 
   loadURI: function(uri, flags, referrer, referrerPolicy, postData, headers, baseURI) {
     if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled) {
       let annotation = uri;
       try {
         let url = Services.io.newURI(uri, null, null);
         // If the current URI contains a username/password, remove it.
@@ -307,24 +318,20 @@ var WebNavigation =  {
     if (referrer)
       referrer = Services.io.newURI(referrer, null, null);
     if (postData)
       postData = makeInputStream(postData);
     if (headers)
       headers = makeInputStream(headers);
     if (baseURI)
       baseURI = Services.io.newURI(baseURI, null, null);
-    this._inLoadURI = true;
-    try {
-      this.webNavigation.loadURIWithOptions(uri, flags, referrer, referrerPolicy,
-                                            postData, headers, baseURI);
-    } finally {
-      this._inLoadURI = false;
-      WebProgressListener.sendLoadCallResult();
-    }
+    this._wrapURIChangeCall(() => {
+      return this.webNavigation.loadURIWithOptions(uri, flags, referrer, referrerPolicy,
+                                                   postData, headers, baseURI);
+    });
   },
 
   reload: function(flags) {
     this.webNavigation.reload(flags);
   },
 
   stop: function(flags) {
     this.webNavigation.stop(flags);
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -34,41 +34,60 @@
       <property name="canGoBack"
                 onget="return this.webNavigation.canGoBack;"
                 readonly="true"/>
 
       <property name="canGoForward"
                 onget="return this.webNavigation.canGoForward;"
                 readonly="true"/>
 
+      <method name="_wrapURIChangeCall">
+        <parameter name="fn"/>
+        <body>
+          <![CDATA[
+            if (!this.isRemoteBrowser) {
+              this.inLoadURI = true;
+              try {
+                fn();
+              } finally {
+                this.inLoadURI = false;
+              }
+            } else {
+              fn();
+            }
+          ]]>
+        </body>
+      </method>
+
+
       <method name="goBack">
         <body>
           <![CDATA[
             var webNavigation = this.webNavigation;
             if (webNavigation.canGoBack) {
               try {
                 this.userTypedClear++;
-                webNavigation.goBack();
+                this._wrapURIChangeCall(() => webNavigation.goBack());
               } finally {
                 if (this.userTypedClear)
                   this.userTypedClear--;
               }
             }
           ]]>
         </body>
       </method>
 
       <method name="goForward">
         <body>
           <![CDATA[
             var webNavigation = this.webNavigation;
             if (webNavigation.canGoForward) {
               try {
                 this.userTypedClear++;
-                webNavigation.goForward();
+                this._wrapURIChangeCall(() => webNavigation.goForward());
               } finally {
                 if (this.userTypedClear)
                   this.userTypedClear--;
               }
             }
           ]]>
         </body>
       </method>
@@ -106,17 +125,18 @@
       <method name="loadURI">
         <parameter name="aURI"/>
         <parameter name="aReferrerURI"/>
         <parameter name="aCharset"/>
         <body>
           <![CDATA[
             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
             const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
-            this.loadURIWithFlags(aURI, flags, aReferrerURI, aCharset);
+            this._wrapURIChangeCall(() =>
+              this.loadURIWithFlags(aURI, flags, aReferrerURI, aCharset));
           ]]>
         </body>
       </method>
 
       <!-- throws exception for unknown schemes -->
       <method name="loadURIWithFlags">
         <parameter name="aURI"/>
         <parameter name="aFlags"/>
@@ -141,19 +161,20 @@
               aCharset = params.charset;
               aPostData = params.postData;
             }
 
             if (!(aFlags & this.webNavigation.LOAD_FLAGS_FROM_EXTERNAL))
               this.userTypedClear++;
 
             try {
+            this._wrapURIChangeCall(() =>
               this.webNavigation.loadURIWithOptions(
                   aURI, aFlags, aReferrerURI, aReferrerPolicy,
-                  aPostData, null, null);
+                  aPostData, null, null));
             } finally {
               if (this.userTypedClear)
                 this.userTypedClear--;
             }
           ]]>
         </body>
       </method>
 
@@ -191,17 +212,17 @@
       </property>
 
       <method name="gotoIndex">
         <parameter name="aIndex"/>
         <body>
           <![CDATA[
             try {
               this.userTypedClear++;
-              this.webNavigation.gotoIndex(aIndex);
+              this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(aIndex));
             } finally {
               if (this.userTypedClear)
                 this.userTypedClear--;
             }
           ]]>
         </body>
       </method>