Changeset 217310 in webkit


Ignore:
Timestamp:
May 23, 2017, 5:01:44 PM (8 years ago)
Author:
mrajca@apple.com
Message:

Replace autoplay events that fire at navigation with a DidAutoplayMediaPastThreshold event.
https://bugs.webkit.org/show_bug.cgi?id=172138

Reviewed by Alex Christensen.

Source/WebCore:

The current autoplay signals that are fired at navigation may not get delivered to the UIProcess if the WebPage is close()'ed around
this time. This patch simplifies this and just notifies clients if a media element has played past a threshold.

Updated API tests.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::playbackProgressTimerFired):
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
(WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
(WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):

  • page/AutoplayEvent.h:

Source/WebKit2:

Updated auto-play event types.

  • Shared/WebCoreArgumentCoders.h:
  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/API/C/WKPageUIClient.h:

Tools:

Added API tests.

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

(TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/silence-long.m4a: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r217298 r217310  
     12017-05-15  Matt Rajca  <mrajca@apple.com>
     2
     3        Replace autoplay events that fire at navigation with a DidAutoplayMediaPastThreshold event.
     4        https://bugs.webkit.org/show_bug.cgi?id=172138
     5
     6        Reviewed by Alex Christensen.
     7
     8        The current autoplay signals that are fired at navigation may not get delivered to the UIProcess if the WebPage is close()'ed around
     9        this time. This patch simplifies this and just notifies clients if a media element has played past a threshold.
     10
     11        Updated API tests.
     12
     13        * html/HTMLMediaElement.cpp:
     14        (WebCore::HTMLMediaElement::playbackProgressTimerFired):
     15        (WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
     16        (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
     17        (WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):
     18        * page/AutoplayEvent.h:
     19
    1202017-05-23  Dean Jackson  <dino@apple.com>
    221
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r217223 r217310  
    166166static const Seconds ScanRepeatDelay { 1.5_s };
    167167static const double ScanMaximumRate = 8;
     168static const double AutoplayInterferenceTimeThreshold = 10;
    168169
    169170static const Seconds hideMediaControlsAfterEndedDelay { 6_s };
     
    35743575        m_mediaSource->monitorSourceBuffers();
    35753576#endif
     3577
     3578    if (!seeking() && m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started && currentTime() - m_playbackWithoutUserGestureStartedTime->toDouble() > AutoplayInterferenceTimeThreshold) {
     3579        handleAutoplayEvent(AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference);
     3580        setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
     3581    }
    35763582}
    35773583
     
    44734479                    addBehaviorRestrictionsOnEndIfNecessary();
    44744480
    4475                 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started)
    4476                     handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
    4477 
    44784481                setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
    44794482            }
     
    52345237    setPausedInternal(true);
    52355238    m_mediaSession->clientWillPausePlayback();
    5236 
    5237     switch (m_playbackWithoutUserGesture) {
    5238     case PlaybackWithoutUserGesture::Started:
    5239         handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
    5240         break;
    5241     case PlaybackWithoutUserGesture::Prevented:
    5242         handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
    5243         break;
    5244     case PlaybackWithoutUserGesture::None:
    5245         break;
    5246     }
    52475239
    52485240    setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
     
    72097201
    72107202    // Only consider interference in the first 10 seconds of automatic playback.
    7211     if (currentTime() - m_playbackWithoutUserGestureStartedTime->toDouble() > 10)
     7203    if (currentTime() - m_playbackWithoutUserGestureStartedTime->toDouble() > AutoplayInterferenceTimeThreshold)
    72127204        return;
    72137205
  • trunk/Source/WebCore/page/AutoplayEvent.h

    r215771 r217310  
    3131    DidPreventMediaFromPlaying,
    3232    DidPlayMediaPreventedFromPlaying,
    33     DidEndMediaPlaybackWithoutUserInterference,
     33    DidAutoplayMediaPastThresholdWithoutUserInterference,
    3434    UserDidInterfereWithPlayback,
    35     UserNeverPlayedMediaPreventedFromPlaying,
    3635};
    3736
  • trunk/Source/WebKit2/ChangeLog

    r217307 r217310  
     12017-05-15  Matt Rajca  <mrajca@apple.com>
     2
     3        Replace autoplay events that fire at navigation with a DidAutoplayMediaPastThreshold event.
     4        https://bugs.webkit.org/show_bug.cgi?id=172138
     5
     6        Reviewed by Alex Christensen.
     7
     8        Updated auto-play event types.
     9
     10        * Shared/WebCoreArgumentCoders.h:
     11        * UIProcess/API/C/WKPage.cpp:
     12        (WKPageSetPageUIClient):
     13        * UIProcess/API/C/WKPageUIClient.h:
     14
    1152017-05-23  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h

    r216967 r217310  
    703703        WebCore::AutoplayEvent::DidPreventMediaFromPlaying,
    704704        WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying,
    705         WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference,
    706         WebCore::AutoplayEvent::UserDidInterfereWithPlayback,
    707         WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying
     705        WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference,
     706        WebCore::AutoplayEvent::UserDidInterfereWithPlayback
    708707    >;
    709708};
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r217228 r217310  
    22662266        {
    22672267            switch (event) {
    2268             case WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference:
    2269                 return kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference;
     2268            case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference:
     2269                return kWKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference;
    22702270            case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying:
    22712271                return kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
     
    22742274            case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
    22752275                return kWKAutoplayEventUserDidInterfereWithPlayback;
    2276             case WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying:
    2277                 return kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying;
    22782276            }
    22792277
  • trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h

    r217101 r217310  
    5252    kWKAutoplayEventDidPreventFromAutoplaying,
    5353    kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
    54     kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference,
     54    kWKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference,
    5555    kWKAutoplayEventUserDidInterfereWithPlayback,
    56     kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying,
    5756};
    5857typedef uint32_t WKAutoplayEvent;
  • trunk/Tools/ChangeLog

    r217303 r217310  
     12017-05-15  Matt Rajca  <mrajca@apple.com>
     2
     3        Replace autoplay events that fire at navigation with a DidAutoplayMediaPastThreshold event.
     4        https://bugs.webkit.org/show_bug.cgi?id=172138
     5
     6        Reviewed by Alex Christensen.
     7
     8        Added API tests.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebKit2/js-autoplay-audio.html: Added.
     12        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
     13        (TEST):
     14        * TestWebKitAPI/Tests/WebKit2Cocoa/silence-long.m4a: Added.
     15
    1162017-05-23  Simon Fraser  <simon.fraser@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r217296 r217310  
    572572                C99BDF891E80980400C7170E /* autoplay-zero-volume-check.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */; };
    573573                C9B1043E1ECF9848000520FA /* autoplay-inherits-gesture-from-document.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9B1043D1ECF9832000520FA /* autoplay-inherits-gesture-from-document.html */; };
     574                C9B4AD2A1ECA6EBE00F5FEA0 /* silence-long.m4a in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9B4AD291ECA6EA500F5FEA0 /* silence-long.m4a */; };
     575                C9B4AD2C1ECA6F7F00F5FEA0 /* js-autoplay-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9B4AD2B1ECA6F7600F5FEA0 /* js-autoplay-audio.html */; };
    574576                C9BF06EF1E9C132500595E3E /* autoplay-muted-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9BF06EE1E9C130400595E3E /* autoplay-muted-with-controls.html */; };
    575577                C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
     
    696698                                C9B1043E1ECF9848000520FA /* autoplay-inherits-gesture-from-document.html in Copy Resources */,
    697699                                3FCC4FE81EC4E8CA0076E37C /* PictureInPictureDelegate.html in Copy Resources */,
     700                                C9B4AD2C1ECA6F7F00F5FEA0 /* js-autoplay-audio.html in Copy Resources */,
     701                                C9B4AD2A1ECA6EBE00F5FEA0 /* silence-long.m4a in Copy Resources */,
    698702                                55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */,
    699703                                5797FE331EB15AB100B2F4A0 /* navigation-client-default-crypto.html in Copy Resources */,
     
    14621466                C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-zero-volume-check.html"; sourceTree = "<group>"; };
    14631467                C9B1043D1ECF9832000520FA /* autoplay-inherits-gesture-from-document.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "autoplay-inherits-gesture-from-document.html"; sourceTree = "<group>"; };
     1468                C9B4AD291ECA6EA500F5FEA0 /* silence-long.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = "silence-long.m4a"; sourceTree = "<group>"; };
     1469                C9B4AD2B1ECA6F7600F5FEA0 /* js-autoplay-audio.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "js-autoplay-audio.html"; sourceTree = "<group>"; };
    14641470                C9BF06EE1E9C130400595E3E /* autoplay-muted-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-muted-with-controls.html"; sourceTree = "<group>"; };
    14651471                C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
     
    19841990                                F415086C1DA040C10044BE9B /* play-audio-on-click.html */,
    19851991                                A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */,
     1992                                C9B4AD291ECA6EA500F5FEA0 /* silence-long.m4a */,
    19861993                                F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */,
    19871994                                515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */,
     
    22842291                                BCBD372E125ABBE600D2C29F /* icon.png */,
    22852292                                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */,
     2293                                C9B4AD2B1ECA6F7600F5FEA0 /* js-autoplay-audio.html */,
    22862294                                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */,
    22872295                                8361F1771E610B2100759B25 /* link-with-download-attribute-with-slashes.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

    r217152 r217310  
    388388
    389389    receivedAutoplayEvent = std::nullopt;
    390     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     390    NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-autoplay-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    391391    [webView loadRequest:jsPlayRequest];
    392     [webView waitForMessage:@"playing"];
    393 
    394     ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
    395 
    396     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
    397     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
    398     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
    399 
    400     receivedAutoplayEvent = std::nullopt;
    401     [webView loadRequest:jsPlayRequest];
    402     [webView waitForMessage:@"ended"];
    403     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
     392    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference);
    404393    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
    405394}
     
    457446}
    458447
    459 TEST(WebKit2, WebsitePoliciesUserNeverPlayedMediaPreventedFromPlaying)
    460 {
    461     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    462     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
    463 
    464     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
    465     [delegate setAutoplayPolicyForURL:^(NSURL *) {
    466         return _WKWebsiteAutoplayPolicyDeny;
    467     }];
    468     [webView setNavigationDelegate:delegate.get()];
    469 
    470     WKPageUIClientV9 uiClient;
    471     memset(&uiClient, 0, sizeof(uiClient));
    472 
    473     uiClient.base.version = 9;
    474     uiClient.handleAutoplayEvent = handleAutoplayEvent;
    475 
    476     WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
    477 
    478     receivedAutoplayEvent = std::nullopt;
    479     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    480     [webView loadRequest:jsPlayRequest];
    481     [webView waitForMessage:@"loaded"];
    482     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
    483 
    484     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
    485     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying);
    486     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
    487 }
    488 
    489448TEST(WebKit2, WebsitePoliciesAutoplayQuirks)
    490449{
Note: See TracChangeset for help on using the changeset viewer.