Remove WebBackForwardListItems when their owning page goes away
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jul 2014 23:17:26 +0000 (23:17 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jul 2014 23:17:26 +0000 (23:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134709
<rdar://problem/17584645>

Reviewed by Dan Bernstein.

* Shared/WebBackForwardListItem.cpp:
(WebKit::WebBackForwardListItem::create):
(WebKit::WebBackForwardListItem::WebBackForwardListItem):
* Shared/WebBackForwardListItem.h:
(WebKit::WebBackForwardListItem::pageID):
Add the associated PageID to the WebBackForwardListItem.

* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::restoreFromState):
Push the current PageID onto the WebBackForwardListItem.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::removeWebPage):
Remove all of the WebBackForwardListItems from m_backForwardListItemMap when
the page they are associated with is removed.

(WebKit::WebProcessProxy::addBackForwardItem):
Push the PageID from the WebProcess onto the WebBackForwardListItem.

* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/WebPage/WebBackForwardListProxy.cpp:
(WebKit::idToHistoryItemMap):
(WebKit::historyItemToIDMap):
(WebKit::updateBackForwardItem):
(WebKit::WebBackForwardListProxy::addItemFromUIProcess):
(WebKit::WK2NotifyHistoryItemChanged):
(WebKit::WebBackForwardListProxy::idForItem):
(WebKit::WebBackForwardListProxy::addItem):
(WebKit::WebBackForwardListProxy::goToItem):
(WebKit::WebBackForwardListProxy::close):
* WebProcess/WebPage/WebBackForwardListProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::restoreSession):
Keep track of the PageID that back-forward items were created by.
Pass the PageID along when registering WebBackForwardListItems.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebBackForwardListItem.cpp
Source/WebKit2/Shared/WebBackForwardListItem.h
Source/WebKit2/UIProcess/WebBackForwardList.cpp
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h
Source/WebKit2/UIProcess/WebProcessProxy.messages.in
Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp
Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index d06cfc79cebf2d2915ad81fe53c23d282ccc6221..04569468f4ba00b29a79d37dec94b236d4056175 100644 (file)
@@ -1,3 +1,48 @@
+2014-07-08  Tim Horton  <timothy_horton@apple.com>
+
+        Remove WebBackForwardListItems when their owning page goes away
+        https://bugs.webkit.org/show_bug.cgi?id=134709
+        <rdar://problem/17584645>
+
+        Reviewed by Dan Bernstein.
+
+        * Shared/WebBackForwardListItem.cpp:
+        (WebKit::WebBackForwardListItem::create):
+        (WebKit::WebBackForwardListItem::WebBackForwardListItem):
+        * Shared/WebBackForwardListItem.h:
+        (WebKit::WebBackForwardListItem::pageID):
+        Add the associated PageID to the WebBackForwardListItem.
+
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::restoreFromState):
+        Push the current PageID onto the WebBackForwardListItem.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::removeWebPage):
+        Remove all of the WebBackForwardListItems from m_backForwardListItemMap when
+        the page they are associated with is removed.
+
+        (WebKit::WebProcessProxy::addBackForwardItem):
+        Push the PageID from the WebProcess onto the WebBackForwardListItem.
+
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
+        (WebKit::idToHistoryItemMap):
+        (WebKit::historyItemToIDMap):
+        (WebKit::updateBackForwardItem):
+        (WebKit::WebBackForwardListProxy::addItemFromUIProcess):
+        (WebKit::WK2NotifyHistoryItemChanged):
+        (WebKit::WebBackForwardListProxy::idForItem):
+        (WebKit::WebBackForwardListProxy::addItem):
+        (WebKit::WebBackForwardListProxy::goToItem):
+        (WebKit::WebBackForwardListProxy::close):
+        * WebProcess/WebPage/WebBackForwardListProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::restoreSession):
+        Keep track of the PageID that back-forward items were created by.
+        Pass the PageID along when registering WebBackForwardListItems.
+
 2014-07-08  Tim Horton  <timothy_horton@apple.com>
 
         [WK2] Expose a few drawing/compositing settings on WKPreferences(Private)
