Changeset 240178 in webkit


Ignore:
Timestamp:
Jan 18, 2019 3:02:55 PM (5 years ago)
Author:
Chris Dumez
Message:

Regression(PSON) Content blockers are sometimes lost on back navigation cross-site
https://bugs.webkit.org/show_bug.cgi?id=193588
<rdar://problem/47131566>

Reviewed by Alex Christensen.

Source/WebKit:

When the WebPageProxy needs to create initialization parameters for its WebPage in the
WebContent process, it calls WebProcessProxy::addWebUserContentControllerProxy()
which calls WebUserContentControllerProxy::addProcess(). This last call is supposed to
register the WebProcessProxy with the WebUserContentControllerProxy and adding the
contentRuleLists to the WebPageCreationParameters. The issue is that if the
WebUserContentControllerProxy already knows about this WebProcessProxy, it would return
early and not populate the WebPageCreationParameters.

In PSON world, when navigating back to a page that failed to enter page cache, we reuse
the process where we previously loaded the page but re-create a new WebPage on the
WebContent process site. When this happens, WebUserContentControllerProxy would not
add the contentRuleLists to the WebPageCreationParameters and the new WebPage in the
previously-suspended process would be missing them.

  • UIProcess/UserContent/WebUserContentControllerProxy.cpp:

(WebKit::WebUserContentControllerProxy::addProcess):

Tools:

