| 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 17 matching lines...) Expand all Loading... |
| 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/StyleEngine.h" | 35 #include "core/dom/StyleEngine.h" |
| 36 #include "core/html/HTMLDocument.h" | 36 #include "core/html/HTMLDocument.h" |
| 37 #include "core/html/imports/HTMLImport.h" | 37 #include "core/html/imports/HTMLImport.h" |
| 38 #include "core/html/imports/HTMLImportLoaderClient.h" | 38 #include "core/html/imports/HTMLImportChild.h" |
| 39 #include "core/loader/DocumentWriter.h" | 39 #include "core/loader/DocumentWriter.h" |
| 40 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" | 40 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" |
| 41 | 41 |
| 42 | 42 |
| 43 namespace WebCore { | 43 namespace WebCore { |
| 44 | 44 |
| 45 HTMLImportLoader::HTMLImportLoader(HTMLImport* import) | 45 HTMLImportLoader::HTMLImportLoader() |
| 46 : m_import(import) | 46 : m_state(StateLoading) |
| 47 , m_state(StateLoading) | |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 HTMLImportLoader::~HTMLImportLoader() | 50 HTMLImportLoader::~HTMLImportLoader() |
| 52 { | 51 { |
| 53 if (m_importedDocument) | 52 if (m_importedDocument) |
| 54 m_importedDocument->setImport(0); | 53 m_importedDocument->setImport(0); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void HTMLImportLoader::startLoading(const ResourcePtr<RawResource>& resource) | 56 void HTMLImportLoader::startLoading(const ResourcePtr<RawResource>& resource) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 83 if (resource->loadFailedOrCanceled() && !m_writer) { | 82 if (resource->loadFailedOrCanceled() && !m_writer) { |
| 84 setState(StateError); | 83 setState(StateError); |
| 85 return; | 84 return; |
| 86 } | 85 } |
| 87 | 86 |
| 88 setState(finishWriting()); | 87 setState(finishWriting()); |
| 89 } | 88 } |
| 90 | 89 |
| 91 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR
esponse& response) | 90 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR
esponse& response) |
| 92 { | 91 { |
| 93 DocumentInit init = DocumentInit(response.url(), 0, m_import->master()->cont
extDocument(), m_import) | 92 ASSERT(!m_imports.isEmpty()); |
| 94 .withRegistrationContext(m_import->master()->registrationContext()); | 93 HTMLImport* firstImport = m_imports[0]; |
| 94 DocumentInit init = DocumentInit(response.url(), 0, firstImport->master()->c
ontextDocument(), firstImport) |
| 95 .withRegistrationContext(firstImport->master()->registrationContext()); |
| 95 m_importedDocument = HTMLDocument::create(init); | 96 m_importedDocument = HTMLDocument::create(init); |
| 96 m_writer = DocumentWriter::create(m_importedDocument.get(), response.mimeTyp
e(), response.textEncodingName()); | 97 m_writer = DocumentWriter::create(m_importedDocument.get(), response.mimeTyp
e(), response.textEncodingName()); |
| 97 | 98 |
| 98 return StateLoading; | 99 return StateLoading; |
| 99 } | 100 } |
| 100 | 101 |
| 101 HTMLImportLoader::State HTMLImportLoader::finishWriting() | 102 HTMLImportLoader::State HTMLImportLoader::finishWriting() |
| 102 { | 103 { |
| 103 return StateWritten; | 104 return StateWritten; |
| 104 } | 105 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 Document* HTMLImportLoader::importedDocument() const | 152 Document* HTMLImportLoader::importedDocument() const |
| 152 { | 153 { |
| 153 if (m_state == StateError) | 154 if (m_state == StateError) |
| 154 return 0; | 155 return 0; |
| 155 return m_importedDocument.get(); | 156 return m_importedDocument.get(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void HTMLImportLoader::didFinishLoading() | 159 void HTMLImportLoader::didFinishLoading() |
| 159 { | 160 { |
| 160 for (size_t i = 0; i < m_clients.size(); ++i) | 161 for (size_t i = 0; i < m_imports.size(); ++i) |
| 161 m_clients[i]->didFinishLoading(); | 162 m_imports[i]->didFinishLoading(); |
| 162 | 163 |
| 163 clearResource(); | 164 clearResource(); |
| 164 | 165 |
| 165 ASSERT(!m_importedDocument || !m_importedDocument->parsing()); | 166 ASSERT(!m_importedDocument || !m_importedDocument->parsing()); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void HTMLImportLoader::addClient(HTMLImportLoaderClient* client) | 169 void HTMLImportLoader::addImport(HTMLImportChild* client) |
| 169 { | 170 { |
| 170 ASSERT(kNotFound == m_clients.find(client)); | 171 ASSERT(kNotFound == m_imports.find(client)); |
| 171 m_clients.append(client); | 172 m_imports.append(client); |
| 172 if (isDone()) | 173 if (isDone()) |
| 173 client->didFinishLoading(); | 174 client->didFinishLoading(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void HTMLImportLoader::removeClient(HTMLImportLoaderClient* client) | 177 void HTMLImportLoader::removeImport(HTMLImportChild* client) |
| 177 { | 178 { |
| 178 ASSERT(kNotFound != m_clients.find(client)); | 179 ASSERT(kNotFound != m_imports.find(client)); |
| 179 m_clients.remove(m_clients.find(client)); | 180 m_imports.remove(m_imports.find(client)); |
| 180 } | 181 } |
| 181 | 182 |
| 182 } // namespace WebCore | 183 } // namespace WebCore |
| OLD | NEW |