Chromium Code Reviews| Index: third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp |
| diff --git a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp |
| index fc58f579134a097d1e2c9faeb4a6bdc1fa959e93..65b2fa0e913cd3297d13486deed390ac3bd6fbe8 100644 |
| --- a/third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp |
| +++ b/third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp |
| @@ -6,6 +6,7 @@ |
| #include "core/InputTypeNames.h" |
| #include "core/events/Event.h" |
| +#include "core/frame/LocalFrameClient.h" |
| #include "core/frame/Settings.h" |
| #include "core/html/HTMLAnchorElement.h" |
| #include "core/html/HTMLMediaElement.h" |
| @@ -14,7 +15,9 @@ |
| #include "core/page/Page.h" |
| #include "modules/media_controls/MediaControlsImpl.h" |
| #include "platform/Histogram.h" |
| +#include "platform/wtf/Functional.h" |
| #include "public/platform/Platform.h" |
| +#include "services/service_manager/public/cpp/interface_provider.h" |
| namespace blink { |
| @@ -88,14 +91,18 @@ bool MediaControlDownloadButtonElement::HasOverflowButton() const { |
| void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) { |
| MediaControlInputElement::SetIsWanted(wanted); |
| - if (!IsWanted()) |
| + if (!IsWanted()) { |
| + DismissInProductHelp(); |
|
mlamouri (slow - plz ping)
2017/07/25 17:29:08
That code should no longer be here, you will have
Khushal
2017/08/03 02:41:21
Done.
|
| return; |
| + } |
| - DCHECK(IsWanted()); |
| if (!show_use_counted_) { |
| show_use_counted_ = true; |
| RecordMetrics(DownloadActionMetrics::kShown); |
| } |
| + |
| + // If the button is wanted, show IPH if possible. |
| + MaybeDispatchInProductHelpTrigger(); |
| } |
| DEFINE_TRACE(MediaControlDownloadButtonElement) { |
| @@ -132,4 +139,77 @@ void MediaControlDownloadButtonElement::RecordMetrics( |
| download_action_histogram.Count(static_cast<int>(metric)); |
| } |
| +void MediaControlDownloadButtonElement::MaybeDispatchInProductHelpTrigger() { |
| + // Is showing in-product help enabled? |
| + if (!MediaElement().GetDocument().GetSettings() || |
| + !MediaElement() |
| + .GetDocument() |
| + .GetSettings() |
| + ->GetMediaDownloadInProductHelpEnabled()) { |
| + return; |
| + } |
| + |
| + // Restrict showing in-product help to once per element. |
| + if (media_download_in_product_trigger_observed_) |
| + return; |
| + |
| + // Download in-product-help is only shown for videos. |
| + if (!MediaElement().IsHTMLVideoElement()) |
| + return; |
|
mlamouri (slow - plz ping)
2017/07/25 17:29:08
Looking at this and what follows, I wonder if it w
Khushal
2017/08/03 02:41:21
We can move this code to a seperate class owned by
|
| + |
| + // If showing the controls is disabled, we can't make them visible to show the |
| + // in-product-help. |
| + if (!static_cast<MediaControlsImpl&>(GetMediaControls()).CanShow()) |
| + return; |
| + |
| + // If the download option is not available for this video, no need to show |
| + // anything. |
| + if (!IsWanted()) |
| + return; |
| + |
| + // Restrict showing in-product-help to when the video is playing. |
| + if (MediaElement().paused()) |
| + return; |
| + |
| + if (!MediaElement().GetDocument().GetFrame()) |
| + return; |
| + |
| + // If the button is not in the viewport, don't show the in-product-help. |
| + IntRect button_rect = VisibleBoundsInVisualViewport(); |
| + if (button_rect.IsEmpty()) |
| + return; |
| + |
| + media_download_in_product_trigger_observed_ = true; |
| + media_in_product_help_ = |
| + WTF::MakeUnique<mojom::blink::MediaDownloadInProductHelpPtr>(); |
| + MediaElement() |
| + .GetDocument() |
| + .GetFrame() |
| + ->Client() |
| + ->GetInterfaceProvider() |
| + ->GetInterface(mojo::MakeRequest(media_in_product_help_.get())); |
| + media_in_product_help_->set_connection_error_handler(ConvertToBaseCallback( |
| + WTF::Bind(&MediaControlDownloadButtonElement::DismissInProductHelp, |
| + WrapWeakPersistent(this)))); |
| + |
| + // MaybeShow should always make the controls visible since we early out if |
| + // CanShow is false for the controls. |
| + GetMediaControls().MaybeShow(); |
| + DCHECK(GetMediaControls().IsVisible()); |
| + (*media_in_product_help_)->ShowInProductHelpWidget(button_rect); |
| +} |
| + |
| +void MediaControlDownloadButtonElement::DismissInProductHelp() { |
| + if (!media_in_product_help_) |
| + return; |
| + |
| + media_in_product_help_.reset(); |
| + static_cast<MediaControlsImpl&>(GetMediaControls()) |
| + .StartHideMediaControlsIfNecessary(); |
| +} |
| + |
| +bool MediaControlDownloadButtonElement::IsShowingInProductHelp() const { |
| + return !!media_in_product_help_; |
| +} |
| + |
| } // namespace blink |