⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287040 in webkit


Ignore:
Timestamp:
Dec 14, 2021, 12:11:03 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Add _WKContentRuleListAction.redirected and .modifiedHeaders
https://bugs.webkit.org/show_bug.cgi?id=234289

Reviewed by Tim Hatcher.

Source/WebCore:

These inform the UI process about new actions taken by the extension.

  • contentextensions/ContentExtensionsBackend.cpp:

(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
(WebCore::ContentExtensions::applyResultsToRequest):

  • contentextensions/ContentRuleListResults.h:

(WebCore::ContentRuleListResults::shouldNotifyApplication const):
(WebCore::ContentRuleListResults::Result::encode const):
(WebCore::ContentRuleListResults::Result::decode):
(WebCore::ContentRuleListResults::Result::shouldNotifyApplication const): Deleted.

Source/WebKit:

  • UIProcess/API/APIContentRuleListAction.cpp:

(API::ContentRuleListAction::redirected const):
(API::ContentRuleListAction::modifiedHeaders const):

  • UIProcess/API/APIContentRuleListAction.h:
  • UIProcess/API/Cocoa/_WKContentRuleListAction.h:
  • UIProcess/API/Cocoa/_WKContentRuleListAction.mm:

(-[_WKContentRuleListAction redirected]):
(-[_WKContentRuleListAction modifiedHeaders]):

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::contentRuleListNotification):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:

(checkURLs):
(TEST_F):

  • TestWebKitAPI/cocoa/TestNavigationDelegate.h:
  • TestWebKitAPI/cocoa/TestNavigationDelegate.mm:

