Bug 625712. Make useGlobalHistory work again on docshells. r=sdwilsh
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 28 Jan 2011 09:29:01 -0500
changeset 61540 5e7903dbbd2854d372da018f273665749c7dfbe0
parent 61539 915e3095944404064d7525c4cbfdac8e0445e778
child 61541 fe8180d48b5dcf9c15a73112017e36a28855fa31
push idunknown
push userunknown
push dateunknown
reviewerssdwilsh
bugs625712
milestone2.0b11pre
Bug 625712. Make useGlobalHistory work again on docshells. r=sdwilsh
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -707,16 +707,17 @@ nsDocShell::nsDocShell():
     mCreatingDocument(PR_FALSE),
     mUseErrorPages(PR_FALSE),
     mObserveErrorPages(PR_TRUE),
     mAllowAuth(PR_TRUE),
     mAllowKeywordFixup(PR_FALSE),
     mIsOffScreenBrowser(PR_FALSE),
     mIsActive(PR_TRUE),
     mIsAppTab(PR_FALSE),
+    mUseGlobalHistory(PR_FALSE),
     mFiredUnloadEvent(PR_FALSE),
     mEODForCurrentDocument(PR_FALSE),
     mURIResultedInDocument(PR_FALSE),
     mIsBeingDestroyed(PR_FALSE),
     mIsExecutingOnLoadHandler(PR_FALSE),
     mIsPrintingOrPP(PR_FALSE),
     mSavingOldViewer(PR_FALSE)
 #ifdef DEBUG
@@ -3085,17 +3086,17 @@ nsDocShell::AddChild(nsIDocShellTreeItem
         if (currentSH) {
             currentSH->HasDynamicallyAddedChild(&dynamic);
         }
     }
     nsCOMPtr<nsIDocShell> childDocShell = do_QueryInterface(aChild);
     childDocShell->SetChildOffset(dynamic ? -1 : mChildList.Count() - 1);
 
     /* Set the child's global history if the parent has one */
-    if (mGlobalHistory) {
+    if (mUseGlobalHistory) {
         nsCOMPtr<nsIDocShellHistory>
             dsHistoryChild(do_QueryInterface(aChild));
         if (dsHistoryChild)
             dsHistoryChild->SetUseGlobalHistory(PR_TRUE);
     }
 
 
     PRInt32 childType = ~mItemType;     // Set it to not us in case the get fails
@@ -3427,33 +3428,35 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry
     return rv;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetUseGlobalHistory(PRBool aUseGlobalHistory)
 {
     nsresult rv;
 
+    mUseGlobalHistory = aUseGlobalHistory;
+
     if (!aUseGlobalHistory) {
         mGlobalHistory = nsnull;
         return NS_OK;
     }
 
     if (mGlobalHistory) {
         return NS_OK;
     }
 
     mGlobalHistory = do_GetService(NS_GLOBALHISTORY2_CONTRACTID, &rv);
     return rv;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetUseGlobalHistory(PRBool *aUseGlobalHistory)
 {
-    *aUseGlobalHistory = (mGlobalHistory != nsnull);
+    *aUseGlobalHistory = mUseGlobalHistory;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::RemoveFromSessionHistory()
 {
     nsCOMPtr<nsISHistoryInternal> internalHistory;
     nsCOMPtr<nsISHistory> sessionHistory;
@@ -4944,17 +4947,17 @@ nsDocShell::SetTitle(const PRUnichar * a
     // tree owner.
     if (!parent) {
         nsCOMPtr<nsIBaseWindow>
             treeOwnerAsWin(do_QueryInterface(mTreeOwner));
         if (treeOwnerAsWin)
             treeOwnerAsWin->SetTitle(aTitle);
     }
 
-    if (mCurrentURI && mLoadType != LOAD_ERROR_PAGE) {
+    if (mCurrentURI && mLoadType != LOAD_ERROR_PAGE && mUseGlobalHistory) {
         nsCOMPtr<IHistory> history = services::GetHistoryService();
         if (history) {
             history->SetURITitle(mCurrentURI, mTitle);
         }
         else if (mGlobalHistory) {
             mGlobalHistory->SetPageTitle(mCurrentURI, nsString(mTitle));
         }
     }
@@ -8347,22 +8350,24 @@ nsDocShell::InternalLoad(nsIURI * aURI,
                 NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
                 nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
                 if (shEntry)
                     shEntry->SetTitle(mTitle);
             }
 
             /* Set the title for the Global History entry for this anchor url.
              */
-            nsCOMPtr<IHistory> history = services::GetHistoryService();
-            if (history) {
-                history->SetURITitle(aURI, mTitle);
-            }
-            else if (mGlobalHistory) {
-                mGlobalHistory->SetPageTitle(aURI, mTitle);
+            if (mUseGlobalHistory) {
+                nsCOMPtr<IHistory> history = services::GetHistoryService();
+                if (history) {
+                    history->SetURITitle(aURI, mTitle);
+                }
+                else if (mGlobalHistory) {
+                    mGlobalHistory->SetPageTitle(aURI, mTitle);
+                }
             }
 
             if (sameDocIdent) {
                 // Set the doc's URI according to the new history entry's URI
                 nsCOMPtr<nsIURI> newURI;
                 mOSHE->GetURI(getter_AddRefs(newURI));
                 NS_ENSURE_TRUE(newURI, NS_ERROR_FAILURE);
                 nsCOMPtr<nsIDocument> doc =
@@ -10521,18 +10526,19 @@ nsDocShell::SaveLastVisit(nsIChannel* aC
 void
 nsDocShell::AddURIVisit(nsIURI* aURI,
                         nsIURI* aReferrerURI,
                         nsIURI* aPreviousURI,
                         PRUint32 aChannelRedirectFlags)
 {
     NS_ASSERTION(aURI, "Visited URI is null!");
 
-    // Only content-type docshells save URI visits.
-    if (mItemType != typeContent) {
+    // Only content-type docshells save URI visits.  Also don't do
+    // anything here if we're not supposed to use global history.
+    if (mItemType != typeContent || !mUseGlobalHistory) {
         return;
     }
 
     nsCOMPtr<IHistory> history = services::GetHistoryService();
 
     if (history) {
         PRUint32 visitURIFlags = 0;
 
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -787,16 +787,17 @@ protected:
     PRPackedBool               mCreatingDocument; // (should be) debugging only
     PRPackedBool               mUseErrorPages;
     PRPackedBool               mObserveErrorPages;
     PRPackedBool               mAllowAuth;
     PRPackedBool               mAllowKeywordFixup;
     PRPackedBool               mIsOffScreenBrowser;
     PRPackedBool               mIsActive;
     PRPackedBool               mIsAppTab;
+    PRPackedBool               mUseGlobalHistory;
 
     // This boolean is set to true right before we fire pagehide and generally
     // unset when we embed a new content viewer.  While it's true no navigation
     // is allowed in this docshell.
     PRPackedBool               mFiredUnloadEvent;
 
     // this flag is for bug #21358. a docshell may load many urls
     // which don't result in new documents being created (i.e. a new