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

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: Modified disable button. Added cast icon and message. Created 3 years, 8 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 // Don't inform |m_webMediaPlayer| this change if Media Remoting is
631 // explicitly disabled by user.
632 if (m_webMediaPlayer && !m_mediaRemotingDisabled) {
628 m_webMediaPlayer->requestRemotePlaybackDisabled( 633 m_webMediaPlayer->requestRemotePlaybackDisabled(
629 !params.newValue.isNull()); 634 !params.newValue.isNull());
630 } 635 }
631 // TODO(mlamouri): there is no direct API to expose if 636 // TODO(mlamouri): there is no direct API to expose if
632 // disableRemotePLayback attribute has changed. It will require a direct 637 // disableRemotePLayback attribute has changed. It will require a direct
633 // access to MediaControls for the moment. 638 // access to MediaControls for the moment.
634 if (mediaControls()) 639 if (mediaControls())
635 mediaControls()->onDisableRemotePlaybackAttributeChanged(); 640 mediaControls()->onDisableRemotePlaybackAttributeChanged();
636 } 641 }
637 } else { 642 } else {
(...skipping 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 return true; 3609 return true;
3605 } 3610 }
3606 3611
3607 return false; 3612 return false;
3608 } 3613 }
3609 3614
3610 bool HTMLMediaElement::textTracksVisible() const { 3615 bool HTMLMediaElement::textTracksVisible() const {
3611 return m_textTracksVisible; 3616 return m_textTracksVisible;
3612 } 3617 }
3613 3618
3614 static void assertShadowRootChildren(ShadowRoot& shadowRoot) { 3619 static void assertShadowRootChildren(ShadowRoot& shadowRoot,
3620 Node* mediaControls) {
3615 #if DCHECK_IS_ON() 3621 #if DCHECK_IS_ON()
3616 // There can be up to two children, either or both of the text 3622 // There can be up to three children: text track container, media controls,
3617 // track container and media controls. If both are present, the 3623 // and media remoting UI. The |mediaControls| has to be the last child if
3618 // text track container must be the first child. 3624 // present.
3619 unsigned numberOfChildren = shadowRoot.countChildren(); 3625 unsigned numberOfChildren = shadowRoot.countChildren();
3620 DCHECK_LE(numberOfChildren, 2u); 3626 DCHECK_LE(numberOfChildren, 3u);
3621 Node* firstChild = shadowRoot.firstChild(); 3627 Node* firstChild = shadowRoot.firstChild();
3622 Node* lastChild = shadowRoot.lastChild();
3623 if (numberOfChildren == 1) { 3628 if (numberOfChildren == 1) {
3624 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls()); 3629 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls());
3625 } else if (numberOfChildren == 2) { 3630 } else if (mediaControls) {
3626 DCHECK(firstChild->isTextTrackContainer()); 3631 Node* lastChild = shadowRoot.lastChild();
3627 DCHECK(lastChild->isMediaControls()); 3632 DCHECK(lastChild == mediaControls);
3628 } 3633 }
3629 #endif 3634 #endif
3630 } 3635 }
3631 3636
3632 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() { 3637 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() {
3633 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); 3638 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
3634 assertShadowRootChildren(shadowRoot); 3639 assertShadowRootChildren(shadowRoot, m_mediaControls);
3635 3640
3636 Node* firstChild = shadowRoot.firstChild(); 3641 Node* firstChild = shadowRoot.firstChild();
3637 if (firstChild && firstChild->isTextTrackContainer()) 3642 if (firstChild && firstChild->isTextTrackContainer())
3638 return toTextTrackContainer(*firstChild); 3643 return toTextTrackContainer(*firstChild);
3639 3644
3640 TextTrackContainer* textTrackContainer = 3645 TextTrackContainer* textTrackContainer =
3641 TextTrackContainer::create(document()); 3646 TextTrackContainer::create(document());
3642 3647
3643 // The text track container should be inserted before the media controls, 3648 // The text track container should be inserted before the media controls,
3644 // so that they are rendered behind them. 3649 // so that they are rendered behind them.
3645 shadowRoot.insertBefore(textTrackContainer, firstChild); 3650 shadowRoot.insertBefore(textTrackContainer, firstChild);
3646 3651
3647 assertShadowRootChildren(shadowRoot); 3652 assertShadowRootChildren(shadowRoot, m_mediaControls);
3648 3653
3649 return *textTrackContainer; 3654 return *textTrackContainer;
3650 } 3655 }
3651 3656
3652 void HTMLMediaElement::updateTextTrackDisplay() { 3657 void HTMLMediaElement::updateTextTrackDisplay() {
3653 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")"; 3658 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")";
3654 3659
3655 ensureTextTrackContainer().updateDisplay( 3660 ensureTextTrackContainer().updateDisplay(
3656 *this, TextTrackContainer::DidNotStartExposingControls); 3661 *this, TextTrackContainer::DidNotStartExposingControls);
3657 } 3662 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 void HTMLMediaElement::ensureMediaControls() { 3754 void HTMLMediaElement::ensureMediaControls() {
3750 if (mediaControls()) 3755 if (mediaControls())
3751 return; 3756 return;
3752 3757
3753 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); 3758 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
3754 m_mediaControls = MediaControls::create(*this, shadowRoot); 3759 m_mediaControls = MediaControls::create(*this, shadowRoot);
3755 3760
3756 // The media controls should be inserted after the text track container, 3761 // 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 3762 // so that they are rendered in front of captions and subtitles. This check
3758 // is verifying the contract. 3763 // is verifying the contract.
3759 assertShadowRootChildren(shadowRoot); 3764 assertShadowRootChildren(shadowRoot, m_mediaControls);
3760 } 3765 }
3761 3766
3762 void HTMLMediaElement::updateControlsVisibility() { 3767 void HTMLMediaElement::updateControlsVisibility() {
3763 if (!isConnected()) { 3768 if (!isConnected()) {
3764 if (mediaControls()) 3769 if (mediaControls())
3765 mediaControls()->hide(); 3770 mediaControls()->hide();
3766 return; 3771 return;
3767 } 3772 }
3768 3773
3769 ensureMediaControls(); 3774 ensureMediaControls();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3882 visitor->trace(m_textTracksWhenResourceSelectionBegan); 3887 visitor->trace(m_textTracksWhenResourceSelectionBegan);
3883 visitor->trace(m_playPromiseResolvers); 3888 visitor->trace(m_playPromiseResolvers);
3884 visitor->trace(m_playPromiseResolveList); 3889 visitor->trace(m_playPromiseResolveList);
3885 visitor->trace(m_playPromiseRejectList); 3890 visitor->trace(m_playPromiseRejectList);
3886 visitor->trace(m_audioSourceProvider); 3891 visitor->trace(m_audioSourceProvider);
3887 visitor->trace(m_autoplayUmaHelper); 3892 visitor->trace(m_autoplayUmaHelper);
3888 visitor->trace(m_srcObject); 3893 visitor->trace(m_srcObject);
3889 visitor->trace(m_autoplayVisibilityObserver); 3894 visitor->trace(m_autoplayVisibilityObserver);
3890 visitor->trace(m_mediaControls); 3895 visitor->trace(m_mediaControls);
3891 visitor->trace(m_controlsList); 3896 visitor->trace(m_controlsList);
3897 visitor->trace(m_remotingInterstitial);
3892 visitor->template registerWeakMembers<HTMLMediaElement, 3898 visitor->template registerWeakMembers<HTMLMediaElement,
3893 &HTMLMediaElement::clearWeakMembers>( 3899 &HTMLMediaElement::clearWeakMembers>(
3894 this); 3900 this);
3895 Supplementable<HTMLMediaElement>::trace(visitor); 3901 Supplementable<HTMLMediaElement>::trace(visitor);
3896 HTMLElement::trace(visitor); 3902 HTMLElement::trace(visitor);
3897 SuspendableObject::trace(visitor); 3903 SuspendableObject::trace(visitor);
3898 } 3904 }
3899 3905
3900 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) { 3906 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) {
3901 visitor->traceWrappers(m_videoTracks); 3907 visitor->traceWrappers(m_videoTracks);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
4240 m_viewportFillDebouncerTimer.startOneShot( 4246 m_viewportFillDebouncerTimer.startOneShot(
4241 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); 4247 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4242 } 4248 }
4243 4249
4244 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { 4250 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4245 m_mostlyFillingViewport = true; 4251 m_mostlyFillingViewport = true;
4246 if (m_webMediaPlayer) 4252 if (m_webMediaPlayer)
4247 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4253 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4248 } 4254 }
4249 4255
4256 void HTMLMediaElement::mediaRemotingStarted() {
4257 if (!m_remotingInterstitial) {
4258 m_remotingInterstitial = new MediaRemotingInterstitial(*this);
4259 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
4260 assertShadowRootChildren(shadowRoot, m_mediaControls);
4261 // Ensure the default mediaControls is the last child of the |shadowRoot|.
4262 Node* lastChild = shadowRoot.lastChild();
4263 if (lastChild && lastChild->isMediaControls())
4264 shadowRoot.insertBefore(m_remotingInterstitial, lastChild);
4265 else
4266 shadowRoot.appendChild(m_remotingInterstitial);
4267 assertShadowRootChildren(shadowRoot, m_mediaControls);
4268 }
4269 if (m_remotingInterstitial)
4270 m_remotingInterstitial->show();
4271 }
4272
4273 void HTMLMediaElement::mediaRemotingStopped() {
4274 if (m_remotingInterstitial)
4275 m_remotingInterstitial->hide();
4276 }
4277
4278 void HTMLMediaElement::disableMediaRemoting() {
4279 if (m_webMediaPlayer)
4280 m_webMediaPlayer->requestRemotePlaybackDisabled(true);
4281 m_mediaRemotingDisabled = true;
4282 if (m_remotingInterstitial)
4283 m_remotingInterstitial->hide();
4284 }
4285
4286 void HTMLMediaElement::onPosterImageChanged() {
4287 if (m_remotingInterstitial)
4288 m_remotingInterstitial->onPosterImageChanged();
4289 }
4290
4250 } // namespace blink 4291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698