Title: [108570] trunk
Revision
108570
Author
[email protected]
Date
2012-02-22 16:16:53 -0800 (Wed, 22 Feb 2012)

Log Message

<rdar://problem/10406044> and https://bugs.webkit.org/show_bug.cgi?id=79279
Synchronous ShouldGoToBackForwardListItem causes lots of WebProcess hangs

Reviewed by NOBODY (OOPS!).

Source/WebKit2:

Anytime the WebProcess sends a sync message up to the UI Process a hang can ensue.

In the case of shouldGoToBackForwardListItem it seems many clients want a back/forward
notification but don't actually want to make a policy decision.

Making it an asynchronous notification instead of a synchronous policy call will remove the
possibility of a hang here.

If clients later decide it is important to have a policy here we should implement a form of
shouldGoToBackForwardListItem in the bundle loader client.

Add a notification "willGoToBackForwardListItem" to the WKPageLoaderClient:
* UIProcess/API/C/WKPage.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::initializeLoaderClient): Tell the WebProcess whether it should be
  sending the shouldGoToBackForwardListItem or willGoToBackForwardListItem form of this message.
(WebKit::WebPageProxy::shouldGoToBackForwardListItem):
(WebKit::WebPageProxy::willGoToBackForwardListItem):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in: Add an asynchronous WillGoToBackForwardListItem message

Store a flag in the WebProcess - Sent from the UIProcess - to tell the FrameLoaderClient which form
of the callback should be used:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::willGoToBackForwardItemCallbackEnabled):
(WebKit::WebPage::setWillGoToBackForwardItemCallbackEnabled):
* WebProcess/WebPage/WebPage.messages.in:

* UIProcess/WebLoaderClient.cpp:
(WebKit::WebLoaderClient::shouldGoToBackForwardListItem): Only consider calling this for
  version 0 clients.
(WebKit::WebLoaderClient::willGoToBackForwardListItem): Later clients get this callback.
* UIProcess/WebLoaderClient.h:
(WebLoaderClient):

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::shouldGoToHistoryItem): Send either the synchronous "should" message
  or the asynchronous "will" message depending on which the WebProcess was last told that the
  UIProcess expects. There is an edge case where the wrong one might be sent because the WebProcess
  hasn't received the message about a change in the WKPageLoaderClient yet but that's probably okay;
  It seems unlikely that a UIProcess client would ever rapidly change between v0 and other versions
  of the loader client and the UIProcess of WebKit2 is equipped to handle that case if it comes up.

Tools:

Update our tools to the new form of the PageLoadClient.

* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController awakeFromNib]):

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (108569 => 108570)