Add layout test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r240176 r240178  
     12019-01-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Regression(PSON) Content blockers are sometimes lost on back navigation cross-site
     4        https://bugs.webkit.org/show_bug.cgi?id=193588
     5        <rdar://problem/47131566>
     6
     7        Reviewed by Alex Christensen.
     8
     9        When the WebPageProxy needs to create initialization parameters for its WebPage in the
     10        WebContent process, it calls WebProcessProxy::addWebUserContentControllerProxy()
     11        which calls WebUserContentControllerProxy::addProcess(). This last call is supposed to
     12        register the WebProcessProxy with the WebUserContentControllerProxy and adding the
     13        contentRuleLists to the WebPageCreationParameters. The issue is that if the
     14        WebUserContentControllerProxy already knows about this WebProcessProxy, it would return
     15        early and not populate the WebPageCreationParameters.
     16
     17        In PSON world, when navigating back to a page that failed to enter page cache, we reuse
     18        the process where we previously loaded the page but re-create a new WebPage on the
     19        WebContent process site. When this happens, WebUserContentControllerProxy would not
     20        add the contentRuleLists to the WebPageCreationParameters and the new WebPage in the
     21        previously-suspended process would be missing them.
     22
     23        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
     24        (WebKit::WebUserContentControllerProxy::addProcess):
     25
    1262019-01-18  Jer Noble  <jer.noble@apple.com>
    227
  • trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp

    r233752 r240178  
    8585void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy, WebPageCreationParameters& parameters)
    8686{
    87     if (!m_processes.add(&webProcessProxy).isNewEntry)
    88         return;
    89 
    90     webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier().toUInt64(), *this);
     87    if (m_processes.add(&webProcessProxy).isNewEntry)
     88        webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier().toUInt64(), *this);
    9189
    9290    ASSERT(parameters.userContentWorlds.isEmpty());
  • trunk/Tools/ChangeLog

    r240176 r240178  
     12019-01-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Regression(PSON) Content blockers are sometimes lost on back navigation cross-site
     4        https://bugs.webkit.org/show_bug.cgi?id=193588
     5        <rdar://problem/47131566>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Add layout test coverage.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     12
    1132019-01-18  Jer Noble  <jer.noble@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r240161 r240178  
    2929#import "Test.h"
    3030#import "TestNavigationDelegate.h"
     31#import <WebKit/WKContentRuleListStore.h>
    3132#import <WebKit/WKNavigationDelegatePrivate.h>
    3233#import <WebKit/WKNavigationPrivate.h>
     
    39213922#endif // PLATFORM(MAC)
    39223923
     3924static NSString *blockmeFilter = @"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*blockme.html\"}}]";
     3925
     3926static const char* contentBlockingAfterProcessSwapTestBytes = R"PSONRESOURCE(
     3927<body>
     3928<script>
     3929let wasSubframeLoaded = false;
     3930// Pages with dedicated workers do not go into page cache.
     3931var myWorker = new Worker('worker.js');
     3932</script>
     3933<iframe src="blockme.html"></iframe>
     3934</body>
     3935)PSONRESOURCE";
     3936
     3937static const char* markSubFrameAsLoadedTestBytes = R"PSONRESOURCE(
     3938<script>
     3939top.wasSubframeLoaded = true;
     3940</script>
     3941)PSONRESOURCE";
     3942
     3943TEST(ProcessSwap, ContentBlockingAfterProcessSwap)
     3944{
     3945    [[WKContentRuleListStore defaultStore] removeContentRuleListForIdentifier:@"ContentBlockingAfterProcessSwapExtension" completionHandler:^(NSError *error) {
     3946        done = true;
     3947    }];
     3948    TestWebKitAPI::Util::run(&done);
     3949    done = false;
     3950
     3951    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     3952    [processPoolConfiguration setProcessSwapsOnNavigation:YES];
     3953    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     3954
     3955    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     3956    [webViewConfiguration setProcessPool:processPool.get()];
     3957
     3958    __block bool doneCompiling = false;
     3959    [[WKContentRuleListStore defaultStore] compileContentRuleListForIdentifier:@"ContentBlockingAfterProcessSwapExtension" encodedContentRuleList:blockmeFilter completionHandler:^(WKContentRuleList *ruleList, NSError *error) {
     3960
     3961        EXPECT_NOT_NULL(ruleList);
     3962        EXPECT_NULL(error);
     3963
     3964        [webViewConfiguration.get().userContentController addContentRuleList:ruleList];
     3965
     3966        doneCompiling = true;
     3967    }];
     3968    TestWebKitAPI::Util::run(&doneCompiling);
     3969
     3970    auto handler = adoptNS([[PSONScheme alloc] init]);
     3971    [handler addMappingFromURLString:@"pson://www.webkit.org/main.html" toData:contentBlockingAfterProcessSwapTestBytes];
     3972    [handler addMappingFromURLString:@"pson://www.webkit.org/blockme.html" toData:markSubFrameAsLoadedTestBytes];
     3973    [handler addMappingFromURLString:@"pson://www.apple.com/main.html" toData:contentBlockingAfterProcessSwapTestBytes];
     3974    [handler addMappingFromURLString:@"pson://www.apple.com/blockme.html" toData:markSubFrameAsLoadedTestBytes];
     3975    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     3976
     3977    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     3978    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
     3979    [webView setNavigationDelegate:delegate.get()];
     3980
     3981    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main.html"]];
     3982    [webView loadRequest:request];
     3983    TestWebKitAPI::Util::run(&done);
     3984    done = false;
     3985
     3986    [webView evaluateJavaScript:@"window.wasSubframeLoaded ? 'FAIL' : 'PASS'" completionHandler: [&] (id result, NSError *error) {
     3987        NSString *blockSuccess = (NSString *)result;
     3988        EXPECT_WK_STREQ(@"PASS", blockSuccess);
     3989        done = true;
     3990    }];
     3991    TestWebKitAPI::Util::run(&done);
     3992    done = false;
     3993
     3994    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.apple.com/main.html"]];
     3995    [webView loadRequest:request];
     3996    TestWebKitAPI::Util::run(&done);
     3997    done = false;
     3998
     3999    [webView evaluateJavaScript:@"window.wasSubframeLoaded ? 'FAIL' : 'PASS'" completionHandler: [&] (id result, NSError *error) {
     4000        NSString *blockSuccess = (NSString *)result;
     4001        EXPECT_WK_STREQ(@"PASS", blockSuccess);
     4002        done = true;
     4003    }];
     4004    TestWebKitAPI::Util::run(&done);
     4005    done = false;
     4006
     4007    [webView goBack];
     4008    TestWebKitAPI::Util::run(&done);
     4009    done = false;
     4010
     4011    [webView evaluateJavaScript:@"window.wasSubframeLoaded ? 'FAIL' : 'PASS'" completionHandler: [&] (id result, NSError *error) {
     4012        NSString *blockSuccess = (NSString *)result;
     4013        EXPECT_WK_STREQ(@"PASS", blockSuccess);
     4014        done = true;
     4015    }];
     4016    TestWebKitAPI::Util::run(&done);
     4017    done = false;
     4018
     4019    [webView goForward];
     4020    TestWebKitAPI::Util::run(&done);
     4021    done = false;
     4022
     4023    [webView evaluateJavaScript:@"window.wasSubframeLoaded ? 'FAIL' : 'PASS'" completionHandler: [&] (id result, NSError *error) {
     4024        NSString *blockSuccess = (NSString *)result;
     4025        EXPECT_WK_STREQ(@"PASS", blockSuccess);
     4026        done = true;
     4027    }];
     4028    TestWebKitAPI::Util::run(&done);
     4029    done = false;
     4030
     4031    [[WKContentRuleListStore defaultStore] removeContentRuleListForIdentifier:@"ContentBlockingAfterProcessSwapExtension" completionHandler:^(NSError *error) {
     4032        done = true;
     4033    }];
     4034    TestWebKitAPI::Util::run(&done);
     4035    done = false;
     4036}
     4037
    39234038#endif // WK_API_ENABLED
Note: See TracChangeset for help on using the changeset viewer.