| 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 16 matching lines...) Expand all Loading... |
| 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 "sky/engine/config.h" | 31 #include "sky/engine/config.h" |
| 32 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 32 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 33 | 33 |
| 34 #include "sky/engine/core/dom/Document.h" | 34 #include "sky/engine/core/dom/Document.h" |
| 35 #include "sky/engine/core/fetch/ResourceFetcher.h" | 35 #include "sky/engine/core/fetch/ResourceFetcher.h" |
| 36 #include "sky/engine/core/frame/LocalFrame.h" | 36 #include "sky/engine/core/frame/LocalFrame.h" |
| 37 #include "sky/engine/core/frame/UseCounter.h" | |
| 38 #include "sky/engine/core/html/imports/HTMLImportChild.h" | 37 #include "sky/engine/core/html/imports/HTMLImportChild.h" |
| 39 #include "sky/engine/core/html/imports/HTMLImportChildClient.h" | 38 #include "sky/engine/core/html/imports/HTMLImportChildClient.h" |
| 40 #include "sky/engine/core/html/imports/HTMLImportLoader.h" | 39 #include "sky/engine/core/html/imports/HTMLImportLoader.h" |
| 41 #include "sky/engine/core/html/imports/HTMLImportTreeRoot.h" | 40 #include "sky/engine/core/html/imports/HTMLImportTreeRoot.h" |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 const char* HTMLImportsController::supplementName() | 44 const char* HTMLImportsController::supplementName() |
| 46 { | 45 { |
| 47 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); | 46 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); |
| 48 return name; | 47 return name; |
| 49 } | 48 } |
| 50 | 49 |
| 51 void HTMLImportsController::provideTo(Document& master) | 50 void HTMLImportsController::provideTo(Document& master) |
| 52 { | 51 { |
| 53 OwnPtr<HTMLImportsController> controller = adoptPtr(new HTMLImportsControlle
r(master)); | 52 OwnPtr<HTMLImportsController> controller = adoptPtr(new HTMLImportsControlle
r(master)); |
| 54 master.setImportsController(controller.get()); | 53 master.setImportsController(controller.get()); |
| 55 DocumentSupplement::provideTo(master, supplementName(), controller.release()
); | 54 DocumentSupplement::provideTo(master, supplementName(), controller.release()
); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void HTMLImportsController::removeFrom(Document& master) | 57 void HTMLImportsController::removeFrom(Document& master) |
| 59 { | 58 { |
| 60 static_cast<DocumentSupplementable&>(master).removeSupplement(supplementName
()); | 59 static_cast<DocumentSupplementable&>(master).removeSupplement(supplementName
()); |
| 61 master.setImportsController(nullptr); | 60 master.setImportsController(nullptr); |
| 62 } | 61 } |
| 63 | 62 |
| 64 HTMLImportsController::HTMLImportsController(Document& master) | 63 HTMLImportsController::HTMLImportsController(Document& master) |
| 65 : m_root(HTMLImportTreeRoot::create(&master)) | 64 : m_root(HTMLImportTreeRoot::create(&master)) |
| 66 { | 65 { |
| 67 UseCounter::count(master, UseCounter::HTMLImports); | |
| 68 } | 66 } |
| 69 | 67 |
| 70 HTMLImportsController::~HTMLImportsController() | 68 HTMLImportsController::~HTMLImportsController() |
| 71 { | 69 { |
| 72 #if !ENABLE(OILPAN) | 70 #if !ENABLE(OILPAN) |
| 73 m_root.clear(); | 71 m_root.clear(); |
| 74 | 72 |
| 75 for (size_t i = 0; i < m_loaders.size(); ++i) | 73 for (size_t i = 0; i < m_loaders.size(); ++i) |
| 76 m_loaders[i]->importDestroyed(); | 74 m_loaders[i]->importDestroyed(); |
| 77 m_loaders.clear(); | 75 m_loaders.clear(); |
| 78 #endif | 76 #endif |
| 79 } | 77 } |
| 80 | 78 |
| 81 static bool makesCycle(HTMLImport* parent, const KURL& url) | 79 static bool makesCycle(HTMLImport* parent, const KURL& url) |
| 82 { | 80 { |
| 83 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ | 81 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ |
| 84 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) | 82 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) |
| 85 return true; | 83 return true; |
| 86 } | 84 } |
| 87 | 85 |
| 88 return false; | 86 return false; |
| 89 } | 87 } |
| 90 | 88 |
| 91 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) | 89 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) |
| 92 { | 90 { |
| 93 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; | 91 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; |
| 94 if (mode == HTMLImport::Async) | |
| 95 UseCounter::count(root()->document(), UseCounter::HTMLImportsAsyncAttrib
ute); | |
| 96 | 92 |
| 97 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); | 93 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); |
| 98 child->setClient(client); | 94 child->setClient(client); |
| 99 parent->appendImport(child.get()); | 95 parent->appendImport(child.get()); |
| 100 loader->addImport(child.get()); | 96 loader->addImport(child.get()); |
| 101 return root()->add(child.release()); | 97 return root()->add(child.release()); |
| 102 } | 98 } |
| 103 | 99 |
| 104 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) | 100 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) |
| 105 { | 101 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 147 |
| 152 return 0; | 148 return 0; |
| 153 } | 149 } |
| 154 | 150 |
| 155 Document* HTMLImportsController::loaderDocumentAt(size_t i) const | 151 Document* HTMLImportsController::loaderDocumentAt(size_t i) const |
| 156 { | 152 { |
| 157 return loaderAt(i)->document(); | 153 return loaderAt(i)->document(); |
| 158 } | 154 } |
| 159 | 155 |
| 160 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |