Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them).
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2018 18:45:40 +0000 (18:45 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2018 18:45:40 +0000 (18:45 +0000)
<rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750

Reviewed by Ryosuke Niwa.

Source/WebCore:

No new tests (Refactor, no behavior change).

In WebCore, we:
- Add a process-unique "BackForwardItemIdentifier"
- Make all HistoryItems have such an identifier as a member

* WebCore.xcodeproj/project.pbxproj:

* history/BackForwardItemIdentifier.h: Added.
(WebCore::BackForwardItemIdentifier::logString const):
(WebCore::operator==):
(WebCore::BackForwardItemIdentifier::encode const):
(WebCore::BackForwardItemIdentifier::decode):
(WebCore::BackForwardItemIdentifier::hash const):
(WTF::BackForwardItemIdentifierHash::hash):
(WTF::BackForwardItemIdentifierHash::equal):
(WTF::HashTraits<WebCore::BackForwardItemIdentifier>::emptyValue):
(WTF::HashTraits<WebCore::BackForwardItemIdentifier>::constructDeletedValue):
(WTF::HashTraits<WebCore::BackForwardItemIdentifier>::isDeletedValue):

* history/HistoryItem.cpp:
(WebCore::HistoryItem::generateSequenceNumber):
(WebCore::HistoryItem::HistoryItem):
(WebCore::generateSequenceNumber): Deleted.

* history/HistoryItem.h:
(WebCore::HistoryItem::create):
(WebCore::HistoryItem::identifier const):

Source/WebKit:

With process swapping, the assumption that "back/forward items belong to a process" is invalid.

All HistoryItem/WebBackForwardListItems now need to be uniquely identified across all processes,
no matter which process they originated from, so there will never be a collision in the UIProcess.

This allows us to:
- Have the UIProcess to keep a single process-wide map of all WebBackForwardListItems
- Get rid of the per-WebProcess WebBackForwardListItem map
- Simplify a lot of WebBackForwardList(Proxy) code that no longer needs to keep that per-process
  map in sync
- Get rid of a lot of other ancillary code

* Shared/SessionState.cpp:
(WebKit::BackForwardListItemState::decode):
* Shared/SessionState.h:

* Shared/WebBackForwardListItem.cpp:
(WebKit::WebBackForwardListItem::WebBackForwardListItem):
(WebKit::WebBackForwardListItem::~WebBackForwardListItem):
(WebKit::WebBackForwardListItem::itemForID):
(WebKit::WebBackForwardListItem::highestUsedItemID): Deleted.
* Shared/WebBackForwardListItem.h:
(WebKit::WebBackForwardListItem::itemID const):

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::itemForID):
(WebKit::WebBackForwardList::pageClosed):
(WebKit::WebBackForwardList::addItem):
(WebKit::WebBackForwardList::restoreFromState):
(WebKit::generateWebBackForwardItemID): Deleted.
* UIProcess/WebBackForwardList.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::maybeCreateSuspendedPage):
(WebKit::WebPageProxy::initializeWebPage):
(WebKit::WebPageProxy::willGoToBackForwardListItem):
(WebKit::WebPageProxy::restoreFromSessionState):
(WebKit::WebPageProxy::backForwardAddItem):
(WebKit::WebPageProxy::backForwardGoToItem):
(WebKit::WebPageProxy::backForwardItemAtIndex):
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::backForwardRemovedItem):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/WebProcessPool.cpp: Explicitly set the UIProcess Process::Identifier so it starts
  at "1" and then the first child process starts at "2", etc etc.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::removeWebPage):
(WebKit::WebProcessProxy::checkURLReceivedFromWebProcess):
(WebKit::WebProcessProxy::updateBackForwardItem):
(WebKit::WebProcessProxy::webBackForwardItem const): Deleted.
(WebKit::WebProcessProxy::registerNewWebBackForwardListItem): Deleted.
(WebKit::WebProcessProxy::removeBackForwardItem): Deleted.
(WebKit::WebProcessProxy::addOrUpdateBackForwardItem): Deleted.
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:

* WebProcess/WebCoreSupport/SessionStateConversion.cpp:
(WebKit::toBackForwardListItemState):
(WebKit::applyFrameState):
(WebKit::toHistoryItem):
(WebKit::toPageState): Deleted.
* WebProcess/WebCoreSupport/SessionStateConversion.h:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::shouldGoToHistoryItem const):

* WebProcess/WebPage/WebBackForwardListProxy.cpp:
(WebKit::WebBackForwardListProxy::addItemFromUIProcess):
(WebKit::WK2NotifyHistoryItemChanged):
(WebKit::WebBackForwardListProxy::itemForID):
(WebKit::WebBackForwardListProxy::removeItem):
(WebKit::WebBackForwardListProxy::addItem): Previously this was a two-step process of adding an item
  to the process and then associating it with the page. Now it's just directly adding it to the page,
  so we don't need to call updateBackForwardItem first.
(WebKit::WebBackForwardListProxy::goToItem):
(WebKit::WebBackForwardListProxy::itemAtIndex):
(WebKit::WebBackForwardListProxy::close):
(WebKit::historyItemToIDMap): Deleted.
(WebKit::generateHistoryItemID): Deleted.
(WebKit::WebBackForwardListProxy::setHighestItemIDFromUIProcess): Deleted.
(WebKit::updateBackForwardItem): Deleted.
(WebKit::WebBackForwardListProxy::idForItem): Deleted.
* WebProcess/WebPage/WebBackForwardListProxy.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_credentialsMessenger):
(WebKit::WebPage::goToBackForwardItem):
(WebKit::WebPage::restoreSessionInternal):
(WebKit::WebPage::didRemoveBackForwardItem):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WTF:

* wtf/DebugUtilities.h:
(WTF::debugString):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230812 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/DebugUtilities.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/history/BackForwardItemIdentifier.h [new file with mode: 0644]
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/history/HistoryItem.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/SessionState.cpp
Source/WebKit/Shared/SessionState.h
Source/WebKit/Shared/WebBackForwardListItem.cpp
Source/WebKit/Shared/WebBackForwardListItem.h
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/glib/WebKitWebViewSessionState.cpp
Source/WebKit/UIProcess/WebBackForwardList.cpp
Source/WebKit/UIProcess/WebBackForwardList.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.cpp
Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.h
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp
Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in

index b93627b..d748615 100644 (file)
@@ -1,3 +1,13 @@
+2018-04-19  Brady Eidson  <beidson@apple.com>
+
+        Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them).
+        <rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750
+
+        Reviewed by Ryosuke Niwa.
+
+        * wtf/DebugUtilities.h:
+        (WTF::debugString):
+
 2018-04-19  Per Arne Vollan  <pvollan@apple.com>
 
         Unreviewed, rolling out r230677.
index a441b5c..db3d566 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/Assertions.h>
+#include <wtf/MainThread.h>
 #include <wtf/ProcessID.h>
 #include <wtf/text/StringConcatenate.h>
 