--- trunk/Source/WebKit2/ChangeLog	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-23 00:16:53 UTC (rev 108570)
@@ -1,3 +1,56 @@
+2012-02-22  Brady Eidson  <[email protected]>
+
+        <rdar://problem/10406044> and https://bugs.webkit.org/show_bug.cgi?id=79279
+        Synchronous ShouldGoToBackForwardListItem causes lots of WebProcess hangs
+
+        Reviewed by Anders Carlsson.
+
+        Anytime the WebProcess sends a sync message up to the UI Process a hang can ensue.
+        
+        In the case of shouldGoToBackForwardListItem it seems many clients want a back/forward
+        notification but don't actually want to make a policy decision.
+
+        Making it an asynchronous notification instead of a synchronous policy call will remove the
+        possibility of a hang here.
+
+        If clients later decide it is important to have a policy here we should implement a form of
+        shouldGoToBackForwardListItem in the bundle loader client.
+
+        Add a notification "willGoToBackForwardListItem" to the WKPageLoaderClient:
+        * UIProcess/API/C/WKPage.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::initializeLoaderClient): Tell the WebProcess whether it should be
+          sending the shouldGoToBackForwardListItem or willGoToBackForwardListItem form of this message.
+        (WebKit::WebPageProxy::shouldGoToBackForwardListItem): 
+        (WebKit::WebPageProxy::willGoToBackForwardListItem):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in: Add an asynchronous WillGoToBackForwardListItem message
+
+        Store a flag in the WebProcess - Sent from the UIProcess - to tell the FrameLoaderClient which form 
+        of the callback should be used:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::willGoToBackForwardItemCallbackEnabled):
+        (WebKit::WebPage::setWillGoToBackForwardItemCallbackEnabled):
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        * UIProcess/WebLoaderClient.cpp:
+        (WebKit::WebLoaderClient::shouldGoToBackForwardListItem): Only consider calling this for
+          version 0 clients.
+        (WebKit::WebLoaderClient::willGoToBackForwardListItem): Later clients get this callback.
+        * UIProcess/WebLoaderClient.h:
+        (WebLoaderClient):
+        
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::shouldGoToHistoryItem): Send either the synchronous "should" message
+          or the asynchronous "will" message depending on which the WebProcess was last told that the
+          UIProcess expects. There is an edge case where the wrong one might be sent because the WebProcess
+          hasn't received the message about a change in the WKPageLoaderClient yet but that's probably okay;
+          It seems unlikely that a UIProcess client would ever rapidly change between v0 and other versions
+          of the loader client and the UIProcess of WebKit2 is equipped to handle that case if it comes up.
+
 2012-02-16  Jon Lee  <[email protected]>
 
         [WK2] Clearing notifications does not clean up internal state

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.h (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.h	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.h	2012-02-23 00:16:53 UTC (rev 108570)
@@ -71,6 +71,7 @@
 typedef bool (*WKPageShouldGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo);
 typedef void (*WKPageDidFailToInitializePluginCallback)(WKPageRef page, WKStringRef mimeType, const void* clientInfo);
 typedef void (*WKPageDidNewFirstVisuallyNonEmptyLayoutCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
+typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo);
 
 struct WKPageLoaderClient {
     int                                                                 version;
@@ -110,6 +111,8 @@
 
     // FIXME: didFirstVisuallyNonEmptyLayoutForFrame and didNewFirstVisuallyNonEmptyLayout should be merged.
     WKPageDidNewFirstVisuallyNonEmptyLayoutCallback                     didNewFirstVisuallyNonEmptyLayout;
+
+    WKPageWillGoToBackForwardListItemCallback                           willGoToBackForwardListItem;
 };
 typedef struct WKPageLoaderClient WKPageLoaderClient;
 

Modified: trunk/Source/WebKit2/UIProcess/WebLoaderClient.cpp (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/WebLoaderClient.cpp	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/WebLoaderClient.cpp	2012-02-23 00:16:53 UTC (rev 108570)
@@ -241,12 +241,21 @@
 
 bool WebLoaderClient::shouldGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item)
 {
-    if (!m_client.shouldGoToBackForwardListItem)
+    // We should only even considering sending the shouldGoToBackForwardListItem() client callback
+    // for version 0 clients. Later versioned clients should get willGoToBackForwardListItem() instead,
+    // but do to XPC race conditions this one might have been called instead.
+    if (m_client.version > 0 || !m_client.shouldGoToBackForwardListItem)
         return true;
-    
+
     return m_client.shouldGoToBackForwardListItem(toAPI(page), toAPI(item), m_client.clientInfo);
 }
 
+void WebLoaderClient::willGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item)
+{
+    if (m_client.willGoToBackForwardListItem)
+        m_client.willGoToBackForwardListItem(toAPI(page), toAPI(item), m_client.clientInfo);
+}
+
 void WebLoaderClient::didFailToInitializePlugin(WebPageProxy* page, const String& mimeType)
 {
     if (!m_client.didFailToInitializePlugin)

Modified: trunk/Source/WebKit2/UIProcess/WebLoaderClient.h (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/WebLoaderClient.h	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/WebLoaderClient.h	2012-02-23 00:16:53 UTC (rev 108570)
@@ -83,6 +83,7 @@
 
     void didChangeBackForwardList(WebPageProxy*, WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems);
     bool shouldGoToBackForwardListItem(WebPageProxy*, WebBackForwardListItem*);
+    void willGoToBackForwardListItem(WebPageProxy*, WebBackForwardListItem*);
 
     void didFailToInitializePlugin(WebPageProxy*, const String& mimeType);
 };

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2012-02-23 00:16:53 UTC (rev 108570)
@@ -254,6 +254,11 @@
 void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
 {
     m_loaderClient.initialize(loadClient);
+    
+    if (!loadClient)
+        return;
+
+    process()->send(Messages::WebPage::SetWillGoToBackForwardItemCallbackEnabled(loadClient->version > 0), m_pageID);
 }
 
 void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
@@ -608,6 +613,12 @@
     shouldGoToBackForwardItem = item && m_loaderClient.shouldGoToBackForwardListItem(this, item);
 }
 
+void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID)
+{
+    if (WebBackForwardListItem* item = process()->webBackForwardItem(itemID))
+        m_loaderClient.willGoToBackForwardListItem(this, item);
+}
+
 String WebPageProxy::activeURL() const
 {
     if (!m_mainFrame)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-02-23 00:16:53 UTC (rev 108570)
@@ -266,6 +266,7 @@
     void tryRestoreScrollPosition();
     void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems);
     void shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardListItem);
+    void willGoToBackForwardListItem(uint64_t itemID);
 
     String activeURL() const;
     String provisionalURL() const;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (108569 => 108570)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-02-23 00:16:53 UTC (rev 108570)
@@ -163,6 +163,7 @@
     BackForwardForwardListCount() -> (int32_t count)
     BackForwardClear()
     ShouldGoToBackForwardListItem(uint64_t itemID) -> (bool shouldGoToBackForwardListItem)
