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

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

Issue 2640023008: Enabling autoplay and fullscreen for downloaded media (Closed)
Patch Set: Changed to override pref from ContentBrowserClient 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"
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 public:
mlamouri (slow - plz ping) 2017/02/21 11:33:03 `WTF_MAKE_NONCOPYABLE(MediaLoadedEventListener);`
shaktisahu 2017/02/21 16:51:57 Done.
122 static MediaLoadedEventListener* create() {
123 return new MediaLoadedEventListener();
124 }
mlamouri (slow - plz ping) 2017/02/21 11:33:03 What's the benefit of using create over the ctor?
shaktisahu 2017/02/21 16:51:57 hmm.. I wanted to keep it consistent with the othe
125
126 bool operator==(const EventListener& other) const override {
127 return this == &other;
128 }
129
130 private:
131 MediaLoadedEventListener() : EventListener(CPPEventListenerType) {}
mlamouri (slow - plz ping) 2017/02/21 11:33:03 `= default;` instead of `{}`
shaktisahu 2017/02/21 16:51:57 I think default works with only empty initializati
132
133 void handleEvent(ExecutionContext* context, Event* event) override {
134 HTMLVideoElement* media = Traversal<HTMLVideoElement>::firstWithin(
135 *event->target()->toNode()->getRootNode(GetRootNodeOptions()));
mlamouri (slow - plz ping) 2017/02/21 11:33:03 Why are you using Traversal<> here? Shouldn't `eve
shaktisahu 2017/02/21 16:51:57 Done.
136 UserGestureIndicator gesture(
137 DocumentUserGestureToken::create(&media->document()));
138 media->webkitEnterFullscreen();
139 media->play();
mlamouri (slow - plz ping) 2017/02/21 11:33:03 Maybe it would be better to start playback when we
shaktisahu 2017/02/21 16:51:57 I plan to revisit this depending on how the experi
140 }
141 };
142
116 void MediaDocumentParser::createDocumentStructure() { 143 void MediaDocumentParser::createDocumentStructure() {
117 DCHECK(document()); 144 DCHECK(document());
118 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); 145 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document());
119 document()->appendChild(rootElement); 146 document()->appendChild(rootElement);
120 rootElement->insertedByParser(); 147 rootElement->insertedByParser();
121 148
122 if (isDetached()) 149 if (isDetached())
123 return; // runScriptsAtDocumentElementAvailable can detach the frame. 150 return; // runScriptsAtDocumentElementAvailable can detach the frame.
124 151
125 HTMLHeadElement* head = HTMLHeadElement::create(*document()); 152 HTMLHeadElement* head = HTMLHeadElement::create(*document());
(...skipping 30 matching lines...) Expand all
156 div->setAttribute(styleAttr, 183 div->setAttribute(styleAttr,
157 "display: flex;" 184 "display: flex;"
158 "flex-direction: column;" 185 "flex-direction: column;"
159 "justify-content: center;" 186 "justify-content: center;"
160 "align-items: center;" 187 "align-items: center;"
161 "min-height: min-content;" 188 "min-height: min-content;"
162 "height: 100%;"); 189 "height: 100%;");
163 HTMLContentElement* content = HTMLContentElement::create(*document()); 190 HTMLContentElement* content = HTMLContentElement::create(*document());
164 div->appendChild(content); 191 div->appendChild(content);
165 192
193 if (document()->settings() &&
194 document()->settings()->getEmbeddedMediaExperienceEnabled()) {
195 EventListener* listener = MediaLoadedEventListener::create();
196 media->addEventListener(EventTypeNames::loadedmetadata, listener, false);
mlamouri (slow - plz ping) 2017/02/21 11:33:03 Would it make sense to do: ``` AddEventListenerOpt
shaktisahu 2017/02/21 16:51:57 Done.
197 }
198
166 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { 199 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) {
167 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); 200 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document());
168 anchor->setAttribute(downloadAttr, ""); 201 anchor->setAttribute(downloadAttr, "");
169 anchor->setURL(document()->url()); 202 anchor->setURL(document()->url());
170 anchor->setTextContent( 203 anchor->setTextContent(
171 document() 204 document()
172 ->getCachedLocale(document()->contentLanguage()) 205 ->getCachedLocale(document()->contentLanguage())
173 .queryString(WebLocalizedString::DownloadButtonLabel) 206 .queryString(WebLocalizedString::DownloadButtonLabel)
174 .upper()); 207 .upper());
175 // Using CSS style according to Android material design. 208 // Using CSS style according to Android material design.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (keyboardEvent->key() == " " || 286 if (keyboardEvent->key() == " " ||
254 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { 287 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) {
255 // space or media key (play/pause) 288 // space or media key (play/pause)
256 video->togglePlayState(); 289 video->togglePlayState();
257 event->setDefaultHandled(); 290 event->setDefaultHandled();
258 } 291 }
259 } 292 }
260 } 293 }
261 294
262 } // namespace blink 295 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698