index fba232c377749f6653a78128ba52d471150681b7..f20cdaceb55d681dc48232cfd8c8a9a8a463060e 100644 (file)
@@ -30,13 +30,14 @@ namespace WebKit {
 
 static uint64_t highestUsedItemID = 0;
 
-PassRefPtr<WebBackForwardListItem> WebBackForwardListItem::create(BackForwardListItemState backForwardListItemState)
+PassRefPtr<WebBackForwardListItem> WebBackForwardListItem::create(BackForwardListItemState backForwardListItemState, uint64_t pageID)
 {
-    return adoptRef(new WebBackForwardListItem(WTF::move(backForwardListItemState)));
+    return adoptRef(new WebBackForwardListItem(WTF::move(backForwardListItemState), pageID));
 }
 
-WebBackForwardListItem::WebBackForwardListItem(BackForwardListItemState backForwardListItemState)
+WebBackForwardListItem::WebBackForwardListItem(BackForwardListItemState backForwardListItemState, uint64_t pageID)
     : m_itemState(WTF::move(backForwardListItemState))
+    , m_pageID(pageID)
 {
     if (m_itemState.identifier > highestUsedItemID)
         highestUsedItemID = m_itemState.identifier;
index 451bd9772d23302643c7079e1e893995d840098d..0960c79ce8cc817daef70ef67f60856c7b7fbecb 100644 (file)
@@ -44,11 +44,12 @@ namespace WebKit {
 
 class WebBackForwardListItem : public API::ObjectImpl<API::Object::Type::BackForwardListItem> {
 public:
-    static PassRefPtr<WebBackForwardListItem> create(BackForwardListItemState);
+    static PassRefPtr<WebBackForwardListItem> create(BackForwardListItemState, uint64_t pageID);
     virtual ~WebBackForwardListItem();
 
     uint64_t itemID() const { return m_itemState.identifier; }
     const BackForwardListItemState& itemState() { return m_itemState; }
+    uint64_t pageID() const { return m_pageID; }
 
     void setPageState(PageState pageState) { m_itemState.pageState = WTF::move(pageState); }
 
@@ -62,9 +63,10 @@ public:
     static uint64_t highedUsedItemID();
 
 private:
-    explicit WebBackForwardListItem(BackForwardListItemState);
+    explicit WebBackForwardListItem(BackForwardListItemState, uint64_t pageID);
 
     BackForwardListItemState m_itemState;
+    uint64_t m_pageID;
 };
 
 typedef Vector<RefPtr<WebBackForwardListItem>> BackForwardListItemVector;
index 8251793a1fac9588510dfe921c7a7148e0ed0c11..66cf07d8bdbfe3117ceaf959452fd50cdcc4f03e 100644 (file)
@@ -411,7 +411,7 @@ void WebBackForwardList::restoreFromState(BackForwardListState backForwardListSt
 
     for (auto& backForwardListItemState : backForwardListState.items) {
         backForwardListItemState.identifier = generateWebBackForwardItemID();
-        items.uncheckedAppend(WebBackForwardListItem::create(WTF::move(backForwardListItemState)));
+        items.uncheckedAppend(WebBackForwardListItem::create(WTF::move(backForwardListItemState), m_page->pageID()));
     }
     m_hasCurrentIndex = !!backForwardListState.currentIndex;
     m_currentIndex = backForwardListState.currentIndex.valueOr(0);
index 9342d5fdcfb9c9b47687499e5bd34446effcfea8..807a892313894a789bc0eb019836395a4464aaff 100644 (file)
@@ -199,6 +199,14 @@ void WebProcessProxy::removeWebPage(uint64_t pageID)
 {
     m_pageMap.remove(pageID);
     globalPageMap().remove(pageID);
+    
+    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);
 
 #if PLATFORM(COCOA)
     m_processSuppressiblePages.remove(pageID);
@@ -310,7 +318,7 @@ bool WebProcessProxy::fullKeyboardAccessEnabled()
 }
 #endif
 
-void WebProcessProxy::addBackForwardItem(uint64_t itemID, const PageState& pageState)
+void WebProcessProxy::addBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState& pageState)
 {
     MESSAGE_CHECK_URL(pageState.mainFrameState.originalURLString);
     MESSAGE_CHECK_URL(pageState.mainFrameState.urlString);
@@ -320,7 +328,7 @@ void WebProcessProxy::addBackForwardItem(uint64_t itemID, const PageState& pageS
         BackForwardListItemState backForwardListItemState;
         backForwardListItemState.identifier = itemID;
         backForwardListItemState.pageState = pageState;
-        backForwardListItem = WebBackForwardListItem::create(WTF::move(backForwardListItemState));
+        backForwardListItem = WebBackForwardListItem::create(WTF::move(backForwardListItemState), pageID);
         return;
     }
 
index 5f4c08507b377dde99351c6c2095bad9c9c40099..6202940fc7d18c27861476676c658e07cda8966e 100644 (file)
@@ -156,7 +156,7 @@ private:
     void disconnect();
 
     // IPC message handlers.
-    void addBackForwardItem(uint64_t itemID, const PageState&);
+    void addBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState&);
     void didDestroyFrame(uint64_t);
     
     void shouldTerminate(bool& shouldTerminate);
index c42cc900aa8bfe5f2a5b3c0c4ddbf62a4f89398c..0a99c26ec6df3bee238cccf37efed3064af4b4da 100644 (file)
@@ -28,7 +28,7 @@ messages -> WebProcessProxy LegacyReceiver {
     DidPerformServerRedirect(uint64_t pageID, String sourceURLString, String destinationURLString, uint64_t frameID)
     DidUpdateHistoryTitle(uint64_t pageID, String title, String url, uint64_t frameID)
 
-    AddBackForwardItem(uint64_t itemID, WebKit::PageState pageState)
+    AddBackForwardItem(uint64_t itemID, uint64_t pageID, WebKit::PageState pageState)
     DidDestroyFrame(uint64_t frameID) 
 
     ShouldTerminate() -> (bool shouldTerminate)
index 7a14888450db2dfce05b99e8d8e1ec6715454d89..017f5bc570903ffcf4bc32dc6c08e3483753a18e 100644 (file)
@@ -45,20 +45,25 @@ 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;
-typedef HashMap<RefPtr<HistoryItem>, uint64_t> HistoryItemToIDMap;
+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;
 
 static IDToHistoryItemMap& idToHistoryItemMap()
 {
     static NeverDestroyed<IDToHistoryItemMap> map;;
     return map;
-} 
+}
 
 static HistoryItemToIDMap& historyItemToIDMap()
 {
     static NeverDestroyed<HistoryItemToIDMap> map;
     return map;
-} 
+}
 
 static uint64_t uniqueHistoryItemID = 1;
 
@@ -82,30 +87,30 @@ void WebBackForwardListProxy::setHighestItemIDFromUIProcess(uint64_t itemID)
          uniqueHistoryItemID = itemID + 1;
 }
 
