| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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), |
| 471 m_mediaRemotingStarted(false), |
| 469 m_audioTracks(this, AudioTrackList::create(*this)), | 472 m_audioTracks(this, AudioTrackList::create(*this)), |
| 470 m_videoTracks(this, VideoTrackList::create(*this)), | 473 m_videoTracks(this, VideoTrackList::create(*this)), |
| 471 m_textTracks(this, nullptr), | 474 m_textTracks(this, nullptr), |
| 472 m_audioSourceNode(nullptr), | 475 m_audioSourceNode(nullptr), |
| 473 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), | 476 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), |
| 474 m_remotePlaybackClient(nullptr), | 477 m_remotePlaybackClient(nullptr), |
| 475 m_autoplayVisibilityObserver(nullptr), | 478 m_autoplayVisibilityObserver(nullptr), |
| 476 m_mediaControls(nullptr), | 479 m_mediaControls(nullptr), |
| 477 m_controlsList(HTMLMediaElementControlsList::create(this)), | 480 m_controlsList(HTMLMediaElementControlsList::create(this)), |
| 481 m_remotingInterstitial(nullptr), |
| 478 m_isPersistentVideo(false) { | 482 m_isPersistentVideo(false) { |
| 479 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; | 483 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; |
| 480 | 484 |
| 481 m_lockedPendingUserGesture = computeLockedPendingUserGesture(document); | 485 m_lockedPendingUserGesture = computeLockedPendingUserGesture(document); |
| 482 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = | 486 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = |
| 483 isDocumentCrossOrigin(document); | 487 isDocumentCrossOrigin(document); |
| 484 | 488 |
| 485 LocalFrame* frame = document.frame(); | 489 LocalFrame* frame = document.frame(); |
| 486 if (frame) { | 490 if (frame) { |
| 487 m_remotePlaybackClient = | 491 m_remotePlaybackClient = |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 if (mediaControls()) | 621 if (mediaControls()) |
| 618 mediaControls()->onControlsListUpdated(); | 622 mediaControls()->onControlsListUpdated(); |
| 619 } | 623 } |
| 620 } else if (name == preloadAttr) { | 624 } else if (name == preloadAttr) { |
| 621 setPlayerPreload(); | 625 setPlayerPreload(); |
| 622 } else if (name == disableremoteplaybackAttr) { | 626 } else if (name == disableremoteplaybackAttr) { |
| 623 // This attribute is an extension described in the Remote Playback API spec. | 627 // This attribute is an extension described in the Remote Playback API spec. |
| 624 // Please see: https://w3c.github.io/remote-playback | 628 // Please see: https://w3c.github.io/remote-playback |
| 625 UseCounter::count(document(), UseCounter::DisableRemotePlaybackAttribute); | 629 UseCounter::count(document(), UseCounter::DisableRemotePlaybackAttribute); |
| 626 if (params.oldValue != params.newValue) { | 630 if (params.oldValue != params.newValue) { |
| 627 if (m_webMediaPlayer) { | 631 // Don't inform |m_webMediaPlayer| this change if Media Remoting is |
| 632 // explicitly disabled by user. |
| 633 if (m_webMediaPlayer && !m_mediaRemotingDisabled) { |
| 628 m_webMediaPlayer->requestRemotePlaybackDisabled( | 634 m_webMediaPlayer->requestRemotePlaybackDisabled( |
| 629 !params.newValue.isNull()); | 635 !params.newValue.isNull()); |
| 630 } | 636 } |
| 631 // TODO(mlamouri): there is no direct API to expose if | 637 // TODO(mlamouri): there is no direct API to expose if |
| 632 // disableRemotePLayback attribute has changed. It will require a direct | 638 // disableRemotePLayback attribute has changed. It will require a direct |
| 633 // access to MediaControls for the moment. | 639 // access to MediaControls for the moment. |
| 634 if (mediaControls()) | 640 if (mediaControls()) |
| 635 mediaControls()->onDisableRemotePlaybackAttributeChanged(); | 641 mediaControls()->onDisableRemotePlaybackAttributeChanged(); |
| 636 } | 642 } |
| 637 } else { | 643 } else { |
| (...skipping 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3604 return true; | 3610 return true; |
| 3605 } | 3611 } |
| 3606 | 3612 |
| 3607 return false; | 3613 return false; |
| 3608 } | 3614 } |
| 3609 | 3615 |
| 3610 bool HTMLMediaElement::textTracksVisible() const { | 3616 bool HTMLMediaElement::textTracksVisible() const { |
| 3611 return m_textTracksVisible; | 3617 return m_textTracksVisible; |
| 3612 } | 3618 } |
| 3613 | 3619 |
| 3614 static void assertShadowRootChildren(ShadowRoot& shadowRoot) { | 3620 static void assertShadowRootChildren(ShadowRoot& shadowRoot, |
| 3621 Node* mediaControls) { |
| 3615 #if DCHECK_IS_ON() | 3622 #if DCHECK_IS_ON() |
| 3616 // There can be up to two children, either or both of the text | 3623 // There can be up to three children: text track container, media controls, |
| 3617 // track container and media controls. If both are present, the | 3624 // and media remoting UI. The |mediaControls| has to be the last child if |
| 3618 // text track container must be the first child. | 3625 // present. |
| 3619 unsigned numberOfChildren = shadowRoot.countChildren(); | 3626 unsigned numberOfChildren = shadowRoot.countChildren(); |
| 3620 DCHECK_LE(numberOfChildren, 2u); | 3627 DCHECK_LE(numberOfChildren, 3u); |
| 3621 Node* firstChild = shadowRoot.firstChild(); | 3628 Node* firstChild = shadowRoot.firstChild(); |
| 3622 Node* lastChild = shadowRoot.lastChild(); | |
| 3623 if (numberOfChildren == 1) { | 3629 if (numberOfChildren == 1) { |
| 3624 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls()); | 3630 DCHECK(firstChild->isTextTrackContainer() || firstChild->isMediaControls()); |
| 3625 } else if (numberOfChildren == 2) { | 3631 } else if (mediaControls) { |
| 3626 DCHECK(firstChild->isTextTrackContainer()); | 3632 Node* lastChild = shadowRoot.lastChild(); |
| 3627 DCHECK(lastChild->isMediaControls()); | 3633 DCHECK(lastChild == mediaControls); |
| 3628 } | 3634 } |
| 3629 #endif | 3635 #endif |
| 3630 } | 3636 } |
| 3631 | 3637 |
| 3632 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() { | 3638 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() { |
| 3633 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); | 3639 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); |
| 3634 assertShadowRootChildren(shadowRoot); | 3640 assertShadowRootChildren(shadowRoot, m_mediaControls); |
| 3635 | 3641 |
| 3636 Node* firstChild = shadowRoot.firstChild(); | 3642 Node* firstChild = shadowRoot.firstChild(); |
| 3637 if (firstChild && firstChild->isTextTrackContainer()) | 3643 if (firstChild && firstChild->isTextTrackContainer()) |
| 3638 return toTextTrackContainer(*firstChild); | 3644 return toTextTrackContainer(*firstChild); |
| 3639 | 3645 |
| 3640 TextTrackContainer* textTrackContainer = | 3646 TextTrackContainer* textTrackContainer = |
| 3641 TextTrackContainer::create(document()); | 3647 TextTrackContainer::create(document()); |
| 3642 | 3648 |
| 3643 // The text track container should be inserted before the media controls, | 3649 // The text track container should be inserted before the media controls, |
| 3644 // so that they are rendered behind them. | 3650 // so that they are rendered behind them. |
| 3645 shadowRoot.insertBefore(textTrackContainer, firstChild); | 3651 shadowRoot.insertBefore(textTrackContainer, firstChild); |
| 3646 | 3652 |
| 3647 assertShadowRootChildren(shadowRoot); | 3653 assertShadowRootChildren(shadowRoot, m_mediaControls); |
| 3648 | 3654 |
| 3649 return *textTrackContainer; | 3655 return *textTrackContainer; |
| 3650 } | 3656 } |
| 3651 | 3657 |
| 3652 void HTMLMediaElement::updateTextTrackDisplay() { | 3658 void HTMLMediaElement::updateTextTrackDisplay() { |
| 3653 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")"; | 3659 BLINK_MEDIA_LOG << "updateTextTrackDisplay(" << (void*)this << ")"; |
| 3654 | 3660 |
| 3655 ensureTextTrackContainer().updateDisplay( | 3661 ensureTextTrackContainer().updateDisplay( |
| 3656 *this, TextTrackContainer::DidNotStartExposingControls); | 3662 *this, TextTrackContainer::DidNotStartExposingControls); |
| 3657 } | 3663 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3749 void HTMLMediaElement::ensureMediaControls() { | 3755 void HTMLMediaElement::ensureMediaControls() { |
| 3750 if (mediaControls()) | 3756 if (mediaControls()) |
| 3751 return; | 3757 return; |
| 3752 | 3758 |
| 3753 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); | 3759 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); |
| 3754 m_mediaControls = MediaControls::create(*this, shadowRoot); | 3760 m_mediaControls = MediaControls::create(*this, shadowRoot); |
| 3755 | 3761 |
| 3756 // The media controls should be inserted after the text track container, | 3762 // 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 | 3763 // so that they are rendered in front of captions and subtitles. This check |
| 3758 // is verifying the contract. | 3764 // is verifying the contract. |
| 3759 assertShadowRootChildren(shadowRoot); | 3765 assertShadowRootChildren(shadowRoot, m_mediaControls); |
| 3760 } | 3766 } |
| 3761 | 3767 |
| 3762 void HTMLMediaElement::updateControlsVisibility() { | 3768 void HTMLMediaElement::updateControlsVisibility() { |
| 3763 if (!isConnected()) { | 3769 if (!isConnected()) { |
| 3764 if (mediaControls()) | 3770 if (mediaControls()) |
| 3765 mediaControls()->hide(); | 3771 mediaControls()->hide(); |
| 3766 return; | 3772 return; |
| 3767 } | 3773 } |
| 3768 | 3774 |
| 3769 ensureMediaControls(); | 3775 ensureMediaControls(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3882 visitor->trace(m_textTracksWhenResourceSelectionBegan); | 3888 visitor->trace(m_textTracksWhenResourceSelectionBegan); |
| 3883 visitor->trace(m_playPromiseResolvers); | 3889 visitor->trace(m_playPromiseResolvers); |
| 3884 visitor->trace(m_playPromiseResolveList); | 3890 visitor->trace(m_playPromiseResolveList); |
| 3885 visitor->trace(m_playPromiseRejectList); | 3891 visitor->trace(m_playPromiseRejectList); |
| 3886 visitor->trace(m_audioSourceProvider); | 3892 visitor->trace(m_audioSourceProvider); |
| 3887 visitor->trace(m_autoplayUmaHelper); | 3893 visitor->trace(m_autoplayUmaHelper); |
| 3888 visitor->trace(m_srcObject); | 3894 visitor->trace(m_srcObject); |
| 3889 visitor->trace(m_autoplayVisibilityObserver); | 3895 visitor->trace(m_autoplayVisibilityObserver); |
| 3890 visitor->trace(m_mediaControls); | 3896 visitor->trace(m_mediaControls); |
| 3891 visitor->trace(m_controlsList); | 3897 visitor->trace(m_controlsList); |
| 3898 visitor->trace(m_remotingInterstitial); |
| 3892 visitor->template registerWeakMembers<HTMLMediaElement, | 3899 visitor->template registerWeakMembers<HTMLMediaElement, |
| 3893 &HTMLMediaElement::clearWeakMembers>( | 3900 &HTMLMediaElement::clearWeakMembers>( |
| 3894 this); | 3901 this); |
| 3895 Supplementable<HTMLMediaElement>::trace(visitor); | 3902 Supplementable<HTMLMediaElement>::trace(visitor); |
| 3896 HTMLElement::trace(visitor); | 3903 HTMLElement::trace(visitor); |
| 3897 SuspendableObject::trace(visitor); | 3904 SuspendableObject::trace(visitor); |
| 3898 } | 3905 } |
| 3899 | 3906 |
| 3900 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) { | 3907 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) { |
| 3901 visitor->traceWrappers(m_videoTracks); | 3908 visitor->traceWrappers(m_videoTracks); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 m_viewportFillDebouncerTimer.startOneShot( | 4247 m_viewportFillDebouncerTimer.startOneShot( |
| 4241 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); | 4248 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); |
| 4242 } | 4249 } |
| 4243 | 4250 |
| 4244 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { | 4251 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { |
| 4245 m_mostlyFillingViewport = true; | 4252 m_mostlyFillingViewport = true; |
| 4246 if (m_webMediaPlayer) | 4253 if (m_webMediaPlayer) |
| 4247 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); | 4254 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); |
| 4248 } | 4255 } |
| 4249 | 4256 |
| 4257 void HTMLMediaElement::mediaRemotingStarted() { |
| 4258 m_mediaRemotingStarted = true; |
| 4259 if (!m_remotingInterstitial) { |
| 4260 m_remotingInterstitial = new MediaRemotingInterstitial(*this); |
| 4261 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); |
| 4262 assertShadowRootChildren(shadowRoot, m_mediaControls); |
| 4263 // Ensure the default mediaControls is the last child of the |shadowRoot|. |
| 4264 Node* lastChild = shadowRoot.lastChild(); |
| 4265 if (lastChild && lastChild->isMediaControls()) |
| 4266 shadowRoot.insertBefore(m_remotingInterstitial, lastChild); |
| 4267 else |
| 4268 shadowRoot.appendChild(m_remotingInterstitial); |
| 4269 assertShadowRootChildren(shadowRoot, m_mediaControls); |
| 4270 } |
| 4271 if (m_remotingInterstitial) |
| 4272 m_remotingInterstitial->show(); |
| 4273 } |
| 4274 |
| 4275 void HTMLMediaElement::mediaRemotingStopped() { |
| 4276 m_mediaRemotingStarted = false; |
| 4277 if (m_remotingInterstitial) |
| 4278 m_remotingInterstitial->hide(); |
| 4279 } |
| 4280 |
| 4281 void HTMLMediaElement::disableMediaRemoting() { |
| 4282 if (m_webMediaPlayer) |
| 4283 m_webMediaPlayer->requestRemotePlaybackDisabled(true); |
| 4284 m_mediaRemotingDisabled = true; |
| 4285 m_mediaRemotingStarted = false; |
| 4286 if (m_remotingInterstitial) |
| 4287 m_remotingInterstitial->hide(); |
| 4288 } |
| 4289 |
| 4290 void HTMLMediaElement::onPosterImageChanged() { |
| 4291 if (m_remotingInterstitial) |
| 4292 m_remotingInterstitial->onPosterImageChanged(); |
| 4293 } |
| 4294 |
| 4250 } // namespace blink | 4295 } // namespace blink |
| OLD | NEW |