Bug 1317212 - Make tab progress listeners smarter at ignoring nsIWebProgress notifications from an initial about:blank. r?Gijs draft
authorMike Conley <mconley@mozilla.com>
Tue, 13 Dec 2016 17:17:51 -0500
changeset 462091 6778bc159b87f8e2819d242724b7cf5cecf76c32
parent 462088 b2b68b6d2dcf79a321b4b1b63ab22cc956b25c23
child 542318 a19fdb37c5f7814ae6ddec280d600fc94ae64d36
push id41673
push usermconley@mozilla.com
push dateMon, 16 Jan 2017 19:17:32 +0000
reviewersGijs
bugs1317212
milestone53.0a1
Bug 1317212 - Make tab progress listeners smarter at ignoring nsIWebProgress notifications from an initial about:blank. r?Gijs MozReview-Commit-ID: Ji1oCNZksge
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -575,16 +575,25 @@
               if ((aRequest instanceof Ci.nsIChannel) &&
                   aRequest.originalURI.schemeIs("about") &&
                   (aRequest.URI.schemeIs("jar") || aRequest.URI.schemeIs("file")))
                 return false;
 
               return true;
             },
 
+            _isForInitialAboutBlank(aWebProgress, aLocation) {
+              if (!this.mBlank || !aWebProgress.isTopLevel) {
+                return false;
+              }
+
+              let location = aLocation ? aLocation.spec : "";
+              return location == "about:blank";
+            },
+
             onProgressChange(aWebProgress, aRequest,
                              aCurSelfProgress, aMaxSelfProgress,
                              aCurTotalProgress, aMaxTotalProgress) {
               this.mTotalProgress = aMaxTotalProgress ? aCurTotalProgress / aMaxTotalProgress : 0;
 
               if (!this._shouldShowProgress(aRequest))
                 return;
 
@@ -604,27 +613,37 @@
                 aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress,
                 aMaxTotalProgress);
             },
 
             onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
               if (!aRequest)
                 return;
 
-              var oldBlank = this.mBlank;
-
               const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
               const nsIChannel = Components.interfaces.nsIChannel;
               let location, originalLocation;
               try {
                 aRequest.QueryInterface(nsIChannel)
                 location = aRequest.URI;
                 originalLocation = aRequest.originalURI;
               } catch (ex) {}
 
+              let ignoreBlank = this._isForInitialAboutBlank(aWebProgress, location);
+              // If we were ignoring some messages about the initial about:blank, and we
+              // got the STATE_STOP for it, we'll want to pay attention to those messages
+              // from here forward. Similarly, if we conclude that this state change
+              // is one that we shouldn't be ignoring, then stop ignoring.
+              if ((ignoreBlank &&
+                   aStateFlags & nsIWebProgressListener.STATE_STOP &&
+                   aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) ||
+                  !ignoreBlank && this.mBlank) {
+                this.mBlank = false;
+              }
+
               if (aStateFlags & nsIWebProgressListener.STATE_START) {
                 this.mRequestCount++;
               } else if (aStateFlags & nsIWebProgressListener.STATE_STOP) {
                 const NS_ERROR_UNKNOWN_HOST = 2152398878;
                 if (--this.mRequestCount > 0 && aStatus == NS_ERROR_UNKNOWN_HOST) {
                   // to prevent bug 235825: wait for the request handled
                   // by the automatic keyword resolver
                   return;
@@ -701,31 +720,28 @@
                   } else if (isSuccessful) {
                     this.mBrowser.urlbarChangeTracker.finishedLoad();
                   }
 
                   if (!this.mBrowser.mIconURL)
                     this.mTabBrowser.useDefaultIcon(this.mTab);
                 }
 
-                if (this.mBlank)
-                  this.mBlank = false;
-
                 // For keyword URIs clear the user typed value since they will be changed into real URIs
                 if (location.scheme == "keyword")
                   this.mBrowser.userTypedValue = null;
 
                 if (this.mTab.label == this.mTabBrowser.mStringBundle.getString("tabs.connecting"))
                   this.mTabBrowser.setTabTitle(this.mTab);
 
                 if (this.mTab.selected)
                   this.mTabBrowser.mIsBusy = false;
               }
 
-              if (oldBlank) {
+              if (ignoreBlank) {
                 this._callProgressListeners("onUpdateCurrentBrowser",
                                             [aStateFlags, aStatus, "", 0],
                                             true, false);
               } else {
                 this._callProgressListeners("onStateChange",
                                             [aWebProgress, aRequest, aStateFlags, aStatus],
                                             true, false);
               }