| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/custom/CustomElement.h" | 35 #include "core/dom/custom/CustomElement.h" |
| 36 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 36 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
| 37 #include "core/html/HTMLImportChildClient.h" | 37 #include "core/html/HTMLImportChildClient.h" |
| 38 #include "core/html/HTMLImportLoader.h" | 38 #include "core/html/HTMLImportLoader.h" |
| 39 | 39 |
| 40 namespace WebCore { | 40 namespace WebCore { |
| 41 | 41 |
| 42 HTMLImportChild::HTMLImportChild(const KURL& url, bool createdByParser) | 42 HTMLImportChild::HTMLImportChild(const KURL& url, bool createdByParser) |
| 43 : HTMLImport(WaitingLoaderOrChildren, createdByParser) | 43 : HTMLImport(createdByParser) |
| 44 , m_url(url) | 44 , m_url(url) |
| 45 , m_customElementMicrotaskStep(0) | 45 , m_customElementMicrotaskStep(0) |
| 46 , m_traversingClients(false) | 46 , m_traversingClients(false) |
| 47 { | 47 { |
| 48 } | 48 } |
| 49 | 49 |
| 50 HTMLImportChild::~HTMLImportChild() | 50 HTMLImportChild::~HTMLImportChild() |
| 51 { | 51 { |
| 52 // importDestroyed() should be called before the destruction. | 52 // importDestroyed() should be called before the destruction. |
| 53 ASSERT(!m_loader); | 53 ASSERT(!m_loader); |
| 54 | 54 |
| 55 if (m_customElementMicrotaskStep) { | 55 if (m_customElementMicrotaskStep) { |
| 56 // if Custom Elements were blocked, must unblock them before death | 56 // if Custom Elements were blocked, must unblock them before death |
| 57 m_customElementMicrotaskStep->importDidFinish(); | 57 m_customElementMicrotaskStep->importDidFinish(); |
| 58 m_customElementMicrotaskStep = 0; | 58 m_customElementMicrotaskStep = 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 for (size_t i = 0; i < m_clients.size(); ++i) { | 61 for (size_t i = 0; i < m_clients.size(); ++i) { |
| 62 TemporaryChange<bool> traversing(m_traversingClients, true); | 62 TemporaryChange<bool> traversing(m_traversingClients, true); |
| 63 m_clients[i]->importChildWasDestroyed(this); | 63 m_clients[i]->importChildWasDestroyed(this); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void HTMLImportChild::wasAlreadyLoaded() | 67 void HTMLImportChild::wasAlreadyLoaded() |
| 68 { | 68 { |
| 69 ASSERT(!m_loader); | 69 ASSERT(!m_loader); |
| 70 ASSERT(m_clients.size()); | 70 ASSERT(m_clients.size()); |
| 71 | 71 stateWillChange(); |
| 72 ensureLoader(); | |
| 73 loaderWasResolved(); | |
| 74 } | 72 } |
| 75 | 73 |
| 76 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) | 74 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) |
| 77 { | 75 { |
| 78 ASSERT(!hasResource()); | 76 ASSERT(!hasResource()); |
| 79 ASSERT(!m_loader); | 77 ASSERT(!m_loader); |
| 80 | 78 |
| 81 if (isCreatedByParser()) { | 79 if (isCreatedByParser()) { |
| 82 ASSERT(!m_customElementMicrotaskStep); | 80 ASSERT(!m_customElementMicrotaskStep); |
| 83 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); | 81 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); |
| 84 } | 82 } |
| 85 | 83 |
| 86 HTMLImportResourceOwner::setResource(resource); | 84 HTMLImportResourceOwner::setResource(resource); |
| 87 | 85 |
| 88 // If the node is "document blocked", it cannot create HTMLImportLoader | 86 // If the node is "document blocked", it cannot create HTMLImportLoader |
| 89 // even if there is no sharable one found, as there is possibility that | 87 // even if there is no sharable one found, as there is possibility that |
| 90 // preceding imports load the sharable imports. | 88 // preceding imports load the sharable imports. |
| 91 // In that case preceding one should win because it comes first in the tree
order. | 89 // In that case preceding one should win because it comes first in the tree
order. |
| 92 // See also didUnblockFromCreatingDocument(). | 90 // See also didUnblockFromCreatingDocument(). |
| 93 if (isBlockedFromCreatingDocument()) | 91 if (isStateBlockedFromCreatingDocument()) |
| 94 return; | 92 return; |
| 95 | 93 |
| 96 ensureLoader(); | 94 ensureLoader(); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void HTMLImportChild::didFinish() | 97 void HTMLImportChild::didFinish() |
| 100 { | 98 { |
| 101 for (size_t i = 0; i < m_clients.size(); ++i) { | 99 for (size_t i = 0; i < m_clients.size(); ++i) { |
| 102 TemporaryChange<bool> traversing(m_traversingClients, true); | 100 TemporaryChange<bool> traversing(m_traversingClients, true); |
| 103 m_clients[i]->didFinish(); | 101 m_clients[i]->didFinish(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 if (m_customElementMicrotaskStep) { | 104 if (m_customElementMicrotaskStep) { |
| 107 m_customElementMicrotaskStep->importDidFinish(); | 105 m_customElementMicrotaskStep->importDidFinish(); |
| 108 m_customElementMicrotaskStep = 0; | 106 m_customElementMicrotaskStep = 0; |
| 109 } | 107 } |
| 110 } | 108 } |
| 111 | 109 |
| 112 void HTMLImportChild::didFinishLoading() | 110 void HTMLImportChild::didFinishLoading() |
| 113 { | 111 { |
| 114 clearResource(); | 112 clearResource(); |
| 115 loaderDidFinish(); | 113 stateWillChange(); |
| 116 } | 114 } |
| 117 | 115 |
| 118 Document* HTMLImportChild::importedDocument() const | 116 Document* HTMLImportChild::importedDocument() const |
| 119 { | 117 { |
| 120 if (!m_loader) | 118 if (!m_loader) |
| 121 return 0; | 119 return 0; |
| 122 return m_loader->importedDocument(); | 120 return m_loader->importedDocument(); |
| 123 } | 121 } |
| 124 | 122 |
| 125 void HTMLImportChild::importDestroyed() | 123 void HTMLImportChild::importDestroyed() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 148 // cleared before Document is destroyed by HTMLImportChild::importDestroyed(
). | 146 // cleared before Document is destroyed by HTMLImportChild::importDestroyed(
). |
| 149 ASSERT_NOT_REACHED(); | 147 ASSERT_NOT_REACHED(); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void HTMLImportChild::didFinishParsing() | 150 void HTMLImportChild::didFinishParsing() |
| 153 { | 151 { |
| 154 ASSERT(m_loader->isOwnedBy(this)); | 152 ASSERT(m_loader->isOwnedBy(this)); |
| 155 m_loader->didFinishParsing(); | 153 m_loader->didFinishParsing(); |
| 156 } | 154 } |
| 157 | 155 |
| 158 // Once all preceding imports are loaded and "document blocking" ends, | 156 void HTMLImportChild::stateDidChange() |
| 159 // HTMLImportChild can decide whether it should load the import by itself | |
| 160 // or it can share existing one. | |
| 161 void HTMLImportChild::didUnblockFromCreatingDocument() | |
| 162 { | 157 { |
| 163 HTMLImport::didUnblockFromCreatingDocument(); | 158 HTMLImport::stateDidChange(); |
| 164 ensureLoader(); | |
| 165 } | |
| 166 | 159 |
| 167 void HTMLImportChild::didBecomeReady() | 160 // Once all preceding imports are loaded, |
| 168 { | 161 // HTMLImportChild can decide whether it should load the import by itself |
| 169 HTMLImport::didBecomeReady(); | 162 // or it can share existing one. |
| 170 didFinish(); | 163 if (!isStateBlockedFromCreatingDocument()) |
| 164 ensureLoader(); |
| 165 if (isStateReady()) |
| 166 didFinish(); |
| 171 } | 167 } |
| 172 | 168 |
| 173 void HTMLImportChild::ensureLoader() | 169 void HTMLImportChild::ensureLoader() |
| 174 { | 170 { |
| 175 if (m_loader) | 171 if (m_loader) |
| 176 return; | 172 return; |
| 177 | 173 |
| 178 if (HTMLImportChild* found = root()->findLinkFor(m_url, this)) | 174 if (HTMLImportChild* found = root()->findLinkFor(m_url, this)) |
| 179 shareLoader(found); | 175 shareLoader(found); |
| 180 else | 176 else |
| 181 createLoader(); | 177 createLoader(); |
| 182 } | 178 } |
| 183 | 179 |
| 184 void HTMLImportChild::createLoader() | 180 void HTMLImportChild::createLoader() |
| 185 { | 181 { |
| 186 ASSERT(!isBlockedFromCreatingDocument()); | 182 ASSERT(!isStateBlockedFromCreatingDocument()); |
| 187 ASSERT(!m_loader); | 183 ASSERT(!m_loader); |
| 188 m_loader = HTMLImportLoader::create(this, parent()->document()->fetcher()); | 184 m_loader = HTMLImportLoader::create(this, parent()->document()->fetcher()); |
| 189 m_loader->addClient(this); | 185 m_loader->addClient(this); |
| 190 m_loader->startLoading(resource()); | 186 m_loader->startLoading(resource()); |
| 191 } | 187 } |
| 192 | 188 |
| 193 void HTMLImportChild::shareLoader(HTMLImportChild* loader) | 189 void HTMLImportChild::shareLoader(HTMLImportChild* loader) |
| 194 { | 190 { |
| 195 ASSERT(!m_loader); | 191 ASSERT(!m_loader); |
| 196 m_loader = loader->m_loader; | 192 m_loader = loader->m_loader; |
| 197 m_loader->addClient(this); | 193 m_loader->addClient(this); |
| 198 root()->blockerGone(); | 194 stateWillChange(); |
| 199 } | 195 } |
| 200 | 196 |
| 201 bool HTMLImportChild::isDone() const | 197 bool HTMLImportChild::isDone() const |
| 202 { | 198 { |
| 203 return m_loader && m_loader->isDone(); | 199 return m_loader && m_loader->isDone(); |
| 204 } | 200 } |
| 205 | 201 |
| 206 bool HTMLImportChild::hasLoader() const | 202 bool HTMLImportChild::hasLoader() const |
| 207 { | 203 { |
| 208 return m_loader; | 204 return m_loader; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 227 } | 223 } |
| 228 | 224 |
| 229 void HTMLImportChild::removeClient(HTMLImportChildClient* client) | 225 void HTMLImportChild::removeClient(HTMLImportChildClient* client) |
| 230 { | 226 { |
| 231 ASSERT(!m_traversingClients); | 227 ASSERT(!m_traversingClients); |
| 232 size_t i = m_clients.find(client); | 228 size_t i = m_clients.find(client); |
| 233 ASSERT(i != kNotFound); | 229 ASSERT(i != kNotFound); |
| 234 m_clients.remove(i); | 230 m_clients.remove(i); |
| 235 } | 231 } |
| 236 | 232 |
| 233 |
| 234 #if !defined(NDEBUG) |
| 235 void HTMLImportChild::showThis() |
| 236 { |
| 237 HTMLImport::showThis(); |
| 238 fprintf(stderr, " loader=%p own=%s async=%s url=%s", |
| 239 m_loader.get(), |
| 240 hasLoader() && ownsLoader() ? "Y" : "N", |
| 241 isCreatedByParser() ? "Y" : "N", |
| 242 url().string().utf8().data()); |
| 243 } |
| 244 #endif |
| 245 |
| 237 } // namespace WebCore | 246 } // namespace WebCore |
| OLD | NEW |