| 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/HTMLImportsController.h" | 32 #include "core/html/HTMLImportsController.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/DocumentFragment.h" | |
| 36 #include "core/dom/DocumentType.h" | 35 #include "core/dom/DocumentType.h" |
| 37 #include "core/dom/Range.h" | 36 #include "core/dom/Range.h" |
| 38 #include "core/html/HTMLDocument.h" | 37 #include "core/html/HTMLDocument.h" |
| 39 #include "core/html/HTMLLinkElement.h" | 38 #include "core/html/HTMLLinkElement.h" |
| 40 #include "core/loader/cache/CachedResourceLoader.h" | 39 #include "core/loader/cache/CachedResourceLoader.h" |
| 41 #include "core/loader/cache/CachedScript.h" | 40 #include "core/loader/cache/CachedScript.h" |
| 42 #include "weborigin/SecurityOrigin.h" | 41 #include "weborigin/SecurityOrigin.h" |
| 43 | 42 |
| 44 namespace WebCore { | 43 namespace WebCore { |
| 45 | 44 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 return StateError; | 70 return StateError; |
| 72 | 71 |
| 73 String error; | 72 String error; |
| 74 if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()
) | 73 if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()
) |
| 75 && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(),
error)) { | 74 && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(),
error)) { |
| 76 m_controller->showSecurityErrorMessage("Import from origin '" + Security
Origin::create(m_resource->response().url())->toString() + "' has been blocked f
rom loading by Cross-Origin Resource Sharing policy: " + error); | 75 m_controller->showSecurityErrorMessage("Import from origin '" + Security
Origin::create(m_resource->response().url())->toString() + "' has been blocked f
rom loading by Cross-Origin Resource Sharing policy: " + error); |
| 77 return StateError; | 76 return StateError; |
| 78 } | 77 } |
| 79 | 78 |
| 80 // FIXME(morrita): This should be done in incremental way. | 79 // FIXME(morrita): This should be done in incremental way. |
| 81 RefPtr<Document> parsingPlaceholder = HTMLDocument::create(0, KURL()); | 80 m_importedDocument = HTMLDocument::create(0, m_resource->response().url()); |
| 82 parsingPlaceholder->setContent(m_resource->script()); | 81 m_importedDocument->setContent(m_resource->script()); |
| 83 | |
| 84 // Doctypes cannot be moved between documents. So we remove it before the mi
gration. | |
| 85 if (RefPtr<Node> doctype = parsingPlaceholder->doctype()) | |
| 86 parsingPlaceholder->removeChild(doctype.get()); | |
| 87 m_importedFragment->takeAllChildrenFrom(parsingPlaceholder.get()); | |
| 88 | 82 |
| 89 return StateReady; | 83 return StateReady; |
| 90 } | 84 } |
| 91 | 85 |
| 92 void LinkImport::notifyFinished(CachedResource*) | 86 void LinkImport::notifyFinished(CachedResource*) |
| 93 { | 87 { |
| 94 setState(finish()); | 88 setState(finish()); |
| 95 } | 89 } |
| 96 | 90 |
| 97 void LinkImport::setState(State state) | 91 void LinkImport::setState(State state) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 125 } | 119 } |
| 126 | 120 |
| 127 CachedResourceRequest request = builder.build(true); | 121 CachedResourceRequest request = builder.build(true); |
| 128 m_resource = m_owner->document()->cachedResourceLoader()->requestScript(requ
est); | 122 m_resource = m_owner->document()->cachedResourceLoader()->requestScript(requ
est); |
| 129 if (!m_resource) | 123 if (!m_resource) |
| 130 return StateError; | 124 return StateError; |
| 131 | 125 |
| 132 m_resource->addClient(this); | 126 m_resource->addClient(this); |
| 133 m_url = builder.url(); | 127 m_url = builder.url(); |
| 134 m_controller->addImport(this); | 128 m_controller->addImport(this); |
| 135 m_importedFragment = m_controller->createDocumentFragment(); | |
| 136 | 129 |
| 137 return StateStarted; | 130 return StateStarted; |
| 138 } | 131 } |
| 139 | 132 |
| 140 DocumentFragment* LinkImport::importedFragment() const | 133 Document* LinkImport::importedDocument() const |
| 141 { | 134 { |
| 142 if (!m_owner) | 135 if (!m_owner) |
| 143 return 0; | 136 return 0; |
| 144 if (m_state != StateReady) | 137 if (m_state != StateReady) |
| 145 return 0; | 138 return 0; |
| 146 | 139 |
| 147 if (m_ofSameLocation) { | 140 if (m_ofSameLocation) { |
| 148 ASSERT(!m_importedFragment); | 141 ASSERT(!m_importedDocument); |
| 149 return m_ofSameLocation->importedFragment(); | 142 return m_ofSameLocation->importedDocument(); |
| 150 } | 143 } |
| 151 | 144 |
| 152 return m_importedFragment.get(); | 145 return m_importedDocument.get(); |
| 153 } | 146 } |
| 154 | 147 |
| 155 void LinkImport::process() | 148 void LinkImport::process() |
| 156 { | 149 { |
| 157 if (StatePreparing != m_state) | 150 if (StatePreparing != m_state) |
| 158 return; | 151 return; |
| 159 setState(startRequest()); | 152 setState(startRequest()); |
| 160 } | 153 } |
| 161 | 154 |
| 162 void LinkImport::ownerRemoved() | 155 void LinkImport::ownerRemoved() |
| 163 { | 156 { |
| 164 m_owner = 0; | 157 m_owner = 0; |
| 165 } | 158 } |
| 166 | 159 |
| 167 void LinkImport::importDestroyed() | 160 void LinkImport::importDestroyed() |
| 168 { | 161 { |
| 169 m_controller = 0; | 162 m_controller = 0; |
| 170 m_importedFragment.clear(); | 163 m_importedDocument.clear(); |
| 171 } | 164 } |
| 172 | 165 |
| 173 PassOwnPtr<HTMLImportsController> HTMLImportsController::create(Document* master
) | 166 PassOwnPtr<HTMLImportsController> HTMLImportsController::create(Document* master
) |
| 174 { | 167 { |
| 175 return adoptPtr(new HTMLImportsController(master)); | 168 return adoptPtr(new HTMLImportsController(master)); |
| 176 } | 169 } |
| 177 | 170 |
| 178 HTMLImportsController::HTMLImportsController(Document* master) | 171 HTMLImportsController::HTMLImportsController(Document* master) |
| 179 : m_master(master) | 172 : m_master(master) |
| 180 , m_importedFragmentOwner(HTMLDocument::create(0, KURL())) | |
| 181 { | 173 { |
| 182 } | 174 } |
| 183 | 175 |
| 184 HTMLImportsController::~HTMLImportsController() | 176 HTMLImportsController::~HTMLImportsController() |
| 185 { | 177 { |
| 186 for (size_t i = 0; i < m_imports.size(); ++i) | 178 for (size_t i = 0; i < m_imports.size(); ++i) |
| 187 m_imports[i]->importDestroyed(); | 179 m_imports[i]->importDestroyed(); |
| 188 } | 180 } |
| 189 | 181 |
| 190 void HTMLImportsController::addImport(PassRefPtr<LinkImport> link) | 182 void HTMLImportsController::addImport(PassRefPtr<LinkImport> link) |
| 191 { | 183 { |
| 192 ASSERT(!link->url().isEmpty() && link->url().isValid()); | 184 ASSERT(!link->url().isEmpty() && link->url().isValid()); |
| 193 m_imports.append(link); | 185 m_imports.append(link); |
| 194 } | 186 } |
| 195 | 187 |
| 196 void HTMLImportsController::showSecurityErrorMessage(const String& message) | 188 void HTMLImportsController::showSecurityErrorMessage(const String& message) |
| 197 { | 189 { |
| 198 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); | 190 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); |
| 199 } | 191 } |
| 200 | 192 |
| 201 void HTMLImportsController::didLoad() | 193 void HTMLImportsController::didLoad() |
| 202 { | 194 { |
| 203 if (haveLoaded()) | 195 if (haveLoaded()) |
| 204 m_master->didLoadAllImports(); | 196 m_master->didLoadAllImports(); |
| 205 } | 197 } |
| 206 | 198 |
| 207 PassRefPtr<DocumentFragment> HTMLImportsController::createDocumentFragment() con
st | |
| 208 { | |
| 209 return m_importedFragmentOwner->createDocumentFragment(); | |
| 210 } | |
| 211 | |
| 212 PassRefPtr<LinkImport> HTMLImportsController::findLinkFor(const KURL& url) const | 199 PassRefPtr<LinkImport> HTMLImportsController::findLinkFor(const KURL& url) const |
| 213 { | 200 { |
| 214 for (size_t i = 0; i < m_imports.size(); ++i) { | 201 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 215 if (m_imports[i]->url() == url) | 202 if (m_imports[i]->url() == url) |
| 216 return m_imports[i]; | 203 return m_imports[i]; |
| 217 } | 204 } |
| 218 | 205 |
| 219 return 0; | 206 return 0; |
| 220 } | 207 } |
| 221 | 208 |
| 222 SecurityOrigin* HTMLImportsController::securityOrigin() const | 209 SecurityOrigin* HTMLImportsController::securityOrigin() const |
| 223 { | 210 { |
| 224 return m_master->securityOrigin(); | 211 return m_master->securityOrigin(); |
| 225 } | 212 } |
| 226 | 213 |
| 227 bool HTMLImportsController::haveLoaded() const | 214 bool HTMLImportsController::haveLoaded() const |
| 228 { | 215 { |
| 229 for (size_t i = 0; i < m_imports.size(); ++i) { | 216 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 230 if (!m_imports[i]->isDone()) | 217 if (!m_imports[i]->isDone()) |
| 231 return false; | 218 return false; |
| 232 } | 219 } |
| 233 | 220 |
| 234 return true; | 221 return true; |
| 235 } | 222 } |
| 236 | 223 |
| 237 } // namespace WebCore | 224 } // namespace WebCore |
| OLD | NEW |