First piece of process swapping on navigation.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 00:05:58 +0000 (00:05 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 00:05:58 +0000 (00:05 +0000)
commita6192bc3fd135a56128c2661e53eb0f4f769b3a0
tree784cae8e543e851a26b0d2b24db297357956b9c7
parent9a37b59242df964d60f16a4d492f3c1e1d9892e0
First piece of process swapping on navigation.
https://bugs.webkit.org/show_bug.cgi?id=183665

Reviewed by Andy Estes.

Source/WebCore:

Covered by API test(s)

This patch:
- A new PolicyAction::Suspend for future use in this feature
- Makes sure that loads triggered as part of a process swap do *not* re-consult the policy delegate

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::continueAfterContentPolicy):

* loader/FrameLoadRequest.h:
(WebCore::FrameLoadRequest::setShouldCheckNavigationPolicy):
(WebCore::FrameLoadRequest::shouldCheckNavigationPolicy const):

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::load):
(WebCore::FrameLoader::loadWithDocumentLoader):
* loader/FrameLoader.h:

* loader/FrameLoaderTypes.h: Add a new Policy type "Suspend" to be used in the future
  by the process-swap-on-navigation mechanism.

* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkNavigationPolicy):
(WebCore::PolicyChecker::checkNewWindowPolicy):

Source/WebKit:

This patch adds the first pieces of the following feature:
"When a navigation originating inside a WKWebView goes to a different origin,
 swap to a new WebProcess for that navigation"

There are significant bugs to be resolved and significant optimizations to be made.
Which is why the feature is disabled by default.

Besides the core logic implementing the feature, this patch does a lot of related
work such as:
- Removing some now-invalid ASSERTs
- Adding some ASSERTs
- Update various switch states to handle the new "Suspend" policy and "NavigationSwap"
  process termination reason

* NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):

* NetworkProcess/capture/NetworkDataTaskReplay.cpp:
(WebKit::NetworkCapture::NetworkDataTaskReplay::didReceiveResponse):

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(toNSURLSessionResponseDisposition):

* Platform/Logging.h:

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

* Shared/ProcessTerminationReason.h: Add "NavigationSwap" as a process termination reason.

* UIProcess/API/APINavigation.h:

* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):

* UIProcess/API/C/WKAPICast.h:
(WebKit::toAPI):

* UIProcess/Cocoa/NavigationState.mm:
(WebKit::wkProcessTerminationReason):

* UIProcess/WebFramePolicyListenerProxy.cpp:
(WebKit::WebFramePolicyListenerProxy::WebFramePolicyListenerProxy):
* UIProcess/WebFramePolicyListenerProxy.h:
(WebKit::WebFramePolicyListenerProxy::create):
(WebKit::WebFramePolicyListenerProxy::policyListenerType const):

* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::setUpPolicyListenerProxy):
(WebKit::WebFrameProxy::activePolicyListenerProxy):
* UIProcess/WebFrameProxy.h:

* UIProcess/WebNavigationState.cpp:
(WebKit::WebNavigationState::navigation):
(WebKit::WebNavigationState::takeNavigation):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reattachToWebProcess):
(WebKit::WebPageProxy::attachToProcessForNavigation): Pretend that the existing process
  terminated using the new "NavigationSwap" reason, then manually start the next load.
(WebKit::WebPageProxy::loadRequest):
(WebKit::WebPageProxy::loadRequestWithNavigation):
(WebKit::WebPageProxy::receivedPolicyDecision):
(WebKit::WebPageProxy::continueNavigationInNewProcess):
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::decidePolicyForResponse):
(WebKit::WebPageProxy::processDidTerminate):
(WebKit::WebPageProxy::resetState):
(WebKit::WebPageProxy::resetStateAfterProcessExited):
* UIProcess/WebPageProxy.h:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::processForNavigation): Determine which process should be used
  for a proposed navigation, creating a new one if necessary.
* UIProcess/WebProcessPool.h:

* UIProcess/WebStorage/StorageManager.cpp:
(WebKit::StorageManager::SessionStorageNamespace::setAllowedConnection):

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadRequest):

Tools:

Expose the "swaps processes on navigation" setting in MiniBrowser UI for testing:

* MiniBrowser/mac/AppDelegate.m:
(defaultConfiguration):
* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]):
(-[SettingsController validateMenuItem:]):
(-[SettingsController processSwapOnNavigationEnabled]):
(-[SettingsController toggleProcessSwapOnNavigation:]):

Makes sure the current behavior is tested:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Added.
(-[PSONNavigationDelegate webView:didFinishNavigation:]):
(-[PSONScheme webView:startURLSchemeTask:]):
(-[PSONScheme webView:stopURLSchemeTask:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
36 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/FrameLoadRequest.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/loader/FrameLoaderTypes.h
Source/WebCore/loader/PolicyChecker.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp
Source/WebKit/NetworkProcess/capture/NetworkDataTaskReplay.cpp
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Source/WebKit/Platform/Logging.h
Source/WebKit/Shared/LoadParameters.cpp
Source/WebKit/Shared/LoadParameters.h
Source/WebKit/Shared/ProcessTerminationReason.h
Source/WebKit/UIProcess/API/APINavigation.h
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp
Source/WebKit/UIProcess/API/C/WKAPICast.h
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/UIProcess/WebFramePolicyListenerProxy.cpp
Source/WebKit/UIProcess/WebFramePolicyListenerProxy.h
Source/WebKit/UIProcess/WebFrameProxy.cpp
Source/WebKit/UIProcess/WebFrameProxy.h
Source/WebKit/UIProcess/WebNavigationState.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebStorage/StorageManager.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/SettingsController.h
Tools/MiniBrowser/mac/SettingsController.m
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm [new file with mode: 0644]