| 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" |
| 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 Loading... |
| 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: |
| 122 static MediaLoadedEventListener* create() { |
| 123 return new MediaLoadedEventListener(); |
| 124 } |
| 125 |
| 126 bool operator==(const EventListener& other) const override { |
| 127 return this == &other; |
| 128 } |
| 129 |
| 130 private: |
| 131 MediaLoadedEventListener() : EventListener(CPPEventListenerType) {} |
| 132 |
| 133 void handleEvent(ExecutionContext* context, Event* event) override { |
| 134 HTMLVideoElement* media = Traversal<HTMLVideoElement>::firstWithin( |
| 135 *event->target()->toNode()->getRootNode(GetRootNodeOptions())); |
| 136 UserGestureIndicator gesture( |
| 137 DocumentUserGestureToken::create(&media->document())); |
| 138 media->webkitEnterFullscreen(); |
| 139 } |
| 140 }; |
| 141 |
| 116 void MediaDocumentParser::createDocumentStructure() { | 142 void MediaDocumentParser::createDocumentStructure() { |
| 117 DCHECK(document()); | 143 DCHECK(document()); |
| 118 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); | 144 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document()); |
| 119 document()->appendChild(rootElement); | 145 document()->appendChild(rootElement); |
| 120 rootElement->insertedByParser(); | 146 rootElement->insertedByParser(); |
| 121 | 147 |
| 122 if (isDetached()) | 148 if (isDetached()) |
| 123 return; // runScriptsAtDocumentElementAvailable can detach the frame. | 149 return; // runScriptsAtDocumentElementAvailable can detach the frame. |
| 124 | 150 |
| 125 HTMLHeadElement* head = HTMLHeadElement::create(*document()); | 151 HTMLHeadElement* head = HTMLHeadElement::create(*document()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 156 div->setAttribute(styleAttr, | 182 div->setAttribute(styleAttr, |
| 157 "display: flex;" | 183 "display: flex;" |
| 158 "flex-direction: column;" | 184 "flex-direction: column;" |
| 159 "justify-content: center;" | 185 "justify-content: center;" |
| 160 "align-items: center;" | 186 "align-items: center;" |
| 161 "min-height: min-content;" | 187 "min-height: min-content;" |
| 162 "height: 100%;"); | 188 "height: 100%;"); |
| 163 HTMLContentElement* content = HTMLContentElement::create(*document()); | 189 HTMLContentElement* content = HTMLContentElement::create(*document()); |
| 164 div->appendChild(content); | 190 div->appendChild(content); |
| 165 | 191 |
| 192 if (document()->settings() && |
| 193 document()->settings()->getEmbeddedMediaExperienceEnabled()) { |
| 194 EventListener* listener = MediaLoadedEventListener::create(); |
| 195 media->addEventListener(EventTypeNames::loadedmetadata, listener, false); |
| 196 } |
| 197 |
| 166 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | 198 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { |
| 167 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); | 199 HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document()); |
| 168 anchor->setAttribute(downloadAttr, ""); | 200 anchor->setAttribute(downloadAttr, ""); |
| 169 anchor->setURL(document()->url()); | 201 anchor->setURL(document()->url()); |
| 170 anchor->setTextContent( | 202 anchor->setTextContent( |
| 171 document() | 203 document() |
| 172 ->getCachedLocale(document()->contentLanguage()) | 204 ->getCachedLocale(document()->contentLanguage()) |
| 173 .queryString(WebLocalizedString::DownloadButtonLabel) | 205 .queryString(WebLocalizedString::DownloadButtonLabel) |
| 174 .upper()); | 206 .upper()); |
| 175 // Using CSS style according to Android material design. | 207 // 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() == " " || | 285 if (keyboardEvent->key() == " " || |
| 254 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { | 286 keyboardEvent->keyCode() == VKEY_MEDIA_PLAY_PAUSE) { |
| 255 // space or media key (play/pause) | 287 // space or media key (play/pause) |
| 256 video->togglePlayState(); | 288 video->togglePlayState(); |
| 257 event->setDefaultHandled(); | 289 event->setDefaultHandled(); |
| 258 } | 290 } |
| 259 } | 291 } |
| 260 } | 292 } |
| 261 | 293 |
| 262 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |