Bug 1488321 - Move the `persist` attribute from nsISHTransaction to nsISHEntry. r=nika
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 05 Sep 2018 09:02:37 +1000
changeset 483050 afb85694d4ff30f62e5b1e52b1f7fd6ed9a46b14
parent 483049 e0a9359cbabccbbfe53a1d337a6b0bb2f1f9ee90
child 483051 107e7b61076279233e169517b64dba0b24db455d
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersnika
bugs1488321
milestone64.0a1
Bug 1488321 - Move the `persist` attribute from nsISHTransaction to nsISHEntry. r=nika This requires making nsISHEntry `builtinclass`.
docshell/shistory/nsISHEntry.idl
docshell/shistory/nsISHTransaction.idl
docshell/shistory/nsSHEntry.cpp
docshell/shistory/nsSHEntry.h
docshell/shistory/nsSHTransaction.cpp
docshell/shistory/nsSHTransaction.h
docshell/shistory/nsSHistory.cpp
toolkit/modules/sessionstore/SessionHistory.jsm
--- a/docshell/shistory/nsISHEntry.idl
+++ b/docshell/shistory/nsISHEntry.idl
@@ -26,17 +26,17 @@ interface nsISHistory;
 #include "nsRect.h"
 class nsDocShellEditorData;
 class nsSHEntryShared;
 %}
 [ref] native nsIntRect(nsIntRect);
 [ptr] native nsDocShellEditorDataPtr(nsDocShellEditorData);
 [ptr] native nsSHEntryShared(nsSHEntryShared);
 
