Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/elements/MediaControlDownloadButtonElement.cpp

Issue 2943983003: chrome/blink: Add functionality for in-product help for media elements. (Closed)
Patch Set: mounir's comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return WebLocalizedString::kOverflowMenuDownload; 84 return WebLocalizedString::kOverflowMenuDownload;
82 } 85 }
83 86
84 bool MediaControlDownloadButtonElement::HasOverflowButton() const { 87 bool MediaControlDownloadButtonElement::HasOverflowButton() const {
85 return true; 88 return true;
86 } 89 }
87 90
88 void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) { 91 void MediaControlDownloadButtonElement::SetIsWanted(bool wanted) {
89 MediaControlInputElement::SetIsWanted(wanted); 92 MediaControlInputElement::SetIsWanted(wanted);
90 93
91 if (!IsWanted()) 94 if (!IsWanted()) {
95 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.
92 return; 96 return;
97 }
93 98
94 DCHECK(IsWanted());
95 if (!show_use_counted_) { 99 if (!show_use_counted_) {
96 show_use_counted_ = true; 100 show_use_counted_ = true;
97 RecordMetrics(DownloadActionMetrics::kShown); 101 RecordMetrics(DownloadActionMetrics::kShown);
98 } 102 }
103
104 // If the button is wanted, show IPH if possible.
105 MaybeDispatchInProductHelpTrigger();
99 } 106 }
100 107
101 DEFINE_TRACE(MediaControlDownloadButtonElement) { 108 DEFINE_TRACE(MediaControlDownloadButtonElement) {
102 visitor->Trace(anchor_); 109 visitor->Trace(anchor_);
103 MediaControlInputElement::Trace(visitor); 110 MediaControlInputElement::Trace(visitor);
104 } 111 }
105 112
106 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) { 113 void MediaControlDownloadButtonElement::DefaultEventHandler(Event* event) {
107 const KURL& url = MediaElement().currentSrc(); 114 const KURL& url = MediaElement().currentSrc();
108 if (event->type() == EventTypeNames::click && 115 if (event->type() == EventTypeNames::click &&
(...skipping 16 matching lines...) Expand all
125 } 132 }
126 133
127 void MediaControlDownloadButtonElement::RecordMetrics( 134 void MediaControlDownloadButtonElement::RecordMetrics(
128 DownloadActionMetrics metric) { 135 DownloadActionMetrics metric) {
129 DEFINE_STATIC_LOCAL(EnumerationHistogram, download_action_histogram, 136 DEFINE_STATIC_LOCAL(EnumerationHistogram, download_action_histogram,
130 ("Media.Controls.Download", 137 ("Media.Controls.Download",
131 static_cast<int>(DownloadActionMetrics::kCount))); 138 static_cast<int>(DownloadActionMetrics::kCount)));
132 download_action_histogram.Count(static_cast<int>(metric)); 139 download_action_histogram.Count(static_cast<int>(metric));
133 } 140 }
134 141
142 void MediaControlDownloadButtonElement::MaybeDispatchInProductHelpTrigger() {
143 // Is showing in-product help enabled?
144 if (!MediaElement().GetDocument().GetSettings() ||
145 !MediaElement()
146 .GetDocument()
147 .GetSettings()
148 ->GetMediaDownloadInProductHelpEnabled()) {
149 return;
150 }
151
152 // Restrict showing in-product help to once per element.
153 if (media_download_in_product_trigger_observed_)
154 return;
155
156 // Download in-product-help is only shown for videos.
157 if (!MediaElement().IsHTMLVideoElement())
158 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
159
160 // If showing the controls is disabled, we can't make them visible to show the
161 // in-product-help.
162 if (!static_cast<MediaControlsImpl&>(GetMediaControls()).CanShow())
163 return;
164
165 // If the download option is not available for this video, no need to show
166 // anything.
167 if (!IsWanted())
168 return;
169
170 // Restrict showing in-product-help to when the video is playing.
171 if (MediaElement().paused())
172 return;
173
174 if (!MediaElement().GetDocument().GetFrame())
175 return;
176
177 // If the button is not in the viewport, don't show the in-product-help.
178 IntRect button_rect = VisibleBoundsInVisualViewport();
179 if (button_rect.IsEmpty())
180 return;
181
182 media_download_in_product_trigger_observed_ = true;
183 media_in_product_help_ =
184 WTF::MakeUnique<mojom::blink::MediaDownloadInProductHelpPtr>();
185 MediaElement()
186 .GetDocument()
187 .GetFrame()
188 ->Client()
189 ->GetInterfaceProvider()
190 ->GetInterface(mojo::MakeRequest(media_in_product_help_.get()));
191 media_in_product_help_->set_connection_error_handler(ConvertToBaseCallback(
192 WTF::Bind(&MediaControlDownloadButtonElement::DismissInProductHelp,
193 WrapWeakPersistent(this))));
194
195 // MaybeShow should always make the controls visible since we early out if
196 // CanShow is false for the controls.
197 GetMediaControls().MaybeShow();
198 DCHECK(GetMediaControls().IsVisible());
199 (*media_in_product_help_)->ShowInProductHelpWidget(button_rect);
200 }
201
202 void MediaControlDownloadButtonElement::DismissInProductHelp() {
203 if (!media_in_product_help_)
204 return;
205
206 media_in_product_help_.reset();
207 static_cast<MediaControlsImpl&>(GetMediaControls())
208 .StartHideMediaControlsIfNecessary();
209 }
210
211 bool MediaControlDownloadButtonElement::IsShowingInProductHelp() const {
212 return !!media_in_product_help_;
213 }
214
135 } // namespace blink 215 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698