+    WillGoToBackForwardListItem(uint64_t itemID)
 
     # Undo/Redo messages
     RegisterEditCommandForUndo(uint64_t commandID, uint32_t editAction)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (108569 => 108570)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2012-02-23 00:16:53 UTC (rev 108570)
@@ -932,6 +932,11 @@
         return false;
     }
     
+    if (webPage->willGoToBackForwardItemCallbackEnabled()) {
+        webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID));
+        return true;
+    }
+    
     bool shouldGoToBackForwardListItem;
     if (!webPage->sendSync(Messages::WebPageProxy::ShouldGoToBackForwardListItem(itemID), Messages::WebPageProxy::ShouldGoToBackForwardListItem::Reply(shouldGoToBackForwardListItem)))
         return false;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (108569 => 108570)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-02-23 00:16:53 UTC (rev 108570)
@@ -210,6 +210,7 @@
     , m_numWheelEventHandlers(0)
     , m_cachedPageCount(0)
     , m_isShowingContextMenu(false)
+    , m_willGoToBackForwardItemCallbackEnabled(true)
 #if PLATFORM(WIN)
     , m_gestureReachedScrollingLimit(false)
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (108569 => 108570)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2012-02-23 00:16:53 UTC (rev 108570)
@@ -503,6 +503,8 @@
     void numWheelEventHandlersChanged(unsigned);
     void recomputeShortCircuitHorizontalWheelEventsState();
 
+    bool willGoToBackForwardItemCallbackEnabled() const { return m_willGoToBackForwardItemCallbackEnabled; }
+    
 private:
     WebPage(uint64_t pageID, const WebPageCreationParameters&);
 
@@ -571,6 +573,8 @@
 
     void didRemoveBackForwardItem(uint64_t);
 
+    void setWillGoToBackForwardItemCallbackEnabled(bool enabled) { m_willGoToBackForwardItemCallbackEnabled = enabled; }
+    
     void setDrawsBackground(bool);
     void setDrawsTransparentBackground(bool);
 
@@ -765,6 +769,8 @@
     unsigned m_cachedPageCount;
 
     bool m_isShowingContextMenu;
+    
+    bool m_willGoToBackForwardItemCallbackEnabled;
 
 #if PLATFORM(WIN)
     bool m_gestureReachedScrollingLimit;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (108569 => 108570)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2012-02-23 00:16:53 UTC (rev 108570)
@@ -74,6 +74,7 @@
     RestoreSessionAndNavigateToCurrentItem(WebKit::SessionState state)
 
     DidRemoveBackForwardItem(uint64_t backForwardItemID)
+    SetWillGoToBackForwardItemCallbackEnabled(bool willGoToBackForwardItemEnabled)
 
     DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID)
 

Modified: trunk/Tools/ChangeLog (108569 => 108570)


--- trunk/Tools/ChangeLog	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Tools/ChangeLog	2012-02-23 00:16:53 UTC (rev 108570)
@@ -1,3 +1,18 @@
+2012-02-22  Brady Eidson  <[email protected]>
+
+        <rdar://problem/10406044> and https://bugs.webkit.org/show_bug.cgi?id=79279
+        Synchronous ShouldGoToBackForwardListItem causes lots of WebProcess hangs
+
+        Reviewed by Anders Carlsson.
+
+        Update our tools to the new form of the PageLoadClient.
+
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (-[BrowserWindowController awakeFromNib]): 
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::initialize):
+
 2012-02-22  Daniel Bates  <[email protected]>
 
         new-run-webkit-tests shouldn't restore Safari state on Lion when showing results

Modified: trunk/Tools/MiniBrowser/mac/BrowserWindowController.m (108569 => 108570)


--- trunk/Tools/MiniBrowser/mac/BrowserWindowController.m	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Tools/MiniBrowser/mac/BrowserWindowController.m	2012-02-23 00:16:53 UTC (rev 108570)
@@ -606,9 +606,10 @@
         processDidExit,
         didChangeBackForwardList,
         0, // shouldGoToBackForwardItem
-        0,  // didFailToInitializePlugin
+        0, // didFailToInitializePlugin
         didDetectXSSForFrame,
         0, // didNewFirstVisuallyNonEmptyLayout
+        0, // willGoToBackForwardListItem
     };
     WKPageSetPageLoaderClient(_webView.pageRef, &loadClient);
     

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (108569 => 108570)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2012-02-22 23:47:56 UTC (rev 108569)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2012-02-23 00:16:53 UTC (rev 108570)
@@ -397,7 +397,8 @@
         0, // shouldGoToBackForwardListItem
         0, // didRunInsecureContentForFrame
         0, // didDetectXSSForFrame 
-        0  // didNewFirstVisuallyNonEmptyLayout 
+        0, // didNewFirstVisuallyNonEmptyLayout
+        0, // willGoToBackForwardListItem
     };
     WKPageSetPageLoaderClient(m_mainWebView->page(), &pageLoaderClient);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to