Changeset 214061 in webkit


Ignore:
Timestamp:
Mar 16, 2017 12:06:43 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Clean up WKContentExtension API
https://bugs.webkit.org/show_bug.cgi?id=169772

Reviewed by Geoffrey Garen.

Source/WebKit2:

Based on feedback I have decided to do the following:

  1. Rename lookup to lookUp because look and up are two words.
  2. Change the parameter of removeContentExtension to a WKContentExtension* to match addContentExtension.
  3. Add an identifier property accessor to WKContentExtension.
  4. Change the order of the new error types. This wasn't exactly based on any feedback, but they look more organized now.
  • UIProcess/API/Cocoa/WKContentExtension.h:
  • UIProcess/API/Cocoa/WKContentExtension.mm:

(-[WKContentExtension identifier]):

  • UIProcess/API/Cocoa/WKContentExtensionStore.h:
  • UIProcess/API/Cocoa/WKContentExtensionStore.mm:

(toWKErrorCode):
(-[WKContentExtensionStore lookUpContentExtensionForIdentifier:completionHandler:]):
(-[WKContentExtensionStore lookupContentExtensionForIdentifier:completionHandler:]): Deleted.

  • UIProcess/API/Cocoa/WKError.h:
  • UIProcess/API/Cocoa/WKError.mm:

(localizedDescriptionForErrorCode):

  • UIProcess/API/Cocoa/WKUserContentController.h:
  • UIProcess/API/Cocoa/WKUserContentController.mm:

(-[WKUserContentController removeContentExtension:]):

  • UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm:

(toUserContentExtensionStoreError):
(-[_WKUserContentExtensionStore lookupContentExtensionForIdentifier:completionHandler:]):

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm:

