| OLD | NEW |
| 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" |
| 31 #include "core/dom/RawDataDocumentParser.h" | 32 #include "core/dom/RawDataDocumentParser.h" |
| 32 #include "core/dom/shadow/ShadowRoot.h" | 33 #include "core/dom/shadow/ShadowRoot.h" |
| 33 #include "core/events/Event.h" | 34 #include "core/events/Event.h" |
| 34 #include "core/events/EventListener.h" | 35 #include "core/events/EventListener.h" |
| 35 #include "core/events/KeyboardEvent.h" | 36 #include "core/events/KeyboardEvent.h" |
| 36 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 38 #include "core/frame/Settings.h" |
| 37 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 38 #include "core/html/HTMLAnchorElement.h" | 40 #include "core/html/HTMLAnchorElement.h" |
| 39 #include "core/html/HTMLBodyElement.h" | 41 #include "core/html/HTMLBodyElement.h" |
| 40 #include "core/html/HTMLContentElement.h" | 42 #include "core/html/HTMLContentElement.h" |
| 41 #include "core/html/HTMLDivElement.h" | 43 #include "core/html/HTMLDivElement.h" |
| 42 #include "core/html/HTMLHeadElement.h" | 44 #include "core/html/HTMLHeadElement.h" |
| 43 #include "core/html/HTMLHtmlElement.h" | 45 #include "core/html/HTMLHtmlElement.h" |
| 44 #include "core/html/HTMLMetaElement.h" | 46 #include "core/html/HTMLMetaElement.h" |
| 45 #include "core/html/HTMLSourceElement.h" | 47 #include "core/html/HTMLSourceElement.h" |
| 46 #include "core/html/HTMLStyleElement.h" | 48 #include "core/html/HTMLStyleElement.h" |
| 47 #include "core/html/HTMLVideoElement.h" | 49 #include "core/html/HTMLVideoElement.h" |
| 48 #include "core/loader/DocumentLoader.h" | 50 #include "core/loader/DocumentLoader.h" |
| 49 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
| 50 #include "core/loader/FrameLoaderClient.h" | 52 #include "core/loader/FrameLoaderClient.h" |
| 51 #include "platform/Histogram.h" | 53 #include "platform/Histogram.h" |
| 52 #include "platform/KeyboardCodes.h" | 54 #include "platform/KeyboardCodes.h" |
| 55 #include "platform/UserGestureIndicator.h" |
| 53 #include "platform/text/PlatformLocale.h" | 56 #include "platform/text/PlatformLocale.h" |
| 54 | 57 |
| 55 namespace blink { | 58 namespace blink { |
| 56 | 59 |
| 57 using namespace HTMLNames; | 60 using namespace HTMLNames; |
| 58 | 61 |
| 59 // Enums used for UMA histogram. | 62 // Enums used for UMA histogram. |
| 60 enum MediaDocumentDownloadButtonValue { | 63 enum MediaDocumentDownloadButtonValue { |
| 61 MediaDocumentDownloadButtonShown, | 64 MediaDocumentDownloadButtonShown, |
| 62 MediaDocumentDownloadButtonClicked, | 65 MediaDocumentDownloadButtonClicked, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void handleEvent(ExecutionContext* context, Event* event) override { | 109 void handleEvent(ExecutionContext* context, Event* event) override { |
| 107 if (!m_clicked) { | 110 if (!m_clicked) { |
| 108 recordDownloadMetric(MediaDocumentDownloadButtonClicked); | 111 recordDownloadMetric(MediaDocumentDownloadButtonClicked); |
| 109 m_clicked = true; | 112 m_clicked = true; |
| 110 } | 113 } |
| 111 } | 114 } |
| 112 | 115 |
| 113 bool m_clicked; | 116 bool m_clicked; |
| 114 }; | 117 }; |
| 115 | 118 |
| 119 class MediaLoadedEventListener final : public EventListener { |
| 120 WTF_MAKE_NONCOPYABLE(MediaLoadedEventListener); |
| 121 |
| 122 public: |
| 123 static MediaLoadedEventListener* create() { |
| 124 return new MediaLoadedEventListener(); |
| 125 } |
| 126 |
| 127 bool operator==(const EventListener& other) const override { |
| 128 return this == &other; |
| 129 } |
| 130 |
| 131 private: |
| 132 MediaLoadedEventListener() : EventListener(CPPEventListenerType) {} |
| 133 |
| 134 void handleEvent(ExecutionContext* context, Event* event) override { |
| 135 HTMLVideoElement* media = |
| 136 static_cast<HTMLVideoElement*>(event->target()->toNode()); |
| 137 UserGestureIndicator gesture( |
| 138 DocumentUserGestureToken::create(&media->document())); |
| 139 media->webkitEnterFullscreen(); |
| 140 media->play(); |
| 141 } |
| 142 }; |
| 143 |
| 116 void MediaDocumentParser::createDocumentStructure() { | 144 void MediaDocumentParser::createDocumentStructure() { |
| 117 DCHECK(document()); | 145 DCHECK(document()); |
| 118 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); | 146 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); |
| 119 document()->appendChild(rootElement); | 147 document()->appendChild(rootElement); |
| 120 rootElement->insertedByParser(); | 148 rootElement->insertedByParser(); |
| 121 | 149 |
| 122 if (isDetached()) | 150 if (isDetached()) |
| 123 return; // runScriptsAtDocumentElementAvailable can detach the frame. | 151 return; // runScriptsAtDocumentElementAvailable can detach the frame. |
| 124 | 152 |
| 125 HTMLHeadElement* head = HTMLHeadElement::create(*document()); | 153 HTMLHeadElement* head = HTMLHeadElement::create(*document()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 156 div->setAttribute(styleAttr, | 184 div->setAttribute(styleAttr, |
| 157 "display: flex;" | 185 "display: flex;" |
| 158 "flex-direction: column;" | 186 "flex-direction: column;" |
| 159 "justify-content: center;" | 187 "justify-content: center;" |
| 160 "align-items: center;" | 188 "align-items: center;" |
| 161 "min-height: min-content;" | 189 "min-height: min-content;" |
| 162 "height: 100%;"); | 190 "height: 100%;"); |
| 163 HTMLContentElement* content = HTMLContentElement::create(*document()); | 191 HTMLContentElement* content = HTMLContentElement::create(*document()); |
| 164 div->appendChild(content); | 192 div->appendChild(content); |
| 165 | 193 |
| 194 if (document()->settings() && |
| 195 document()->settings()->getEmbeddedMediaExperienceEnabled()) { |
| 196 EventListener* listener = MediaLoadedEventListener::create(); |
| 197 AddEventListenerOptions options; |
| 198 options.setOnce(true); |
| 199 AddEventListenerOptionsOrBoolean optionsOrBoolean; |
| 200 optionsOrBoolean.setAddEventListenerOptions(options); |
| 201 media->addEventListener(EventTypeNames::loadedmetadata, listener, |
| 202 optionsOrBoolean); |
| 203 } |
| 204 |
| 166 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | 205 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { |
| 167 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); | 206 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); |
| 168 anchor->setAttribute(downloadAttr, ""); | 207 anchor->setAttribute(downloadAttr, ""); |
| 169 anchor->setURL(document()->url()); | 208 anchor->setURL(document()->url()); |
| 170 anchor->setTextContent( | 209 anchor->setTextContent( |
| 171 document() | 210 document() |
| 172 ->getCachedLocale(document()->contentLanguage()) | 211 ->getCachedLocale(document()->contentLanguage()) |
| 173 .queryString(WebLocalizedString::DownloadButtonLabel) | 212 .queryString(WebLocalizedString::DownloadButtonLabel) |
| 174 .upper()); | 213 .upper()); |
| 175 // Using CSS style according to Android material design. | 214 // Using CSS style according to Android material design. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (keyboardEvent->key() == " " || | 292 if (keyboardEvent->key() == " " || |
| 254 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { | 293 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { |
| 255 // space or media key (play/pause) | 294 // space or media key (play/pause) |
| 256 video->togglePlayState(); | 295 video->togglePlayState(); |
| 257 event->setDefaultHandled(); | 296 event->setDefaultHandled(); |
| 258 } | 297 } |
| 259 } | 298 } |
| 260 } | 299 } |
| 261 | 300 |
| 262 } // namespace blink | 301 } // namespace blink |
| OLD | NEW |