Bug 1534638 - Part 3: rename SetRootDocShell to ClearDocShell. r=qdot
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 04 Apr 2019 16:20:19 +0000
changeset 468981 0cfd7d9e0d985d0e779fb7c09a21c61ed632aadb
parent 468980 bd1df73257d565abbc787394c924bc3d1b76be2f
child 468982 6e87244c4b89ce588c5259cea63b04f35cd85bc4
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1534638
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1534638 - Part 3: rename SetRootDocShell to ClearDocShell. r=qdot Depends on D25763 Differential Revision: https://phabricator.services.mozilla.com/D25764
docshell/base/nsDocShell.cpp
docshell/shistory/ChildSHistory.cpp
docshell/shistory/nsISHistory.idl
docshell/shistory/nsSHistory.cpp
docshell/shistory/nsSHistory.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -424,17 +424,17 @@ nsDocShell::~nsDocShell() {
 
 #ifdef MOZ_GECKO_PROFILER
   profiler_unregister_pages(mHistoryID);
 #endif
 
   Destroy();
 
   if (mSessionHistory) {
-    mSessionHistory->LegacySHistory()->SetRootDocShell(nullptr);
+    mSessionHistory->LegacySHistory()->ClearRootDocShell();
   }
 
   if (--gDocShellCount == 0) {
     NS_IF_RELEASE(sURIFixup);
   }
 
   MOZ_LOG(gDocShellLeakLog, LogLevel::Debug, ("DOCSHELL %p destroyed\n", this));
 
--- a/docshell/shistory/ChildSHistory.cpp
+++ b/docshell/shistory/ChildSHistory.cpp
@@ -13,20 +13,17 @@
 #include "nsDocShell.h"
 #include "nsISHEntry.h"
 #include "nsXULAppAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 ChildSHistory::ChildSHistory(nsDocShell* aDocShell)
-    : mDocShell(aDocShell), mHistory(new nsSHistory()) {
-  MOZ_ASSERT(mDocShell);
-  mHistory->SetRootDocShell(mDocShell);
-}
+    : mDocShell(aDocShell), mHistory(new nsSHistory(aDocShell)) {}
 
 ChildSHistory::~ChildSHistory() {}
 
 int32_t ChildSHistory::Count() { return mHistory->GetCount(); }
 
 int32_t ChildSHistory::Index() {
   int32_t index;
   mHistory->GetIndex(&index);
--- a/docshell/shistory/nsISHistory.idl
+++ b/docshell/shistory/nsISHistory.idl
@@ -144,20 +144,21 @@ interface nsISHistory: nsISupports
    * @param aPersist          If true this specifies that the entry should
    *                          persist in the list. If false, this means that
    *                          when new entries are added this element will not
    *                          appear in the session history list.
    */
   void addEntry(in nsISHEntry aEntry, in boolean aPersist);
 
   /**
-   * Sets the toplevel docshell object to which this SHistory object belongs to.
+   * Clear the reference to the toplevel docshell object that this SHistory
+   * object belongs to.
    */
   [noscript, notxpcom]
-  void setRootDocShell(in nsIDocShell rootDocShell);
+  void ClearRootDocShell();
 
   /**
    * Update the index maintained by sessionHistory
    */
   void updateIndex();
 
   /**
    * Replace the nsISHEntry at a particular index
--- a/docshell/shistory/nsSHistory.cpp
+++ b/docshell/shistory/nsSHistory.cpp
@@ -180,20 +180,42 @@ void nsSHistory::EvictContentViewerForEn
   // When dropping bfcache, we have to remove associated dynamic entries as
   // well.
   int32_t index = GetIndexOfEntry(aEntry);
   if (index != -1) {
     RemoveDynEntries(index, aEntry);
   }
 }
 
-nsSHistory::nsSHistory()
-    : mIndex(-1), mRequestedIndex(-1), mRootDocShell(nullptr) {
+nsSHistory::nsSHistory(nsDocShell* aRootDocShell)
+    : mIndex(-1), mRequestedIndex(-1), mRootDocShell(aRootDocShell) {
   // Add this new SHistory object to the list
   gSHistoryList.insertBack(this);
+
+  // Init mHistoryTracker on setting mRootDocShell so we can bind its event
+  // target to the tabGroup.
+  nsCOMPtr<nsPIDOMWindowOuter> win = mRootDocShell->GetWindow();
+  if (win) {
+    // Seamonkey moves shistory between <xul:browser>s when restoring a tab.
+    // Let's try not to break our friend too badly...
+    if (mHistoryTracker) {
+      NS_WARNING(
+          "Change the root docshell of a shistory is unsafe and "
+          "potentially problematic.");
+      mHistoryTracker->AgeAllGenerations();
+    }
+
+    nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(win);
+
+    mHistoryTracker = mozilla::MakeUnique<HistoryTracker>(
+        this,
+        mozilla::Preferences::GetUint(CONTENT_VIEWER_TIMEOUT_SECONDS,
+                                      CONTENT_VIEWER_TIMEOUT_SECONDS_DEFAULT),
+        global->EventTargetFor(mozilla::TaskCategory::Other));
+  }
 }
 
 nsSHistory::~nsSHistory() {}
 
 NS_IMPL_ADDREF(nsSHistory)
 NS_IMPL_RELEASE(nsSHistory)
 
 NS_INTERFACE_MAP_BEGIN(nsSHistory)
@@ -570,16 +592,21 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntr
   // Purge History list if it is too long
   if (gHistoryMaxSize >= 0 && Length() > gHistoryMaxSize) {
     PurgeHistory(Length() - gHistoryMaxSize);
   }
 
   return NS_OK;
 }
 
+NS_IMETHODIMP_(void)
+nsSHistory::ClearRootDocShell() {
+  mRootDocShell = nullptr;
+}
+
 /* Get size of the history list */
 NS_IMETHODIMP
 nsSHistory::GetCount(int32_t* aResult) {
   MOZ_ASSERT(aResult, "null out param?");
   *aResult = Length();
   return NS_OK;
 }
 
@@ -1450,39 +1477,8 @@ nsresult nsSHistory::InitiateLoad(nsISHE
   loadState->SetTriggeringPrincipal(triggeringPrincipal);
   loadState->SetFirstParty(false);
   nsCOMPtr<nsIContentSecurityPolicy> csp = aFrameEntry->GetCsp();
   loadState->SetCsp(csp);
 
   // Time to initiate a document load
   return aFrameDS->LoadURI(loadState);
 }
-
-NS_IMETHODIMP_(void)
-nsSHistory::SetRootDocShell(nsIDocShell* aDocShell) {
-  mRootDocShell = aDocShell;
-
-  // Init mHistoryTracker on setting mRootDocShell so we can bind its event
-  // target to the tabGroup.
-  if (mRootDocShell) {
-    nsCOMPtr<nsPIDOMWindowOuter> win = mRootDocShell->GetWindow();
-    if (!win) {
-      return;
-    }
-
-    // Seamonkey moves shistory between <xul:browser>s when restoring a tab.
-    // Let's try not to break our friend too badly...
-    if (mHistoryTracker) {
-      NS_WARNING(
-          "Change the root docshell of a shistory is unsafe and "
-          "potentially problematic.");
-      mHistoryTracker->AgeAllGenerations();
-    }
-
-    nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(win);
-
-    mHistoryTracker = mozilla::MakeUnique<HistoryTracker>(
-        this,
-        mozilla::Preferences::GetUint(CONTENT_VIEWER_TIMEOUT_SECONDS,
-                                      CONTENT_VIEWER_TIMEOUT_SECONDS_DEFAULT),
-        global->EventTargetFor(mozilla::TaskCategory::Other));
-  }
-}
--- a/docshell/shistory/nsSHistory.h
+++ b/docshell/shistory/nsSHistory.h
@@ -53,17 +53,17 @@ class nsSHistory final : public mozilla:
   // Structure used in SetChildHistoryEntry
   struct SwapEntriesData {
     nsDocShell* ignoreShell;     // constant; the shell to ignore
     nsISHEntry* destTreeRoot;    // constant; the root of the dest tree
     nsISHEntry* destTreeParent;  // constant; the node under destTreeRoot
                                  // whose children will correspond to aEntry
   };
 
-  nsSHistory();
+  explicit nsSHistory(nsDocShell* aRootDocShell);
   NS_DECL_ISUPPORTS
   NS_DECL_NSISHISTORY
 
   nsresult Reload(uint32_t aReloadFlags);
 
   // One time initialization method called upon docshell module construction
   static nsresult Startup();
   static void Shutdown();