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

Side by Side Diff: third_party/WebKit/Source/core/html/MediaDocument.cpp

Issue 2640023008: Enabling autoplay and fullscreen for downloaded media (Closed)
Patch Set: comments Created 3 years, 10 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 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/html/MediaDocument.h" 26 #include "core/html/MediaDocument.h"
27 27
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/dom/DocumentUserGestureToken.h"
30 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ElementTraversal.h"
32 #include "core/dom/GetRootNodeOptions.h"
mlamouri (slow - plz ping) 2017/02/22 12:15:27 I don't think you still need this include.
shaktisahu 2017/02/23 22:43:27 Done.
31 #include "core/dom/RawDataDocumentParser.h" 33 #include "core/dom/RawDataDocumentParser.h"
32 #include "core/dom/shadow/ShadowRoot.h" 34 #include "core/dom/shadow/ShadowRoot.h"
33 #include "core/events/Event.h" 35 #include "core/events/Event.h"
34 #include "core/events/EventListener.h" 36 #include "core/events/EventListener.h"
35 #include "core/events/KeyboardEvent.h" 37 #include "core/events/KeyboardEvent.h"
36 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
39 #include "core/frame/Settings.h"
37 #include "core/frame/UseCounter.h" 40 #include "core/frame/UseCounter.h"
38 #include "core/html/HTMLAnchorElement.h" 41 #include "core/html/HTMLAnchorElement.h"
39 #include "core/html/HTMLBodyElement.h" 42 #include "core/html/HTMLBodyElement.h"
40 #include "core/html/HTMLContentElement.h" 43 #include "core/html/HTMLContentElement.h"
41 #include "core/html/HTMLDivElement.h" 44 #include "core/html/HTMLDivElement.h"
42 #include "core/html/HTMLHeadElement.h" 45 #include "core/html/HTMLHeadElement.h"
43 #include "core/html/HTMLHtmlElement.h" 46 #include "core/html/HTMLHtmlElement.h"
44 #include "core/html/HTMLMetaElement.h" 47 #include "core/html/HTMLMetaElement.h"
45 #include "core/html/HTMLSourceElement.h" 48 #include "core/html/HTMLSourceElement.h"
46 #include "core/html/HTMLStyleElement.h" 49 #include "core/html/HTMLStyleElement.h"
47 #include "core/html/HTMLVideoElement.h" 50 #include "core/html/HTMLVideoElement.h"
48 #include "core/loader/DocumentLoader.h" 51 #include "core/loader/DocumentLoader.h"
49 #include "core/loader/FrameLoader.h" 52 #include "core/loader/FrameLoader.h"
50 #include "core/loader/FrameLoaderClient.h" 53 #include "core/loader/FrameLoaderClient.h"
51 #include "platform/Histogram.h" 54 #include "platform/Histogram.h"
52 #include "platform/KeyboardCodes.h" 55 #include "platform/KeyboardCodes.h"
56 #include "platform/UserGestureIndicator.h"
53 #include "platform/text/PlatformLocale.h" 57 #include "platform/text/PlatformLocale.h"
54 58
55 namespace blink { 59 namespace blink {
56 60
57 using namespace HTMLNames; 61 using namespace HTMLNames;
58 62
59 // Enums used for UMA histogram. 63 // Enums used for UMA histogram.
60 enum MediaDocumentDownloadButtonValue { 64 enum MediaDocumentDownloadButtonValue {
61 MediaDocumentDownloadButtonShown, 65 MediaDocumentDownloadButtonShown,
62 MediaDocumentDownloadButtonClicked, 66 MediaDocumentDownloadButtonClicked,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void handleEvent(ExecutionContext* context, Event* event) override { 110 void handleEvent(ExecutionContext* context, Event* event) override {
107 if (!m_clicked) { 111 if (!m_clicked) {
108 recordDownloadMetric(MediaDocumentDownloadButtonClicked); 112 recordDownloadMetric(MediaDocumentDownloadButtonClicked);
109 m_clicked = true; 113 m_clicked = true;
110 } 114 }
111 } 115 }
112 116
113 bool m_clicked; 117 bool m_clicked;
114 }; 118 };
115 119
120 class MediaLoadedEventListener final : public EventListener {
121 WTF_MAKE_NONCOPYABLE(MediaLoadedEventListener);
122
123 public:
124 static MediaLoadedEventListener* create() {
125 return new MediaLoadedEventListener();
126 }
127
128 bool operator==(const EventListener& other) const override {
129 return this == &other;
130 }
131
132 private:
133 MediaLoadedEventListener() : EventListener(CPPEventListenerType) {}
134
135 void handleEvent(ExecutionContext* context, Event* event) override {
136 HTMLVideoElement* media =
137 static_cast<HTMLVideoElement*>(event->target()->toNode());
138 UserGestureIndicator gesture(
139 DocumentUserGestureToken::create(&media->document()));
140 media->webkitEnterFullscreen();
141 media->play();
142 }
143 };
144
116 void MediaDocumentParser::createDocumentStructure() { 145 void MediaDocumentParser::createDocumentStructure() {
117 DCHECK(document()); 146 DCHECK(document());
118 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); 147 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document());
119 document()->appendChild(rootElement); 148 document()->appendChild(rootElement);
120 rootElement->insertedByParser(); 149 rootElement->insertedByParser();
121 150
122 if (isDetached()) 151 if (isDetached())
123 return; // runScriptsAtDocumentElementAvailable can detach the frame. 152 return; // runScriptsAtDocumentElementAvailable can detach the frame.
124 153
125 HTMLHeadElement* head = HTMLHeadElement::create(*document()); 154 HTMLHeadElement* head = HTMLHeadElement::create(*document());
(...skipping 30 matching lines...) Expand all
156 div->setAttribute(styleAttr, 185 div->setAttribute(styleAttr,
157 "display: flex;" 186 "display: flex;"
158 "flex-direction: column;" 187 "flex-direction: column;"
159 "justify-content: center;" 188 "justify-content: center;"
160 "align-items: center;" 189 "align-items: center;"
161 "min-height: min-content;" 190 "min-height: min-content;"
162 "height: 100%;"); 191 "height: 100%;");
163 HTMLContentElement* content = HTMLContentElement::create(*document()); 192 HTMLContentElement* content = HTMLContentElement::create(*document());
164 div->appendChild(content); 193 div->appendChild(content);
165 194
195 if (document()->settings() &&
196 document()->settings()->getEmbeddedMediaExperienceEnabled()) {
197 EventListener* listener = MediaLoadedEventListener::create();
198 AddEventListenerOptions options;
199 options.setOnce(true);
200 AddEventListenerOptionsOrBoolean optionsOrBoolean;
201 optionsOrBoolean.setAddEventListenerOptions(options);
202 media->addEventListener(EventTypeNames::loadedmetadata, listener,
203 optionsOrBoolean);
204 }
205
166 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { 206 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) {
167 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); 207 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document());
168 anchor->setAttribute(downloadAttr, ""); 208 anchor->setAttribute(downloadAttr, "");
169 anchor->setURL(document()->url()); 209 anchor->setURL(document()->url());
170 anchor->setTextContent( 210 anchor->setTextContent(
171 document() 211 document()
172 ->getCachedLocale(document()->contentLanguage()) 212 ->getCachedLocale(document()->contentLanguage())
173 .queryString(WebLocalizedString::DownloadButtonLabel) 213 .queryString(WebLocalizedString::DownloadButtonLabel)
174 .upper()); 214 .upper());
175 // Using CSS style according to Android material design. 215 // Using CSS style according to Android material design.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (keyboardEvent->key() == " " || 293 if (keyboardEvent->key() == " " ||
254 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { 294 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) {
255 // space or media key (play/pause) 295 // space or media key (play/pause)
256 video->togglePlayState(); 296 video->togglePlayState();
257 event->setDefaultHandled(); 297 event->setDefaultHandled();
258 } 298 }
259 } 299 }
260 } 300 }
261 301
262 } // namespace blink 302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698