-static void updateBackForwardItem(uint64_t itemID, HistoryItem* item)
+static void updateBackForwardItem(uint64_t itemID, uint64_t pageID, HistoryItem* item)
 {
-    WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::AddBackForwardItem(itemID, toPageState(*item)), 0);
+    WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::AddBackForwardItem(itemID, pageID, toPageState(*item)), 0);
 }
 
-void WebBackForwardListProxy::addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem> prpItem)
+void WebBackForwardListProxy::addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem> prpItem, uint64_t pageID)
 {
     RefPtr<HistoryItem> item = prpItem;
     
     // This item/itemID pair should not already exist in our maps.
     ASSERT(!historyItemToIDMap().contains(item.get()));
     ASSERT(!idToHistoryItemMap().contains(itemID));
-        
-    historyItemToIDMap().set(item, itemID);
+
+    historyItemToIDMap().set<ItemAndPageID>(item, { .itemID = itemID, .pageID = pageID });
     idToHistoryItemMap().set(itemID, item);
 }
 
 static void WK2NotifyHistoryItemChanged(HistoryItem* item)
 {
-    uint64_t itemID = historyItemToIDMap().get(item);
-    if (!itemID)
+    ItemAndPageID ids = historyItemToIDMap().get(item);
+    if (!ids.itemID)
         return;
 
-    updateBackForwardItem(itemID, item);
+    updateBackForwardItem(ids.itemID, ids.pageID, item);
 }
 
 HistoryItem* WebBackForwardListProxy::itemForID(uint64_t itemID)
