Changeset 203928 in webkit


Ignore:
Timestamp:
Jul 29, 2016 5:11:27 PM (8 years ago)
Author:
Wenson Hsieh
Message:

Media controls are not displayed for some autoplaying videos at certain browser dimensions
https://bugs.webkit.org/show_bug.cgi?id=160360
<rdar://problem/27179484>

Reviewed by Myles C. Maxfield.

Source/WebCore:

Previously, if a video's aspect ratio fell outside of the range [0.5, 1.8], we would
not consider it main content and would subsequently not show media controls for it.
This meant that on many websites that scale video dimensions to match the mainframe,
if the mainframe is too wide (e.g. full bounds on a widescreen display) we would not
consider the video to be main content. To fix this, we only consider aspect ratio to
be a requirement if the video does not already take up most of the space in the
mainframe.

Covered by two new TestWebKitAPI unit tests.

  • html/MediaElementSession.cpp:

(WebCore::isElementLargeRelativeToMainFrame):
(WebCore::isElementLargeEnoughForMainContent):

Tools:

Adds two tests verifying that videos may be considered main content as long as they
are large enough and cover a majority of the mainframe's viewport.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html: Added.
  • TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203924 r203928  
     12016-07-29  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls are not displayed for some autoplaying videos at certain browser dimensions
     4        https://bugs.webkit.org/show_bug.cgi?id=160360
     5        <rdar://problem/27179484>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        Previously, if a video's aspect ratio fell outside of the range [0.5, 1.8], we would
     10        not consider it main content and would subsequently not show media controls for it.
     11        This meant that on many websites that scale video dimensions to match the mainframe,
     12        if the mainframe is too wide (e.g. full bounds on a widescreen display) we would not
     13        consider the video to be main content. To fix this, we only consider aspect ratio to
     14        be a requirement if the video does not already take up most of the space in the
     15        mainframe.
     16
     17        Covered by two new TestWebKitAPI unit tests.
     18
     19        * html/MediaElementSession.cpp:
     20        (WebCore::isElementLargeRelativeToMainFrame):
     21        (WebCore::isElementLargeEnoughForMainContent):
     22
    1232016-07-29  Zalan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/html/MediaElementSession.cpp

    r203765 r203928  
    600600}
    601601
     602static bool isElementLargeRelativeToMainFrame(const HTMLMediaElement& element)
     603{
     604    static const double minimumPercentageOfMainFrameAreaForMainContent = 0.9;
     605    auto* renderer = element.renderer();
     606    if (!renderer)
     607        return false;
     608
     609    auto* documentFrame = element.document().frame();
     610    if (!documentFrame)
     611        return false;
     612
     613    if (!documentFrame->mainFrame().view())
     614        return false;
     615
     616    auto& mainFrameView = *documentFrame->mainFrame().view();
     617    auto maxVisibleClientWidth = std::min(renderer->clientWidth().toInt(), mainFrameView.visibleWidth());
     618    auto maxVisibleClientHeight = std::min(renderer->clientHeight().toInt(), mainFrameView.visibleHeight());
     619
     620    return maxVisibleClientWidth * maxVisibleClientHeight > minimumPercentageOfMainFrameAreaForMainContent * mainFrameView.visibleWidth() * mainFrameView.visibleHeight();
     621}
     622
    602623static bool isElementLargeEnoughForMainContent(const HTMLMediaElement& element)
    603624{
    604625    static const double elementMainContentAreaMinimum = 400 * 300;
    605626    static const double maximumAspectRatio = 1.8; // Slightly larger than 16:9.
    606     static const double minimumAspectRatio = .5; // Slightly smaller than 16:9.
     627    static const double minimumAspectRatio = .5; // Slightly smaller than 9:16.
    607628
    608629    // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content.
     
    615636    double area = width * height;
    616637    double aspectRatio = width / height;
    617     return area >= elementMainContentAreaMinimum && aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio;
     638
     639    if (area < elementMainContentAreaMinimum)
     640        return false;
     641
     642    if (aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio)
     643        return true;
     644
     645    return isElementLargeRelativeToMainFrame(element);
    618646}
    619647
  • trunk/Tools/ChangeLog

    r203915 r203928  
     12016-07-29  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls are not displayed for some autoplaying videos at certain browser dimensions
     4        https://bugs.webkit.org/show_bug.cgi?id=160360
     5        <rdar://problem/27179484>
     6
     7        Reviewed by Myles C. Maxfield.
     8
     9        Adds two tests verifying that videos may be considered main content as long as they
     10        are large enough and cover a majority of the mainframe's viewport.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
     14        (TestWebKitAPI::TEST):
     15        * TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html: Added.
     16        * TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html: Added.
     17
    1182016-07-29  Mark Lam  <mark.lam@apple.com>
    219
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r203842 r203928  
    436436                E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
    437437                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
     438                F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
     439                F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
    438440                F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
    439441                F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
     
    505507                        dstSubfolderSpec = 7;
    506508                        files = (
     509                                F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */,
     510                                F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */,
    507511                                515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */,
    508512                                2E1DFDF11D42E1E400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html in Copy Resources */,
     
    10841088                E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
    10851089                F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
     1090                F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
     1091                F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
    10861092                F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
    10871093                F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; };
     
    13571363                        isa = PBXGroup;
    13581364                        children = (
     1365                                F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */,
     1366                                F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */,
    13591367                                2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */,
    13601368                                2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm

    r203905 r203928  
    416416}
    417417
     418TEST(VideoControlsManager, VideoControlsManagerLongSkinnyVideoInWideMainFrame)
     419{
     420    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     421    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
     422    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]);
     423    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     424    [[window contentView] addSubview:webView.get()];
     425
     426    RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]);
     427    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
     428    [handler setExpectedToHaveControlsManager:NO];
     429
     430    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"skinny-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     431    [webView loadRequest:request];
     432
     433    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
     434    TestWebKitAPI::Util::run(&receivedScriptMessage);
     435}
     436
     437TEST(VideoControlsManager, VideoControlsManagerFullSizeVideoInWideMainFrame)
     438{
     439    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     440    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
     441    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]);
     442    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     443    [[window contentView] addSubview:webView.get()];
     444
     445    RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]);
     446    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
     447    [handler setExpectedToHaveControlsManager:YES];
     448
     449    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"full-size-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     450    [webView loadRequest:request];
     451
     452    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
     453    TestWebKitAPI::Util::run(&receivedScriptMessage);
     454}
     455
    418456} // namespace TestWebKitAPI
    419457
Note: See TracChangeset for help on using the changeset viewer.