Changeset 221172 in webkit


Ignore:
Timestamp:
Aug 24, 2017, 5:28:56 PM (8 years ago)
Author:
achristensen@apple.com
Message:

Add WKUIDelegatePrivate equivalent of WKPageUIClient's handleAutoplayEvent
https://bugs.webkit.org/show_bug.cgi?id=175965
<rdar://problem/29270035>

Reviewed by Tim Horton.

Source/WebKit:

Covered by updating API tests to use UIDelegate instead of _pageForTesting and WKPageUIClient.

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::toWKFocusDirection):
(WebKit::toWKAutoplayEventFlags):
(WebKit::toWKAutoplayEvent):
(WebKit::UIDelegate::UIClient::handleAutoplayEvent):

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:

(TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:

(-[AutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
(TEST):
(handleAutoplayEvent): Deleted.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221165 r221172  
     12017-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
    1202017-08-24  Brady Eidson  <beidson@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r221164 r221172  
    4848#else
    4949typedef NS_ENUM(NSInteger, _WKFocusDirection) {
    50     WKFocusDirectionBackward,
    51     WKFocusDirectionForward,
     50    _WKFocusDirectionBackward,
     51    _WKFocusDirectionForward,
     52} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     53
     54typedef NS_ENUM(NSInteger, _WKAutoplayEvent) {
     55    _WKAutoplayEventDidPreventFromAutoplaying,
     56    _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
     57    _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference,
     58    _WKAutoplayEventUserDidInterfereWithPlayback,
     59} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     60
     61typedef NS_OPTIONS(NSInteger, _WKAutoplayEventFlags) {
     62    _WKAutoplayEventFlagsNone = 0,
     63    _WKAutoplayEventFlagsHasAudio = 1 << 0,
    5264} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    5365#endif
     
    131143- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    132144- (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));
    133146- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
    134147- (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  
    102102        void unfocus(WebPageProxy*) final;
    103103        void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final;
     104        void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
    104105        bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
    105106#endif
     
    147148        bool webViewTakeFocus : 1;
    148149        bool webViewDidNotHandleWheelEvent : 1;
     150        bool webViewHandleAutoplayEventWithFlags : 1;
    149151        bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
    150152#endif
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r221164 r221172  
    107107    m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
    108108    m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
     109    m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
    109110    m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
    110111#endif
     
    382383    switch (direction) {
    383384    case kWKFocusDirectionBackward:
    384         return WKFocusDirectionBackward;
     385        return _WKFocusDirectionBackward;
    385386    case kWKFocusDirectionForward:
    386         return WKFocusDirectionForward;
     387        return _WKFocusDirectionForward;
    387388    }
    388389    ASSERT_NOT_REACHED();
    389     return WKFocusDirectionForward;
     390    return _WKFocusDirectionForward;
    390391}
    391392
     
    436437   
    437438    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didNotHandleWheelEvent:event.nativeEvent()];
     439}
     440
     441static _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
     450static _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
     466void 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)];
    438476}
    439477
  • trunk/Tools/ChangeLog

    r221171 r221172  
     12017-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
    1162017-08-24  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm

    r221171 r221172  
    134134    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com/"]];
    135135    TestWebKitAPI::Util::run(&done);
    136     ASSERT_EQ(takenDirection, WKFocusDirectionBackward);
     136    ASSERT_EQ(takenDirection, _WKFocusDirectionBackward);
    137137}
    138138
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

    r219106 r221172  
    3030#import <WebKit/WKPagePrivate.h>
    3131#import <WebKit/WKPreferencesRefPrivate.h>
     32#import <WebKit/WKUIDelegatePrivate.h>
    3233#import <WebKit/WKURLSchemeTaskPrivate.h>
    3334#import <WebKit/WKUserContentControllerPrivate.h>
     
    5354
    5455#if PLATFORM(MAC)
    55 static std::optional<WKAutoplayEvent> receivedAutoplayEvent;
    56 static std::optional<WKAutoplayEventFlags> receivedAutoplayEventFlags;
     56static std::optional<_WKAutoplayEvent> receivedAutoplayEvent;
     57static std::optional<_WKAutoplayEventFlags> receivedAutoplayEventFlags;
    5758#endif
    5859
     
    163164}
    164165
    165 @interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
     166@interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
    166167@property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *);
    167168@property (nonatomic, copy) _WKWebsiteAutoplayQuirk(^allowedAutoplayQuirksForURL)(NSURL *);
     
    187188}
    188189
     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
    189198@end
    190199
     
    284293
    285294#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 
    292295static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
    293296{
     
    306309    }];
    307310    [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
    316313    NSPoint playButtonClickPoint = NSMakePoint(20, 256);
    317314
     
    380377    }];
    381378    [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()];
    390380
    391381    receivedAutoplayEvent = std::nullopt;
     
    406396    }];
    407397    [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()];
    416399
    417400    receivedAutoplayEvent = std::nullopt;
     
    541524    }];
    542525    [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()];
    550527   
    551528    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]];
     
    557534    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    558535    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 
    568536    auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
    569537    [webView setNavigationDelegate:delegate.get()];
     538    [webView setUIDelegate:delegate.get()];
    570539
    571540    NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
Note: See TracChangeset for help on using the changeset viewer.