| Index: third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp
|
| diff --git a/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp b/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp
|
| index a6289dbe9e516d390c539aa9ccc507d119752c04..58d85af640fea295d259f51ca5dfe4993fbcb5a8 100644
|
| --- a/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp
|
| +++ b/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp
|
| @@ -29,6 +29,10 @@
|
| #include "bindings/core/v8/ExceptionState.h"
|
| #include "core/dom/ClientRect.h"
|
| #include "core/dom/Fullscreen.h"
|
| +#include "core/dom/MutationCallback.h"
|
| +#include "core/dom/MutationObserver.h"
|
| +#include "core/dom/MutationObserverInit.h"
|
| +#include "core/dom/MutationRecord.h"
|
| #include "core/dom/ResizeObserver.h"
|
| #include "core/dom/ResizeObserverCallback.h"
|
| #include "core/dom/ResizeObserverEntry.h"
|
| @@ -63,6 +67,8 @@
|
| #include "modules/media_controls/elements/MediaControlTimelineElement.h"
|
| #include "modules/media_controls/elements/MediaControlToggleClosedCaptionsButtonElement.h"
|
| #include "modules/media_controls/elements/MediaControlVolumeSliderElement.h"
|
| +#include "modules/remoteplayback/HTMLMediaElementRemotePlayback.h"
|
| +#include "modules/remoteplayback/RemotePlayback.h"
|
| #include "platform/EventDispatchForbiddenScope.h"
|
|
|
| namespace blink {
|
| @@ -132,7 +138,9 @@ bool ShouldShowCastButton(HTMLMediaElement& media_element) {
|
| return false;
|
| }
|
|
|
| - return media_element.HasRemoteRoutes();
|
| + RemotePlayback* remote =
|
| + HTMLMediaElementRemotePlayback::remote(media_element);
|
| + return remote && remote->RemotePlaybackAvailable();
|
| }
|
|
|
| bool PreferHiddenVolumeControls(const Document& document) {
|
| @@ -193,6 +201,57 @@ class MediaControlsImpl::MediaControlsResizeObserverCallback final
|
| Member<MediaControlsImpl> controls_;
|
| };
|
|
|
| +// Observes changes to the HTMLMediaElement attributes that affect controls.
|
| +// Currently only observes the disableRemotePlayback attribute.
|
| +class MediaControlsImpl::MediaElementMutationCallback
|
| + : public MutationCallback {
|
| + public:
|
| + explicit MediaElementMutationCallback(MediaControlsImpl* controls)
|
| + : controls_(controls) {
|
| + observer_ = MutationObserver::Create(this);
|
| + Vector<String> filter;
|
| + filter.push_back(HTMLNames::disableremoteplaybackAttr.ToString());
|
| + MutationObserverInit init;
|
| + init.setAttributeOldValue(true);
|
| + init.setAttributes(true);
|
| + init.setAttributeFilter(filter);
|
| + observer_->observe(&controls_->MediaElement(), init, ASSERT_NO_EXCEPTION);
|
| + }
|
| +
|
| + DEFINE_INLINE_VIRTUAL_TRACE() {
|
| + visitor->Trace(controls_);
|
| + visitor->Trace(observer_);
|
| + MutationCallback::Trace(visitor);
|
| + }
|
| +
|
| + void Disconnect() { observer_->disconnect(); }
|
| +
|
| + private:
|
| + void Call(const HeapVector<Member<MutationRecord>>& records,
|
| + MutationObserver*) override {
|
| + for (const auto& record : records) {
|
| + if (record->type() != "attributes")
|
| + continue;
|
| +
|
| + const Element& element = *ToElement(record->target());
|
| + if (record->oldValue() == element.getAttribute(record->attributeName()))
|
| + continue;
|
| +
|
| + DCHECK_EQ(HTMLNames::disableremoteplaybackAttr.ToString(),
|
| + record->attributeName());
|
| + controls_->RefreshCastButtonVisibility();
|
| + return;
|
| + }
|
| + }
|
| +
|
| + ExecutionContext* GetExecutionContext() const override {
|
| + return &controls_->GetDocument();
|
| + }
|
| +
|
| + Member<MediaControlsImpl> controls_;
|
| + Member<MutationObserver> observer_;
|
| +};
|
| +
|
| MediaControls* MediaControlsImpl::Factory::Create(
|
| HTMLMediaElement& media_element,
|
| ShadowRoot& shadow_root) {
|
| @@ -417,6 +476,9 @@ Node::InsertionNotificationRequest MediaControlsImpl::InsertedInto(
|
| resize_observer_->observe(&html_media_element);
|
| }
|
|
|
| + if (!element_mutation_callback_)
|
| + element_mutation_callback_ = new MediaElementMutationCallback(this);
|
| +
|
| return HTMLDivElement::InsertedInto(root);
|
| }
|
|
|
| @@ -432,6 +494,11 @@ void MediaControlsImpl::RemovedFrom(ContainerNode*) {
|
| orientation_lock_delegate_->Detach();
|
|
|
| resize_observer_.Clear();
|
| +
|
| + if (element_mutation_callback_) {
|
| + element_mutation_callback_->Disconnect();
|
| + element_mutation_callback_.Clear();
|
| + }
|
| }
|
|
|
| void MediaControlsImpl::Reset() {
|
| @@ -517,12 +584,16 @@ void MediaControlsImpl::MakeTransparent() {
|
| bool MediaControlsImpl::ShouldHideMediaControls(unsigned behavior_flags) const {
|
| // Never hide for a media element without visual representation.
|
| if (!MediaElement().IsHTMLVideoElement() || !MediaElement().HasVideo() ||
|
| - MediaElement().IsPlayingRemotely() ||
|
| toHTMLVideoElement(MediaElement()).GetMediaRemotingStatus() ==
|
| HTMLVideoElement::MediaRemotingStatus::kStarted) {
|
| return false;
|
| }
|
|
|
| + RemotePlayback* remote =
|
| + HTMLMediaElementRemotePlayback::remote(MediaElement());
|
| + if (remote && remote->GetState() != WebRemotePlaybackState::kDisconnected)
|
| + return false;
|
| +
|
| // Keep the controls visible as long as the timer is running.
|
| const bool ignore_wait_for_timer = behavior_flags & kIgnoreWaitForTimer;
|
| if (!ignore_wait_for_timer && keep_showing_until_timer_fires_)
|
| @@ -662,8 +733,9 @@ void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() {
|
|
|
| void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() {
|
| if (MediaElement().ShouldShowControls() ||
|
| - !ShouldShowCastButton(MediaElement()))
|
| + !ShouldShowCastButton(MediaElement())) {
|
| return;
|
| + }
|
|
|
| overlay_cast_button_->TryShowOverlay();
|
| ResetHideMediaControlsTimer();
|
| @@ -677,14 +749,9 @@ void MediaControlsImpl::ExitFullscreen() {
|
| Fullscreen::ExitFullscreen(GetDocument());
|
| }
|
|
|
| -void MediaControlsImpl::StartedCasting() {
|
| - cast_button_->SetIsPlayingRemotely(true);
|
| - overlay_cast_button_->SetIsPlayingRemotely(true);
|
| -}
|
| -
|
| -void MediaControlsImpl::StoppedCasting() {
|
| - cast_button_->SetIsPlayingRemotely(false);
|
| - overlay_cast_button_->SetIsPlayingRemotely(false);
|
| +void MediaControlsImpl::RemotePlaybackStateChanged() {
|
| + cast_button_->UpdateDisplayType();
|
| + overlay_cast_button_->UpdateDisplayType();
|
| }
|
|
|
| void MediaControlsImpl::DefaultEventHandler(Event* event) {
|
| @@ -1108,6 +1175,7 @@ void MediaControlsImpl::HideAllMenus() {
|
| }
|
|
|
| DEFINE_TRACE(MediaControlsImpl) {
|
| + visitor->Trace(element_mutation_callback_);
|
| visitor->Trace(resize_observer_);
|
| visitor->Trace(panel_);
|
| visitor->Trace(overlay_play_button_);
|
|
|