Changeset 214061 in webkit
- Timestamp:
- Mar 16, 2017 12:06:43 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r214034 r214061 1 2017-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 1 32 2017-03-16 Tomas Popela <tpopela@redhat.com> 2 33 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtension.h
r213696 r214061 31 31 @interface WKContentExtension : NSObject 32 32 33 /*! @abstract A copy of the identifier of the content extension. */ 34 @property (nonatomic, readonly, copy) NSString *identifier; 35 33 36 @end 34 37 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtension.mm
r213696 r214061 47 47 } 48 48 49 - (NSString *)identifier 50 { 51 return _contentExtension->name(); 52 } 53 49 54 @end 50 55 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.h
r213696 r214061 37 37 38 38 - (void)compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *) encodedContentExtension completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler; 39 - (void)look upContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;39 - (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler; 40 40 - (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler; 41 41 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.mm
r213988 r214061 38 38 switch (static_cast<API::ContentExtensionStore::Error>(error.value())) { 39 39 case API::ContentExtensionStore::Error::LookupFailed: 40 return WKErrorContentExtensionStoreLook upFailed;40 return WKErrorContentExtensionStoreLookUpFailed; 41 41 case API::ContentExtensionStore::Error::VersionMismatch: 42 42 return WKErrorContentExtensionStoreVersionMismatch; … … 102 102 } 103 103 104 - (void)look upContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler104 - (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler 105 105 { 106 106 auto handler = adoptNS([completionHandler copy]); … … 112 112 auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Extension lookup failed: %s", error.message().c_str()]}; 113 113 auto wkError = toWKErrorCode(error); 114 ASSERT(wkError == WKErrorContentExtensionStoreLook upFailed || wkError == WKErrorContentExtensionStoreVersionMismatch);114 ASSERT(wkError == WKErrorContentExtensionStoreLookUpFailed || wkError == WKErrorContentExtensionStoreVersionMismatch); 115 115 rawHandler(nil, [NSError errorWithDomain:WKErrorDomain code:wkError userInfo:userInfo]); 116 116 return; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h
r213988 r214061 42 42 @constant WKErrorJavaScriptExceptionOccurred Indicates that a JavaScript exception occurred. 43 43 @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. 45 47 @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.48 48 */ 49 49 typedef NS_ENUM(NSInteger, WKErrorCode) { … … 53 53 WKErrorJavaScriptExceptionOccurred, 54 54 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)), 56 58 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)),59 59 } WK_API_AVAILABLE(macosx(10.10), ios(8.0)); 60 60 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm
r213696 r214061 59 59 return WEB_UI_STRING("JavaScript execution returned a result of an unsupported type", "WKErrorJavaScriptResultTypeIsUnsupported description"); 60 60 61 case WKErrorContentExtensionStoreLook upFailed:61 case WKErrorContentExtensionStoreLookUpFailed: 62 62 return WEB_UI_STRING("Looking up a WKUserContentExtension failed", "WKErrorContentExtensionStoreLookupFailed description"); 63 63 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.h
r213781 r214061 80 80 @param name The identifier of the user content extension to remove. 81 81 */ 82 - (void)removeContentExtension:( NSString *)identifierWK_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)); 83 83 84 84 /*! @abstract Removes all associated user content extensions. -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm
r213696 r214061 100 100 } 101 101 102 - (void)removeContentExtension:( NSString *)identifier103 { 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()); 106 106 #endif 107 107 } -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm
r213988 r214061 46 46 ASSERT(error.domain == WKErrorDomain); 47 47 switch (error.code) { 48 case WKErrorContentExtensionStoreLook upFailed:48 case WKErrorContentExtensionStoreLookUpFailed: 49 49 return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorLookupFailed userInfo:error.userInfo]; 50 50 case WKErrorContentExtensionStoreVersionMismatch: … … 81 81 - (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler 82 82 { 83 [_contentExtensionStore look upContentExtensionForIdentifier:identifier completionHandler:^(WKContentExtension *contentExtension, NSError *error) {83 [_contentExtensionStore lookUpContentExtensionForIdentifier:identifier completionHandler:^(WKContentExtension *contentExtension, NSError *error) { 84 84 _WKUserContentFilter *contentFilter = contentExtension ? [[[_WKUserContentFilter alloc] _initWithWKContentExtension:contentExtension] autorelease] : nil; 85 85 completionHandler(contentFilter, toUserContentExtensionStoreError(error)); -
trunk/Tools/ChangeLog
r214046 r214061 1 2017-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 1 12 2017-03-16 Jonathan Bedard <jbedard@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm
r213988 r214061 31 31 #import "PlatformUtilities.h" 32 32 #import "Test.h" 33 #import <WebKit/WKContentExtension.h> 33 34 #import <WebKit/WKContentExtensionStorePrivate.h> 34 35 #import <wtf/RetainPtr.h> … … 93 94 94 95 __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"); 97 99 EXPECT_NOT_NULL(filter); 98 100 EXPECT_NULL(error); … … 106 108 { 107 109 __block bool doneLookingUp = false; 108 [[WKContentExtensionStore defaultStore] look upContentExtensionForIdentifier:@"DoesNotExist" completionHandler:^(WKContentExtension *filter, NSError *error) {110 [[WKContentExtensionStore defaultStore] lookUpContentExtensionForIdentifier:@"DoesNotExist" completionHandler:^(WKContentExtension *filter, NSError *error) { 109 111 110 112 EXPECT_NULL(filter); 111 113 EXPECT_NOT_NULL(error); 112 114 checkDomain(error); 113 EXPECT_EQ(error.code, WKErrorContentExtensionStoreLook upFailed);115 EXPECT_EQ(error.code, WKErrorContentExtensionStoreLookUpFailed); 114 116 EXPECT_STREQ("Extension lookup failed: Unspecified error during lookup.", [[error helpAnchor] UTF8String]); 115 117 … … 135 137 136 138 __block bool doneLookingUp = false; 137 [[WKContentExtensionStore defaultStore] look upContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error)139 [[WKContentExtensionStore defaultStore] lookUpContentExtensionForIdentifier:@"TestExtension" completionHandler:^(WKContentExtension *filter, NSError *error) 138 140 { 139 141 … … 256 258 } 257 259 260 static size_t alertCount { 0 }; 261 static 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 296 TEST_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 258 337 #endif
Note: See TracChangeset
for help on using the changeset viewer.