@@ -116,7 +121,7 @@ HistoryItem* WebBackForwardListProxy::itemForID(uint64_t itemID)
 uint64_t WebBackForwardListProxy::idForItem(HistoryItem* item)
 {
     ASSERT(item);
-    return historyItemToIDMap().get(item);
+    return historyItemToIDMap().get(item).itemID;
 }
 
 void WebBackForwardListProxy::removeItem(uint64_t itemID)
@@ -150,10 +155,10 @@ void WebBackForwardListProxy::addItem(PassRefPtr<HistoryItem> prpItem)
 
     m_associatedItemIDs.add(itemID);
 
-    historyItemToIDMap().set(item, itemID);
+    historyItemToIDMap().set<ItemAndPageID>(item, { .itemID = itemID, .pageID = m_page->pageID() });
     idToHistoryItemMap().set(itemID, item);
 
-    updateBackForwardItem(itemID, item.get());
+    updateBackForwardItem(itemID, m_page->pageID(), item.get());
     m_page->send(Messages::WebPageProxy::BackForwardAddItem(itemID));
 }
 
@@ -163,7 +168,7 @@ void WebBackForwardListProxy::goToItem(HistoryItem* item)
         return;
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(historyItemToIDMap().get(item)), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle));
+    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(historyItemToIDMap().get(item).itemID), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle));
     m_page->sandboxExtensionTracker().beginLoad(m_page->mainWebFrame(), sandboxExtensionHandle);
 }
 
@@ -214,7 +219,7 @@ void WebBackForwardListProxy::close()
 
     m_associatedItemIDs.clear();
 
-    m_page = 0;
+    m_page = nullptr;
 }
 
 bool WebBackForwardListProxy::isActive()
index e47eed74f4d04e4518b8144e1dee0fefec4057f2..ef219e05fb8ea9b4f762e934d72af036e485ee94 100644 (file)
@@ -42,7 +42,7 @@ public:
     static uint64_t idForItem(WebCore::HistoryItem*);
     static void removeItem(uint64_t itemID);
 
-    static void addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem>);
+    static void addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem>, uint64_t pageID);
     static void setHighestItemIDFromUIProcess(uint64_t itemID);
     
     void clear();
index 7dec4707a51f4d96e493a3e6d1db84a167b54b52..b32580bc827c0e3c573792015958da233c1f1ef7 100644 (file)
@@ -1964,7 +1964,7 @@ void WebPage::executeEditCommand(const String& commandName)
 void WebPage::restoreSession(const Vector<BackForwardListItemState>& itemStates)
 {
     for (const auto& itemState : itemStates)
-        WebBackForwardListProxy::addItemFromUIProcess(itemState.identifier, toHistoryItem(itemState.pageState));
+        WebBackForwardListProxy::addItemFromUIProcess(itemState.identifier, toHistoryItem(itemState.pageState), m_pageID);
 }
 
 #if ENABLE(TOUCH_EVENTS)