@@ -42,6 +43,12 @@ do { \
 
 namespace WTF {
 
+template<typename StringType>
+const char* debugString(StringType string)
+{
+    return debugString(string, "");
+}
+
 template<typename... StringTypes>
 const char* debugString(StringTypes... strings)
 {
index 19222a3..4fe6332 100644 (file)
@@ -1,3 +1,39 @@
+2018-04-19  Brady Eidson  <beidson@apple.com>
+
+        Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them).
+        <rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750
+
+        Reviewed by Ryosuke Niwa.
+
+        No new tests (Refactor, no behavior change).
+
+        In WebCore, we:
+        - Add a process-unique "BackForwardItemIdentifier"
+        - Make all HistoryItems have such an identifier as a member
+
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * history/BackForwardItemIdentifier.h: Added.
+        (WebCore::BackForwardItemIdentifier::logString const):
+        (WebCore::operator==):
+        (WebCore::BackForwardItemIdentifier::encode const):
+        (WebCore::BackForwardItemIdentifier::decode):
+        (WebCore::BackForwardItemIdentifier::hash const):
+        (WTF::BackForwardItemIdentifierHash::hash):
+        (WTF::BackForwardItemIdentifierHash::equal):
+        (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::emptyValue):
+        (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::constructDeletedValue):
+        (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::isDeletedValue):
+
+        * history/HistoryItem.cpp:
+        (WebCore::HistoryItem::generateSequenceNumber):
+        (WebCore::HistoryItem::HistoryItem):
+        (WebCore::generateSequenceNumber): Deleted.
+
+        * history/HistoryItem.h:
+        (WebCore::HistoryItem::create):
+        (WebCore::HistoryItem::identifier const):
+
 2018-04-19  Nan Wang  <n_wang@apple.com>
 
         AX: AOM: respect the accessibility setting for dispatching the accessible events
index 6662e67..f85e14a 100644 (file)
                519DBC721DC10F5200329BF5 /* IDBGetAllResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 519DBC711DC10D3300329BF5 /* IDBGetAllResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A052331058774F00CC9E95 /* CredentialStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A052311058774F00CC9E95 /* CredentialStorage.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A052561058874000CC9E95 /* ProtectionSpaceHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A052551058874000CC9E95 /* ProtectionSpaceHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51A1B87D2087C4C000979A75 /* BackForwardItemIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A1B87B2087C4B800979A75 /* BackForwardItemIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A4BB0A1954D61600FA5C2E /* Gamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4BB071954D61600FA5C2E /* Gamepad.cpp */; };
                51A4BB101954D62700FA5C2E /* NavigatorGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4BB0D1954D62700FA5C2E /* NavigatorGamepad.cpp */; };
                51A748E32005D0E80075BA68 /* MessageWithMessagePorts.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A748E02005D0E00075BA68 /* MessageWithMessagePorts.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51A052311058774F00CC9E95 /* CredentialStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CredentialStorage.h; sourceTree = "<group>"; };
                51A052321058774F00CC9E95 /* CredentialStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CredentialStorage.cpp; sourceTree = "<group>"; };
                51A052551058874000CC9E95 /* ProtectionSpaceHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtectionSpaceHash.h; sourceTree = "<group>"; };
+               51A1B87B2087C4B800979A75 /* BackForwardItemIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackForwardItemIdentifier.h; sourceTree = "<group>"; };
                51A4BB071954D61600FA5C2E /* Gamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Gamepad.cpp; sourceTree = "<group>"; };
                51A4BB081954D61600FA5C2E /* Gamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Gamepad.h; sourceTree = "<group>"; };
                51A4BB091954D61600FA5C2E /* Gamepad.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Gamepad.idl; sourceTree = "<group>"; };
                                51741D0B0B07259A00ED442C /* BackForwardClient.h */,
                                BCA8C81D11E3D36900812FB7 /* BackForwardController.cpp */,
                                BCA8C81C11E3D36900812FB7 /* BackForwardController.h */,
+                               51A1B87B2087C4B800979A75 /* BackForwardItemIdentifier.h */,
                                51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */,
                                51C0AA380F2AA10A001648C2 /* CachedFrame.h */,
                                51CBFC980D10E483002DBF51 /* CachedFramePlatformData.h */,
                                91C9F2F91AE3BEB00095B61C /* AXTextStateChangeIntent.h in Headers */,
                                51741D0F0B07259A00ED442C /* BackForwardClient.h in Headers */,
                                BCA8C81E11E3D36900812FB7 /* BackForwardController.h in Headers */,
+                               51A1B87D2087C4C000979A75 /* BackForwardItemIdentifier.h in Headers */,
                                BC124EE80C2641CD009E2349 /* BarProp.h in Headers */,
                                460BB6161D0A1BF000221812 /* Base64Utilities.h in Headers */,
                                379E61CA126CA5C400B63E8D /* BaseButtonInputType.h in Headers */,
diff --git a/Source/WebCore/history/BackForwardItemIdentifier.h b/Source/WebCore/history/BackForwardItemIdentifier.h
new file mode 100644 (file)
index 0000000..6ded64a
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Process.h"
+#include <wtf/DebugUtilities.h>
+#include <wtf/Hasher.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct BackForwardItemIdentifier {
+    ProcessIdentifier processIdentifier;
+    enum ItemIdentifierType { };
+    ObjectIdentifier<ItemIdentifierType> itemIdentifier;
+
+    unsigned hash() const;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<BackForwardItemIdentifier> decode(Decoder&);
+
+#if !LOG_DISABLED
+    const char* logString() const;
+#endif
+};
+
+#if !LOG_DISABLED
+inline const char* BackForwardItemIdentifier::logString() const
+{
+    return debugString(String::number(processIdentifier.toUInt64()), "-", String::number(itemIdentifier.toUInt64()));
+}
+#endif
+
+inline bool operator==(const BackForwardItemIdentifier& a, const BackForwardItemIdentifier& b)
+{
+    return a.processIdentifier == b.processIdentifier &&  a.itemIdentifier == b.itemIdentifier;
+}
+
+template<class Encoder>
+void BackForwardItemIdentifier::encode(Encoder& encoder) const
+{
+    encoder << processIdentifier << itemIdentifier;
+}
+
+template<class Decoder>
+std::optional<BackForwardItemIdentifier> BackForwardItemIdentifier::decode(Decoder& decoder)
+{
+    std::optional<ProcessIdentifier> processIdentifier;
+    decoder >> processIdentifier;
+    if (!processIdentifier)
+        return std::nullopt;
+
+    std::optional<ObjectIdentifier<ItemIdentifierType>> itemIdentifier;
+    decoder >> itemIdentifier;
+    if (!itemIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*processIdentifier), WTFMove(*itemIdentifier) } };
+}
+
+inline unsigned BackForwardItemIdentifier::hash() const
+{
+    return computeHash(processIdentifier.toUInt64(), itemIdentifier.toUInt64());
+}
+
+} // namespace WebCore
+
+namespace WTF {
+
+struct BackForwardItemIdentifierHash {
+    static unsigned hash(const WebCore::BackForwardItemIdentifier& key) { return key.hash(); }
+    static bool equal(const WebCore::BackForwardItemIdentifier& a, const WebCore::BackForwardItemIdentifier& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
+template<> struct HashTraits<WebCore::BackForwardItemIdentifier> : GenericHashTraits<WebCore::BackForwardItemIdentifier> {
+    static WebCore::BackForwardItemIdentifier emptyValue() { return { }; }
+
+    static void constructDeletedValue(WebCore::BackForwardItemIdentifier& slot) { slot.processIdentifier = ObjectIdentifier<WebCore::ProcessIdentifierType>(HashTableDeletedValue); }
+
+    static bool isDeletedValue(const WebCore::BackForwardItemIdentifier& slot) { return slot.processIdentifier.toUInt64() == std::numeric_limits<uint64_t>::max(); }
+};
+
+template<> struct DefaultHash<WebCore::BackForwardItemIdentifier> {
+    typedef BackForwardItemIdentifierHash Hash;
+};
+
+} // namespace WTF
index 9d86898..a5ba95e 100644 (file)
@@ -40,7 +40,7 @@
 
 namespace WebCore {
 
-static long long generateSequenceNumber()
+int64_t HistoryItem::generateSequenceNumber()
 {
     // Initialize to the current time to reduce the likelihood of generating
     // identifiers that overlap with those from past/future browser sessions.
@@ -55,31 +55,27 @@ static void defaultNotifyHistoryItemChanged(HistoryItem*)
 WEBCORE_EXPORT void (*notifyHistoryItemChanged)(HistoryItem*) = defaultNotifyHistoryItemChanged;
 
 HistoryItem::HistoryItem()
-    : m_itemSequenceNumber(generateSequenceNumber())
-    , m_documentSequenceNumber(generateSequenceNumber())
-    , m_pruningReason(PruningReason::None)
+    : HistoryItem({ }, { })
 {
 }
 
 HistoryItem::HistoryItem(const String& urlString, const String& title)
-    : m_urlString(urlString)
-    , m_originalURLString(urlString)
-    , m_title(title)
-    , m_itemSequenceNumber(generateSequenceNumber())
-    , m_documentSequenceNumber(generateSequenceNumber())
-    , m_pruningReason(PruningReason::None)
+    : HistoryItem(urlString, title, { })
 {
 }
 
 HistoryItem::HistoryItem(const String& urlString, const String& title, const String& alternateTitle)
+    : HistoryItem(urlString, title, alternateTitle, { Process::identifier(), generateObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>() })
+{
+}
+
+HistoryItem::HistoryItem(const String& urlString, const String& title, const String& alternateTitle, BackForwardItemIdentifier BackForwardItemIdentifier)
     : m_urlString(urlString)
     , m_originalURLString(urlString)
     , m_title(title)
     , m_displayTitle(alternateTitle)
-    , m_pageScaleFactor(0)
-    , m_itemSequenceNumber(generateSequenceNumber())
-    , m_documentSequenceNumber(generateSequenceNumber())
     , m_pruningReason(PruningReason::None)
+    , m_identifier(BackForwardItemIdentifier)
 {
 }
 
index 4d1e2cd..ee466c7 100644 (file)
@@ -26,6 +26,7 @@
 
 #pragma once
 
+#include "BackForwardItemIdentifier.h"
 #include "FloatRect.h"
 #include "FrameLoaderTypes.h"
 #include "IntPoint.h"
@@ -62,20 +63,32 @@ class HistoryItem : public RefCounted<HistoryItem> {
     friend class PageCache;
 
 public: 
-    static Ref<HistoryItem> create() { return adoptRef(*new HistoryItem); }
+    static Ref<HistoryItem> create()
+    {
+        return adoptRef(*new HistoryItem);
+    }
+
     static Ref<HistoryItem> create(const String& urlString, const String& title)
     {
         return adoptRef(*new HistoryItem(urlString, title));
     }
+
     static Ref<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle)
     {
         return adoptRef(*new HistoryItem(urlString, title, alternateTitle));
     }
+
+    static Ref<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, BackForwardItemIdentifier identifier)
+    {
+        return adoptRef(*new HistoryItem(urlString, title, alternateTitle, identifier));
+    }
     
     WEBCORE_EXPORT ~HistoryItem();
 
     WEBCORE_EXPORT Ref<HistoryItem> copy() const;
 
+    const BackForwardItemIdentifier& identifier() const { return m_identifier; }
+
     // Resets the HistoryItem to its initial state, as returned by create().
     void reset();
     
@@ -206,9 +219,12 @@ private:
     WEBCORE_EXPORT HistoryItem();
     WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title);
     WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title, const String& alternateTitle);
+    WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title, const String& alternateTitle, BackForwardItemIdentifier);
 
     HistoryItem(const HistoryItem&);
 
