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 9bf2b7bd75b07965ea592663da13bd45c8245d39..1498533c56ac016b0031882a77cafb13f9003b11 100644 |
--- a/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp |
+++ b/third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp |
@@ -38,6 +38,7 @@ |
#include "core/dom/TaskRunnerHelper.h" |
#include "core/events/KeyboardEvent.h" |
#include "core/events/MouseEvent.h" |
+#include "core/frame/LocalFrameClient.h" |
#include "core/frame/Settings.h" |
#include "core/frame/UseCounter.h" |
#include "core/html/HTMLMediaElement.h" |
@@ -74,6 +75,8 @@ |
#include "modules/remoteplayback/RemotePlayback.h" |
#include "platform/EventDispatchForbiddenScope.h" |
#include "platform/RuntimeEnabledFeatures.h" |
+#include "platform/wtf/Functional.h" |
+#include "services/service_manager/public/cpp/interface_provider.h" |
namespace blink { |
@@ -563,6 +566,7 @@ void MediaControlsImpl::OnControlsListUpdated() { |
download_button_->SetIsWanted( |
download_button_->ShouldDisplayDownloadButton()); |
+ UpdateDownloadInProductHelpState(); |
} |
LayoutObject* MediaControlsImpl::PanelLayoutObject() { |
@@ -581,6 +585,7 @@ void MediaControlsImpl::MaybeShow() { |
// Only make the controls visible if they won't get hidden by OnTimeUpdate. |
if (MediaElement().paused() || !ShouldHideMediaControls()) |
MakeOpaque(); |
+ UpdateDownloadInProductHelpState(); |
} |
void MediaControlsImpl::Hide() { |
@@ -588,6 +593,7 @@ void MediaControlsImpl::Hide() { |
panel_->SetIsDisplayed(false); |
if (overlay_play_button_) |
overlay_play_button_->SetIsWanted(false); |
+ UpdateDownloadInProductHelpState(); |
} |
bool MediaControlsImpl::IsVisible() const { |
@@ -643,6 +649,10 @@ bool MediaControlsImpl::ShouldHideMediaControls(unsigned behavior_flags) const { |
if (text_track_list_->IsWanted() || overflow_list_->IsWanted()) |
return false; |
+ // Don't hide the media controls while the in product help is showing. |
+ if (media_in_product_help_) |
+ return false; |
+ |
return true; |
} |
@@ -971,6 +981,7 @@ void MediaControlsImpl::OnPlay() { |
UpdatePlayState(); |
timeline_->SetPosition(MediaElement().currentTime()); |
UpdateCurrentTimeDisplay(); |
+ MaybeDispatchDownloadIPHTrigger(); |
} |
void MediaControlsImpl::OnPlaying() { |
@@ -1216,6 +1227,52 @@ void MediaControlsImpl::HideAllMenus() { |
text_track_list_->SetVisible(false); |
} |
+void MediaControlsImpl::MaybeDispatchDownloadIPHTrigger() { |
whywhat
2017/07/10 15:29:28
nit: I think we should either use IPH or InProduct
Khushal
2017/07/10 20:38:02
Done.
|
+ if (!media_download_in_product_trigger_observed_ && |
+ download_button_->IsWanted() && |
+ MediaElement().GetDocument().GetSettings() && |
+ MediaElement() |
+ .GetDocument() |
+ .GetSettings() |
+ ->GetMediaDownloadInProductHelpEnabled()) { |
+ DCHECK(!media_in_product_help_); |
+ |
+ media_download_in_product_trigger_observed_ = true; |
+ media_in_product_help_ = |
+ WTF::MakeUnique<mojom::blink::MediaInProductHelpPtr>(); |
+ MediaElement() |
+ .GetDocument() |
+ .GetFrame() |
+ ->Client() |
+ ->GetInterfaceProvider() |
+ ->GetInterface(mojo::MakeRequest(media_in_product_help_.get())); |
+ media_in_product_help_->set_connection_error_handler(ConvertToBaseCallback( |
+ WTF::Bind(&MediaControlsImpl::DismissDownloadInProductHelp, |
+ WrapWeakPersistent(this)))); |
+ MaybeShow(); |
+ } |
+} |
+ |
+void MediaControlsImpl::UpdateDownloadInProductHelpState() { |
+ if (!media_in_product_help_) |
+ return; |
+ |
+ if (IsVisible() && download_button_->IsWanted()) { |
+ (*media_in_product_help_) |
+ ->ShowInProductHelpWidget( |
+ download_button_->VisibleBoundsInVisualViewport()); |
+ return; |
+ } |
+ |
+ DismissDownloadInProductHelp(); |
+} |
+ |
+void MediaControlsImpl::DismissDownloadInProductHelp() { |
+ media_in_product_help_.reset(); |
+ if (ShouldHideMediaControls()) |
+ StartHideMediaControlsTimer(); |
+} |
+ |
DEFINE_TRACE(MediaControlsImpl) { |
visitor->Trace(element_mutation_callback_); |
visitor->Trace(resize_observer_); |