Bug 1144988 - Don't let other pages to load while doing scroll-to-anchor. r=bz, a=lmandel
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 19 Mar 2015 21:53:32 -0400
changeset 250462 9b93e6033d5d
parent 250461 2e6977da201e
child 250463 790546ceb89f
child 250465 78170a73d2c8
child 250467 1efc8c39543c
push id4595
push userryanvm@gmail.com
push date2015-03-20 01:56 +0000
treeherdermozilla-beta@9b93e6033d5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lmandel
bugs1144988
milestone37.0
Bug 1144988 - Don't let other pages to load while doing scroll-to-anchor. r=bz, a=lmandel
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4570,17 +4570,18 @@ nsDocShell::IsPrintingOrPP(bool aDisplay
   return mIsPrintingOrPP;
 }
 
 bool
 nsDocShell::IsNavigationAllowed(bool aDisplayPrintErrorDialog,
                                 bool aCheckIfUnloadFired)
 {
   bool isAllowed = !IsPrintingOrPP(aDisplayPrintErrorDialog) &&
-                   (!aCheckIfUnloadFired || !mFiredUnloadEvent);
+                   (!aCheckIfUnloadFired || !mFiredUnloadEvent) &&
+                   !mBlockNavigation;
   if (!isAllowed) {
     return false;
   }
   if (!mContentViewer) {
     return true;
   }
   bool firingBeforeUnload;
   mContentViewer->GetBeforeUnloadFiring(&firingBeforeUnload);
@@ -9850,23 +9851,28 @@ nsDocShell::InternalLoad(nsIURI * aURI,
            sameExceptHashes && !newHash.IsEmpty());
 
         if (doShortCircuitedLoad) {
             // Save the position of the scrollers.
             nscoord cx = 0, cy = 0;
             GetCurScrollPos(ScrollOrientation_X, &cx);
             GetCurScrollPos(ScrollOrientation_Y, &cy);
 
-            // ScrollToAnchor doesn't necessarily cause us to scroll the window;
-            // the function decides whether a scroll is appropriate based on the
-            // arguments it receives.  But even if we don't end up scrolling,
-            // ScrollToAnchor performs other important tasks, such as informing
-            // the presShell that we have a new hash.  See bug 680257.
-            rv = ScrollToAnchor(curHash, newHash, aLoadType);
-            NS_ENSURE_SUCCESS(rv, rv);
+            {
+                AutoRestore<bool> scrollingToAnchor(mBlockNavigation);
+                mBlockNavigation = true;
+
+                // ScrollToAnchor doesn't necessarily cause us to scroll the window;
+                // the function decides whether a scroll is appropriate based on the
+                // arguments it receives.  But even if we don't end up scrolling,
+                // ScrollToAnchor performs other important tasks, such as informing
+                // the presShell that we have a new hash.  See bug 680257.
+                rv = ScrollToAnchor(curHash, newHash, aLoadType);
+                NS_ENSURE_SUCCESS(rv, rv);
+            }
 
             // Reset mLoadType to its original value once we exit this block,
             // because this short-circuited load might have started after a
             // normal, network load, and we don't want to clobber its load type.
             // See bug 737307.
             AutoRestore<uint32_t> loadTypeResetter(mLoadType);
 
             // If a non-short-circuit load (i.e., a network load) is pending,
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -878,16 +878,17 @@ protected:
     bool                       mIsOffScreenBrowser;
     bool                       mIsActive;
     bool                       mIsPrerendered;
     bool                       mIsAppTab;
     bool                       mUseGlobalHistory;
     bool                       mInPrivateBrowsing;
     bool                       mUseRemoteTabs;
     bool                       mDeviceSizeIsPageSize;
+    bool                       mBlockNavigation;
 
     // Because scriptability depends on the mAllowJavascript values of our
     // ancestors, we cache the effective scriptability and recompute it when
     // it might have changed;
     bool                       mCanExecuteScripts;
     void RecomputeCanExecuteScripts();
 
     // This boolean is set to true right before we fire pagehide and generally