-[scriptable, uuid(0dad26b8-a259-42c7-93f1-2fa7fc076e45)]
+[builtinclass, scriptable, uuid(0dad26b8-a259-42c7-93f1-2fa7fc076e45)]
 interface nsISHEntry : nsISupports
 {
     /**
      * A readonly property that returns the URI
      * of the current entry. The object returned is
      * of type nsIURI
      */
     readonly attribute nsIURI URI;
@@ -395,16 +395,23 @@ interface nsISHEntry : nsISupports
     nsISHEntry GetChildAt(in long aIndex);
 
     /**
      * Replaces a child which is for the same docshell as aNewChild
      * with aNewChild.
      * @throw if nothing was replaced.
      */
     void ReplaceChild(in nsISHEntry aNewChild);
+
+    /**
+     * When an entry is serving as a transaction within nsISHistory, this
+     * property specifies if it should persist. If not it will be replaced by
+     * new additions to the list.
+     */
+    [infallible] attribute boolean persist;
 };
 
 %{ C++
 // {BFD1A791-AD9F-11d3-BDC7-0050040A9B44}
 #define NS_SHENTRY_CID \
 {0xbfd1a791, 0xad9f, 0x11d3, {0xbd, 0xc7, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44}}
 
 #define NS_SHENTRY_CONTRACTID \
--- a/docshell/shistory/nsISHTransaction.idl
+++ b/docshell/shistory/nsISHTransaction.idl
@@ -9,16 +9,10 @@ interface nsISHEntry;
 
 [builtinclass, scriptable, uuid(2EDF705F-D252-4971-9F09-71DD0F760DC6)]
 interface nsISHTransaction : nsISupports
 {
   /**
    * The nsISHEntry for the current transaction. Never null.
    */
   [infallible] attribute nsISHEntry sHEntry;
-
-  /**
-   * Specifies if this transaction should persist. If not it will be replaced
-   * by new additions to the list.
-   */
-  [infallible] attribute boolean persist;
 };
 
--- a/docshell/shistory/nsSHEntry.cpp
+++ b/docshell/shistory/nsSHEntry.cpp
@@ -33,16 +33,17 @@ nsSHEntry::nsSHEntry()
   , mScrollPositionX(0)
   , mScrollPositionY(0)
   , mParent(nullptr)
   , mLoadReplace(false)
   , mURIWasModified(false)
   , mIsSrcdocEntry(false)
   , mScrollRestorationIsManual(false)
   , mLoadedInThisProcess(false)
+  , mPersist(true)
 {
 }
 
 nsSHEntry::nsSHEntry(const nsSHEntry& aOther)
   : mShared(aOther.mShared)
   , mURI(aOther.mURI)
   , mOriginalURI(aOther.mOriginalURI)
   , mResultPrincipalURI(aOther.mResultPrincipalURI)
@@ -996,8 +997,25 @@ nsSHEntry::SetSHistory(nsISHistory* aSHi
 
 NS_IMETHODIMP
 nsSHEntry::SetAsHistoryLoad()
 {
   // Set the LoadType by default to loadHistory during creation
   mLoadType = LOAD_HISTORY;
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsSHEntry::GetPersist(bool* aPersist)
+{
+  NS_ENSURE_ARG_POINTER(aPersist);
+
+  *aPersist = mPersist;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsSHEntry::SetPersist(bool aPersist)
+{
+  mPersist = aPersist;
+  return NS_OK;
+}
+
--- a/docshell/shistory/nsSHEntry.h
+++ b/docshell/shistory/nsSHEntry.h
@@ -56,11 +56,12 @@ private:
   nsCOMPtr<nsIStructuredCloneContainer> mStateData;
   nsString mSrcdocData;
   nsCOMPtr<nsIURI> mBaseURI;
   bool mLoadReplace;
   bool mURIWasModified;
   bool mIsSrcdocEntry;
   bool mScrollRestorationIsManual;
   bool mLoadedInThisProcess;
+  bool mPersist;
 };
 
 #endif /* nsSHEntry_h */
--- a/docshell/shistory/nsSHTransaction.cpp
+++ b/docshell/shistory/nsSHTransaction.cpp
@@ -2,19 +2,18 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSHTransaction.h"
 #include "nsISHEntry.h"
 
-nsSHTransaction::nsSHTransaction(nsISHEntry* aSHEntry, bool aPersist)
+nsSHTransaction::nsSHTransaction(nsISHEntry* aSHEntry)
   : mSHEntry(aSHEntry)
-  , mPersist(aPersist)
 {
   MOZ_ASSERT(aSHEntry);
 }
 
 nsSHTransaction::~nsSHTransaction()
 {
 }
 
@@ -38,23 +37,8 @@ nsSHTransaction::GetSHEntry(nsISHEntry**
 NS_IMETHODIMP
 nsSHTransaction::SetSHEntry(nsISHEntry* aSHEntry)
 {
   MOZ_ASSERT(aSHEntry);
   mSHEntry = aSHEntry;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsSHTransaction::SetPersist(bool aPersist)
-{
-  mPersist = aPersist;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSHTransaction::GetPersist(bool* aPersist)
-{
-  NS_ENSURE_ARG_POINTER(aPersist);
-
-  *aPersist = mPersist;
-  return NS_OK;
-}
--- a/docshell/shistory/nsSHTransaction.h
+++ b/docshell/shistory/nsSHTransaction.h
@@ -13,19 +13,18 @@
 class nsISHEntry;
 
 class nsSHTransaction : public nsISHTransaction
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSISHTRANSACTION
 
-  nsSHTransaction(nsISHEntry* aSHEntry, bool aPersist);
+  explicit nsSHTransaction(nsISHEntry* aSHEntry);
 
 protected:
   virtual ~nsSHTransaction();
 
 protected:
   nsCOMPtr<nsISHEntry> mSHEntry;  // never null
-  bool mPersist;
 };
 
 #endif /* nsSHTransaction_h */
--- a/docshell/shistory/nsSHistory.cpp
+++ b/docshell/shistory/nsSHistory.cpp
@@ -620,31 +620,35 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntr
 
   // If we have a root docshell, update the docshell id of the root shentry to
   // match the id of that docshell
   if (mRootDocShell) {
     nsID docshellID = mRootDocShell->HistoryID();
     aSHEntry->SetDocshellID(&docshellID);
   }
 
-  if (currentTxn && !currentTxn->GetPersist()) {
-    NOTIFY_LISTENERS(OnHistoryReplaceEntry, (mIndex));
-    currentTxn->SetSHEntry(aSHEntry);
-    currentTxn->SetPersist(aPersist);
-    return NS_OK;
+  if (currentTxn) {
+    nsCOMPtr<nsISHEntry> entry = currentTxn->GetSHEntry();
+    if (!entry->GetPersist()) {
+      NOTIFY_LISTENERS(OnHistoryReplaceEntry, (mIndex));
+      currentTxn->SetSHEntry(aSHEntry);
+      aSHEntry->SetPersist(aPersist);
+      return NS_OK;
+    }
   }
 
   nsCOMPtr<nsIURI> uri;
   aSHEntry->GetURI(getter_AddRefs(uri));
   NOTIFY_LISTENERS(OnHistoryNewEntry, (uri, mIndex));
 
   // Remove all transactions after the current one, add the new one, and set
   // the new one as the current one.
   MOZ_ASSERT(mIndex >= -1);
-  nsCOMPtr<nsISHTransaction> txn = new nsSHTransaction(aSHEntry, aPersist);
+  nsCOMPtr<nsISHTransaction> txn = new nsSHTransaction(aSHEntry);
+  aSHEntry->SetPersist(aPersist);
   mTransactions.TruncateLength(mIndex + 1);
   mTransactions.AppendElement(txn);
   mIndex++;
 
   NOTIFY_LISTENERS(OnLengthChanged, (Length()));
   NOTIFY_LISTENERS(OnIndexChanged, (mIndex));
 
   // Purge History list if it is too long
@@ -889,17 +893,17 @@ nsSHistory::ReplaceEntry(int32_t aIndex,
   NS_ENSURE_SUCCESS(rv, rv);
 
   aReplaceEntry->SetSHistory(this);
 
   NOTIFY_LISTENERS(OnHistoryReplaceEntry, (aIndex));
 
   // Set the replacement entry in the transaction
   currentTxn->SetSHEntry(aReplaceEntry);
-  currentTxn->SetPersist(true);
+  aReplaceEntry->SetPersist(true);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSHistory::NotifyOnHistoryReload(nsIURI* aReloadURI, uint32_t aReloadFlags,
                                   bool* aCanReload)
 {
--- a/toolkit/modules/sessionstore/SessionHistory.jsm
+++ b/toolkit/modules/sessionstore/SessionHistory.jsm
@@ -76,28 +76,25 @@ var SessionHistoryInternal = {
 
     let data = {entries: [], userContextId: loadContext.originAttributes.userContextId };
     // We want to keep track how many entries we *could* have collected and
     // how many we skipped, so we can sanitiy-check the current history index
     // and also determine whether we need to get any fallback data or not.
     let skippedCount = 0, entryCount = 0;
 
     if (history && history.count > 0) {
-      // Loop over the transactions so we can get the persist property for each
-      // one.
       let shistory = history.legacySHistory.QueryInterface(Ci.nsISHistory);
       let count = shistory.count;
       for ( ; entryCount < count; entryCount++) {
         let txn = shistory.GetTransactionAtIndex(entryCount);
         if (entryCount <= aFromIdx) {
           skippedCount++;
           continue;
         }
         let entry = this.serializeEntry(txn.sHEntry);
-        entry.persist = txn.persist;
         data.entries.push(entry);
       }
 
       // Ensure the index isn't out of bounds if an exception was thrown above.
       data.index = Math.min(history.index + 1, entryCount);
     }
 
     // If either the session history isn't available yet or doesn't have any
@@ -247,16 +244,18 @@ var SessionHistoryInternal = {
         }
       }
 
       if (children.length) {
         entry.children = children;
       }
     }
 
+    entry.persist = shEntry.persist;
+
     return entry;
   },
 
   /**
    * Get an object that is a serializable representation of a PresState.
    *
    * @param layoutHistoryState
    *        nsILayoutHistoryState instance