Changeset 221172 in webkit
- Timestamp:
- Aug 24, 2017, 5:28:56 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r221165 r221172 1 2017-08-24 Alex Christensen <achristensen@webkit.org> 2 3 Add WKUIDelegatePrivate equivalent of WKPageUIClient's handleAutoplayEvent 4 https://bugs.webkit.org/show_bug.cgi?id=175965 5 <rdar://problem/29270035> 6 7 Reviewed by Tim Horton. 8 9 Covered by updating API tests to use UIDelegate instead of _pageForTesting and WKPageUIClient. 10 11 * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: 12 * UIProcess/Cocoa/UIDelegate.h: 13 * UIProcess/Cocoa/UIDelegate.mm: 14 (WebKit::UIDelegate::setDelegate): 15 (WebKit::toWKFocusDirection): 16 (WebKit::toWKAutoplayEventFlags): 17 (WebKit::toWKAutoplayEvent): 18 (WebKit::UIDelegate::UIClient::handleAutoplayEvent): 19 1 20 2017-08-24 Brady Eidson <beidson@apple.com> 2 21 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
r221164 r221172 48 48 #else 49 49 typedef NS_ENUM(NSInteger, _WKFocusDirection) { 50 WKFocusDirectionBackward, 51 WKFocusDirectionForward, 50 _WKFocusDirectionBackward, 51 _WKFocusDirectionForward, 52 } WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 53 54 typedef NS_ENUM(NSInteger, _WKAutoplayEvent) { 55 _WKAutoplayEventDidPreventFromAutoplaying, 56 _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying, 57 _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference, 58 _WKAutoplayEventUserDidInterfereWithPlayback, 59 } WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 60 61 typedef NS_OPTIONS(NSInteger, _WKAutoplayEventFlags) { 62 _WKAutoplayEventFlagsNone = 0, 63 _WKAutoplayEventFlagsHasAudio = 1 << 0, 52 64 } WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 53 65 #endif … … 131 143 - (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 132 144 - (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 145 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 133 146 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12)); 134 147 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12)); -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h
r221164 r221172 102 102 void unfocus(WebPageProxy*) final; 103 103 void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final; 104 void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final; 104 105 bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final; 105 106 #endif … … 147 148 bool webViewTakeFocus : 1; 148 149 bool webViewDidNotHandleWheelEvent : 1; 150 bool webViewHandleAutoplayEventWithFlags : 1; 149 151 bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1; 150 152 #endif -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
r221164 r221172 107 107 m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)]; 108 108 m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)]; 109 m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)]; 109 110 m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)]; 110 111 #endif … … 382 383 switch (direction) { 383 384 case kWKFocusDirectionBackward: 384 return WKFocusDirectionBackward;385 return _WKFocusDirectionBackward; 385 386 case kWKFocusDirectionForward: 386 return WKFocusDirectionForward;387 return _WKFocusDirectionForward; 387 388 } 388 389 ASSERT_NOT_REACHED(); 389 return WKFocusDirectionForward;390 return _WKFocusDirectionForward; 390 391 } 391 392 … … 436 437 437 438 [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didNotHandleWheelEvent:event.nativeEvent()]; 439 } 440 441 static _WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags) 442 { 443 _WKAutoplayEventFlags wkFlags = _WKAutoplayEventFlagsNone; 444 if (flags.contains(WebCore::AutoplayEventFlags::HasAudio)) 445 wkFlags |= _WKAutoplayEventFlagsHasAudio; 446 447 return wkFlags; 448 } 449 450 static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event) 451 { 452 switch (event) { 453 case WebCore::AutoplayEvent::DidPreventMediaFromPlaying: 454 return _WKAutoplayEventDidPreventFromAutoplaying; 455 case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying: 456 return _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying; 457 case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference: 458 return _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference; 459 case WebCore::AutoplayEvent::UserDidInterfereWithPlayback: 460 return _WKAutoplayEventUserDidInterfereWithPlayback; 461 } 462 ASSERT_NOT_REACHED(); 463 return _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying; 464 } 465 466 void UIDelegate::UIClient::handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags) 467 { 468 if (!m_uiDelegate.m_delegateMethods.webViewHandleAutoplayEventWithFlags) 469 return; 470 471 auto delegate = m_uiDelegate.m_delegate.get(); 472 if (!delegate) 473 return; 474 475 [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)]; 438 476 } 439 477 -
trunk/Tools/ChangeLog
r221171 r221172 1 2017-08-24 Alex Christensen <achristensen@webkit.org> 2 3 Add WKUIDelegatePrivate equivalent of WKPageUIClient's handleAutoplayEvent 4 https://bugs.webkit.org/show_bug.cgi?id=175965 5 <rdar://problem/29270035> 6 7 Reviewed by Tim Horton. 8 9 * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm: 10 (TEST): 11 * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm: 12 (-[AutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]): 13 (TEST): 14 (handleAutoplayEvent): Deleted. 15 1 16 2017-08-24 Alex Christensen <achristensen@webkit.org> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm
r221171 r221172 134 134 [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com/"]]; 135 135 TestWebKitAPI::Util::run(&done); 136 ASSERT_EQ(takenDirection, WKFocusDirectionBackward);136 ASSERT_EQ(takenDirection, _WKFocusDirectionBackward); 137 137 } 138 138 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm
r219106 r221172 30 30 #import <WebKit/WKPagePrivate.h> 31 31 #import <WebKit/WKPreferencesRefPrivate.h> 32 #import <WebKit/WKUIDelegatePrivate.h> 32 33 #import <WebKit/WKURLSchemeTaskPrivate.h> 33 34 #import <WebKit/WKUserContentControllerPrivate.h> … … 53 54 54 55 #if PLATFORM(MAC) 55 static std::optional< WKAutoplayEvent> receivedAutoplayEvent;56 static std::optional< WKAutoplayEventFlags> receivedAutoplayEventFlags;56 static std::optional<_WKAutoplayEvent> receivedAutoplayEvent; 57 static std::optional<_WKAutoplayEventFlags> receivedAutoplayEventFlags; 57 58 #endif 58 59 … … 163 164 } 164 165 165 @interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate >166 @interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate> 166 167 @property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *); 167 168 @property (nonatomic, copy) _WKWebsiteAutoplayQuirk(^allowedAutoplayQuirksForURL)(NSURL *); … … 187 188 } 188 189 190 #if PLATFORM(MAC) 191 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags 192 { 193 receivedAutoplayEventFlags = flags; 194 receivedAutoplayEvent = event; 195 } 196 #endif 197 189 198 @end 190 199 … … 284 293 285 294 #if PLATFORM(MAC) 286 static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo)287 {288 receivedAutoplayEventFlags = flags;289 receivedAutoplayEvent = event;290 }291 292 295 static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event) 293 296 { … … 306 309 }]; 307 310 [webView setNavigationDelegate:delegate.get()]; 308 309 WKPageUIClientV9 uiClient; 310 memset(&uiClient, 0, sizeof(uiClient)); 311 312 uiClient.base.version = 9; 313 uiClient.handleAutoplayEvent = handleAutoplayEvent; 314 315 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 311 [webView setUIDelegate:delegate.get()]; 312 316 313 NSPoint playButtonClickPoint = NSMakePoint(20, 256); 317 314 … … 380 377 }]; 381 378 [webView setNavigationDelegate:delegate.get()]; 382 383 WKPageUIClientV9 uiClient; 384 memset(&uiClient, 0, sizeof(uiClient)); 385 386 uiClient.base.version = 9; 387 uiClient.handleAutoplayEvent = handleAutoplayEvent; 388 389 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 379 [webView setUIDelegate:delegate.get()]; 390 380 391 381 receivedAutoplayEvent = std::nullopt; … … 406 396 }]; 407 397 [webView setNavigationDelegate:delegate.get()]; 408 409 WKPageUIClientV9 uiClient; 410 memset(&uiClient, 0, sizeof(uiClient)); 411 412 uiClient.base.version = 9; 413 uiClient.handleAutoplayEvent = handleAutoplayEvent; 414 415 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 398 [webView setUIDelegate:delegate.get()]; 416 399 417 400 receivedAutoplayEvent = std::nullopt; … … 541 524 }]; 542 525 [webView setNavigationDelegate:delegate.get()]; 543 544 WKPageUIClientV9 uiClient; 545 memset(&uiClient, 0, sizeof(uiClient)); 546 uiClient.base.version = 9; 547 uiClient.handleAutoplayEvent = handleAutoplayEvent; 548 549 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 526 [webView setUIDelegate:delegate.get()]; 550 527 551 528 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]]; … … 557 534 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 558 535 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 559 560 WKPageUIClientV9 uiClient;561 memset(&uiClient, 0, sizeof(uiClient));562 563 uiClient.base.version = 9;564 uiClient.handleAutoplayEvent = handleAutoplayEvent;565 566 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);567 568 536 auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]); 569 537 [webView setNavigationDelegate:delegate.get()]; 538 [webView setUIDelegate:delegate.get()]; 570 539 571 540 NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
Note:
See TracChangeset
for help on using the changeset viewer.