(TEST_F):
(-[ContentExtensionDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r214034 r214061  
     12017-03-16  Alex Christensen  <achristensen@webkit.org>
     2
     3        Clean up WKContentExtension API
     4        https://bugs.webkit.org/show_bug.cgi?id=169772
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Based on feedback I have decided to do the following:
     9        1. Rename lookup to lookUp because look and up are two words.
     10        2. Change the parameter of removeContentExtension to a WKContentExtension* to match addContentExtension.
     11        3. Add an identifier property accessor to WKContentExtension.
     12        4. Change the order of the new error types.  This wasn't exactly based on any feedback, but they look more organized now.
     13
     14        * UIProcess/API/Cocoa/WKContentExtension.h:
     15        * UIProcess/API/Cocoa/WKContentExtension.mm:
     16        (-[WKContentExtension identifier]):
     17        * UIProcess/API/Cocoa/WKContentExtensionStore.h:
     18        * UIProcess/API/Cocoa/WKContentExtensionStore.mm:
     19        (toWKErrorCode):
     20        (-[WKContentExtensionStore lookUpContentExtensionForIdentifier:completionHandler:]):
     21        (-[WKContentExtensionStore lookupContentExtensionForIdentifier:completionHandler:]): Deleted.
     22        * UIProcess/API/Cocoa/WKError.h:
     23        * UIProcess/API/Cocoa/WKError.mm:
     24        (localizedDescriptionForErrorCode):
     25        * UIProcess/API/Cocoa/WKUserContentController.h:
     26        * UIProcess/API/Cocoa/WKUserContentController.mm:
     27        (-[WKUserContentController removeContentExtension:]):
     28        * UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm:
     29        (toUserContentExtensionStoreError):
     30        (-[_WKUserContentExtensionStore lookupContentExtensionForIdentifier:completionHandler:]):
     31
    1322017-03-16  Tomas Popela  <tpopela@redhat.com>
    233
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtension.h

    r213696 r214061  
    3131@interface WKContentExtension : NSObject
    3232
     33/*! @abstract A copy of the identifier of the content extension. */
     34@property (nonatomic, readonly, copy) NSString *identifier;
     35
    3336@end
    3437
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtension.mm

    r213696 r214061  
    4747}
    4848
     49- (NSString *)identifier
     50{
     51    return _contentExtension->name();
     52}
     53
    4954@end
    5055
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.h

    r213696 r214061  
    3737
    3838- (void)compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *) encodedContentExtension completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;
    39 - (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;
     39- (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;
    4040- (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler;
    4141
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.mm

    r213988 r214061  
    3838    switch (static_cast<API::ContentExtensionStore::Error>(error.value())) {
    3939    case API::ContentExtensionStore::Error::LookupFailed:
    40         return WKErrorContentExtensionStoreLookupFailed;
     40        return WKErrorContentExtensionStoreLookUpFailed;
    4141    case API::ContentExtensionStore::Error::VersionMismatch:
    4242        return WKErrorContentExtensionStoreVersionMismatch;
     
    102102}
    103103
    104 - (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler
     104- (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler
    105105{
    106106    auto handler = adoptNS([completionHandler copy]);
     
    112112            auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Extension lookup failed: %s", error.message().c_str()]};
    113113            auto wkError = toWKErrorCode(error);
    114             ASSERT(wkError == WKErrorContentExtensionStoreLookupFailed || wkError == WKErrorContentExtensionStoreVersionMismatch);
     114            ASSERT(wkError == WKErrorContentExtensionStoreLookUpFailed || wkError == WKErrorContentExtensionStoreVersionMismatch);
    115115            rawHandler(nil, [NSError errorWithDomain:WKErrorDomain code:wkError userInfo:userInfo]);
    116116            return;
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h

    r213988 r214061  
    4242 @constant WKErrorJavaScriptExceptionOccurred          Indicates that a JavaScript exception occurred.
    4343 @constant WKErrorJavaScriptResultTypeIsUnsupported    Indicates that the result of JavaScript execution could not be returned.
    44  @constant WKErrorContentExtensionStoreLookupFailed    Indicates that looking up a WKUserContentExtension failed.
     44 @constant WKErrorContentExtensionStoreCompileFailed   Indicates that compiling a WKUserContentExtension failed.
     45 @constant WKErrorContentExtensionStoreLookUpFailed    Indicates that looking up a WKUserContentExtension failed.
     46 @constant WKErrorContentExtensionStoreRemoveFailed    Indicates that removing a WKUserContentExtension failed.
    4547 @constant WKErrorContentExtensionStoreVersionMismatch Indicates that the WKUserContentExtension version did not match the latest.
    46  @constant WKErrorContentExtensionStoreCompileFailed   Indicates that compiling a WKUserContentExtension failed.
    47  @constant WKErrorContentExtensionStoreRemoveFailed    Indicates that removing a WKUserContentExtension failed.
    4848 */
    4949typedef NS_ENUM(NSInteger, WKErrorCode) {
     
    5353    WKErrorJavaScriptExceptionOccurred,
    5454    WKErrorJavaScriptResultTypeIsUnsupported WK_API_AVAILABLE(macosx(10.11), ios(9.0)),
    55     WKErrorContentExtensionStoreLookupFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
     55    WKErrorContentExtensionStoreCompileFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
     56    WKErrorContentExtensionStoreLookUpFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
     57    WKErrorContentExtensionStoreRemoveFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
    5658    WKErrorContentExtensionStoreVersionMismatch WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
    57     WKErrorContentExtensionStoreCompileFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
    58     WKErrorContentExtensionStoreRemoveFailed WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
    5959} WK_API_AVAILABLE(macosx(10.10), ios(8.0));
    6060
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm

    r213696 r214061  
    5959        return WEB_UI_STRING("JavaScript execution returned a result of an unsupported type", "WKErrorJavaScriptResultTypeIsUnsupported description");
    6060
    61     case WKErrorContentExtensionStoreLookupFailed:
     61    case WKErrorContentExtensionStoreLookUpFailed:
    6262        return WEB_UI_STRING("Looking up a WKUserContentExtension failed", "WKErrorContentExtensionStoreLookupFailed description");
    6363
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.h

    r213781 r214061  
    8080 @param name The identifier of the user content extension to remove.
    8181 */
    82 - (void)removeContentExtension:(NSString *)identifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     82- (void)removeContentExtension:(WKContentExtension *)contentExtension WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    8383
    8484/*! @abstract Removes all associated user content extensions.
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm

    r213696 r214061  
    100100}
    101101
    102 - (void)removeContentExtension:(NSString *)identifier
    103 {
    104 #if ENABLE(CONTENT_EXTENSIONS)
    105     _userContentControllerProxy->removeContentExtension(identifier);
     102- (void)removeContentExtension:(WKContentExtension *)contentExtension
     103{
     104#if ENABLE(CONTENT_EXTENSIONS)
     105    _userContentControllerProxy->removeContentExtension(contentExtension->_contentExtension->name());
    106106#endif
    107107}
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm

    r213988 r214061  
    4646    ASSERT(error.domain == WKErrorDomain);
    4747    switch (error.code) {
    48     case WKErrorContentExtensionStoreLookupFailed:
     48    case WKErrorContentExtensionStoreLookUpFailed:
    4949        return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorLookupFailed userInfo:error.userInfo];
    5050    case WKErrorContentExtensionStoreVersionMismatch:
     
    8181- (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler
    8282{
    83     [_contentExtensionStore lookupContentExtensionForIdentifier:identifier completionHandler:^(WKContentExtension *contentExtension, NSError *error) {
     83    [_contentExtensionStore lookUpContentExtensionForIdentifier:identifier completionHandler:^(WKContentExtension *contentExtension, NSError *error) {
    8484        _WKUserContentFilter *contentFilter = contentExtension ? [[[_WKUserContentFilter alloc] _initWithWKContentExtension:contentExtension] autorelease] : nil;
    8585        completionHandler(contentFilter, toUserContentExtensionStoreError(error));
  • trunk/Tools/ChangeLog

    r214046 r214061  
     12017-03-16  Alex Christensen  <achristensen@webkit.org>
     2
     3        Clean up WKContentExtension API
     4        https://bugs.webkit.org/show_bug.cgi?id=169772
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm:
     9        (TEST_F):
     10        (-[ContentExtensionDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     11
    1122017-03-16  Jonathan Bedard  <jbedard@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm

    r213988 r214061  
    3131#import "PlatformUtilities.h"
    3232#import "Test.h"
     33#import <WebKit/WKContentExtension.h>
    3334#import <WebKit/WKContentExtensionStorePrivate.h>
    3435#import <wtf/RetainPtr.h>
     
    9394
    9495    __block bool doneLookingUp = false;
    95     [[WKContentExtensionStore defaultStore] lookupContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error) {
    96    
     96    [[WKContentExtensionStore defaultStore] lookUpContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error) {
     97
     98        EXPECT_STREQ(filter.identifier.UTF8String, "TestExtension");
    9799        EXPECT_NOT_NULL(filter);
    98100        EXPECT_NULL(error);
     
    106108{
    107109    __block bool doneLookingUp = false;
    108     [[WKContentExtensionStore defaultStore] lookupContentExtensionForIdentifier:@"DoesNotExist" completionHandler:^(WKContentExtension *filter, NSError *error) {
     110    [[WKContentExtensionStore defaultStore] lookUpContentExtensionForIdentifier:@"DoesNotExist" completionHandler:^(WKContentExtension *filter, NSError *error) {
    109111   
    110112        EXPECT_NULL(filter);
    111113        EXPECT_NOT_NULL(error);
    112114        checkDomain(error);
    113         EXPECT_EQ(error.code, WKErrorContentExtensionStoreLookupFailed);
     115        EXPECT_EQ(error.code, WKErrorContentExtensionStoreLookUpFailed);
    114116        EXPECT_STREQ("Extension lookup failed: Unspecified error during lookup.", [[error helpAnchor] UTF8String]);
    115117       
     
    135137   
    136138    __block bool doneLookingUp = false;
    137     [[WKContentExtensionStore defaultStore] lookupContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error)
     139    [[WKContentExtensionStore defaultStore] lookUpContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error)
    138140    {
    139141       
     
    256258}
    257259
     260static size_t alertCount { 0 };
     261static bool receivedAlert { false };
     262
     263@interface ContentExtensionDelegate : NSObject <WKUIDelegate>
     264@end
     265
     266@implementation ContentExtensionDelegate
     267
     268- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
     269{
     270    switch (alertCount++) {
     271    case 0:
     272        // FIXME: The first content blocker should be enabled here.
     273        // ContentExtensionsBackend::addContentExtension isn't being called in the WebProcess
     274        // until after the first main resource starts loading, so we need to send a message to the
     275        // WebProcess before loading if we have installed content blockers.
     276        // See rdar://problem/27788755
     277        EXPECT_STREQ("content blockers disabled", message.UTF8String);
     278        break;
     279    case 1:
     280        // Default behavior.
     281        EXPECT_STREQ("content blockers enabled", message.UTF8String);
     282        break;
     283    case 2:
     284        // After having removed the content extension.
     285        EXPECT_STREQ("content blockers disabled", message.UTF8String);
     286        break;
     287    default:
     288        EXPECT_TRUE(false);
     289    }
     290    receivedAlert = true;
     291    completionHandler();
     292}
     293
     294@end
     295
     296TEST_F(WKContentExtensionStoreTest, AddRemove)
     297{
     298    [[WKContentExtensionStore defaultStore] _removeAllContentExtensions];
     299
     300    __block bool doneCompiling = false;
     301    NSString* contentBlocker = @"[{\"action\":{\"type\":\"css-display-none\",\"selector\":\".hidden\"},\"trigger\":{\"url-filter\":\".*\"}}]";
     302    __block RetainPtr<WKContentExtension> extension;
     303    [[WKContentExtensionStore defaultStore] compileContentExtensionForIdentifier:@"TestAddRemove" encodedContentExtension:contentBlocker completionHandler:^(WKContentExtension *compiledExtension, NSError *error) {
     304        EXPECT_TRUE(error == nil);
     305        extension = compiledExtension;
     306        doneCompiling = true;
     307    }];
     308    TestWebKitAPI::Util::run(&doneCompiling);
     309    EXPECT_NOT_NULL(extension);
     310
     311    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     312    [[configuration userContentController] addContentExtension:extension.get()];
     313
     314    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     315
     316    auto delegate = adoptNS([[ContentExtensionDelegate alloc] init]);
     317    [webView setUIDelegate:delegate.get()];
     318
     319    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"contentBlockerCheck" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     320    alertCount = 0;
     321    receivedAlert = false;
     322    [webView loadRequest:request];
     323    TestWebKitAPI::Util::run(&receivedAlert);
     324
     325    receivedAlert = false;
     326    [webView reload];
     327    TestWebKitAPI::Util::run(&receivedAlert);
     328
     329    [[configuration userContentController] removeContentExtension:extension.get()];
     330
     331    receivedAlert = false;
     332    [webView reload];
     333    TestWebKitAPI::Util::run(&receivedAlert);
     334}
     335
     336
    258337#endif
Note: See TracChangeset for help on using the changeset viewer.