+    static int64_t generateSequenceNumber();
+
     bool hasSameDocumentTree(HistoryItem& otherItem) const;
 
     String m_urlString;
@@ -235,12 +251,12 @@ private:
     // clones of one another.  Traversing history from one such HistoryItem to
     // another is a no-op.  HistoryItem clones are created for parent and
     // sibling frames when only a subframe navigates.
-    int64_t m_itemSequenceNumber;
+    int64_t m_itemSequenceNumber { generateSequenceNumber() };
 
     // If two HistoryItems have the same document sequence number, then they
     // refer to the same instance of a document.  Traversing history from one
     // such HistoryItem to another preserves the document.
-    int64_t m_documentSequenceNumber;
+    int64_t m_documentSequenceNumber { generateSequenceNumber() };
 
     // Support for HTML5 History
     RefPtr<SerializedScriptValue> m_stateObject;
@@ -268,6 +284,8 @@ private:
     RetainPtr<id> m_viewState;
     std::unique_ptr<HashMap<String, RetainPtr<id>>> m_transientProperties;
 #endif
+
+    BackForwardItemIdentifier m_identifier;
 };
 
 } // namespace WebCore
index 8be6fcd..230acdd 100644 (file)
@@ -1,3 +1,110 @@
+2018-04-19  Brady Eidson  <beidson@apple.com>
+
+        Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them).
+        <rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750
+
+        Reviewed by Ryosuke Niwa.
+
+        With process swapping, the assumption that "back/forward items belong to a process" is invalid.
+
+        All HistoryItem/WebBackForwardListItems now need to be uniquely identified across all processes,
+        no matter which process they originated from, so there will never be a collision in the UIProcess.
+
+        This allows us to:
+        - Have the UIProcess to keep a single process-wide map of all WebBackForwardListItems
+        - Get rid of the per-WebProcess WebBackForwardListItem map
+        - Simplify a lot of WebBackForwardList(Proxy) code that no longer needs to keep that per-process
+          map in sync
+        - Get rid of a lot of other ancillary code
+
+        * Shared/SessionState.cpp:
+        (WebKit::BackForwardListItemState::decode):
+        * Shared/SessionState.h:
+
+        * Shared/WebBackForwardListItem.cpp:
+        (WebKit::WebBackForwardListItem::WebBackForwardListItem):
+        (WebKit::WebBackForwardListItem::~WebBackForwardListItem):
+        (WebKit::WebBackForwardListItem::itemForID):
+        (WebKit::WebBackForwardListItem::highestUsedItemID): Deleted.
+        * Shared/WebBackForwardListItem.h:
+        (WebKit::WebBackForwardListItem::itemID const):
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::itemForID):
+        (WebKit::WebBackForwardList::pageClosed):
+        (WebKit::WebBackForwardList::addItem):
+        (WebKit::WebBackForwardList::restoreFromState):
+        (WebKit::generateWebBackForwardItemID): Deleted.
+        * UIProcess/WebBackForwardList.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::maybeCreateSuspendedPage):
+        (WebKit::WebPageProxy::initializeWebPage):
+        (WebKit::WebPageProxy::willGoToBackForwardListItem):
+        (WebKit::WebPageProxy::restoreFromSessionState):
+        (WebKit::WebPageProxy::backForwardAddItem):
+        (WebKit::WebPageProxy::backForwardGoToItem):
+        (WebKit::WebPageProxy::backForwardItemAtIndex):
+        (WebKit::WebPageProxy::creationParameters):
+        (WebKit::WebPageProxy::backForwardRemovedItem):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/WebProcessPool.cpp: Explicitly set the UIProcess Process::Identifier so it starts
+          at "1" and then the first child process starts at "2", etc etc.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::removeWebPage):
+        (WebKit::WebProcessProxy::checkURLReceivedFromWebProcess):
+        (WebKit::WebProcessProxy::updateBackForwardItem):
+        (WebKit::WebProcessProxy::webBackForwardItem const): Deleted.
+        (WebKit::WebProcessProxy::registerNewWebBackForwardListItem): Deleted.
+        (WebKit::WebProcessProxy::removeBackForwardItem): Deleted.
+        (WebKit::WebProcessProxy::addOrUpdateBackForwardItem): Deleted.
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+
+        * WebProcess/WebCoreSupport/SessionStateConversion.cpp:
+        (WebKit::toBackForwardListItemState):
+        (WebKit::applyFrameState):
+        (WebKit::toHistoryItem):
+        (WebKit::toPageState): Deleted.
+        * WebProcess/WebCoreSupport/SessionStateConversion.h:
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::shouldGoToHistoryItem const):
+
+        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
+        (WebKit::WebBackForwardListProxy::addItemFromUIProcess):
+        (WebKit::WK2NotifyHistoryItemChanged):
+        (WebKit::WebBackForwardListProxy::itemForID):
+        (WebKit::WebBackForwardListProxy::removeItem):
+        (WebKit::WebBackForwardListProxy::addItem): Previously this was a two-step process of adding an item
+          to the process and then associating it with the page. Now it's just directly adding it to the page,
+          so we don't need to call updateBackForwardItem first.
+        (WebKit::WebBackForwardListProxy::goToItem):
+        (WebKit::WebBackForwardListProxy::itemAtIndex):
+        (WebKit::WebBackForwardListProxy::close):
+        (WebKit::historyItemToIDMap): Deleted.
+        (WebKit::generateHistoryItemID): Deleted.
+        (WebKit::WebBackForwardListProxy::setHighestItemIDFromUIProcess): Deleted.
+        (WebKit::updateBackForwardItem): Deleted.
+        (WebKit::WebBackForwardListProxy::idForItem): Deleted.
+        * WebProcess/WebPage/WebBackForwardListProxy.h:
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_credentialsMessenger):
+        (WebKit::WebPage::goToBackForwardItem):
+        (WebKit::WebPage::restoreSessionInternal):
+        (WebKit::WebPage::didRemoveBackForwardItem):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2018-04-19  Youenn Fablet  <youenn@apple.com>
 
         NetworkProcess should use CSP/content blockers for sync XHR
index 911d2e7..d77bbe7 100644 (file)
@@ -27,6 +27,7 @@
 #include "SessionState.h"
 
 #include "WebCoreArgumentCoders.h"
+#include <WebCore/BackForwardItemIdentifier.h>
 
 using namespace WebCore;
 
