Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" | 5 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" |
| 6 | 6 |
| 7 #include "core/InputTypeNames.h" | 7 #include "core/InputTypeNames.h" |
| 8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
| 9 #include "core/frame/LocalFrameClient.h" | |
| 9 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| 10 #include "core/html/HTMLAnchorElement.h" | 11 #include "core/html/HTMLAnchorElement.h" |
| 11 #include "core/html/HTMLMediaElement.h" | 12 #include "core/html/HTMLMediaElement.h" |
| 12 #include "core/html/media/HTMLMediaElementControlsList.h" | 13 #include "core/html/media/HTMLMediaElementControlsList.h" |
| 13 #include "core/html/media/HTMLMediaSource.h" | 14 #include "core/html/media/HTMLMediaSource.h" |
| 14 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
| 15 #include "modules/media_controls/MediaControlsImpl.h" | 16 #include "modules/media_controls/MediaControlsImpl.h" |
| 16 #include "platform/Histogram.h" | 17 #include "platform/Histogram.h" |
| 18 #include "platform/wtf/Functional.h" | |
| 17 #include "public/platform/Platform.h" | 19 #include "public/platform/Platform.h" |
| 20 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 18 | 21 |
| 19 namespace blink { | 22 namespace blink { |
| 20 | 23 |
| 21 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( | 24 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( |
| 22 MediaControlsImpl& media_controls) | 25 MediaControlsImpl& media_controls) |
| 23 : MediaControlInputElement(media_controls, kMediaDownloadButton) { | 26 : MediaControlInputElement(media_controls, kMediaDownloadButton) { |
| 24 EnsureUserAgentShadowRoot(); | 27 EnsureUserAgentShadowRoot(); |
| 25 setType(InputTypeNames::button); | 28 setType(InputTypeNames::button); |
| 26 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); | 29 SetShadowPseudoId(AtomicString("-internal-media-controls-download-button")); |
| 27 SetIsWanted(false); | 30 SetIsWanted(false); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 bool MediaControlDownloadButtonElement::HasOverflowButton() { | 87 bool MediaControlDownloadButtonElement::HasOverflowButton() { |
| 85 return true; | 88 return true; |
| 86 } | 89 } |
| 87 | 90 |
| 88 void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) { | 91 void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) { |
| 89 MediaControlElement::SetIsWanted(wanted); | 92 MediaControlElement::SetIsWanted(wanted); |
| 90 | 93 |
| 91 if (!IsWanted()) | 94 if (!IsWanted()) |
| 92 return; | 95 return; |
| 93 | 96 |
| 94 DCHECK(IsWanted()); | |
| 95 if (!show_use_counted_) { | 97 if (!show_use_counted_) { |
| 96 show_use_counted_ = true; | 98 show_use_counted_ = true; |
| 97 RecordMetrics(DownloadActionMetrics::kShown); | 99 RecordMetrics(DownloadActionMetrics::kShown); |
| 98 } | 100 } |
| 101 | |
| 102 // If the button is wanted, show IPH if possible. | |
| 103 MaybeDispatchInProductHelpTrigger(); | |
| 104 UpdateInProductHelpState(); | |
| 99 } | 105 } |
| 100 | 106 |
| 101 DEFINE_TRACE(MediaControlDownloadButtonElement) { | 107 DEFINE_TRACE(MediaControlDownloadButtonElement) { |
| 102 visitor->Trace(anchor_); | 108 visitor->Trace(anchor_); |
| 103 MediaControlInputElement::Trace(visitor); | 109 MediaControlInputElement::Trace(visitor); |
| 104 } | 110 } |
| 105 | 111 |
| 106 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { | 112 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { |
| 107 const KURL& url = MediaElement().currentSrc(); | 113 const KURL& url = MediaElement().currentSrc(); |
| 108 if (event->type() == EventTypeNames::click && | 114 if (event->type() == EventTypeNames::click && |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 125 } | 131 } |
| 126 | 132 |
| 127 void MediaControlDownloadButtonElement::RecordMetrics( | 133 void MediaControlDownloadButtonElement::RecordMetrics( |
| 128 DownloadActionMetrics metric) { | 134 DownloadActionMetrics metric) { |
| 129 DEFINE_STATIC_LOCAL(EnumerationHistogram, download_action_histogram, | 135 DEFINE_STATIC_LOCAL(EnumerationHistogram, download_action_histogram, |
| 130 ("Media.Controls.Download", | 136 ("Media.Controls.Download", |
| 131 static_cast<int>(DownloadActionMetrics::kCount))); | 137 static_cast<int>(DownloadActionMetrics::kCount))); |
| 132 download_action_histogram.Count(static_cast<int>(metric)); | 138 download_action_histogram.Count(static_cast<int>(metric)); |
| 133 } | 139 } |
| 134 | 140 |
| 141 void MediaControlDownloadButtonElement::MaybeDispatchInProductHelpTrigger() { | |
|
mlamouri (slow - plz ping)
2017/07/13 21:14:27
For what I can see, this setting up the mojo pipe.
Khushal
2017/07/17 17:52:21
MaybeShow would have called UpdateInProductHelpSta
| |
| 142 if (!media_download_in_product_trigger_observed_ && IsWanted() && | |
| 143 !MediaElement().paused() && MediaElement().GetDocument().GetSettings() && | |
| 144 MediaElement() | |
| 145 .GetDocument() | |
| 146 .GetSettings() | |
| 147 ->GetMediaDownloadInProductHelpEnabled()) { | |
|
mlamouri (slow - plz ping)
2017/07/13 21:14:27
For readability, can you do an early return?
Khushal
2017/07/17 17:52:21
Done.
| |
| 148 DCHECK(!media_in_product_help_); | |
| 149 | |
| 150 media_download_in_product_trigger_observed_ = true; | |
| 151 media_in_product_help_ = | |
| 152 WTF::MakeUnique<mojom::blink::MediaInProductHelpPtr>(); | |
| 153 MediaElement() | |
| 154 .GetDocument() | |
| 155 .GetFrame() | |
|
mlamouri (slow - plz ping)
2017/07/13 21:14:27
Can you check that `GetFrame()` doesn't return `nu
Khushal
2017/07/17 17:52:21
Done.
| |
| 156 ->Client() | |
| 157 ->GetInterfaceProvider() | |
| 158 ->GetInterface(mojo::MakeRequest(media_in_product_help_.get())); | |
| 159 media_in_product_help_->set_connection_error_handler( | |
| 160 ConvertToBaseCallback(WTF::Bind( | |
| 161 &MediaControlDownloadButtonElement::DismissDownloadInProductHelp, | |
| 162 WrapWeakPersistent(this)))); | |
| 163 GetMediaControls().MaybeShow(); | |
|
mlamouri (slow - plz ping)
2017/07/13 21:14:27
Does that mean that when a download button will be
Khushal
2017/07/17 17:52:21
I updated the code to take the CanShow aspect into
| |
| 164 } | |
| 165 } | |
| 166 | |
| 167 void MediaControlDownloadButtonElement::UpdateInProductHelpState() { | |
|
mlamouri (slow - plz ping)
2017/07/13 21:14:27
Isn't this method actually triggering the UI?
Khushal
2017/07/17 17:52:21
Restructured to move this into MaybeDispatchInProd
| |
| 168 if (!media_in_product_help_) | |
| 169 return; | |
| 170 | |
| 171 if (static_cast<MediaControlsImpl&>(GetMediaControls()).IsVisible() && | |
| 172 IsWanted()) { | |
| 173 (*media_in_product_help_) | |
| 174 ->ShowInProductHelpWidget(VisibleBoundsInVisualViewport()); | |
| 175 return; | |
| 176 } | |
| 177 | |
| 178 DismissDownloadInProductHelp(); | |
| 179 } | |
| 180 | |
| 181 void MediaControlDownloadButtonElement::DismissDownloadInProductHelp() { | |
| 182 media_in_product_help_.reset(); | |
| 183 static_cast<MediaControlsImpl&>(GetMediaControls()).HideControlsIfNecessary(); | |
| 184 } | |
| 185 | |
| 186 bool MediaControlDownloadButtonElement::IsShowingInProductHelp() const { | |
| 187 return !!media_in_product_help_; | |
| 188 } | |
| 189 | |
| 135 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |