Title: [230812] trunk/Source
Revision
230812
Author
beid...@apple.com
Date
2018-04-19 11:45:40 -0700 (Thu, 19 Apr 2018)

Log Message

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.

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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (230811 => 230812)


--- trunk/Source/WTF/ChangeLog	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WTF/ChangeLog	2018-04-19 18:45:40 UTC (rev 230812)
@@ -1,3 +1,13 @@
+2018-04-19  Brady Eidson  <beid...@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  <pvol...@apple.com>
 
         Unreviewed, rolling out r230677.

Modified: trunk/Source/WTF/wtf/DebugUtilities.h (230811 => 230812)


--- trunk/Source/WTF/wtf/DebugUtilities.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WTF/wtf/DebugUtilities.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
 
 namespace WTF {
 
+template<typename StringType>
+const char* debugString(StringType string)
+{
+    return debugString(string, "");
+}
+
 template<typename... StringTypes>
 const char* debugString(StringTypes... strings)
 {

Modified: trunk/Source/WebCore/ChangeLog (230811 => 230812)


--- trunk/Source/WebCore/ChangeLog	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebCore/ChangeLog	2018-04-19 18:45:40 UTC (rev 230812)
@@ -1,3 +1,39 @@
+2018-04-19  Brady Eidson  <beid...@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_w...@apple.com>
 
         AX: AOM: respect the accessibility setting for dispatching the accessible events

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (230811 => 230812)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-04-19 18:45:40 UTC (rev 230812)
@@ -1466,6 +1466,7 @@
 		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, ); }; };
@@ -7954,6 +7955,7 @@
 		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>"; };
@@ -17586,6 +17588,7 @@
 				51741D0B0B07259A00ED442C /* BackForwardClient.h */,
 				BCA8C81D11E3D36900812FB7 /* BackForwardController.cpp */,
 				BCA8C81C11E3D36900812FB7 /* BackForwardController.h */,
+				51A1B87B2087C4B800979A75 /* BackForwardItemIdentifier.h */,
 				51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */,
 				51C0AA380F2AA10A001648C2 /* CachedFrame.h */,
 				51CBFC980D10E483002DBF51 /* CachedFramePlatformData.h */,
@@ -26922,6 +26925,7 @@
 				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 */,

Added: trunk/Source/WebCore/history/BackForwardItemIdentifier.h (0 => 230812)


--- trunk/Source/WebCore/history/BackForwardItemIdentifier.h	                        (rev 0)
+++ trunk/Source/WebCore/history/BackForwardItemIdentifier.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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

Modified: trunk/Source/WebCore/history/HistoryItem.cpp (230811 => 230812)


--- trunk/Source/WebCore/history/HistoryItem.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebCore/history/HistoryItem.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
 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)
 {
 }
 

Modified: trunk/Source/WebCore/history/HistoryItem.h (230811 => 230812)


--- trunk/Source/WebCore/history/HistoryItem.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebCore/history/HistoryItem.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -26,6 +26,7 @@
 
 #pragma once
 
+#include "BackForwardItemIdentifier.h"
 #include "FloatRect.h"
 #include "FrameLoaderTypes.h"
 #include "IntPoint.h"
@@ -62,20 +63,32 @@
     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 @@
     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 @@
     // 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 @@
     RetainPtr<id> m_viewState;
     std::unique_ptr<HashMap<String, RetainPtr<id>>> m_transientProperties;
 #endif
+
+    BackForwardItemIdentifier m_identifier;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (230811 => 230812)


--- trunk/Source/WebKit/ChangeLog	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/ChangeLog	2018-04-19 18:45:40 UTC (rev 230812)
@@ -1,3 +1,110 @@
+2018-04-19  Brady Eidson  <beid...@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  <you...@apple.com>
 
         NetworkProcess should use CSP/content blockers for sync XHR

Modified: trunk/Source/WebKit/Shared/SessionState.cpp (230811 => 230812)


--- trunk/Source/WebKit/Shared/SessionState.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/SessionState.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -27,6 +27,7 @@
 #include "SessionState.h"
 
 #include "WebCoreArgumentCoders.h"
+#include <WebCore/BackForwardItemIdentifier.h>
 
 using namespace WebCore;
 
@@ -232,8 +233,10 @@
 {
     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;

Modified: trunk/Source/WebKit/Shared/SessionState.h (230811 => 230812)


--- trunk/Source/WebKit/Shared/SessionState.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/SessionState.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
     void encode(IPC::Encoder&) const;
     static std::optional<BackForwardListItemState> decode(IPC::Decoder&);
 
-    uint64_t identifier;
+    WebCore::BackForwardItemIdentifier identifier;
 
     PageState pageState;
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp (230811 => 230812)


--- trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -28,10 +28,10 @@
 
 #include <WebCore/URL.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
-static uint64_t highestItemID = 0;
-
 Ref<WebBackForwardListItem> WebBackForwardListItem::create(BackForwardListItemState&& backForwardListItemState, uint64_t pageID)
 {
     return adoptRef(*new WebBackForwardListItem(WTFMove(backForwardListItemState), pageID));
@@ -41,14 +41,27 @@
     : 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)
 {
     for (const auto& child : frameState.children) {
@@ -98,11 +111,6 @@
     return documentTreesAreEqual(mainFrameState, otherMainFrameState);
 }
 
-uint64_t WebBackForwardListItem::highestUsedItemID()
-{
-    return highestItemID;
-}
-
 void WebBackForwardListItem::setSuspendedPage(SuspendedPageProxy& page)
 {
     m_suspendedPage = &page;

Modified: trunk/Source/WebKit/Shared/WebBackForwardListItem.h (230811 => 230812)


--- trunk/Source/WebKit/Shared/WebBackForwardListItem.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/WebBackForwardListItem.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -48,7 +48,10 @@
     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 @@
 #endif
     void setSuspendedPage(SuspendedPageProxy&);
 
-    static uint64_t highestUsedItemID();
-
 private:
     explicit WebBackForwardListItem(BackForwardListItemState&&, uint64_t pageID);
 

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp (230811 => 230812)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -53,7 +53,6 @@
     encoder << userAgent;
     encoder << itemStates;
     encoder << sessionID;
-    encoder << highestUsedBackForwardItemID;
     encoder << userContentControllerID.toUInt64();
     encoder << visitedLinkTableID;
     encoder << websiteDataStoreID;
@@ -177,8 +176,6 @@
 
     if (!decoder.decode(parameters.sessionID))
         return std::nullopt;
-    if (!decoder.decode(parameters.highestUsedBackForwardItemID))
-        return std::nullopt;
 
     std::optional<uint64_t> userContentControllerIdentifier;
     decoder >> userContentControllerIdentifier;

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.h (230811 => 230812)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -96,7 +96,6 @@
 
     Vector<BackForwardListItemState> itemStates;
     PAL::SessionID sessionID;
-    uint64_t highestUsedBackForwardItemID;
 
     UserContentControllerIdentifier userContentControllerID;
     uint64_t visitedLinkTableID;

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewSessionState.cpp (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewSessionState.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewSessionState.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
     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);

Modified: trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -36,19 +36,6 @@
 
 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 @@
     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 @@
             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,6 +139,7 @@
             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.
@@ -145,7 +146,7 @@
         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.
@@ -152,10 +153,10 @@
         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 @@
     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;

Modified: trunk/Source/WebKit/UIProcess/WebBackForwardList.h (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebBackForwardList.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebBackForwardList.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
 
     virtual ~WebBackForwardList();
 
-    void addItem(WebBackForwardListItem*);
+    WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
+
+    void addItem(Ref<WebBackForwardListItem>&&);
     void goToItem(WebBackForwardListItem&);
     void removeAllItems();
     void clear();

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -670,7 +670,7 @@
 
     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 @@
 {
     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 @@
     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 @@
 
     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 @@
 
 // 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 @@
     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 @@
     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 @@
     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);
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -174,6 +174,7 @@
 enum class ShouldSample;
 
 struct ApplicationManifest;
+struct BackForwardItemIdentifier;
 struct DictionaryPopupInfo;
 struct ExceptionDetails;
 struct FileChooserSettings;
@@ -446,7 +447,7 @@
     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 @@
 
     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 @@
     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();

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-04-19 18:45:40 UTC (rev 230812)
@@ -219,13 +219,13 @@
 #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)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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 @@
     std::call_once(onceFlag, [] {
         WTF::setProcessPrivileges(allPrivileges());
         WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true);
+        Process::setIdentifier(generateObjectIdentifier<WebCore::ProcessIdentifierType>());
     });
 
     if (m_configuration->shouldHaveLegacyDataStore())

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -427,14 +427,6 @@
     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 @@
     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 @@
     // 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 @@
 }
 #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)

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -92,7 +92,6 @@
 
 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 @@
     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 @@
 
     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 @@
     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 @@
     WebPageProxyMap m_pageMap;
     HashMap<uint64_t, SuspendedPageProxy*> m_suspendedPageMap;
     WebFrameProxyMap m_frameMap;
-    WebBackForwardListItemMap m_backForwardListItemMap;
     UserInitiatedActionMap m_userInitiatedActionMap;
 
     HashSet<VisitedLinkStore*> m_visitedLinkStores;

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in (230811 => 230812)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2018-04-19 18:45:40 UTC (rev 230812)
@@ -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) 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.cpp (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -112,15 +112,15 @@
     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,7 +182,7 @@
 #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));
@@ -189,12 +189,12 @@
     }
 }
 
-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;
 }

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.h (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/SessionStateConversion.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -34,10 +34,11 @@
 
 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
 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -1136,13 +1136,6 @@
     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 @@
     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;
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -47,14 +47,7 @@
 // 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;
@@ -61,71 +54,26 @@
     return map;
 }
 
-static HistoryItemToIDMap& historyItemToIDMap()
+void WebBackForwardListProxy::addItemFromUIProcess(const BackForwardItemIdentifier& itemID, Ref<HistoryItem>&& item, uint64_t pageID)
 {
-    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)
-{
-    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)
+void WebBackForwardListProxy::removeItem(const BackForwardItemIdentifier& itemID)
 {
-    ASSERT(item);
-    return historyItemToIDMap().get(item).itemID;
-}
-
-void WebBackForwardListProxy::removeItem(uint64_t itemID)
-{
     RefPtr<HistoryItem> item = idToHistoryItemMap().take(itemID);
     if (!item)
         return;
@@ -132,7 +80,6 @@
         
     PageCache::singleton().remove(*item);
     WebCore::Page::clearPreviousItemFromAllPages(item.get());
-    historyItemToIDMap().remove(item);
 }
 
 WebBackForwardListProxy::WebBackForwardListProxy(WebPage* page)
@@ -143,20 +90,13 @@
 
 void WebBackForwardListProxy::addItem(Ref<HistoryItem>&& item)
 {
-    ASSERT(!historyItemToIDMap().contains(item.ptr()));
-
     if (!m_page)
         return;
 
-    uint64_t itemID = generateHistoryItemID();
+    auto result = idToHistoryItemMap().add(item->identifier(), item.ptr());
+    ASSERT_UNUSED(result, result.isNewEntry);
 
-    ASSERT(!idToHistoryItemMap().contains(itemID));
-
-    historyItemToIDMap().set<ItemAndPageID>(item.ptr(), { itemID, m_page->pageID() });
-    idToHistoryItemMap().set(itemID, item.ptr());
-
-    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 @@
         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,7 +114,7 @@
     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;
 
@@ -181,7 +121,7 @@
     if (!itemID)
         return nullptr;
 
-    return idToHistoryItemMap().get(itemID);
+    return idToHistoryItemMap().get(*itemID);
 }
 
 int WebBackForwardListProxy::backListCount()
@@ -210,6 +150,7 @@
 
 void WebBackForwardListProxy::close()
 {
+    ASSERT(m_page);
     m_page = nullptr;
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -29,6 +29,10 @@
 #include <WebCore/BackForwardClient.h>
 #include <wtf/HashSet.h>
 
+namespace WebCore {
+struct BackForwardItemIdentifier;
+}
+
 namespace WebKit {
 
 class WebPage;
@@ -37,12 +41,10 @@
 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();
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-04-19 18:45:40 UTC (rev 230812)
@@ -523,8 +523,6 @@
     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::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::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 @@
     m_page->mainFrame().loader().reloadWithOverrideEncoding(encoding);
 }
 
-void WebPage::didRemoveBackForwardItem(uint64_t itemID)
+void WebPage::didRemoveBackForwardItem(const BackForwardItemIdentifier& itemID)
 {
     WebBackForwardListProxy::removeItem(itemID);
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-04-19 18:45:40 UTC (rev 230812)
@@ -154,6 +154,7 @@
 enum class NavigationPolicyCheck;
 enum class TextIndicatorPresentationTransition : uint8_t;
 
+struct BackForwardItemIdentifier;
 struct CompositionUnderline;
 struct DictationAlternative;
 struct GlobalFrameIdentifier;
@@ -1156,7 +1157,7 @@
     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 @@
     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);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (230811 => 230812)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-04-19 18:25:36 UTC (rev 230811)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-04-19 18:45:40 UTC (rev 230812)
@@ -131,7 +131,7 @@
     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 @@
     
     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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to