(-[TestNavigationDelegate _webView:contentRuleListWithIdentifier:performedAction:forURL:]):

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287038 r287040  
     12021-12-14  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add _WKContentRuleListAction.redirected and .modifiedHeaders
     4        https://bugs.webkit.org/show_bug.cgi?id=234289
     5
     6        Reviewed by Tim Hatcher.
     7
     8        These inform the UI process about new actions taken by the extension.
     9
     10        * contentextensions/ContentExtensionsBackend.cpp:
     11        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
     12        (WebCore::ContentExtensions::applyResultsToRequest):
     13        * contentextensions/ContentRuleListResults.h:
     14        (WebCore::ContentRuleListResults::shouldNotifyApplication const):
     15        (WebCore::ContentRuleListResults::Result::encode const):
     16        (WebCore::ContentRuleListResults::Result::decode):
     17        (WebCore::ContentRuleListResults::Result::shouldNotifyApplication const): Deleted.
     18
    1192021-12-14  Tyler Wilcock  <tyler_w@apple.com>
    220
  • trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp

    r287010 r287040  
    249249                RELEASE_ASSERT_NOT_REACHED();
    250250            }, [&] (const ModifyHeadersAction& action) {
    251                 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url))
     251                if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url)) {
     252                    result.modifiedHeaders = true;
    252253                    results.summary.modifyHeadersActions.append(action);
     254                }
    253255            }, [&] (const RedirectAction& redirectAction) {
    254                 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url))
     256                if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url)) {
     257                    result.redirected = true;
    255258                    results.summary.redirectActions.append({ redirectAction, m_contentExtensions.get(contentRuleListIdentifier)->extensionBaseURL() });
     259                }
    256260            }), action.data());
    257261        }
  • trunk/Source/WebCore/contentextensions/ContentRuleListResults.h

    r286084 r287040  
    4040        bool madeHTTPS { false };
    4141        bool blockedCookies { false };
     42        bool modifiedHeaders { false };
     43        bool redirected { false };
    4244        Vector<String> notifications;
    4345       
     
    4749                || madeHTTPS
    4850                || blockedCookies
     51                || modifiedHeaders
     52                || redirected
    4953                || !notifications.isEmpty();
    5054        }
     
    7478            || summary.madeHTTPS
    7579            || summary.blockedCookies
     80            || !summary.modifyHeadersActions.isEmpty()
     81            || !summary.redirectActions.isEmpty()
    7682            || summary.hasNotifications;
    7783    }
     
    106112    encoder << madeHTTPS;
    107113    encoder << blockedCookies;
     114    encoder << modifiedHeaders;
     115    encoder << redirected;
    108116    encoder << notifications;
    109117}
     
    124132    decoder >> blockedCookies;
    125133    if (!blockedCookies)
     134        return std::nullopt;
     135   
     136    std::optional<bool> modifiedHeaders;
     137    decoder >> modifiedHeaders;
     138    if (!modifiedHeaders)
     139        return std::nullopt;
     140   
     141    std::optional<bool> redirected;
     142    decoder >> redirected;
     143    if (!redirected)
    126144        return std::nullopt;
    127145   
     
    135153        WTFMove(*madeHTTPS),
    136154        WTFMove(*blockedCookies),
     155        WTFMove(*modifiedHeaders),
     156        WTFMove(*redirected),
    137157        WTFMove(*notifications)
    138158    }};
  • trunk/Source/WebKit/ChangeLog

    r287039 r287040  
     12021-12-14  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add _WKContentRuleListAction.redirected and .modifiedHeaders
     4        https://bugs.webkit.org/show_bug.cgi?id=234289
     5
     6        Reviewed by Tim Hatcher.
     7
     8        * UIProcess/API/APIContentRuleListAction.cpp:
     9        (API::ContentRuleListAction::redirected const):
     10        (API::ContentRuleListAction::modifiedHeaders const):
     11        * UIProcess/API/APIContentRuleListAction.h:
     12        * UIProcess/API/Cocoa/_WKContentRuleListAction.h:
     13        * UIProcess/API/Cocoa/_WKContentRuleListAction.mm:
     14        (-[_WKContentRuleListAction redirected]):
     15        (-[_WKContentRuleListAction modifiedHeaders]):
     16        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     17        (WebKit::WebChromeClient::contentRuleListNotification):
     18
    1192021-12-14  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListAction.cpp

    r285980 r287040  
    5858}
    5959
     60bool ContentRuleListAction::redirected() const
     61{
     62    return m_result.redirected;
     63}
     64
     65bool ContentRuleListAction::modifiedHeaders() const
     66{
     67    return m_result.modifiedHeaders;
     68}
     69
    6070const Vector<WTF::String>& ContentRuleListAction::notifications() const
    6171{
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListAction.h

    r285980 r287040  
    4141    bool madeHTTPS() const;
    4242    bool blockedCookies() const;
     43    bool redirected() const;
     44    bool modifiedHeaders() const;
    4345    const Vector<WTF::String>& notifications() const;
    4446
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKContentRuleListAction.h

    r252174 r287040  
    3333@property (nonatomic, readonly) BOOL blockedCookies;
    3434@property (nonatomic, readonly) BOOL madeHTTPS;
     35@property (nonatomic, readonly) BOOL redirected WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     36@property (nonatomic, readonly) BOOL modifiedHeaders WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    3537@property (nonatomic, readonly, copy) NSArray<NSString *> *notifications;
    3638
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKContentRuleListAction.mm

    r285980 r287040  
    6969}
    7070
     71- (BOOL)redirected
     72{
     73#if ENABLE(CONTENT_EXTENSIONS)
     74    return _action->redirected();
     75#else
     76    return NO;
     77#endif
     78}
     79
     80- (BOOL)modifiedHeaders
     81{
     82#if ENABLE(CONTENT_EXTENSIONS)
     83    return _action->modifiedHeaders();
     84#else
     85    return NO;
     86#endif
     87}
     88
    7189- (NSArray<NSString *> *)notifications
    7290{
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r286886 r287040  
    10031003{
    10041004#if ENABLE(CONTENT_EXTENSIONS)
    1005     ASSERT(results.shouldNotifyApplication());
    10061005    m_page.send(Messages::WebPageProxy::ContentRuleListNotification(url, results));
    10071006#endif
  • trunk/Tools/ChangeLog

    r287039 r287040  
     12021-12-14  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add _WKContentRuleListAction.redirected and .modifiedHeaders
     4        https://bugs.webkit.org/show_bug.cgi?id=234289
     5
     6        Reviewed by Tim Hatcher.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:
     9        (checkURLs):
     10        (TEST_F):
     11        * TestWebKitAPI/cocoa/TestNavigationDelegate.h:
     12        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
     13        (-[TestNavigationDelegate _webView:contentRuleListWithIdentifier:performedAction:forURL:]):
     14
    1152021-12-14  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm

    r286545 r287040  
    3535#import <WebKit/WKUserContentControllerPrivate.h>
    3636#import <WebKit/WKWebpagePreferencesPrivate.h>
     37#import <WebKit/_WKContentRuleListAction.h>
    3738#import <WebKit/_WKUserContentExtensionStore.h>
    3839#import <WebKit/_WKUserContentFilter.h>
    3940#import <wtf/RetainPtr.h>
    4041#import <wtf/Vector.h>
     42#import <wtf/text/WTFString.h>
    4143
    4244class WKContentRuleListStoreTest : public testing::Test {
     
    504506    };
    505507    return delegate;
     508}
     509
     510static void checkURLs(const Vector<String>& actual, const Vector<String>& expected)
     511{
     512    EXPECT_EQ(actual.size(), expected.size());
     513    for (size_t i = 0; i < std::min(actual.size(), expected.size()); i++)
     514        EXPECT_WK_STREQ(actual[i], expected[i]);
    506515}
    507516
     
    563572    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testscheme"];
    564573    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSZeroRect configuration:configuration.get()]);
    565     webView.get().navigationDelegate = navigationDelegateAllowingActiveActionsOnTestHost().get();
     574    auto delegate = navigationDelegateAllowingActiveActionsOnTestHost().get();
     575    webView.get().navigationDelegate = delegate;
     576    __block bool receivedActionNotification { false };
     577    __block Vector<String> urls;
     578    delegate.contentRuleListPerformedAction = ^(WKWebView *, NSString *identifier, _WKContentRuleListAction *action, NSURL *url) {
     579        urls.append(url.absoluteString);
     580        EXPECT_TRUE(action.modifiedHeaders);
     581        receivedActionNotification = true;
     582    };
    566583    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"testscheme://testhost/main.html"]]];
    567584    TestWebKitAPI::Util::run(&receivedAllRequests);
     585    TestWebKitAPI::Util::run(&receivedActionNotification);
     586    checkURLs(urls, {
     587        "testscheme://testhost/main.html",
     588        "testscheme://testhost/fetch.txt"
     589    });
    568590   
    569591    // FIXME: Appending to the User-Agent replaces the user agent because we haven't added the user agent yet when processing the request.
     
    668690    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"othertestscheme"];
    669691    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSZeroRect configuration:configuration.get()]);
    670     webView.get().navigationDelegate = navigationDelegateAllowingActiveActionsOnTestHost().get();
     692    auto delegate = navigationDelegateAllowingActiveActionsOnTestHost().get();
     693    webView.get().navigationDelegate = delegate;
     694    __block bool receivedActionNotification { false };
     695    __block Vector<String> urlsFromCallback;
     696    delegate.contentRuleListPerformedAction = ^(WKWebView *, NSString *identifier, _WKContentRuleListAction *action, NSURL *url) {
     697        urlsFromCallback.append(url.absoluteString);
     698        EXPECT_TRUE(action.redirected);
     699        receivedActionNotification = true;
     700    };
     701
    671702    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"testscheme://testhost/main.html"]]];
    672703    TestWebKitAPI::Util::run(&receivedAllRequests);
    673 
    674     Vector<const char*> expectedRequestedURLs {
     704    TestWebKitAPI::Util::run(&receivedActionNotification);
     705
     706    Vector<String> expectedRequestedURLs {
    675707        "testscheme://testhost/main.html",
    676708        "othertestscheme://not-testhost/1-redirected.txt",
     
    686718    for (size_t i = 0; i < expectedRequestedURLs.size(); i++)
    687719        EXPECT_WK_STREQ(expectedRequestedURLs[i], [[urls objectAtIndex:i] absoluteString]);
     720
     721    expectedRequestedURLs.remove(0);
     722    expectedRequestedURLs[1] = "testscheme://testhost:123/2.txt";
     723    checkURLs(urlsFromCallback, expectedRequestedURLs);
    688724}
    689725
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h

    r275166 r287040  
    2727#import <WebKit/WebKit.h>
    2828
     29@class _WKContentRuleListAction;
     30
    2931@interface TestNavigationDelegate : NSObject <WKNavigationDelegate>
    3032
     
    3941@property (nonatomic, copy) void (^webContentProcessDidTerminate)(WKWebView *);
    4042@property (nonatomic, copy) void (^didReceiveAuthenticationChallenge)(WKWebView *, NSURLAuthenticationChallenge *, void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *));
     43@property (nonatomic, copy) void (^contentRuleListPerformedAction)(WKWebView *, NSString *, _WKContentRuleListAction *, NSURL *);
    4144
    4245- (void)waitForDidStartProvisionalNavigation;
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm

    r275166 r287040  
    170170}
    171171
     172- (void)_webView:(WKWebView *)webView contentRuleListWithIdentifier:(NSString *)identifier performedAction:(_WKContentRuleListAction *)action forURL:(NSURL *)url
     173{
     174    if (_contentRuleListPerformedAction)
     175        _contentRuleListPerformedAction(webView, identifier, action, url);
     176}
     177
    172178@end
    173179
Note: See TracChangeset for help on using the changeset viewer.