Title: [230315] trunk
Revision
230315
Author
beid...@apple.com
Date
2018-04-05 16:18:01 -0700 (Thu, 05 Apr 2018)

Log Message

Process Swap on Navigation causes many webpages to hang due to attempted process swap for iframe navigations.
<rdar://problem/39162236> and https://bugs.webkit.org/show_bug.cgi?id=184318

Reviewed by Andy Estes.

Source/WebKit:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::receivedPolicyDecision): Don't consider a swap if the navigation is not in the main frame.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
(-[PSONMessageHandler userContentController:didReceiveScriptMessage:]):
(-[PSONScheme addMappingFromURLString:toData:]):
(-[PSONScheme webView:startURLSchemeTask:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230314 => 230315)


--- trunk/Source/WebKit/ChangeLog	2018-04-05 21:21:50 UTC (rev 230314)
+++ trunk/Source/WebKit/ChangeLog	2018-04-05 23:18:01 UTC (rev 230315)
@@ -1,3 +1,13 @@
+2018-04-05  Brady Eidson  <beid...@apple.com>
+
+        Process Swap on Navigation causes many webpages to hang due to attempted process swap for iframe navigations.
+        <rdar://problem/39162236> and https://bugs.webkit.org/show_bug.cgi?id=184318
+
+        Reviewed by Andy Estes.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::receivedPolicyDecision): Don't consider a swap if the navigation is not in the main frame.
+
 2018-04-05  Ryosuke Niwa  <rn...@webkit.org>
 
         WebContent process sometimes hangs in WebProcess::ensureNetworkProcessConnection

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (230314 => 230315)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-04-05 21:21:50 UTC (rev 230314)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-04-05 23:18:01 UTC (rev 230315)
@@ -2350,7 +2350,7 @@
     if (activePolicyListener && activePolicyListener->policyListenerType() == PolicyListenerType::NavigationAction) {
         ASSERT(activePolicyListener->listenerID() == listenerID);
 
-        if (action == PolicyAction::Use && navigation) {
+        if (action == PolicyAction::Use && navigation && frame.isMainFrame()) {
             auto proposedProcess = process().processPool().processForNavigation(*this, *navigation, action);
 
             if (proposedProcess.ptr() != &process()) {

Modified: trunk/Tools/ChangeLog (230314 => 230315)


--- trunk/Tools/ChangeLog	2018-04-05 21:21:50 UTC (rev 230314)
+++ trunk/Tools/ChangeLog	2018-04-05 23:18:01 UTC (rev 230315)
@@ -1,3 +1,15 @@
+2018-04-05  Brady Eidson  <beid...@apple.com>
+
+        Process Swap on Navigation causes many webpages to hang due to attempted process swap for iframe navigations.
+        <rdar://problem/39162236> and https://bugs.webkit.org/show_bug.cgi?id=184318
+
+        Reviewed by Andy Estes.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+        (-[PSONMessageHandler userContentController:didReceiveScriptMessage:]):
+        (-[PSONScheme addMappingFromURLString:toData:]):
+        (-[PSONScheme webView:startURLSchemeTask:]):
+
 2018-04-05  Yusuke Suzuki  <utatane....@gmail.com>
 
         [WTF] Remove StaticLock

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (230314 => 230315)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2018-04-05 21:21:50 UTC (rev 230314)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2018-04-05 23:18:01 UTC (rev 230315)
@@ -73,6 +73,7 @@
         [receivedMessages addObject:@""];
 
     receivedMessage = true;
+    seenPIDs.add([message.webView _webProcessIdentifier]);
 }
 @end
 
@@ -134,9 +135,11 @@
 @interface PSONScheme : NSObject <WKURLSchemeHandler> {
     const char* _bytes;
     HashMap<String, String> _redirects;
+    HashMap<String, RetainPtr<NSData *>> _dataMappings;
 }
 - (instancetype)initWithBytes:(const char*)bytes;
 - (void)addRedirectFromURLString:(NSString *)sourceURLString toURLString:(NSString *)destinationURLString;
+- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data;
 @end
 
 @implementation PSONScheme
@@ -153,6 +156,11 @@
     _redirects.set(sourceURLString, destinationURLString);
 }
 
+- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data
+{
+    _dataMappings.set(urlString, [NSData dataWithBytesNoCopy:(void*)data length:strlen(data) freeWhenDone:NO]);
+}
+
 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
 {
     NSURL *finalURL = task.request.URL;
@@ -169,7 +177,9 @@
     RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:finalURL MIMEType:@"text/html" expectedContentLength:1 textEncodingName:nil]);
     [task didReceiveResponse:response.get()];
 
-    if (_bytes) {
+    if (auto data = "" absoluteString]))
+        [task didReceiveData:data.get()];
+    else if (_bytes) {
         RetainPtr<NSData> data = "" alloc] initWithBytesNoCopy:(void *)_bytes length:strlen(_bytes) freeWhenDone:NO]);
         [task didReceiveData:data.get()];
     } else
@@ -687,4 +697,58 @@
     EXPECT_TRUE([receivedMessages.get()[1] isEqualToString:@"I exist!"]);
 }
 
+static const char* mainFramesOnlyMainFrame = R"PSONRESOURCE(
+<script>
+function loaded() {
+    setTimeout('window.frames[0].location.href = "" 0);
+}
+</script>
+<body _onload_="loaded();">
+Some text
+<iframe src=""
+</body>
+)PSONRESOURCE";
+
+static const char* mainFramesOnlySubframe = R"PSONRESOURCE(
+Some content
+)PSONRESOURCE";
+
+
+static const char* mainFramesOnlySubframe2 = R"PSONRESOURCE(
+<script>
+    window.webkit.messageHandlers.pson.postMessage("Done");
+</script>
+)PSONRESOURCE";
+
+TEST(ProcessSwap, MainFramesOnly)
+{
+    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+    [processPoolConfiguration setProcessSwapsOnNavigation:YES];
+    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setProcessPool:processPool.get()];
+    auto handler = adoptNS([[PSONScheme alloc] init]);
+    [handler addMappingFromURLString:@"pson1://host/main.html" toData:mainFramesOnlyMainFrame];
+    [handler addMappingFromURLString:@"pson1://host/iframe" toData:mainFramesOnlySubframe];
+    [handler addMappingFromURLString:@"pson2://host2/main.html" toData:mainFramesOnlySubframe2];
+    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON1"];
+    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON2"];
+
+    auto messageHandler = adoptNS([[PSONMessageHandler alloc] init]);
+    [[webViewConfiguration userContentController] addScriptMessageHandler:messageHandler.get() name:@"pson"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson1://host/main.html"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&receivedMessage);
+    receivedMessage = false;
+
+    EXPECT_EQ(1u, seenPIDs.size());
+}
+
 #endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to