| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "sky/engine/core/html/imports/HTMLImportsController.h" | |
| 32 | |
| 33 #include "sky/engine/core/dom/Document.h" | |
| 34 #include "sky/engine/core/fetch/ResourceFetcher.h" | |
| 35 #include "sky/engine/core/frame/LocalFrame.h" | |
| 36 #include "sky/engine/core/html/imports/HTMLImportChild.h" | |
| 37 #include "sky/engine/core/html/imports/HTMLImportChildClient.h" | |
| 38 #include "sky/engine/core/html/imports/HTMLImportLoader.h" | |
| 39 #include "sky/engine/core/html/imports/HTMLImportTreeRoot.h" | |
| 40 | |
| 41 namespace blink { | |
| 42 | |
| 43 const char* HTMLImportsController::supplementName() | |
| 44 { | |
| 45 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); | |
| 46 return name; | |
| 47 } | |
| 48 | |
| 49 void HTMLImportsController::provideTo(Document& master) | |
| 50 { | |
| 51 OwnPtr<HTMLImportsController> controller = adoptPtr(new HTMLImportsControlle
r(master)); | |
| 52 master.setImportsController(controller.get()); | |
| 53 DocumentSupplement::provideTo(master, supplementName(), controller.release()
); | |
| 54 } | |
| 55 | |
| 56 void HTMLImportsController::removeFrom(Document& master) | |
| 57 { | |
| 58 static_cast<DocumentSupplementable&>(master).removeSupplement(supplementName
()); | |
| 59 master.setImportsController(nullptr); | |
| 60 } | |
| 61 | |
| 62 HTMLImportsController::HTMLImportsController(Document& master) | |
| 63 : m_root(HTMLImportTreeRoot::create(&master)) | |
| 64 { | |
| 65 } | |
| 66 | |
| 67 HTMLImportsController::~HTMLImportsController() | |
| 68 { | |
| 69 #if !ENABLE(OILPAN) | |
| 70 m_root.clear(); | |
| 71 | |
| 72 for (size_t i = 0; i < m_loaders.size(); ++i) | |
| 73 m_loaders[i]->importDestroyed(); | |
| 74 m_loaders.clear(); | |
| 75 #endif | |
| 76 } | |
| 77 | |
| 78 static bool makesCycle(HTMLImport* parent, const KURL& url) | |
| 79 { | |
| 80 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ | |
| 81 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) | |
| 89 { | |
| 90 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; | |
| 91 | |
| 92 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); | |
| 93 child->setClient(client); | |
| 94 parent->appendImport(child.get()); | |
| 95 loader->addImport(child.get()); | |
| 96 return root()->add(child.release()); | |
| 97 } | |
| 98 | |
| 99 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) | |
| 100 { | |
| 101 ASSERT(!request.url().isEmpty() && request.url().isValid()); | |
| 102 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor
t(toHTMLImportChild(parent))); | |
| 103 | |
| 104 if (HTMLImportChild* childToShareWith = root()->find(request.url())) { | |
| 105 HTMLImportLoader* loader = childToShareWith->loader(); | |
| 106 ASSERT(loader); | |
| 107 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); | |
| 108 child->didShareLoader(); | |
| 109 return child; | |
| 110 } | |
| 111 | |
| 112 HTMLImportLoader* loader = createLoader(); | |
| 113 HTMLImportChild* child = createChild(request.url(), loader, parent, client); | |
| 114 // We set resource after the import tree is built since | |
| 115 // Resource::addClient() immediately calls back to feed the bytes when the r
esource is cached. | |
| 116 loader->startLoading(request.url()); | |
| 117 child->didStartLoading(); | |
| 118 return child; | |
| 119 } | |
| 120 | |
| 121 Document* HTMLImportsController::master() const | |
| 122 { | |
| 123 return root()->document(); | |
| 124 } | |
| 125 | |
| 126 bool HTMLImportsController::shouldBlockScriptExecution(const Document& document)
const | |
| 127 { | |
| 128 ASSERT(document.importsController() == this); | |
| 129 if (HTMLImportLoader* loader = loaderFor(document)) | |
| 130 return loader->shouldBlockScriptExecution(); | |
| 131 return root()->state().shouldBlockScriptExecution(); | |
| 132 } | |
| 133 | |
| 134 HTMLImportLoader* HTMLImportsController::createLoader() | |
| 135 { | |
| 136 m_loaders.append(HTMLImportLoader::create(this)); | |
| 137 return m_loaders.last().get(); | |
| 138 } | |
| 139 | |
| 140 HTMLImportLoader* HTMLImportsController::loaderFor(const Document& document) con
st | |
| 141 { | |
| 142 for (size_t i = 0; i < m_loaders.size(); ++i) { | |
| 143 if (m_loaders[i]->document() == &document) | |
| 144 return m_loaders[i].get(); | |
| 145 } | |
| 146 | |
| 147 return 0; | |
| 148 } | |
| 149 | |
| 150 Document* HTMLImportsController::loaderDocumentAt(size_t i) const | |
| 151 { | |
| 152 return loaderAt(i)->document(); | |
| 153 } | |
| 154 | |
| 155 } // namespace blink | |
| OLD | NEW |