| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "core/loader/FrameLoaderClient.h" | 42 #include "core/loader/FrameLoaderClient.h" |
| 43 #include "platform/KeyboardCodes.h" | 43 #include "platform/KeyboardCodes.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 using namespace HTMLNames; | 47 using namespace HTMLNames; |
| 48 | 48 |
| 49 // FIXME: Share more code with PluginDocumentParser. | 49 // FIXME: Share more code with PluginDocumentParser. |
| 50 class MediaDocumentParser : public RawDataDocumentParser { | 50 class MediaDocumentParser : public RawDataDocumentParser { |
| 51 public: | 51 public: |
| 52 static PassRefPtrWillBeRawPtr<MediaDocumentParser> create(MediaDocument* doc
ument) | 52 static RawPtr<MediaDocumentParser> create(MediaDocument* document) |
| 53 { | 53 { |
| 54 return adoptRefWillBeNoop(new MediaDocumentParser(document)); | 54 return new MediaDocumentParser(document); |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 explicit MediaDocumentParser(Document* document) | 58 explicit MediaDocumentParser(Document* document) |
| 59 : RawDataDocumentParser(document) | 59 : RawDataDocumentParser(document) |
| 60 , m_didBuildDocumentStructure(false) | 60 , m_didBuildDocumentStructure(false) |
| 61 { | 61 { |
| 62 } | 62 } |
| 63 | 63 |
| 64 void appendBytes(const char*, size_t) override; | 64 void appendBytes(const char*, size_t) override; |
| 65 | 65 |
| 66 void createDocumentStructure(); | 66 void createDocumentStructure(); |
| 67 | 67 |
| 68 bool m_didBuildDocumentStructure; | 68 bool m_didBuildDocumentStructure; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 void MediaDocumentParser::createDocumentStructure() | 71 void MediaDocumentParser::createDocumentStructure() |
| 72 { | 72 { |
| 73 ASSERT(document()); | 73 ASSERT(document()); |
| 74 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*d
ocument()); | 74 RawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*document()); |
| 75 rootElement->insertedByParser(); | 75 rootElement->insertedByParser(); |
| 76 document()->appendChild(rootElement); | 76 document()->appendChild(rootElement); |
| 77 | 77 |
| 78 document()->frame()->loader().dispatchDocumentElementAvailable(); | 78 document()->frame()->loader().dispatchDocumentElementAvailable(); |
| 79 document()->frame()->loader().runScriptsAtDocumentElementAvailable(); | 79 document()->frame()->loader().runScriptsAtDocumentElementAvailable(); |
| 80 if (isDetached()) | 80 if (isDetached()) |
| 81 return; // runScriptsAtDocumentElementAvailable can detach the frame. | 81 return; // runScriptsAtDocumentElementAvailable can detach the frame. |
| 82 | 82 |
| 83 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*document
()); | 83 RawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*document()); |
| 84 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*document
()); | 84 RawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*document()); |
| 85 meta->setAttribute(nameAttr, "viewport"); | 85 meta->setAttribute(nameAttr, "viewport"); |
| 86 meta->setAttribute(contentAttr, "width=device-width"); | 86 meta->setAttribute(contentAttr, "width=device-width"); |
| 87 head->appendChild(meta.release()); | 87 head->appendChild(meta.release()); |
| 88 | 88 |
| 89 RefPtrWillBeRawPtr<HTMLVideoElement> media = HTMLVideoElement::create(*docum
ent()); | 89 RawPtr<HTMLVideoElement> media = HTMLVideoElement::create(*document()); |
| 90 media->setAttribute(controlsAttr, ""); | 90 media->setAttribute(controlsAttr, ""); |
| 91 media->setAttribute(autoplayAttr, ""); | 91 media->setAttribute(autoplayAttr, ""); |
| 92 media->setAttribute(nameAttr, "media"); | 92 media->setAttribute(nameAttr, "media"); |
| 93 | 93 |
| 94 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do
cument()); | 94 RawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*document()); |
| 95 source->setSrc(document()->url()); | 95 source->setSrc(document()->url()); |
| 96 | 96 |
| 97 if (DocumentLoader* loader = document()->loader()) | 97 if (DocumentLoader* loader = document()->loader()) |
| 98 source->setType(loader->responseMIMEType()); | 98 source->setType(loader->responseMIMEType()); |
| 99 | 99 |
| 100 media->appendChild(source.release()); | 100 media->appendChild(source.release()); |
| 101 | 101 |
| 102 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document
()); | 102 RawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document()); |
| 103 body->appendChild(media.release()); | 103 body->appendChild(media.release()); |
| 104 | 104 |
| 105 rootElement->appendChild(head.release()); | 105 rootElement->appendChild(head.release()); |
| 106 rootElement->appendChild(body.release()); | 106 rootElement->appendChild(body.release()); |
| 107 | 107 |
| 108 m_didBuildDocumentStructure = true; | 108 m_didBuildDocumentStructure = true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void MediaDocumentParser::appendBytes(const char*, size_t) | 111 void MediaDocumentParser::appendBytes(const char*, size_t) |
| 112 { | 112 { |
| 113 if (m_didBuildDocumentStructure) | 113 if (m_didBuildDocumentStructure) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 LocalFrame* frame = document()->frame(); | 116 LocalFrame* frame = document()->frame(); |
| 117 if (!frame->loader().client()->allowMedia(document()->url())) | 117 if (!frame->loader().client()->allowMedia(document()->url())) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 createDocumentStructure(); | 120 createDocumentStructure(); |
| 121 finish(); | 121 finish(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 MediaDocument::MediaDocument(const DocumentInit& initializer) | 124 MediaDocument::MediaDocument(const DocumentInit& initializer) |
| 125 : HTMLDocument(initializer, MediaDocumentClass) | 125 : HTMLDocument(initializer, MediaDocumentClass) |
| 126 { | 126 { |
| 127 setCompatibilityMode(QuirksMode); | 127 setCompatibilityMode(QuirksMode); |
| 128 lockCompatibilityMode(); | 128 lockCompatibilityMode(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 PassRefPtrWillBeRawPtr<DocumentParser> MediaDocument::createParser() | 131 RawPtr<DocumentParser> MediaDocument::createParser() |
| 132 { | 132 { |
| 133 return MediaDocumentParser::create(this); | 133 return MediaDocumentParser::create(this); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void MediaDocument::defaultEventHandler(Event* event) | 136 void MediaDocument::defaultEventHandler(Event* event) |
| 137 { | 137 { |
| 138 Node* targetNode = event->target()->toNode(); | 138 Node* targetNode = event->target()->toNode(); |
| 139 if (!targetNode) | 139 if (!targetNode) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 if (event->type() == EventTypeNames::keydown && event->isKeyboardEvent()) { | 142 if (event->type() == EventTypeNames::keydown && event->isKeyboardEvent()) { |
| 143 HTMLVideoElement* video = Traversal<HTMLVideoElement>::firstWithin(*targ
etNode); | 143 HTMLVideoElement* video = Traversal<HTMLVideoElement>::firstWithin(*targ
etNode); |
| 144 if (!video) | 144 if (!video) |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 147 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
| 148 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode
() == VKEY_MEDIA_PLAY_PAUSE) { | 148 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode
() == VKEY_MEDIA_PLAY_PAUSE) { |
| 149 // space or media key (play/pause) | 149 // space or media key (play/pause) |
| 150 video->togglePlayState(); | 150 video->togglePlayState(); |
| 151 event->setDefaultHandled(); | 151 event->setDefaultHandled(); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |