Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2767823002: Media Remoting: Add interstitial elements to media element shadow dom. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "core/frame/UseCounter.h" 50 #include "core/frame/UseCounter.h"
51 #include "core/frame/csp/ContentSecurityPolicy.h" 51 #include "core/frame/csp/ContentSecurityPolicy.h"
52 #include "core/html/AutoplayUmaHelper.h" 52 #include "core/html/AutoplayUmaHelper.h"
53 #include "core/html/HTMLMediaSource.h" 53 #include "core/html/HTMLMediaSource.h"
54 #include "core/html/HTMLSourceElement.h" 54 #include "core/html/HTMLSourceElement.h"
55 #include "core/html/HTMLTrackElement.h" 55 #include "core/html/HTMLTrackElement.h"
56 #include "core/html/MediaError.h" 56 #include "core/html/MediaError.h"
57 #include "core/html/MediaFragmentURIParser.h" 57 #include "core/html/MediaFragmentURIParser.h"
58 #include "core/html/TimeRanges.h" 58 #include "core/html/TimeRanges.h"
59 #include "core/html/shadow/MediaControls.h" 59 #include "core/html/shadow/MediaControls.h"
60 #include "core/html/shadow/MediaRemotingInterstitial.h"
60 #include "core/html/track/AudioTrack.h" 61 #include "core/html/track/AudioTrack.h"
61 #include "core/html/track/AudioTrackList.h" 62 #include "core/html/track/AudioTrackList.h"
62 #include "core/html/track/AutomaticTrackSelection.h" 63 #include "core/html/track/AutomaticTrackSelection.h"
63 #include "core/html/track/CueTimeline.h" 64 #include "core/html/track/CueTimeline.h"
64 #include "core/html/track/InbandTextTrack.h" 65 #include "core/html/track/InbandTextTrack.h"
65 #include "core/html/track/TextTrackContainer.h" 66 #include "core/html/track/TextTrackContainer.h"
66 #include "core/html/track/TextTrackList.h" 67 #include "core/html/track/TextTrackList.h"
67 #include "core/html/track/VideoTrack.h" 68 #include "core/html/track/VideoTrack.h"
68 #include "core/html/track/VideoTrackList.h" 69 #include "core/html/track/VideoTrackList.h"
69 #include "core/inspector/ConsoleMessage.h" 70 #include "core/inspector/ConsoleMessage.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 m_seeking(false), 460 m_seeking(false),
460 m_sentStalledEvent(false), 461 m_sentStalledEvent(false),
461 m_ignorePreloadNone(false), 462 m_ignorePreloadNone(false),
462 m_textTracksVisible(false), 463 m_textTracksVisible(false),
463 m_shouldPerformAutomaticTrackSelection(true), 464 m_shouldPerformAutomaticTrackSelection(true),
464 m_tracksAreReady(true), 465 m_tracksAreReady(true),
465 m_processingPreferenceChange(false), 466 m_processingPreferenceChange(false),
466 m_playingRemotely(false), 467 m_playingRemotely(false),
467 m_inOverlayFullscreenVideo(false), 468 m_inOverlayFullscreenVideo(false),
468 m_mostlyFillingViewport(false), 469 m_mostlyFillingViewport(false),
470 m_mediaRemotingDisabled(false),
469 m_audioTracks(this, AudioTrackList::create(*this)), 471 m_audioTracks(this, AudioTrackList::create(*this)),
470 m_videoTracks(this, VideoTrackList::create(*this)), 472 m_videoTracks(this, VideoTrackList::create(*this)),
471 m_textTracks(this, nullptr), 473 m_textTracks(this, nullptr),
472 m_audioSourceNode(nullptr), 474 m_audioSourceNode(nullptr),
473 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), 475 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)),
474 m_remotePlaybackClient(nullptr), 476 m_remotePlaybackClient(nullptr),
475 m_autoplayVisibilityObserver(nullptr), 477 m_autoplayVisibilityObserver(nullptr),
476 m_mediaControls(nullptr), 478 m_mediaControls(nullptr),
477 m_controlsList(HTMLMediaElementControlsList::create(this)), 479 m_controlsList(HTMLMediaElementControlsList::create(this)),
480 m_remotingInterstitial(nullptr),
478 m_isPersistentVideo(false) { 481 m_isPersistentVideo(false) {
479 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 482 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
480 483
481 m_lockedPendingUserGesture = computeLockedPendingUserGesture(document); 484 m_lockedPendingUserGesture = computeLockedPendingUserGesture(document);
482 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = 485 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled =
483 isDocumentCrossOrigin(document); 486 isDocumentCrossOrigin(document);
484 487
485 LocalFrame* frame = document.frame(); 488 LocalFrame* frame = document.frame();
486 if (frame) { 489 if (frame) {
487 m_remotePlaybackClient = 490 m_remotePlaybackClient =
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (mediaControls()) 620 if (mediaControls())
618 mediaControls()->onControlsListUpdated(); 621 mediaControls()->onControlsListUpdated();
619 } 622 }
620 } else if (name == preloadAttr) { 623 } else if (name == preloadAttr) {
621 setPlayerPreload(); 624 setPlayerPreload();
622 } else if (name == disableremoteplaybackAttr) { 625 } else if (name == disableremoteplaybackAttr) {
623 // This attribute is an extension described in the Remote Playback API spec. 626 // This attribute is an extension described in the Remote Playback API spec.
624 // Please see: https://w3c.github.io/remote-playback 627 // Please see: https://w3c.github.io/remote-playback
625 UseCounter::count(document(), UseCounter::DisableRemotePlaybackAttribute); 628 UseCounter::count(document(), UseCounter::DisableRemotePlaybackAttribute);
626 if (params.oldValue != params.newValue) { 629 if (params.oldValue != params.newValue) {
627 if (m_webMediaPlayer) { 630 if (m_webMediaPlayer && !m_mediaRemotingDisabled) {
628 m_webMediaPlayer->requestRemotePlaybackDisabled( 631 m_webMediaPlayer->requestRemotePlaybackDisabled(
629 !params.newValue.isNull()); 632 !params.newValue.isNull());
630 } 633 }
631 // TODO(mlamouri): there is no direct API to expose if 634 // TODO(mlamouri): there is no direct API to expose if
632 // disableRemotePLayback attribute has changed. It will require a direct 635 // disableRemotePLayback attribute has changed. It will require a direct
633 // access to MediaControls for the moment. 636 // access to MediaControls for the moment.
634 if (mediaControls()) 637 if (mediaControls())
635 mediaControls()->onDisableRemotePlaybackAttributeChanged(); 638 mediaControls()->onDisableRemotePlaybackAttributeChanged();
636 } 639 }
637 } else { 640 } else {
(...skipping 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 return true; 3607 return true;
3605 } 3608 }
3606 3609
3607 return false; 3610 return false;
3608 } 3611 }
3609 3612
3610 bool HTMLMediaElement::textTracksVisible() const { 3613 bool HTMLMediaElement::textTracksVisible() const {
3611 return m_textTracksVisible; 3614 return m_textTracksVisible;
3612 } 3615 }
3613 3616
3614 static void assertShadowRootChildren(ShadowRoot& shadowRoot) { 3617 static void assertShadowRootChildren(ShadowRoot& shadowRoot,
3618 Node* mediaControls) {
3615 #if DCHECK_IS_ON() 3619 #if DCHECK_IS_ON()
3616 // There can be up to two children, either or both of the text 3620 // There can be up to three children: text track container, media controls,
3617 // track container and media controls. If both are present, the 3621 // and media remoting UI. The |mediaControls| has to be the last child if
3618 // text track container must be the first child. 3622 // present.
3619 unsigned numberOfChildren = shadowRoot.countChildren(); 3623 unsigned numberOfChildren = shadowRoot.countChildren();
3620 DCHECK_LE(numberOfChildren, 2u); 3624 DCHECK_LE(numberOfChildren, 3u);
3621 Node* firstChild = shadowRoot.firstChild(); 3625 Node* firstChild = shadowRoot.firstChild();
3622 Node* lastChild = shadowRoot.lastChild();
3623 if (numberOfChildren == 1) { 3626 if (numberOfChildren == 1) {
3624 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls()); 3627 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls());
3625 } else if (numberOfChildren == 2) { 3628 } else if (mediaControls) {
3626 DCHECK(firstChild->isTextTrackContainer()); 3629 Node* lastChild = shadowRoot.lastChild();
3627 DCHECK(lastChild->isMediaControls()); 3630 DCHECK(lastChild == mediaControls);
3628 } 3631 }
3629 #endif 3632 #endif
3630 } 3633 }
3631 3634
3632 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() { 3635 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() {
3633 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); 3636 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
3634 assertShadowRootChildren(shadowRoot); 3637 assertShadowRootChildren(shadowRoot, m_mediaControls);
3635 3638
3636 Node* firstChild = shadowRoot.firstChild(); 3639 Node* firstChild = shadowRoot.firstChild();
3637 if (firstChild && firstChild->isTextTrackContainer()) 3640 if (firstChild && firstChild->isTextTrackContainer())
3638 return toTextTrackContainer(*firstChild); 3641 return toTextTrackContainer(*firstChild);
3639 3642
3640 TextTrackContainer* textTrackContainer = 3643 TextTrackContainer* textTrackContainer =
3641 TextTrackContainer::create(document()); 3644 TextTrackContainer::create(document());
3642 3645
3643 // The text track container should be inserted before the media controls, 3646 // The text track container should be inserted before the media controls,
3644 // so that they are rendered behind them. 3647 // so that they are rendered behind them.
3645 shadowRoot.insertBefore(textTrackContainer, firstChild); 3648 shadowRoot.insertBefore(textTrackContainer, firstChild);
3646 3649
3647 assertShadowRootChildren(shadowRoot); 3650 assertShadowRootChildren(shadowRoot, m_mediaControls);
3648 3651
3649 return *textTrackContainer; 3652 return *textTrackContainer;
3650 } 3653 }
3651 3654
3652 void HTMLMediaElement::updateTextTrackDisplay() { 3655 void HTMLMediaElement::updateTextTrackDisplay() {
3653 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")"; 3656 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")";
3654 3657
3655 ensureTextTrackContainer().updateDisplay( 3658 ensureTextTrackContainer().updateDisplay(
3656 *this, TextTrackContainer::DidNotStartExposingControls); 3659 *this, TextTrackContainer::DidNotStartExposingControls);
3657 } 3660 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 void HTMLMediaElement::ensureMediaControls() { 3752 void HTMLMediaElement::ensureMediaControls() {
3750 if (mediaControls()) 3753 if (mediaControls())
3751 return; 3754 return;
3752 3755
3753 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); 3756 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
3754 m_mediaControls = MediaControls::create(*this, shadowRoot); 3757 m_mediaControls = MediaControls::create(*this, shadowRoot);
3755 3758
3756 // The media controls should be inserted after the text track container, 3759 // The media controls should be inserted after the text track container,
3757 // so that they are rendered in front of captions and subtitles. This check 3760 // so that they are rendered in front of captions and subtitles. This check
3758 // is verifying the contract. 3761 // is verifying the contract.
3759 assertShadowRootChildren(shadowRoot); 3762 assertShadowRootChildren(shadowRoot, m_mediaControls);
3760 } 3763 }
3761 3764
3762 void HTMLMediaElement::updateControlsVisibility() { 3765 void HTMLMediaElement::updateControlsVisibility() {
3763 if (!isConnected()) { 3766 if (!isConnected()) {
3764 if (mediaControls()) 3767 if (mediaControls())
3765 mediaControls()->hide(); 3768 mediaControls()->hide();
3766 return; 3769 return;
3767 } 3770 }
3768 3771
3769 ensureMediaControls(); 3772 ensureMediaControls();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3882 visitor->trace(m_textTracksWhenResourceSelectionBegan); 3885 visitor->trace(m_textTracksWhenResourceSelectionBegan);
3883 visitor->trace(m_playPromiseResolvers); 3886 visitor->trace(m_playPromiseResolvers);
3884 visitor->trace(m_playPromiseResolveList); 3887 visitor->trace(m_playPromiseResolveList);
3885 visitor->trace(m_playPromiseRejectList); 3888 visitor->trace(m_playPromiseRejectList);
3886 visitor->trace(m_audioSourceProvider); 3889 visitor->trace(m_audioSourceProvider);
3887 visitor->trace(m_autoplayUmaHelper); 3890 visitor->trace(m_autoplayUmaHelper);
3888 visitor->trace(m_srcObject); 3891 visitor->trace(m_srcObject);
3889 visitor->trace(m_autoplayVisibilityObserver); 3892 visitor->trace(m_autoplayVisibilityObserver);
3890 visitor->trace(m_mediaControls); 3893 visitor->trace(m_mediaControls);
3891 visitor->trace(m_controlsList); 3894 visitor->trace(m_controlsList);
3895 visitor->trace(m_remotingInterstitial);
3892 visitor->template registerWeakMembers<HTMLMediaElement, 3896 visitor->template registerWeakMembers<HTMLMediaElement,
3893 &HTMLMediaElement::clearWeakMembers>( 3897 &HTMLMediaElement::clearWeakMembers>(
3894 this); 3898 this);
3895 Supplementable<HTMLMediaElement>::trace(visitor); 3899 Supplementable<HTMLMediaElement>::trace(visitor);
3896 HTMLElement::trace(visitor); 3900 HTMLElement::trace(visitor);
3897 SuspendableObject::trace(visitor); 3901 SuspendableObject::trace(visitor);
3898 } 3902 }
3899 3903
3900 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) { 3904 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) {
3901 visitor->traceWrappers(m_videoTracks); 3905 visitor->traceWrappers(m_videoTracks);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
4240 m_viewportFillDebouncerTimer.startOneShot( 4244 m_viewportFillDebouncerTimer.startOneShot(
4241 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); 4245 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4242 } 4246 }
4243 4247
4244 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { 4248 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4245 m_mostlyFillingViewport = true; 4249 m_mostlyFillingViewport = true;
4246 if (m_webMediaPlayer) 4250 if (m_webMediaPlayer)
4247 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4251 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4248 } 4252 }
4249 4253
4254 void HTMLMediaElement::mediaRemotingStarted() {
4255 if (!m_remotingInterstitial) {
4256 m_remotingInterstitial = new MediaRemotingInterstitial(*this);
4257 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
4258 assertShadowRootChildren(shadowRoot, m_mediaControls);
4259 // Ensure the default mediaControls is the last child of the |shadowRoot|.
4260 Node* lastChild = shadowRoot.lastChild();
4261 if (lastChild && lastChild->isMediaControls())
4262 shadowRoot.insertBefore(m_remotingInterstitial, lastChild);
4263 else
4264 shadowRoot.appendChild(m_remotingInterstitial);
4265 assertShadowRootChildren(shadowRoot, m_mediaControls);
4266 }
4267 if (m_remotingInterstitial)
4268 m_remotingInterstitial->show();
4269 }
4270
4271 void HTMLMediaElement::mediaRemotingStopped() {
4272 if (m_remotingInterstitial)
4273 m_remotingInterstitial->hide();
4274 }
4275
4276 void HTMLMediaElement::disableMediaRemoting() {
4277 if (m_webMediaPlayer)
4278 m_webMediaPlayer->requestRemotePlaybackDisabled(true);
4279 m_mediaRemotingDisabled = true;
4280 if (m_remotingInterstitial)
4281 m_remotingInterstitial->hide();
4282 }
4283
4250 } // namespace blink 4284 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698