Changeset 211193 in webkit


Ignore:
Timestamp:
Jan 25, 2017 6:18:00 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Notify clients when the user plays media otherwise prevented from autoplaying
https://bugs.webkit.org/show_bug.cgi?id=167390

Patch by Matt Rajca <mrajca@apple.com> on 2017-01-25
Reviewed by Alex Christensen.

Source/WebCore:

The API is tested.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::playInternal):

  • page/ChromeClient.h:

Source/WebKit2:

  • UIProcess/API/APIUIClient.h:

(API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/API/C/WKPageUIClient.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):

  • WebProcess/WebCoreSupport/WebChromeClient.h:

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2/autoplay-with-controls.html: Added.
  • TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html: Added.
  • TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:

(didPlayMediaPreventedFromPlayingWithoutUserGesture):
(TEST):

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

(-[TestWKWebViewHostWindow _mouseUpAtPoint:]):
(-[TestWKWebView waitForLoad]):
(-[TestWKWebView mouseUpAtPoint:]):

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::createOtherPage):
(WTR::TestController::createWebViewWithOptions):

Location:
trunk
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211192 r211193  
     12017-01-25  Matt Rajca  <mrajca@apple.com>
     2
     3        Notify clients when the user plays media otherwise prevented from autoplaying
     4        https://bugs.webkit.org/show_bug.cgi?id=167390
     5
     6        Reviewed by Alex Christensen.
     7
     8        The API is tested.
     9
     10        * html/HTMLMediaElement.cpp:
     11        (WebCore::HTMLMediaElement::playInternal):
     12        * page/ChromeClient.h:
     13
    1142017-01-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r211097 r211193  
    31683168
    31693169    if (ScriptController::processingUserGestureForMedia() && m_preventedFromPlayingWithoutUserGesture) {
    3170         // FIXME: notify clients a user gesture was made and started playback of an element that was otherwise prevented from playing.
     3170        if (Page* page = document().page())
     3171            page->chrome().client().didPlayMediaPreventedFromPlayingWithoutUserGesture();
    31713172        m_preventedFromPlayingWithoutUserGesture = false;
    31723173    }
  • trunk/Source/WebCore/page/ChromeClient.h

    r211042 r211193  
    421421
    422422    virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
     423    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture() { }
    423424
    424425#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebKit2/ChangeLog

    r211192 r211193  
     12017-01-25  Matt Rajca  <mrajca@apple.com>
     2
     3        Notify clients when the user plays media otherwise prevented from autoplaying
     4        https://bugs.webkit.org/show_bug.cgi?id=167390
     5
     6        Reviewed by Alex Christensen.
     7
     8        * UIProcess/API/APIUIClient.h:
     9        (API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):
     10        * UIProcess/API/C/WKPage.cpp:
     11        (WKPageSetPageUIClient):
     12        * UIProcess/API/C/WKPageUIClient.h:
     13        * UIProcess/WebPageProxy.cpp:
     14        (WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture):
     15        * UIProcess/WebPageProxy.h:
     16        * UIProcess/WebPageProxy.messages.in:
     17        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     18        (WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):
     19        * WebProcess/WebCoreSupport/WebChromeClient.h:
     20
    1212017-01-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    222
  • trunk/Source/WebKit2/UIProcess/API/APIUIClient.h

    r209010 r211193  
    153153    virtual void didBeginCaptureSession() { }
    154154    virtual void didEndCaptureSession() { }
     155    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebKit::WebPageProxy&) { }
    155156
    156157#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r209558 r211193  
    22362236        }
    22372237#endif
     2238
     2239        void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebPageProxy& page) override
     2240        {
     2241            if (!m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture)
     2242                return;
     2243
     2244            m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture(toAPI(&page), m_client.base.clientInfo);
     2245        }
    22382246    };
    22392247
  • trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h

    r208903 r211193  
    103103typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
    104104typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo);
     105typedef void (*WKDidPlayMediaPreventedFromPlayingWithoutUserGesture)(WKPageRef page, const void* clientInfo);
    105106typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
    106107
     
    726727    WKRequestPointerLockCallback                                        requestPointerLock;
    727728    WKDidLosePointerLockCallback                                        didLosePointerLock;
     729    WKDidPlayMediaPreventedFromPlayingWithoutUserGesture                didPlayMediaPreventedFromPlayingWithoutUserGesture;
    728730} WKPageUIClientV8;
    729731   
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r211165 r211193  
    65286528#endif
    65296529
     6530void WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture()
     6531{
     6532    m_uiClient->didPlayMediaPreventedFromPlayingWithoutUserGesture(*this);
     6533}
     6534
    65306535#if PLATFORM(MAC)
    65316536void WebPageProxy::removeNavigationGestureSnapshot()
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r211165 r211193  
    10591059    bool hasActiveVideoStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveVideoCaptureDevice; }
    10601060    WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
     1061    void didPlayMediaPreventedFromPlayingWithoutUserGesture();
    10611062
    10621063#if PLATFORM(MAC)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r211165 r211193  
    440440
    441441    IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
     442    DidPlayMediaPreventedFromPlayingWithoutUserGesture()
    442443
    443444#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r211042 r211193  
    10851085}
    10861086
     1087void WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture()
     1088{
     1089    m_page.send(Messages::WebPageProxy::DidPlayMediaPreventedFromPlayingWithoutUserGesture());
     1090}
     1091
    10871092#if ENABLE(MEDIA_SESSION)
    10881093
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r211042 r211193  
    298298
    299299    void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
     300    void didPlayMediaPreventedFromPlayingWithoutUserGesture() final;
    300301
    301302#if ENABLE(MEDIA_SESSION)
  • trunk/Tools/ChangeLog

    r211174 r211193  
     12017-01-25  Matt Rajca  <mrajca@apple.com>
     2
     3        Notify clients when the user plays media otherwise prevented from autoplaying
     4        https://bugs.webkit.org/show_bug.cgi?id=167390
     5
     6        Reviewed by Alex Christensen.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit2/autoplay-with-controls.html: Added.
     10        * TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html: Added.
     11        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
     12        (didPlayMediaPreventedFromPlayingWithoutUserGesture):
     13        (TEST):
     14        * TestWebKitAPI/cocoa/TestWKWebView.h:
     15        * TestWebKitAPI/cocoa/TestWKWebView.mm:
     16        (-[TestWKWebViewHostWindow _mouseUpAtPoint:]):
     17        (-[TestWKWebView waitForLoad]):
     18        (-[TestWKWebView mouseUpAtPoint:]):
     19        * WebKitTestRunner/TestController.cpp:
     20        (WTR::TestController::createOtherPage):
     21        (WTR::TestController::createWebViewWithOptions):
     22
    1232017-01-25  Matt Rajca  <mrajca@apple.com>
    224
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r211097 r211193  
    510510                C95984F51E36BC6B002C0D45 /* autoplay-no-audio-check.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */; };
    511511                C95984F71E36BCEF002C0D45 /* test-without-audio-track.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = C95984F61E36BCD7002C0D45 /* test-without-audio-track.mp4 */; };
     512                C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */; };
     513                C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */; };
     514                C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */; };
    512515                CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
    513516                CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
     
    608611                        dstSubfolderSpec = 7;
    609612                        files = (
     613                                C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
     614                                C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */,
     615                                C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */,
    610616                                C95984F71E36BCEF002C0D45 /* test-without-audio-track.mp4 in Copy Resources */,
    611617                                C95984F41E36BC6B002C0D45 /* autoplay-check.html in Copy Resources */,
     
    12751281                C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-no-audio-check.html"; sourceTree = "<group>"; };
    12761282                C95984F61E36BCD7002C0D45 /* test-without-audio-track.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "test-without-audio-track.mp4"; sourceTree = "<group>"; };
     1283                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-with-controls.html"; sourceTree = "<group>"; };
     1284                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "js-play-with-controls.html"; sourceTree = "<group>"; };
     1285                C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "no-autoplay-with-controls.html"; sourceTree = "<group>"; };
    12771286                CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
    12781287                CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
     
    19621971                                C95984F21E36BC55002C0D45 /* autoplay-check.html */,
    19631972                                C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */,
     1973                                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */,
    19641974                                7C486BA01AA1254B003F6F9B /* bundle-file.html */,
    19651975                                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,
     
    19821992                                BCBD372E125ABBE600D2C29F /* icon.png */,
    19831993                                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */,
     1994                                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */,
    19841995                                8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */,
    19851996                                378E647816326FDF00B6C676 /* link-with-title.html */,
     
    19922003                                7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */,
    19932004                                33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */,
     2005                                C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */,
    19942006                                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
    19952007                                F6FDDDD514241C48004F1729 /* push-state.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

    r211174 r211193  
    4040#if WK_API_ENABLED
    4141
     42@interface WKWebView ()
     43- (WKPageRef)_pageForTesting;
     44@end
     45
    4246static bool doneCompiling;
    4347static bool receivedAlert;
     
    214218}
    215219
    216 #endif
     220#if PLATFORM(MAC)
     221static void didPlayMediaPreventedFromPlayingWithoutUserGesture(WKPageRef page, const void* clientInfo)
     222{
     223    receivedAlert = true;
     224}
     225
     226TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
     227{
     228    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     229    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
     230
     231    auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
     232    [delegate setAutoplayPolicy:_WKWebsiteAutoplayPolicyDeny];
     233    [webView setNavigationDelegate:delegate.get()];
     234
     235    WKPageUIClientV8 uiClient;
     236    memset(&uiClient, 0, sizeof(uiClient));
     237
     238    uiClient.base.version = 8;
     239    uiClient.didPlayMediaPreventedFromPlayingWithoutUserGesture = didPlayMediaPreventedFromPlayingWithoutUserGesture;
     240
     241    WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
     242    NSPoint playButtonClickPoint = NSMakePoint(20, 256);
     243
     244    receivedAlert = false;
     245    NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     246    [webView loadRequest:jsPlayRequest];
     247    [webView waitForMessage:@"loaded"];
     248    [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     249    [webView mouseUpAtPoint:playButtonClickPoint];
     250    TestWebKitAPI::Util::run(&receivedAlert);
     251
     252    receivedAlert = false;
     253    [webView loadHTMLString:@"" baseURL:nil];
     254
     255    NSURLRequest *autoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     256    [webView loadRequest:autoplayRequest];
     257    [webView waitForMessage:@"loaded"];
     258    [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     259    [webView mouseUpAtPoint:playButtonClickPoint];
     260    TestWebKitAPI::Util::run(&receivedAlert);
     261
     262    receivedAlert = false;
     263    [webView loadHTMLString:@"" baseURL:nil];
     264
     265    NSURLRequest *noAutoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"no-autoplay-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     266    [webView loadRequest:noAutoplayRequest];
     267    [webView waitForMessage:@"loaded"];
     268    [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     269    [webView mouseUpAtPoint:playButtonClickPoint];
     270    [webView waitForMessage:@"played"];
     271    ASSERT_FALSE(receivedAlert);
     272}
     273#endif
     274
     275#endif
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h

    r211045 r211193  
    4545// Simulates clicking with a pressure-sensitive device, if possible.
    4646- (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure;
     47- (void)mouseUpAtPoint:(NSPoint)point;
    4748- (void)typeCharacter:(char)character;
    4849@end
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r211045 r211193  
    121121#endif
    122122}
     123
     124- (void)_mouseUpAtPoint:(NSPoint)point
     125{
     126    [self sendEvent:[NSEvent mouseEventWithType:NSEventTypeLeftMouseUp location:point modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:self.windowNumber context:[NSGraphicsContext currentContext] eventNumber:++gEventNumber clickCount:1 pressure:0]];
     127}
    123128#endif // PLATFORM(MAC)
    124129
     
    251256}
    252257
     258- (void)mouseUpAtPoint:(NSPoint)point
     259{
     260    [_hostWindow _mouseUpAtPoint:point];
     261}
     262
    253263- (void)typeCharacter:(char)character {
    254264    NSString *characterAsString = [NSString stringWithFormat:@"%c" , character];
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r210446 r211193  
    280280        requestPointerLock,
    281281        0,
     282        0, // didPlayMediaPreventedFromPlayingWithoutUserGesture
    282283    };
    283284    WKPageSetPageUIClient(newPage, &otherPageUIClient.base);
     
    552553        requestPointerLock,
    553554        0,
     555        0, // didPlayMediaPreventedFromPlayingWithoutUserGesture
    554556    };
    555557    WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base);
Note: See TracChangeset for help on using the changeset viewer.