⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 252438 in webkit


Ignore:
Timestamp:
Nov 13, 2019, 4:25:27 PM (7 years ago)
Author:
jer.noble@apple.com
Message:

Link mediaDataLoadsAutomatically setting to AutoplayPolicy
https://bugs.webkit.org/show_bug.cgi?id=201738
<rdar://problem/55315194>

Reviewed by Eric Carlson.

Source/WebCore:

This change has two effects: on Mac, when the embedding app sets an AutoplayPolicy to
deny autoplay, this will also deny the ability to load media data beyond "preload"; on iOS
when the embedding app sets an AutoplayPolicy to allow autoplay, this will also allow media
data to load beyond "preload".

  • dom/Document.cpp:

(WebCore::Document::mediaDataLoadsAutomatically const):

  • dom/Document.h:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::finishInitialization):

  • html/MediaElementSession.cpp:

(WebCore::MediaElementSession::allowsAutomaticMediaDataLoading const):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit/media-loading.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:

(TEST):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252436 r252438  
     12019-11-13  Jer Noble  <jer.noble@apple.com>
     2
     3        Link mediaDataLoadsAutomatically setting to AutoplayPolicy
     4        https://bugs.webkit.org/show_bug.cgi?id=201738
     5        <rdar://problem/55315194>
     6
     7        Reviewed by Eric Carlson.
     8
     9        This change has two effects: on Mac, when the embedding app sets an AutoplayPolicy to
     10        deny autoplay, this will also deny the ability to load media data beyond "preload"; on iOS
     11        when the embedding app sets an AutoplayPolicy to allow autoplay, this will also allow media
     12        data to load beyond "preload".
     13
     14        * dom/Document.cpp:
     15        (WebCore::Document::mediaDataLoadsAutomatically const):
     16        * dom/Document.h:
     17        * html/HTMLMediaElement.cpp:
     18        (WebCore::HTMLMediaElement::finishInitialization):
     19        * html/MediaElementSession.cpp:
     20        (WebCore::MediaElementSession::allowsAutomaticMediaDataLoading const):
     21
    1222019-11-13  Devin Rousso  <drousso@apple.com>
    223
  • trunk/Source/WebCore/dom/Document.cpp

    r252221 r252438  
    53625362}
    53635363
     5364bool Document::mediaDataLoadsAutomatically() const
     5365{
     5366    if (auto* loader = this->loader()) {
     5367        AutoplayPolicy policy = loader->autoplayPolicy();
     5368        if (policy != AutoplayPolicy::Default)
     5369            return policy != AutoplayPolicy::Deny;
     5370    }
     5371
     5372    return settings().mediaDataLoadsAutomatically();
     5373}
     5374
    53645375void Document::storageBlockingStateDidChange()
    53655376{
  • trunk/Source/WebCore/dom/Document.h

    r252205 r252438  
    10951095    bool audioPlaybackRequiresUserGesture() const;
    10961096    bool videoPlaybackRequiresUserGesture() const;
     1097    bool mediaDataLoadsAutomatically() const;
    10971098
    10981099#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r252325 r252438  
    526526#endif
    527527
    528         if (!document.settings().mediaDataLoadsAutomatically() && !document.quirks().needsPreloadAutoQuirk())
     528        if (!document.mediaDataLoadsAutomatically() && !document.quirks().needsPreloadAutoQuirk())
    529529            m_mediaSession->addBehaviorRestriction(MediaElementSession::AutoPreloadingNotPermitted);
    530530
  • trunk/Tools/ChangeLog

    r252437 r252438  
     12019-11-13  Jer Noble  <jer.noble@apple.com>
     2
     3        Link mediaDataLoadsAutomatically setting to AutoplayPolicy
     4        https://bugs.webkit.org/show_bug.cgi?id=201738
     5        <rdar://problem/55315194>
     6
     7        Reviewed by Eric Carlson.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKit/media-loading.html: Added.
     11        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
     12        (TEST):
     13
    1142019-11-13  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r252309 r252438  
    906906                CD78E11E1DB7EE2A0014A2DE /* FullscreenDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */; };
    907907                CD7F89DC22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */; };
     908                CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD8394DE232AF15E00149495 /* media-loading.html */; };
    908909                CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD9E292D1C90C1BA000BB800 /* audio-only.html */; };
    909910                CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */; };
     
    11391140                        dstSubfolderSpec = 7;
    11401141                        files = (
     1142                                CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */,
    11411143                                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
    11421144                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
     
    24102412                CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenDelegate.html; sourceTree = "<group>"; };
    24112413                CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewSuspendAllMediaPlayback.mm; sourceTree = "<group>"; };
     2414                CD8394DE232AF15E00149495 /* media-loading.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "media-loading.html"; sourceTree = "<group>"; };
    24122415                CD89D0381C4EDB2A00040A04 /* WebCoreNSURLSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLSession.mm; sourceTree = "<group>"; };
    24132416                CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequiresUserActionForPlayback.mm; sourceTree = "<group>"; };
     
    38703873                                1C2B81841C8924A200A5529F /* webfont.html */,
    38713874                                468F2F932368DAA700F4B864 /* window-open-then-document-open.html */,
     3875                                CD8394DE232AF15E00149495 /* media-loading.html */,
    38723876                        );
    38733877                        name = Resources;
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm

    r249705 r252438  
    175175}
    176176
    177 @interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
     177@interface AutoplayPoliciesDelegate : TestNavigationDelegate <WKNavigationDelegate, WKUIDelegatePrivate>
    178178@property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *);
    179179@property (nonatomic, copy) _WKWebsiteAutoplayQuirk(^allowedAutoplayQuirksForURL)(NSURL *);
     
    536536    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
    537537    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
     538}
     539
     540TEST(WebKit, WebsitePoliciesPerDocumentAutoplayBehaviorMediaLoading)
     541{
     542    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     543    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     544
     545    auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
     546    [webView setNavigationDelegate:delegate.get()];
     547
     548    __block bool receivedLoadedEvent = false;
     549    __block bool receivedSuspendEvent = false;
     550
     551    [webView performAfterReceivingMessage:@"loadeddata" action:^{ receivedLoadedEvent = true; }];
     552    [webView performAfterReceivingMessage:@"suspend" action:^{ receivedSuspendEvent = true; }];
     553
     554    [delegate setAutoplayPolicyForURL:^(NSURL *) {
     555        return _WKWebsiteAutoplayPolicyDeny;
     556    }];
     557
     558    [webView loadTestPageNamed:@"media-loading"];
     559
     560    TestWebKitAPI::Util::run(&receivedSuspendEvent);
     561    EXPECT_FALSE(receivedLoadedEvent);
     562
     563    [webView loadHTMLString:@"" baseURL:nil];
     564    [delegate waitForDidFinishNavigation];
     565
     566    [webView setNavigationDelegate:delegate.get()];
     567
     568    receivedLoadedEvent = false;
     569    receivedSuspendEvent = false;
     570
     571    [delegate setAutoplayPolicyForURL:^(NSURL *) {
     572        return _WKWebsiteAutoplayPolicyAllow;
     573    }];
     574
     575    [webView loadTestPageNamed:@"media-loading"];
     576
     577    TestWebKitAPI::Util::run(&receivedLoadedEvent);
    538578}
    539579
Note: See TracChangeset for help on using the changeset viewer.