@@ -232,8 +233,10 @@ std::optional<BackForwardListItemState> BackForwardListItemState::decode(IPC::De
 {
     BackForwardListItemState result;
 
-    if (!decoder.decode(result.identifier))
+    auto identifier = BackForwardItemIdentifier::decode(decoder);
+    if (!identifier)
         return std::nullopt;
+    result.identifier = *identifier;
 
     if (!decoder.decode(result.pageState))
         return std::nullopt;
index 1482144..db3dfda 100644 (file)
@@ -29,6 +29,7 @@
 #include "ViewSnapshotStore.h"
 #endif
 
+#include <WebCore/BackForwardItemIdentifier.h>
 #include <WebCore/FloatRect.h>
 #include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/IntRect.h>
@@ -127,7 +128,7 @@ struct BackForwardListItemState {
     void encode(IPC::Encoder&) const;
     static std::optional<BackForwardListItemState> decode(IPC::Decoder&);
 
-    uint64_t identifier;
+    WebCore::BackForwardItemIdentifier identifier;
 
     PageState pageState;
 #if PLATFORM(COCOA)
index 1acd5dd..a738c7d 100644 (file)
@@ -28,9 +28,9 @@
 
 #include <WebCore/URL.h>
 
-namespace WebKit {
+using namespace WebCore;
 
-static uint64_t highestItemID = 0;
+namespace WebKit {
 
 Ref<WebBackForwardListItem> WebBackForwardListItem::create(BackForwardListItemState&& backForwardListItemState, uint64_t pageID)
 {
@@ -41,12 +41,25 @@ WebBackForwardListItem::WebBackForwardListItem(BackForwardListItemState&& backFo
     : m_itemState(WTFMove(backForwardListItemState))
     , m_pageID(pageID)
 {
-    if (m_itemState.identifier > highestItemID)
-        highestItemID = m_itemState.identifier;
+    auto result = allItems().add(m_itemState.identifier, this);
+    ASSERT_UNUSED(result, result.isNewEntry);
 }
 
 WebBackForwardListItem::~WebBackForwardListItem()
 {
+    ASSERT(allItems().get(m_itemState.identifier) == this);
+    allItems().remove(m_itemState.identifier);
+}
+
+HashMap<BackForwardItemIdentifier, WebBackForwardListItem*>& WebBackForwardListItem::allItems()
+{
+    static NeverDestroyed<HashMap<BackForwardItemIdentifier, WebBackForwardListItem*>> items;
+    return items;
+}
+
+WebBackForwardListItem* WebBackForwardListItem::itemForID(const BackForwardItemIdentifier& identifier)
+{
+    return allItems().get(identifier);
 }
 
 static const FrameState* childItemWithDocumentSequenceNumber(const FrameState& frameState, int64_t number)
@@ -98,11 +111,6 @@ bool WebBackForwardListItem::itemIsInSameDocument(const WebBackForwardListItem&
     return documentTreesAreEqual(mainFrameState, otherMainFrameState);
 }
 
-uint64_t WebBackForwardListItem::highestUsedItemID()
-{
-    return highestItemID;
-}
-
 void WebBackForwardListItem::setSuspendedPage(SuspendedPageProxy& page)
 {
     m_suspendedPage = &page;
index 4ea2ca7..3c1cc29 100644 (file)
@@ -48,7 +48,10 @@ public:
     static Ref<WebBackForwardListItem> create(BackForwardListItemState&&, uint64_t pageID);
     virtual ~WebBackForwardListItem();
 
-    uint64_t itemID() const { return m_itemState.identifier; }
+    static WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
+    static HashMap<WebCore::BackForwardItemIdentifier, WebBackForwardListItem*>& allItems();
+
+    const WebCore::BackForwardItemIdentifier& itemID() const { return m_itemState.identifier; }
     const BackForwardListItemState& itemState() { return m_itemState; }
     uint64_t pageID() const { return m_pageID; }
 
@@ -67,8 +70,6 @@ public:
 #endif
     void setSuspendedPage(SuspendedPageProxy&);
 
-    static uint64_t highestUsedItemID();
-
 private:
     explicit WebBackForwardListItem(BackForwardListItemState&&, uint64_t pageID);
 
index 263034a..3cfe3b2 100644 (file)
@@ -53,7 +53,6 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << userAgent;
     encoder << itemStates;
     encoder << sessionID;
-    encoder << highestUsedBackForwardItemID;
     encoder << userContentControllerID.toUInt64();
     encoder << visitedLinkTableID;
     encoder << websiteDataStoreID;
@@ -177,8 +176,6 @@ std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::
 
     if (!decoder.decode(parameters.sessionID))
         return std::nullopt;
-    if (!decoder.decode(parameters.highestUsedBackForwardItemID))
-        return std::nullopt;
 
     std::optional<uint64_t> userContentControllerIdentifier;
     decoder >> userContentControllerIdentifier;
index baebaf4..573e179 100644 (file)
@@ -96,7 +96,6 @@ struct WebPageCreationParameters {
 
     Vector<BackForwardListItemState> itemStates;
     PAL::SessionID sessionID;
-    uint64_t highestUsedBackForwardItemID;
 
     UserContentControllerIdentifier userContentControllerID;
     uint64_t visitedLinkTableID;
index 9cb5d93..b7cbf8b 100644 (file)
@@ -21,6 +21,7 @@
 #include "WebKitWebViewSessionState.h"
 
 #include "WebKitWebViewSessionStatePrivate.h"
+#include <WebCore/BackForwardItemIdentifier.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
 
@@ -344,7 +345,7 @@ static inline void decodeBackForwardListItemState(GVariantIter* backForwardListS
     unsigned shouldOpenExternalURLsPolicy;
     while (g_variant_iter_loop(backForwardListStateIter, BACK_FORWARD_LIST_ITEM_FORMAT_STRING_V1, &identifier, &title, &frameStateVariant, &shouldOpenExternalURLsPolicy)) {
         BackForwardListItemState state;
-        state.identifier = identifier;
+        state.identifier = { WebCore::Process::identifier(), generateObjectIdentifier<WebCore::BackForwardItemIdentifier::ItemIdentifierType>() };
         state.pageState.title = String::fromUTF8(title);
         decodeFrameState(frameStateVariant, state.pageState.mainFrameState);
         state.pageState.shouldOpenExternalURLsPolicy = toWebCoreExternalURLsPolicy(shouldOpenExternalURLsPolicy);
index 9982d81..f0c3941 100644 (file)
@@ -36,19 +36,6 @@ namespace WebKit {
 
 using namespace WebCore;
 
-// FIXME: Make this static once WebBackForwardListCF.cpp is no longer using it.
-uint64_t generateWebBackForwardItemID();
-
-uint64_t generateWebBackForwardItemID()
-{
-    // These IDs exist in the UIProcess for items created by the UIProcess.
-    // The IDs generated here need to never collide with the IDs created in WebBackForwardListProxy in the WebProcess.
-    // We accomplish this by starting from 2, and only ever using even ids.
-    static uint64_t uniqueHistoryItemID = 0;
-    uniqueHistoryItemID += 2;
-    return uniqueHistoryItemID;
-}
-
 static const unsigned DefaultCapacity = 100;
 
 WebBackForwardList::WebBackForwardList(WebPageProxy& page)
@@ -65,6 +52,19 @@ WebBackForwardList::~WebBackForwardList()
     ASSERT((!m_page && !m_hasCurrentIndex) || !m_page->isValid());
 }
 
+WebBackForwardListItem* WebBackForwardList::itemForID(const BackForwardItemIdentifier& identifier)
+{
+    if (!m_page)
+        return nullptr;
+
+    auto* item = WebBackForwardListItem::itemForID(identifier);
+    if (!item)
+        return nullptr;
+
+    ASSERT(item->pageID() == m_page->pageID());
+    return item;
+}
+
 void WebBackForwardList::pageClosed()
 {
     // We should have always started out with an m_page and we should never close the page twice.
@@ -76,16 +76,16 @@ void WebBackForwardList::pageClosed()
             didRemoveItem(m_entries[i]);
     }
 
-    m_page = 0;
+    m_page = nullptr;
     m_entries.clear();
     m_hasCurrentIndex = false;
 }
 
-void WebBackForwardList::addItem(WebBackForwardListItem* newItem)
+void WebBackForwardList::addItem(Ref<WebBackForwardListItem>&& newItem)
 {
     ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size());
 
-    if (!m_capacity || !newItem || !m_page)
+    if (!m_capacity || !m_page)
         return;
 
     Vector<Ref<WebBackForwardListItem>> removedItems;
@@ -139,23 +139,24 @@ void WebBackForwardList::addItem(WebBackForwardListItem* newItem)
             m_currentIndex++;
     }
 
+    auto* newItemPtr = newItem.ptr();
     if (!shouldKeepCurrentItem) {
         // m_current should never be pointing past the end of the entries Vector.
         // If it is, something has gone wrong and we should not try to swap in the new item.
         ASSERT(m_currentIndex < m_entries.size());
 
         removedItems.append(m_entries[m_currentIndex].copyRef());
-        m_entries[m_currentIndex] = *newItem;
+        m_entries[m_currentIndex] = WTFMove(newItem);
     } else {
         // m_current should never be pointing more than 1 past the end of the entries Vector.
         // If it is, something has gone wrong and we should not try to insert the new item.
         ASSERT(m_currentIndex <= m_entries.size());
 
         if (m_currentIndex <= m_entries.size())
-            m_entries.insert(m_currentIndex, *newItem);
+            m_entries.insert(m_currentIndex, WTFMove(newItem));
     }
 
-    m_page->didChangeBackForwardList(newItem, WTFMove(removedItems));
+    m_page->didChangeBackForwardList(newItemPtr, WTFMove(removedItems));
 }
 
 void WebBackForwardList::goToItem(WebBackForwardListItem& item)
@@ -418,7 +419,7 @@ void WebBackForwardList::restoreFromState(BackForwardListState backForwardListSt
     items.reserveInitialCapacity(backForwardListState.items.size());
 
     for (auto& backForwardListItemState : backForwardListState.items) {
-        backForwardListItemState.identifier = generateWebBackForwardItemID();
+        backForwardListItemState.identifier = { Process::identifier(), generateObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>() };
         items.uncheckedAppend(WebBackForwardListItem::create(WTFMove(backForwardListItemState), m_page->pageID()));
     }
     m_hasCurrentIndex = !!backForwardListState.currentIndex;
index fcdaf03..28fcea3 100644 (file)
@@ -28,6 +28,7 @@
 #include "APIObject.h"
 #include "WebBackForwardListItem.h"
 #include "WebPageProxy.h"
+#include <WebCore/BackForwardItemIdentifier.h>
 #include <wtf/Ref.h>
 #include <wtf/Vector.h>
 
@@ -45,7 +46,9 @@ public:
 
     virtual ~WebBackForwardList();
 
-    void addItem(WebBackForwardListItem*);
+    WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
+
+    void addItem(Ref<WebBackForwardListItem>&&);
     void goToItem(WebBackForwardListItem&);
     void removeAllItems();
     void clear();
index dab6cd5..9739d2b 100644 (file)
@@ -670,7 +670,7 @@ SuspendedPageProxy* WebPageProxy::maybeCreateSuspendedPage(WebProcessProxy& proc
 
     m_suspendedPage = SuspendedPageProxy::create(*this, process, *currentItem);
 
-    LOG(ProcessSwapping, "WebPageProxy %" PRIu64 " created suspended page %s for process pid %i, back/forward item %" PRIu64, pageID(), m_suspendedPage->loggingString(), process.processIdentifier(), currentItem->itemID());
+    LOG(ProcessSwapping, "WebPageProxy %" PRIu64 " created suspended page %s for process pid %i, back/forward item %s" PRIu64, pageID(), m_suspendedPage->loggingString(), process.processIdentifier(), currentItem->itemID().logString());
 
     return m_suspendedPage.get();
 }
@@ -773,10 +773,6 @@ void WebPageProxy::initializeWebPage()
 {
     ASSERT(isValid());
 
-    const BackForwardListItemVector& items = m_backForwardList->entries();
-    for (size_t i = 0; i < items.size(); ++i)
-        m_process->registerNewWebBackForwardListItem(items[i].get());
-
     m_drawingArea = m_pageClient.createDrawingAreaProxy();
     ASSERT(m_drawingArea);
 
@@ -1271,11 +1267,11 @@ void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vecto
     m_pageLoadState.setCanGoForward(transaction, m_backForwardList->forwardItem());
 }
 
-void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, bool inPageCache, const UserData& userData)
+void WebPageProxy::willGoToBackForwardListItem(const BackForwardItemIdentifier& itemID, bool inPageCache, const UserData& userData)
 {
     PageClientProtector protector(m_pageClient);
 
-    if (auto* item = m_process->webBackForwardItem(itemID)) {
+    if (auto* item = m_backForwardList->itemForID(itemID)) {
         if (m_navigationClient && m_navigationClient->willGoToBackForwardListItem(*this, *item, inPageCache, m_process->transformHandlesToObjects(userData.object()).get()))
             return;
         m_loaderClient->willGoToBackForwardListItem(*this, *item, m_process->transformHandlesToObjects(userData.object()).get());
@@ -2557,10 +2553,6 @@ RefPtr<API::Navigation> WebPageProxy::restoreFromSessionState(SessionState sessi
 
     if (hasBackForwardList) {
         m_backForwardList->restoreFromState(WTFMove(sessionState.backForwardListState));
-
-        for (const auto& entry : m_backForwardList->entries())
-            process().registerNewWebBackForwardListItem(entry.get());
-
         process().send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()), m_pageID);
 
         auto transaction = m_pageLoadState.transaction();
@@ -4685,14 +4677,14 @@ void WebPageProxy::setNeedsPlainTextQuirk(bool needsPlainTextQuirk)
 
 // BackForwardList
 
-void WebPageProxy::backForwardAddItem(uint64_t itemID)
+void WebPageProxy::backForwardAddItem(BackForwardListItemState&& itemState)
 {
-    m_backForwardList->addItem(m_process->webBackForwardItem(itemID));
+    m_backForwardList->addItem(WebBackForwardListItem::create(WTFMove(itemState), pageID()));
 }
 
-void WebPageProxy::backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle& sandboxExtensionHandle)
+void WebPageProxy::backForwardGoToItem(const BackForwardItemIdentifier& itemID, SandboxExtension::Handle& sandboxExtensionHandle)
 {
-    WebBackForwardListItem* item = m_process->webBackForwardItem(itemID);
+    WebBackForwardListItem* item = m_backForwardList->itemForID(itemID);
     if (!item)
         return;
 
@@ -4702,10 +4694,13 @@ void WebPageProxy::backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle
     m_backForwardList->goToItem(*item);
 }
 
-void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
+void WebPageProxy::backForwardItemAtIndex(int32_t index, std::optional<BackForwardItemIdentifier>& itemID)
 {
     WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
-    itemID = item ? item->itemID() : 0;
+    if (item)
+        itemID = item->itemID();
+    else
+        itemID = std::nullopt;
 }
 
 void WebPageProxy::backForwardBackListCount(int32_t& count)
@@ -5955,7 +5950,6 @@ WebPageCreationParameters WebPageProxy::creationParameters()
     parameters.userAgent = userAgent();
     parameters.itemStates = m_backForwardList->itemStates();
     parameters.sessionID = sessionID();
-    parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highestUsedItemID();
     parameters.userContentControllerID = m_userContentController->identifier();
     parameters.visitedLinkTableID = m_visitedLinkStore->identifier();
     parameters.websiteDataStoreID = m_websiteDataStore->identifier();
@@ -6362,9 +6356,8 @@ void WebPageProxy::didFinishLoadingDataForCustomContentProvider(const String& su
     m_pageClient.didFinishLoadingDataForCustomContentProvider(suggestedFilename, dataReference);
 }
 
-void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
+void WebPageProxy::backForwardRemovedItem(const BackForwardItemIdentifier& itemID)
 {
-    m_process->removeBackForwardItem(itemID);
     m_process->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
 }
 
index d561be5..5408448 100644 (file)
@@ -174,6 +174,7 @@ enum class NotificationDirection;
 enum class ShouldSample;
 
 struct ApplicationManifest;
+struct BackForwardItemIdentifier;
 struct DictionaryPopupInfo;
 struct ExceptionDetails;
 struct FileChooserSettings;
@@ -446,7 +447,7 @@ public:
     RefPtr<API::Navigation> goToBackForwardItem(WebBackForwardListItem&);
     void tryRestoreScrollPosition();
     void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<Ref<WebBackForwardListItem>>&& removed);
-    void willGoToBackForwardListItem(uint64_t itemID, bool inPageCache, const UserData&);
+    void willGoToBackForwardListItem(const WebCore::BackForwardItemIdentifier&, bool inPageCache, const UserData&);
 
     bool shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem&);
 
@@ -880,7 +881,7 @@ public:
 
     void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy&, uint64_t listenerID, API::Navigation* navigationID, std::optional<WebsitePoliciesData>&&);
 
-    void backForwardRemovedItem(uint64_t itemID);
+    void backForwardRemovedItem(const WebCore::BackForwardItemIdentifier&);
 
 #if ENABLE(DRAG_SUPPORT)    
     // Drag and drop support.
@@ -1473,9 +1474,9 @@ private:
     void setNeedsPlainTextQuirk(bool);
 
     // Back/Forward list management
-    void backForwardAddItem(uint64_t itemID);
-    void backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle&);
-    void backForwardItemAtIndex(int32_t index, uint64_t& itemID);
+    void backForwardAddItem(BackForwardListItemState&&);
+    void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, SandboxExtension::Handle&);
+    void backForwardItemAtIndex(int32_t index, std::optional<WebCore::BackForwardItemIdentifier>&);
     void backForwardBackListCount(int32_t& count);
     void backForwardForwardListCount(int32_t& count);
     void backForwardClear();
index 53fb183..eb08357 100644 (file)
@@ -219,13 +219,13 @@ messages -> WebPageProxy {
 #endif
 
     # BackForward messages
-    BackForwardAddItem(uint64_t itemID)
-    BackForwardGoToItem(uint64_t itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle)
-    BackForwardItemAtIndex(int32_t itemIndex) -> (uint64_t itemID)
+    BackForwardAddItem(struct WebKit::BackForwardListItemState itemState)
+    BackForwardGoToItem(struct WebCore::BackForwardItemIdentifier itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle)
+    BackForwardItemAtIndex(int32_t itemIndex) -> (std::optional<WebCore::BackForwardItemIdentifier> itemID)
     BackForwardBackListCount() -> (int32_t count)
     BackForwardForwardListCount() -> (int32_t count)
     BackForwardClear()
-    WillGoToBackForwardListItem(uint64_t itemID, bool inPageCache, WebKit::UserData userData)
+    WillGoToBackForwardListItem(struct WebCore::BackForwardItemIdentifier itemID, bool inPageCache, WebKit::UserData userData)
 
     # Undo/Redo messages
     RegisterEditCommandForUndo(uint64_t commandID, uint32_t editAction)
index ab9c8b0..c01198c 100644 (file)
@@ -80,6 +80,7 @@
 #include <WebCore/LogInitialization.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PlatformScreen.h>
+#include <WebCore/Process.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/URLParser.h>
 #include <pal/SessionID.h>
@@ -248,6 +249,7 @@ WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration)
     std::call_once(onceFlag, [] {
         WTF::setProcessPrivileges(allPrivileges());
         WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true);
+        Process::setIdentifier(generateObjectIdentifier<WebCore::ProcessIdentifierType>());
     });
 
     if (m_configuration->shouldHaveLegacyDataStore())
index 9a01d5b..493e88d 100644 (file)
@@ -427,14 +427,6 @@ void WebProcessProxy::removeWebPage(WebPageProxy& webPage, uint64_t pageID)
     m_processPool->pageEndUsingWebsiteDataStore(webPage);
 
     updateBackgroundResponsivenessTimer();
-    
-    Vector<uint64_t> itemIDsToRemove;
-    for (auto& idAndItem : m_backForwardListItemMap) {
-        if (idAndItem.value->pageID() == pageID)
-            itemIDsToRemove.append(idAndItem.key);
-    }
-    for (auto itemID : itemIDsToRemove)
-        m_backForwardListItemMap.remove(itemID);
 
     maybeShutDown();
 }
@@ -463,25 +455,6 @@ void WebProcessProxy::didDestroyWebUserContentControllerProxy(WebUserContentCont
     m_webUserContentControllerProxies.remove(&proxy);
 }
 
-WebBackForwardListItem* WebProcessProxy::webBackForwardItem(uint64_t itemID) const
-{
-    return m_backForwardListItemMap.get(itemID);
-}
-
-void WebProcessProxy::registerNewWebBackForwardListItem(WebBackForwardListItem& item)
-{
-    // This item was just created by the UIProcess and is being added to the map for the first time
-    // so we should not already have an item for this ID.
-    ASSERT(!m_backForwardListItemMap.contains(item.itemID()));
-
-    m_backForwardListItemMap.set(item.itemID(), &item);
-}
-
-void WebProcessProxy::removeBackForwardItem(uint64_t itemID)
-{
-    m_backForwardListItemMap.remove(itemID);
-}
-
 void WebProcessProxy::assumeReadAccessToBaseURL(const String& urlString)
 {
     URL url(URL(), urlString);
@@ -547,11 +520,11 @@ bool WebProcessProxy::checkURLReceivedFromWebProcess(const URL& url)
     // Items in back/forward list have been already checked.
     // One case where we don't have sandbox extensions for file URLs in b/f list is if the list has been reinstated after a crash or a browser restart.
     String path = url.fileSystemPath();
-    for (WebBackForwardListItemMap::iterator iter = m_backForwardListItemMap.begin(), end = m_backForwardListItemMap.end(); iter != end; ++iter) {
-        URL itemURL(URL(), iter->value->url());
+    for (auto& item : WebBackForwardListItem::allItems().values()) {
+        URL itemURL(URL(), item->url());
         if (itemURL.isLocalFile() && itemURL.fileSystemPath() == path)
             return true;
-        URL itemOriginalURL(URL(), iter->value->originalURL());
+        URL itemOriginalURL(URL(), item->originalURL());
         if (itemOriginalURL.isLocalFile() && itemOriginalURL.fileSystemPath() == path)
             return true;
     }
@@ -568,22 +541,10 @@ bool WebProcessProxy::fullKeyboardAccessEnabled()
 }
 #endif
 
-void WebProcessProxy::addOrUpdateBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState& pageState)
+void WebProcessProxy::updateBackForwardItem(const BackForwardListItemState& itemState)
 {
-    MESSAGE_CHECK_URL(pageState.mainFrameState.originalURLString);
-    MESSAGE_CHECK_URL(pageState.mainFrameState.urlString);
-
-    auto& backForwardListItem = m_backForwardListItemMap.add(itemID, nullptr).iterator->value;
-    if (!backForwardListItem) {
-        BackForwardListItemState backForwardListItemState;
-        backForwardListItemState.identifier = itemID;
-        backForwardListItemState.pageState = pageState;
-        backForwardListItem = WebBackForwardListItem::create(WTFMove(backForwardListItemState), pageID);
-        return;
-    }
-
-    // Update existing item.
-    backForwardListItem->setPageState(pageState);
+    if (auto* item = WebBackForwardListItem::itemForID(itemState.identifier))
+        item->setPageState(itemState.pageState);
 }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
index 607b9b2..ed10f93 100644 (file)
@@ -92,7 +92,6 @@ typedef BackgroundWebProcessCounter::Token BackgroundWebProcessToken;
 
 class WebProcessProxy : public ChildProcessProxy, public ResponsivenessTimer::Client, private ProcessThrottlerClient {
 public:
-    typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem>> WebBackForwardListItemMap;
     typedef HashMap<uint64_t, RefPtr<WebFrameProxy>> WebFrameProxyMap;
     typedef HashMap<uint64_t, WebPageProxy*> WebPageProxyMap;
     typedef HashMap<uint64_t, RefPtr<API::UserInitiatedAction>> UserInitiatedActionMap;
@@ -124,7 +123,6 @@ public:
     void didDestroyVisitedLinkStore(VisitedLinkStore&);
     void didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy&);
 
-    WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
     RefPtr<API::UserInitiatedAction> userInitiatedActivity(uint64_t);
 
     ResponsivenessTimer& responsivenessTimer() { return m_responsivenessTimer; }
@@ -142,9 +140,6 @@ public:
 
     void updateTextCheckerState();
 
-    void registerNewWebBackForwardListItem(WebBackForwardListItem&);
-    void removeBackForwardItem(uint64_t);
-
     void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
     void assumeReadAccessToBaseURL(const String&);
     bool hasAssumedReadAccessToURL(const WebCore::URL&) const;
@@ -233,7 +228,7 @@ private:
     void maybeShutDown();
 
     // IPC message handlers.
-    void addOrUpdateBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState&);
+    void updateBackForwardItem(const BackForwardListItemState&);
     void didDestroyFrame(uint64_t);
     void didDestroyUserGestureToken(uint64_t);
 
@@ -310,7 +305,6 @@ private:
     WebPageProxyMap m_pageMap;
     HashMap<uint64_t, SuspendedPageProxy*> m_suspendedPageMap;
     WebFrameProxyMap m_frameMap;
-    WebBackForwardListItemMap m_backForwardListItemMap;
     UserInitiatedActionMap m_userInitiatedActionMap;
 
     HashSet<VisitedLinkStore*> m_visitedLinkStores;
index ec7cf50..edb05a7 100644 (file)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebProcessProxy LegacyReceiver {
-    AddOrUpdateBackForwardItem(uint64_t itemID, uint64_t pageID, struct WebKit::PageState pageState)
+    UpdateBackForwardItem(struct WebKit::BackForwardListItemState backForwardListItemState)
     DidDestroyFrame(uint64_t frameID) 
 
     DidDestroyUserGestureToken(uint64_t userGestureTokenID) 
index a5d45a9..a44722a 100644 (file)
@@ -112,15 +112,15 @@ static FrameState toFrameState(const HistoryItem& historyItem)
     return frameState;
 }
 
-PageState toPageState(const WebCore::HistoryItem& historyItem)
+BackForwardListItemState toBackForwardListItemState(const WebCore::HistoryItem& historyItem)
 {
-    PageState pageState;
-
-    pageState.title = historyItem.title();
-    pageState.mainFrameState = toFrameState(historyItem);
-    pageState.shouldOpenExternalURLsPolicy = historyItem.shouldOpenExternalURLsPolicy();
-    pageState.sessionStateObject = historyItem.stateObject();
-    return pageState;
+    BackForwardListItemState state;
+    state.identifier = historyItem.identifier();
+    state.pageState.title = historyItem.title();
+    state.pageState.mainFrameState = toFrameState(historyItem);
+    state.pageState.shouldOpenExternalURLsPolicy = historyItem.shouldOpenExternalURLsPolicy();
+    state.pageState.sessionStateObject = historyItem.stateObject();
+    return state;
 }
 
 static Ref<FormData> toFormData(const HTTPBody& httpBody)
@@ -182,19 +182,19 @@ static void applyFrameState(HistoryItem& historyItem, const FrameState& frameSta
 #endif
 
     for (const auto& childFrameState : frameState.children) {
-        Ref<HistoryItem> childHistoryItem = HistoryItem::create(childFrameState.urlString, String());
+        Ref<HistoryItem> childHistoryItem = HistoryItem::create(childFrameState.urlString, { }, { }, { Process::identifier(), generateObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>() });
         applyFrameState(childHistoryItem, childFrameState);
 
         historyItem.addChildItem(WTFMove(childHistoryItem));
     }
 }
 
-Ref<HistoryItem> toHistoryItem(const PageState& pageState)
+Ref<HistoryItem> toHistoryItem(const BackForwardListItemState& itemState)
 {
-    Ref<HistoryItem> historyItem = HistoryItem::create(pageState.mainFrameState.urlString, pageState.title);
-    historyItem->setShouldOpenExternalURLsPolicy(pageState.shouldOpenExternalURLsPolicy);
-    historyItem->setStateObject(pageState.sessionStateObject.get());
-    applyFrameState(historyItem, pageState.mainFrameState);
+    Ref<HistoryItem> historyItem = HistoryItem::create(itemState.pageState.mainFrameState.urlString, itemState.pageState.title, { }, itemState.identifier);
+    historyItem->setShouldOpenExternalURLsPolicy(itemState.pageState.shouldOpenExternalURLsPolicy);
+    historyItem->setStateObject(itemState.pageState.sessionStateObject.get());
+    applyFrameState(historyItem, itemState.pageState.mainFrameState);
 
     return historyItem;
 }
index bee9d22..e0e11fc 100644 (file)
@@ -34,10 +34,11 @@ class HistoryItem;
 
 namespace WebKit {
 
+struct BackForwardListItemState;
 struct PageState;
 
-PageState toPageState(const WebCore::HistoryItem&);
-Ref<WebCore::HistoryItem> toHistoryItem(const PageState&);
+BackForwardListItemState toBackForwardListItemState(const WebCore::HistoryItem&);
+Ref<WebCore::HistoryItem> toHistoryItem(const BackForwardListItemState&);
 
 } // namespace WebKit
 
index a4eeaca..74ac8b2 100644 (file)
@@ -1136,13 +1136,6 @@ bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
     WebPage* webPage = m_frame->page();
     if (!webPage)
         return false;
-    
-    uint64_t itemID = WebBackForwardListProxy::idForItem(item);
-    if (!itemID) {
-        // We should never be considering navigating to an item that is not actually in the back/forward list.
-        ASSERT_NOT_REACHED();
-        return false;
-    }
 
     RefPtr<InjectedBundleBackForwardListItem> bundleItem = InjectedBundleBackForwardListItem::create(item);
     RefPtr<API::Object> userData;
@@ -1152,7 +1145,7 @@ bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
     if (!shouldGoToBackForwardListItem)
         return false;
 
-    webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID, bundleItem->isInPageCache(), UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
+    webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(item->identifier(), bundleItem->isInPageCache(), UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
     return true;
 }
 
index 7c10c78..e8a3cb7 100644 (file)
@@ -47,84 +47,32 @@ namespace WebKit {
 // FIXME <rdar://problem/8819268>: This leaks all HistoryItems that go into these maps.
 // We need to clear up the life time of these objects.
 
-typedef HashMap<uint64_t, RefPtr<HistoryItem>> IDToHistoryItemMap; // "ID" here is the item ID.
-    
-struct ItemAndPageID {
-    uint64_t itemID;
-    uint64_t pageID;
-};
-typedef HashMap<RefPtr<HistoryItem>, ItemAndPageID> HistoryItemToIDMap;
-
+typedef HashMap<BackForwardItemIdentifier, RefPtr<HistoryItem>> IDToHistoryItemMap; // "ID" here is the item ID.
 static IDToHistoryItemMap& idToHistoryItemMap()
 {
     static NeverDestroyed<IDToHistoryItemMap> map;
     return map;
 }
 
-static HistoryItemToIDMap& historyItemToIDMap()
-{
-    static NeverDestroyed<HistoryItemToIDMap> map;
-    return map;
-}
-
-static uint64_t uniqueHistoryItemID = 1;
-
-static uint64_t generateHistoryItemID()
-{
-    // These IDs exist in the WebProcess for items created by the WebProcess.
-    // The IDs generated here need to never collide with the IDs created in WebBackForwardList in the UIProcess.
-    // We accomplish this by starting from 3, and only ever using odd ids.
-    uniqueHistoryItemID += 2;
-    return uniqueHistoryItemID;
-}
-
-void WebBackForwardListProxy::setHighestItemIDFromUIProcess(uint64_t itemID)
+void WebBackForwardListProxy::addItemFromUIProcess(const BackForwardItemIdentifier& itemID, Ref<HistoryItem>&& item, uint64_t pageID)
 {
-    if (itemID <= uniqueHistoryItemID)
-        return;
-    
-     if (itemID % 2)
-         uniqueHistoryItemID = itemID;
-     else
-         uniqueHistoryItemID = itemID + 1;
-}
-
-static void updateBackForwardItem(uint64_t itemID, uint64_t pageID, HistoryItem* item)
-{
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::AddOrUpdateBackForwardItem(itemID, pageID, toPageState(*item)), 0);
-}
-
-void WebBackForwardListProxy::addItemFromUIProcess(uint64_t itemID, Ref<HistoryItem>&& item, uint64_t pageID)
-{
-    // This item/itemID pair should not already exist in our maps.
-    ASSERT(!historyItemToIDMap().contains(item.ptr()));
+    // This item/itemID pair should not already exist in our map.
     ASSERT(!idToHistoryItemMap().contains(itemID));
 
-    historyItemToIDMap().set<ItemAndPageID>(item.ptr(), { itemID, pageID });
     idToHistoryItemMap().set(itemID, item.ptr());
 }
 
 static void WK2NotifyHistoryItemChanged(HistoryItem* item)
 {
-    ItemAndPageID ids = historyItemToIDMap().get(item);
-    if (!ids.itemID)
-        return;
-
-    updateBackForwardItem(ids.itemID, ids.pageID, item);
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::UpdateBackForwardItem(toBackForwardListItemState(*item)), 0);
 }
 
-HistoryItem* WebBackForwardListProxy::itemForID(uint64_t itemID)
+HistoryItem* WebBackForwardListProxy::itemForID(const BackForwardItemIdentifier& itemID)
 {
     return idToHistoryItemMap().get(itemID);
 }
 
-uint64_t WebBackForwardListProxy::idForItem(HistoryItem* item)
-{
-    ASSERT(item);
-    return historyItemToIDMap().get(item).itemID;
-}
-
-void WebBackForwardListProxy::removeItem(uint64_t itemID)
+void WebBackForwardListProxy::removeItem(const BackForwardItemIdentifier& itemID)
 {
     RefPtr<HistoryItem> item = idToHistoryItemMap().take(itemID);
     if (!item)
@@ -132,7 +80,6 @@ void WebBackForwardListProxy::removeItem(uint64_t itemID)
         
     PageCache::singleton().remove(*item);
     WebCore::Page::clearPreviousItemFromAllPages(item.get());
-    historyItemToIDMap().remove(item);
 }
 
 WebBackForwardListProxy::WebBackForwardListProxy(WebPage* page)
@@ -143,20 +90,13 @@ WebBackForwardListProxy::WebBackForwardListProxy(WebPage* page)
 
 void WebBackForwardListProxy::addItem(Ref<HistoryItem>&& item)
 {
-    ASSERT(!historyItemToIDMap().contains(item.ptr()));
-
     if (!m_page)
         return;
 
-    uint64_t itemID = generateHistoryItemID();
-
-    ASSERT(!idToHistoryItemMap().contains(itemID));
-
-    historyItemToIDMap().set<ItemAndPageID>(item.ptr(), { itemID, m_page->pageID() });
-    idToHistoryItemMap().set(itemID, item.ptr());
+    auto result = idToHistoryItemMap().add(item->identifier(), item.ptr());
+    ASSERT_UNUSED(result, result.isNewEntry);
 
-    updateBackForwardItem(itemID, m_page->pageID(), item.ptr());
-    m_page->send(Messages::WebPageProxy::BackForwardAddItem(itemID));
+    m_page->send(Messages::WebPageProxy::BackForwardAddItem(toBackForwardListItemState(item.get())));
 }
 
 void WebBackForwardListProxy::goToItem(HistoryItem* item)
@@ -165,7 +105,7 @@ void WebBackForwardListProxy::goToItem(HistoryItem* item)
         return;
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(historyItemToIDMap().get(item).itemID), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle));
+    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(item->identifier()), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle));
     m_page->sandboxExtensionTracker().beginLoad(m_page->mainWebFrame(), WTFMove(sandboxExtensionHandle));
 }
 
