Introduce SuspendedPageProxy to keep old web processes around after their WebPageProx...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2018 18:04:22 +0000 (18:04 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2018 18:04:22 +0000 (18:04 +0000)
commitaf3883362ae54329b6442c2731dd8008289fea6f
tree49f4be5e4b8e6353d5c9cd5520015e7cd38347dd
parent24d7a584db780298b42f0c86fab43105d0a061ff
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one.
https://bugs.webkit.org/show_bug.cgi?id=184559

Reviewed by Alex Christensen.

Source/WebCore:

Covered by new API test.

WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::redirectReceived):
(WebCore::DocumentLoader::willSendRequest):
(WebCore::DocumentLoader::startLoadingMainResource):
* loader/DocumentLoader.h:

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::init):
(WebCore::FrameLoader::continueLoadAfterNavigationPolicy):

Source/WebKit:

Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away.

This is not desirable for a few reasons:
1 - We can't keep the PageCache working for back/forward scenarios
2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch
    and initialize a new web process.

This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it.

For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process.
Additionally, that process is never reused.

So no benefit is achieved with this patch, but it enables future benefits.

* Platform/Logging.h:

* Shared/WebBackForwardListItem.cpp:
(WebKit::WebBackForwardListItem::setSuspendedPage):
* Shared/WebBackForwardListItem.h:

New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view.
* UIProcess/SuspendedPageProxy.cpp: Added.
(WebKit::SuspendedPageProxy::SuspendedPageProxy):
(WebKit::SuspendedPageProxy::~SuspendedPageProxy):
(WebKit::SuspendedPageProxy::webProcessDidClose):
(WebKit::SuspendedPageProxy::didFinishLoad):
(WebKit::SuspendedPageProxy::didReceiveMessage):
(WebKit::SuspendedPageProxy::loggingString const):
* UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h.
(WebKit::SuspendedPageProxy::create):
(WebKit::SuspendedPageProxy::page const):
(WebKit::SuspendedPageProxy::process const):
(WebKit::SuspendedPageProxy::item const):
(WebKit::SuspendedPageProxy::finishedSuspending const):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reattachToWebProcess):
(WebKit::WebPageProxy::attachToProcessForNavigation):
(WebKit::WebPageProxy::maybeCreateSuspendedPage):
(WebKit::WebPageProxy::suspendedPageProcessClosed):
(WebKit::WebPageProxy::receivedPolicyDecision):
(WebKit::WebPageProxy::didFinishLoadForFrame):
* UIProcess/WebPageProxy.h:

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::suspendWebPageProxy):
(WebKit::WebProcessProxy::suspendedPageWasDestroyed):
(WebKit::WebProcessProxy::removeWebPage):
(WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects.
(WebKit::WebProcessProxy::didClose):
(WebKit::WebProcessProxy::maybeShutDown):
(WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages.
* UIProcess/WebProcessProxy.h:

* WebKit.xcodeproj/project.pbxproj:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setIsSuspended):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon.
* WebProcess/WebPage/WebPage.messages.in:

* WebProcess/WebProcess.messages.in:
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name.

Source/WTF:

* wtf/DebugUtilities.h:
(WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop.
  This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/DebugUtilities.h
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebKit/ChangeLog
Source/WebKit/Platform/Logging.h
Source/WebKit/Shared/WebBackForwardListItem.cpp
Source/WebKit/Shared/WebBackForwardListItem.h
Source/WebKit/UIProcess/SuspendedPageProxy.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/SuspendedPageProxy.h [new file with mode: 0644]
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebProcess.messages.in
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm