| 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 2007c5d81496f008d9a3228e482bb144f32c404f..aa2e410bb48a2db5686efa8f5094b5dbacc980a1 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 {
|
|
|
| @@ -91,11 +94,14 @@ void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) {
|
| if (!IsWanted())
|
| return;
|
|
|
| - DCHECK(IsWanted());
|
| if (!show_use_counted_) {
|
| show_use_counted_ = true;
|
| RecordMetrics(DownloadActionMetrics::kShown);
|
| }
|
| +
|
| + // If the button is wanted, show IPH if possible.
|
| + MaybeDispatchInProductHelpTrigger();
|
| + UpdateInProductHelpState();
|
| }
|
|
|
| DEFINE_TRACE(MediaControlDownloadButtonElement) {
|
| @@ -132,4 +138,53 @@ void MediaControlDownloadButtonElement::RecordMetrics(
|
| download_action_histogram.Count(static_cast<int>(metric));
|
| }
|
|
|
| +void MediaControlDownloadButtonElement::MaybeDispatchInProductHelpTrigger() {
|
| + if (!media_download_in_product_trigger_observed_ && 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(
|
| + &MediaControlDownloadButtonElement::DismissDownloadInProductHelp,
|
| + WrapWeakPersistent(this))));
|
| + GetMediaControls().MaybeShow();
|
| + }
|
| +}
|
| +
|
| +void MediaControlDownloadButtonElement::UpdateInProductHelpState() {
|
| + if (!media_in_product_help_)
|
| + return;
|
| +
|
| + if (static_cast<MediaControlsImpl&>(GetMediaControls()).IsVisible() &&
|
| + IsWanted()) {
|
| + (*media_in_product_help_)
|
| + ->ShowInProductHelpWidget(VisibleBoundsInVisualViewport());
|
| + return;
|
| + }
|
| +
|
| + DismissDownloadInProductHelp();
|
| +}
|
| +
|
| +void MediaControlDownloadButtonElement::DismissDownloadInProductHelp() {
|
| + media_in_product_help_.reset();
|
| + static_cast<MediaControlsImpl&>(GetMediaControls()).HideControlsIfNecessary();
|
| +}
|
| +
|
| +bool MediaControlDownloadButtonElement::IsShowingInProductHelp() const {
|
| + return !!media_in_product_help_;
|
| +}
|
| +
|
| } // namespace blink
|
|
|