| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/html/imports/HTMLImportLoader.h" | 32 #include "core/html/imports/HTMLImportLoader.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/DocumentParser.h" |
| 35 #include "core/dom/StyleEngine.h" | 36 #include "core/dom/StyleEngine.h" |
| 36 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" | 37 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" |
| 37 #include "core/html/HTMLDocument.h" | 38 #include "core/html/HTMLDocument.h" |
| 38 #include "core/html/imports/HTMLImportChild.h" | 39 #include "core/html/imports/HTMLImportChild.h" |
| 39 #include "core/html/imports/HTMLImportsController.h" | 40 #include "core/html/imports/HTMLImportsController.h" |
| 40 #include "core/loader/DocumentWriter.h" | |
| 41 | |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 HTMLImportLoader::HTMLImportLoader(HTMLImportsController* controller) | 44 HTMLImportLoader::HTMLImportLoader(HTMLImportsController* controller) |
| 46 : m_controller(controller) | 45 : m_controller(controller) |
| 47 , m_state(StateLoading) | 46 , m_state(StateLoading) |
| 48 , m_microtaskQueue(CustomElementSyncMicrotaskQueue::create()) | 47 , m_microtaskQueue(CustomElementSyncMicrotaskQueue::create()) |
| 49 { | 48 { |
| 50 } | 49 } |
| 51 | 50 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 | 63 |
| 65 void HTMLImportLoader::clear() | 64 void HTMLImportLoader::clear() |
| 66 { | 65 { |
| 67 m_controller = nullptr; | 66 m_controller = nullptr; |
| 68 if (m_document) { | 67 if (m_document) { |
| 69 m_document->setImportsController(0); | 68 m_document->setImportsController(0); |
| 70 m_document->cancelParsing(); | 69 m_document->cancelParsing(); |
| 71 m_document.clear(); | 70 m_document.clear(); |
| 72 } | 71 } |
| 73 m_fetcher.clear(); | 72 m_fetcher.clear(); |
| 74 m_drainer.clear(); | |
| 75 } | 73 } |
| 76 #endif | 74 #endif |
| 77 | 75 |
| 78 void HTMLImportLoader::startLoading(const KURL& url) | 76 void HTMLImportLoader::startLoading(const KURL& url) |
| 79 { | 77 { |
| 80 m_fetcher = adoptPtr(new MojoFetcher(this, url)); | 78 m_fetcher = adoptPtr(new MojoFetcher(this, url)); |
| 81 } | 79 } |
| 82 | 80 |
| 83 void HTMLImportLoader::OnReceivedResponse(mojo::URLResponsePtr response) | 81 void HTMLImportLoader::OnReceivedResponse(mojo::URLResponsePtr response) |
| 84 { | 82 { |
| 85 if (response->error || response->status_code >= 400) { | 83 if (response->error || response->status_code >= 400) { |
| 86 setState(StateError); | 84 setState(StateError); |
| 87 return; | 85 return; |
| 88 } | 86 } |
| 89 mojo::ScopedDataPipeConsumerHandle body = response->body.Pass(); | |
| 90 setState(startWritingAndParsing(response.Pass())); | 87 setState(startWritingAndParsing(response.Pass())); |
| 91 m_drainer = adoptPtr(new DataPipeDrainer(this, body.Pass())); | |
| 92 } | |
| 93 | |
| 94 void HTMLImportLoader::OnDataAvailable(const void* data, size_t length) | |
| 95 { | |
| 96 RefPtrWillBeRawPtr<DocumentWriter> protectingWriter(m_writer.get()); | |
| 97 m_writer->addData(static_cast<const char*>(data), length); | |
| 98 } | |
| 99 | |
| 100 void HTMLImportLoader::OnDataComplete() | |
| 101 { | |
| 102 setState(finishWriting()); | |
| 103 } | 88 } |
| 104 | 89 |
| 105 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(mojo::URLRespon
sePtr response) | 90 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(mojo::URLRespon
sePtr response) |
| 106 { | 91 { |
| 107 ASSERT(!m_imports.isEmpty()); | 92 ASSERT(!m_imports.isEmpty()); |
| 108 KURL url(ParsedURLString, String::fromUTF8(response->url)); | 93 KURL url(ParsedURLString, String::fromUTF8(response->url)); |
| 109 DocumentInit init = DocumentInit(url, 0, m_controller->master()->contextDocu
ment(), m_controller) | 94 DocumentInit init = DocumentInit(url, 0, m_controller->master()->contextDocu
ment(), m_controller) |
| 110 .withRegistrationContext(m_controller->master()->registrationContext()); | 95 .withRegistrationContext(m_controller->master()->registrationContext()); |
| 111 m_document = HTMLDocument::create(init); | 96 m_document = HTMLDocument::create(init); |
| 112 m_writer = DocumentWriter::create(m_document.get()); | 97 m_document->startParsing(); |
| 113 | 98 m_document->parser()->parse(response->body.Pass()); |
| 114 return StateLoading; | 99 return StateLoading; |
| 115 } | 100 } |
| 116 | 101 |
| 117 HTMLImportLoader::State HTMLImportLoader::finishWriting() | 102 HTMLImportLoader::State HTMLImportLoader::finishWriting() |
| 118 { | 103 { |
| 119 return StateWritten; | 104 return StateWritten; |
| 120 } | 105 } |
| 121 | 106 |
| 122 HTMLImportLoader::State HTMLImportLoader::finishParsing() | 107 HTMLImportLoader::State HTMLImportLoader::finishParsing() |
| 123 { | 108 { |
| 124 return StateParsed; | 109 return StateParsed; |
| 125 } | 110 } |
| 126 | 111 |
| 127 HTMLImportLoader::State HTMLImportLoader::finishLoading() | 112 HTMLImportLoader::State HTMLImportLoader::finishLoading() |
| 128 { | 113 { |
| 129 return StateLoaded; | 114 return StateLoaded; |
| 130 } | 115 } |
| 131 | 116 |
| 132 void HTMLImportLoader::setState(State state) | 117 void HTMLImportLoader::setState(State state) |
| 133 { | 118 { |
| 134 if (m_state == state) | 119 if (m_state == state) |
| 135 return; | 120 return; |
| 136 | 121 |
| 137 m_state = state; | 122 m_state = state; |
| 138 | 123 |
| 139 if (m_state == StateParsed || m_state == StateError || m_state == StateWritt
en) { | 124 if (m_state == StateParsed || m_state == StateError || m_state == StateWritt
en) |
| 140 if (RefPtrWillBeRawPtr<DocumentWriter> writer = m_writer.release()) | 125 m_document->cancelParsing(); |
| 141 writer->end(); | |
| 142 } | |
| 143 | 126 |
| 144 // Since DocumentWriter::end() can let setState() reenter, we shouldn't refe
r to m_state here. | 127 // Since DocumentWriter::end() can let setState() reenter, we shouldn't refe
r to m_state here. |
| 145 if (state == StateLoaded || state == StateError) | 128 if (state == StateLoaded || state == StateError) |
| 146 didFinishLoading(); | 129 didFinishLoading(); |
| 147 } | 130 } |
| 148 | 131 |
| 149 void HTMLImportLoader::didFinishParsing() | 132 void HTMLImportLoader::didFinishParsing() |
| 150 { | 133 { |
| 151 setState(finishParsing()); | 134 setState(finishParsing()); |
| 152 setState(finishLoading()); | 135 setState(finishLoading()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return m_microtaskQueue; | 185 return m_microtaskQueue; |
| 203 } | 186 } |
| 204 | 187 |
| 205 void HTMLImportLoader::trace(Visitor* visitor) | 188 void HTMLImportLoader::trace(Visitor* visitor) |
| 206 { | 189 { |
| 207 visitor->trace(m_controller); | 190 visitor->trace(m_controller); |
| 208 #if ENABLE(OILPAN) | 191 #if ENABLE(OILPAN) |
| 209 visitor->trace(m_imports); | 192 visitor->trace(m_imports); |
| 210 #endif | 193 #endif |
| 211 visitor->trace(m_document); | 194 visitor->trace(m_document); |
| 212 visitor->trace(m_writer); | |
| 213 visitor->trace(m_microtaskQueue); | 195 visitor->trace(m_microtaskQueue); |
| 214 } | 196 } |
| 215 | 197 |
| 216 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |