| 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_client(0) | 46 , m_client(0) |
| 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 if (m_client) | 61 if (m_client) |
| 62 m_client->importChildWasDestroyed(this); | 62 m_client->importChildWasDestroyed(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void HTMLImportChild::wasAlreadyLoaded() | 65 void HTMLImportChild::wasAlreadyLoaded() |
| 66 { | 66 { |
| 67 ASSERT(!m_loader); | 67 ASSERT(!m_loader); |
| 68 ASSERT(m_client); | 68 ASSERT(m_client); |
| 69 | 69 stateWillChange(); |
| 70 ensureLoader(); | |
| 71 loaderWasResolved(); | |
| 72 } | 70 } |
| 73 | 71 |
| 74 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) | 72 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) |
| 75 { | 73 { |
| 76 ASSERT(!hasResource()); | 74 ASSERT(!hasResource()); |
| 77 ASSERT(!m_loader); | 75 ASSERT(!m_loader); |
| 78 | 76 |
| 79 if (isCreatedByParser()) { | 77 if (isCreatedByParser()) { |
| 80 ASSERT(!m_customElementMicrotaskStep); | 78 ASSERT(!m_customElementMicrotaskStep); |
| 81 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); | 79 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); |
| 82 } | 80 } |
| 83 | 81 |
| 84 HTMLImportResourceOwner::setResource(resource); | 82 HTMLImportResourceOwner::setResource(resource); |
| 85 | 83 |
| 86 // If the node is "document blocked", it cannot create HTMLImportLoader | 84 // If the node is "document blocked", it cannot create HTMLImportLoader |
| 87 // even if there is no sharable one found, as there is possibility that | 85 // even if there is no sharable one found, as there is possibility that |
| 88 // preceding imports load the sharable imports. | 86 // preceding imports load the sharable imports. |
| 89 // In that case preceding one should win because it comes first in the tree
order. | 87 // In that case preceding one should win because it comes first in the tree
order. |
| 90 // See also didUnblockFromCreatingDocument(). | 88 // See also didUnblockFromCreatingDocument(). |
| 91 if (isBlockedFromCreatingDocument()) | 89 if (isStateBlockedFromCreatingDocument()) |
| 92 return; | 90 return; |
| 93 | 91 |
| 94 ensureLoader(); | 92 ensureLoader(); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void HTMLImportChild::didFinish() | 95 void HTMLImportChild::didFinish() |
| 98 { | 96 { |
| 99 if (m_client) | 97 if (m_client) |
| 100 m_client->didFinish(); | 98 m_client->didFinish(); |
| 101 | 99 |
| 102 if (m_customElementMicrotaskStep) { | 100 if (m_customElementMicrotaskStep) { |
| 103 m_customElementMicrotaskStep->importDidFinish(); | 101 m_customElementMicrotaskStep->importDidFinish(); |
| 104 m_customElementMicrotaskStep = 0; | 102 m_customElementMicrotaskStep = 0; |
| 105 } | 103 } |
| 106 } | 104 } |
| 107 | 105 |
| 108 void HTMLImportChild::didFinishLoading() | 106 void HTMLImportChild::didFinishLoading() |
| 109 { | 107 { |
| 110 clearResource(); | 108 clearResource(); |
| 111 loaderDidFinish(); | 109 stateWillChange(); |
| 112 } | 110 } |
| 113 | 111 |
| 114 Document* HTMLImportChild::importedDocument() const | 112 Document* HTMLImportChild::importedDocument() const |
| 115 { | 113 { |
| 116 if (!m_loader) | 114 if (!m_loader) |
| 117 return 0; | 115 return 0; |
| 118 return m_loader->importedDocument(); | 116 return m_loader->importedDocument(); |
| 119 } | 117 } |
| 120 | 118 |
| 121 void HTMLImportChild::importDestroyed() | 119 void HTMLImportChild::importDestroyed() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 144 // cleared before Document is destroyed by HTMLImportChild::importDestroyed(
). | 142 // cleared before Document is destroyed by HTMLImportChild::importDestroyed(
). |
| 145 ASSERT_NOT_REACHED(); | 143 ASSERT_NOT_REACHED(); |
| 146 } | 144 } |
| 147 | 145 |
| 148 void HTMLImportChild::didFinishParsing() | 146 void HTMLImportChild::didFinishParsing() |
| 149 { | 147 { |
| 150 ASSERT(m_loader->isOwnedBy(this)); | 148 ASSERT(m_loader->isOwnedBy(this)); |
| 151 m_loader->didFinishParsing(); | 149 m_loader->didFinishParsing(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 // Once all preceding imports are loaded and "document blocking" ends, | 152 void HTMLImportChild::stateDidChange() |
| 155 // HTMLImportChild can decide whether it should load the import by itself | |
| 156 // or it can share existing one. | |
| 157 void HTMLImportChild::didUnblockFromCreatingDocument() | |
| 158 { | 153 { |
| 159 HTMLImport::didUnblockFromCreatingDocument(); | 154 HTMLImport::stateDidChange(); |
| 160 ensureLoader(); | |
| 161 } | |
| 162 | 155 |
| 163 void HTMLImportChild::didBecomeReady() | 156 // Once all preceding imports are loaded, |
| 164 { | 157 // HTMLImportChild can decide whether it should load the import by itself |
| 165 HTMLImport::didBecomeReady(); | 158 // or it can share existing one. |
| 166 didFinish(); | 159 if (!isStateBlockedFromCreatingDocument()) |
| 160 ensureLoader(); |
| 161 if (isStateReady()) |
| 162 didFinish(); |
| 167 } | 163 } |
| 168 | 164 |
| 169 void HTMLImportChild::ensureLoader() | 165 void HTMLImportChild::ensureLoader() |
| 170 { | 166 { |
| 171 if (m_loader) | 167 if (m_loader) |
| 172 return; | 168 return; |
| 173 | 169 |
| 174 if (HTMLImportChild* found = root()->findLinkFor(m_url, this)) | 170 if (HTMLImportChild* found = root()->findLinkFor(m_url, this)) |
| 175 shareLoader(found); | 171 shareLoader(found); |
| 176 else | 172 else |
| 177 createLoader(); | 173 createLoader(); |
| 178 } | 174 } |
| 179 | 175 |
| 180 void HTMLImportChild::createLoader() | 176 void HTMLImportChild::createLoader() |
| 181 { | 177 { |
| 182 ASSERT(!isBlockedFromCreatingDocument()); | 178 ASSERT(!isStateBlockedFromCreatingDocument()); |
| 183 ASSERT(!m_loader); | 179 ASSERT(!m_loader); |
| 184 m_loader = HTMLImportLoader::create(this, parent()->document()->fetcher()); | 180 m_loader = HTMLImportLoader::create(this, parent()->document()->fetcher()); |
| 185 m_loader->addClient(this); | 181 m_loader->addClient(this); |
| 186 m_loader->startLoading(resource()); | 182 m_loader->startLoading(resource()); |
| 187 } | 183 } |
| 188 | 184 |
| 189 void HTMLImportChild::shareLoader(HTMLImportChild* loader) | 185 void HTMLImportChild::shareLoader(HTMLImportChild* loader) |
| 190 { | 186 { |
| 191 ASSERT(!m_loader); | 187 ASSERT(!m_loader); |
| 192 m_loader = loader->m_loader; | 188 m_loader = loader->m_loader; |
| 193 m_loader->addClient(this); | 189 m_loader->addClient(this); |
| 194 root()->blockerGone(); | 190 stateWillChange(); |
| 195 } | 191 } |
| 196 | 192 |
| 197 bool HTMLImportChild::isDone() const | 193 bool HTMLImportChild::isDone() const |
| 198 { | 194 { |
| 199 return m_loader && m_loader->isDone(); | 195 return m_loader && m_loader->isDone(); |
| 200 } | 196 } |
| 201 | 197 |
| 202 bool HTMLImportChild::hasLoader() const | 198 bool HTMLImportChild::hasLoader() const |
| 203 { | 199 { |
| 204 return m_loader; | 200 return m_loader; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 222 m_client = client; | 218 m_client = client; |
| 223 } | 219 } |
| 224 | 220 |
| 225 void HTMLImportChild::clearClient() | 221 void HTMLImportChild::clearClient() |
| 226 { | 222 { |
| 227 // Doesn't check m_client nullity because we allow | 223 // Doesn't check m_client nullity because we allow |
| 228 // clearClient() to reenter. | 224 // clearClient() to reenter. |
| 229 m_client = 0; | 225 m_client = 0; |
| 230 } | 226 } |
| 231 | 227 |
| 228 |
| 229 #if !defined(NDEBUG) |
| 230 void HTMLImportChild::showThis() |
| 231 { |
| 232 HTMLImport::showThis(); |
| 233 fprintf(stderr, " loader=%p own=%s async=%s url=%s", |
| 234 m_loader.get(), |
| 235 hasLoader() && ownsLoader() ? "Y" : "N", |
| 236 isCreatedByParser() ? "Y" : "N", |
| 237 url().string().utf8().data()); |
| 238 } |
| 239 #endif |
| 240 |
| 232 } // namespace WebCore | 241 } // namespace WebCore |
| OLD | NEW |