@@ -174,14 +114,14 @@ HistoryItem* WebBackForwardListProxy::itemAtIndex(int itemIndex)
     if (!m_page)
         return nullptr;
 
-    uint64_t itemID = 0;
+    std::optional<BackForwardItemIdentifier> itemID;
     if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardItemAtIndex(itemIndex), Messages::WebPageProxy::BackForwardItemAtIndex::Reply(itemID), m_page->pageID()))
         return nullptr;
 
     if (!itemID)
         return nullptr;
 
-    return idToHistoryItemMap().get(itemID);
+    return idToHistoryItemMap().get(*itemID);
 }
 
 int WebBackForwardListProxy::backListCount()
@@ -210,6 +150,7 @@ int WebBackForwardListProxy::forwardListCount()
 
 void WebBackForwardListProxy::close()
 {
+    ASSERT(m_page);
     m_page = nullptr;
 }
 
index d43f948..cad70e8 100644 (file)
 #include <WebCore/BackForwardClient.h>
 #include <wtf/HashSet.h>
 
+namespace WebCore {
+struct BackForwardItemIdentifier;
+}
+
 namespace WebKit {
 
 class WebPage;
@@ -37,12 +41,10 @@ class WebBackForwardListProxy : public WebCore::BackForwardClient {
 public: 
     static Ref<WebBackForwardListProxy> create(WebPage* page) { return adoptRef(*new WebBackForwardListProxy(page)); }
 
-    static WebCore::HistoryItem* itemForID(uint64_t);
-    static uint64_t idForItem(WebCore::HistoryItem*);
-    static void removeItem(uint64_t itemID);
+    static WebCore::HistoryItem* itemForID(const WebCore::BackForwardItemIdentifier&);
+    static void removeItem(const WebCore::BackForwardItemIdentifier&);
 
-    void addItemFromUIProcess(uint64_t itemID, Ref<WebCore::HistoryItem>&&, uint64_t pageID);
-    static void setHighestItemIDFromUIProcess(uint64_t itemID);
+    void addItemFromUIProcess(const WebCore::BackForwardItemIdentifier&, Ref<WebCore::HistoryItem>&&, uint64_t pageID);
     
     void clear();
 
index 89fae1a..5a09db2 100644 (file)
@@ -523,8 +523,6 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     setTopContentInset(parameters.topContentInset);
 
     m_userAgent = parameters.userAgent;
-
-    WebBackForwardListProxy::setHighestItemIDFromUIProcess(parameters.highestUsedBackForwardItemID);
     
     if (!parameters.itemStates.isEmpty())
         restoreSessionInternal(parameters.itemStates, WasRestoredByAPIRequest::No);
@@ -1390,7 +1388,7 @@ void WebPage::reload(uint64_t navigationID, uint32_t reloadOptions, SandboxExten
     }
 }
 
-void WebPage::goToBackForwardItem(uint64_t navigationID, uint64_t backForwardItemID, FrameLoadType backForwardType, NavigationPolicyCheck navigationPolicyCheck)
+void WebPage::goToBackForwardItem(uint64_t navigationID, const BackForwardItemIdentifier& backForwardItemID, FrameLoadType backForwardType, NavigationPolicyCheck navigationPolicyCheck)
 {
     SendStopResponsivenessTimer stopper;
 
@@ -2495,7 +2493,7 @@ void WebPage::executeEditCommand(const String& commandName, const String& argume
 void WebPage::restoreSessionInternal(const Vector<BackForwardListItemState>& itemStates, WasRestoredByAPIRequest restoredByAPIRequest)
 {
     for (const auto& itemState : itemStates) {
-        auto historyItem = toHistoryItem(itemState.pageState);
+        auto historyItem = toHistoryItem(itemState);
         historyItem->setWasRestoredFromSession(restoredByAPIRequest == WasRestoredByAPIRequest::Yes);
         static_cast<WebBackForwardListProxy*>(corePage()->backForward().client())->addItemFromUIProcess(itemState.identifier, WTFMove(historyItem), m_pageID);
     }
@@ -4089,7 +4087,7 @@ void WebPage::setCustomTextEncodingName(const String& encoding)
     m_page->mainFrame().loader().reloadWithOverrideEncoding(encoding);
 }
 
-void WebPage::didRemoveBackForwardItem(uint64_t itemID)
+void WebPage::didRemoveBackForwardItem(const BackForwardItemIdentifier& itemID)
 {
     WebBackForwardListProxy::removeItem(itemID);
 }
index 8e775cd..29c459b 100644 (file)
@@ -154,6 +154,7 @@ enum SyntheticClickType : int8_t;
 enum class NavigationPolicyCheck;
 enum class TextIndicatorPresentationTransition : uint8_t;
 
+struct BackForwardItemIdentifier;
 struct CompositionUnderline;
 struct DictationAlternative;
 struct GlobalFrameIdentifier;
@@ -1156,7 +1157,7 @@ private:
     void loadAlternateHTMLString(const LoadParameters&);
     void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);
     void reload(uint64_t navigationID, uint32_t reloadOptions, SandboxExtension::Handle&&);
-    void goToBackForwardItem(uint64_t navigationID, uint64_t, WebCore::FrameLoadType, WebCore::NavigationPolicyCheck);
+    void goToBackForwardItem(uint64_t navigationID, const WebCore::BackForwardItemIdentifier&, WebCore::FrameLoadType, WebCore::NavigationPolicyCheck);
     void tryRestoreScrollPosition();
     void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&, CallbackID);
     void updateIsInWindow(bool isInitialState = false);
@@ -1189,7 +1190,7 @@ private:
     enum class WasRestoredByAPIRequest { No, Yes };
     void restoreSessionInternal(const Vector<BackForwardListItemState>&, WasRestoredByAPIRequest);
     void restoreSession(const Vector<BackForwardListItemState>&);
-    void didRemoveBackForwardItem(uint64_t);
+    void didRemoveBackForwardItem(const WebCore::BackForwardItemIdentifier&);
 
 #if ENABLE(REMOTE_INSPECTOR)
     void setAllowsRemoteInspection(bool);
index a3c716f..b6027bd 100644 (file)
@@ -131,7 +131,7 @@ messages -> WebPage LegacyReceiver {
     ScrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
     CenterSelectionInVisibleArea()
 
-    GoToBackForwardItem(uint64_t navigationID, uint64_t backForwardItemID, enum WebCore::FrameLoadType backForwardType, enum WebCore::NavigationPolicyCheck navigationPolicyCheck)
+    GoToBackForwardItem(uint64_t navigationID, struct WebCore::BackForwardItemIdentifier backForwardItemID, enum WebCore::FrameLoadType backForwardType, enum WebCore::NavigationPolicyCheck navigationPolicyCheck)
     TryRestoreScrollPosition()
 
     LoadURLInFrame(WebCore::URL url, uint64_t frameID)
@@ -149,7 +149,7 @@ messages -> WebPage LegacyReceiver {
     
     RestoreSession(Vector<WebKit::BackForwardListItemState> itemStates)
 
-    DidRemoveBackForwardItem(uint64_t backForwardItemID)
+    DidRemoveBackForwardItem(struct WebCore::BackForwardItemIdentifier backForwardItemID)
 
     UpdateWebsitePolicies(struct WebKit::WebsitePoliciesData websitePolicies)
     DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, enum WebCore::PolicyAction policyAction, uint64_t navigationID, WebKit::DownloadID downloadID, std::optional<WebKit::WebsitePoliciesData> websitePolicies)