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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 if (m_client) | 65 if (m_client) |
66 m_client->importChildWasDestroyed(this); | 66 m_client->importChildWasDestroyed(this); |
67 | 67 |
68 m_master.guardDeref(); | 68 m_master.guardDeref(); |
69 } | 69 } |
70 | 70 |
71 void HTMLImportChild::wasAlreadyLoaded() | 71 void HTMLImportChild::wasAlreadyLoaded() |
72 { | 72 { |
73 ASSERT(!m_loader); | 73 ASSERT(!m_loader); |
74 ASSERT(m_client); | 74 ASSERT(m_client); |
75 ensureLoader(); | |
75 stateWillChange(); | 76 stateWillChange(); |
76 } | 77 } |
77 | 78 |
78 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) | 79 void HTMLImportChild::startLoading(const ResourcePtr<RawResource>& resource) |
79 { | 80 { |
80 ASSERT(!this->resource()); | 81 ASSERT(!this->resource()); |
81 ASSERT(!m_loader); | 82 ASSERT(!m_loader); |
82 | 83 |
83 if (isSync()) { | |
84 ASSERT(!m_customElementMicrotaskStep); | |
85 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); | |
86 } | |
87 | |
88 setResource(resource); | 84 setResource(resource); |
89 | 85 |
90 // If the node is "document blocked", it cannot create HTMLImportLoader | |
91 // even if there is no sharable one found, as there is possibility that | |
92 // preceding imports load the sharable imports. | |
93 // In that case preceding one should win because it comes first in the tree order. | |
94 // See also didUnblockFromCreatingDocument(). | |
95 if (state().shouldBlockDocumentCreation()) | |
96 return; | |
97 | |
98 ensureLoader(); | 86 ensureLoader(); |
99 } | 87 } |
100 | 88 |
101 void HTMLImportChild::didFinish() | 89 void HTMLImportChild::didFinish() |
102 { | 90 { |
103 if (m_client) | 91 if (m_client) |
104 m_client->didFinish(); | 92 m_client->didFinish(); |
105 | 93 |
106 if (m_customElementMicrotaskStep) { | 94 if (m_customElementMicrotaskStep) { |
107 m_customElementMicrotaskStep->importDidFinish(); | 95 m_customElementMicrotaskStep->importDidFinish(); |
(...skipping 19 matching lines...) Expand all Loading... | |
127 if (parent()) | 115 if (parent()) |
128 parent()->removeChild(this); | 116 parent()->removeChild(this); |
129 if (m_loader) { | 117 if (m_loader) { |
130 m_loader->removeImport(this); | 118 m_loader->removeImport(this); |
131 m_loader = 0; | 119 m_loader = 0; |
132 } | 120 } |
133 } | 121 } |
134 | 122 |
135 Document* HTMLImportChild::document() const | 123 Document* HTMLImportChild::document() const |
136 { | 124 { |
137 return (m_loader && m_loader->isOwnedBy(this)) ? m_loader->document() : 0; | 125 return m_loader ? m_loader->document() : 0; |
138 } | 126 } |
139 | 127 |
140 void HTMLImportChild::stateWillChange() | 128 void HTMLImportChild::stateWillChange() |
141 { | 129 { |
142 toHTMLImportsController(root())->scheduleRecalcState(); | 130 toHTMLImportsController(root())->scheduleRecalcState(); |
143 } | 131 } |
144 | 132 |
145 void HTMLImportChild::stateDidChange() | 133 void HTMLImportChild::stateDidChange() |
146 { | 134 { |
147 HTMLImport::stateDidChange(); | 135 HTMLImport::stateDidChange(); |
148 | 136 |
149 // Once all preceding imports are loaded, | 137 ensureLoader(); |
150 // HTMLImportChild can decide whether it should load the import by itself | |
151 // or it can share existing one. | |
152 if (!state().shouldBlockDocumentCreation()) | |
153 ensureLoader(); | |
154 if (state().isReady()) | 138 if (state().isReady()) |
155 didFinish(); | 139 didFinish(); |
156 } | 140 } |
157 | 141 |
158 void HTMLImportChild::ensureLoader() | 142 void HTMLImportChild::ensureLoader() |
159 { | 143 { |
160 if (m_loader) | 144 if (m_loader) |
161 return; | 145 return; |
162 | 146 |
163 if (HTMLImportChild* found = toHTMLImportsController(root())->findLinkFor(m_ url, this)) | 147 if (HTMLImportChild* found = toHTMLImportsController(root())->findLinkFor(m_ url, this)) |
164 shareLoader(found); | 148 shareLoader(found); |
165 else | 149 else |
166 createLoader(); | 150 createLoader(); |
151 | |
152 if (isSync() && !isDone()) { | |
153 ASSERT(!m_customElementMicrotaskStep); | |
154 m_customElementMicrotaskStep = CustomElement::didCreateImport(this); | |
dominicc (has gone to gerrit)
2014/04/18 00:56:26
I like the simplicity of this. Its a bit wasteful
Hajime Morrita
2014/04/18 01:48:33
That's my thinking, and making it lazy complicates
| |
155 } | |
167 } | 156 } |
168 | 157 |
169 void HTMLImportChild::createLoader() | 158 void HTMLImportChild::createLoader() |
170 { | 159 { |
171 ASSERT(!state().shouldBlockDocumentCreation()); | |
172 ASSERT(!m_loader); | 160 ASSERT(!m_loader); |
173 m_loader = toHTMLImportsController(root())->createLoader(); | 161 m_loader = toHTMLImportsController(root())->createLoader(); |
174 m_loader->addImport(this); | 162 m_loader->addImport(this); |
175 m_loader->startLoading(resource()); | 163 m_loader->startLoading(resource()); |
176 } | 164 } |
177 | 165 |
178 void HTMLImportChild::shareLoader(HTMLImportChild* loader) | 166 void HTMLImportChild::shareLoader(HTMLImportChild* loader) |
179 { | 167 { |
180 ASSERT(!m_loader); | 168 ASSERT(!m_loader); |
181 m_loader = loader->m_loader; | 169 m_loader = loader->m_loader; |
182 m_loader->addImport(this); | 170 m_loader->addImport(this); |
183 stateWillChange(); | 171 stateWillChange(); |
184 } | 172 } |
185 | 173 |
186 bool HTMLImportChild::isDone() const | 174 bool HTMLImportChild::isDone() const |
187 { | 175 { |
188 return m_loader && m_loader->isDone(); | 176 return m_loader && m_loader->isDone(); |
189 } | 177 } |
190 | 178 |
191 bool HTMLImportChild::hasLoader() const | |
192 { | |
193 return m_loader; | |
194 } | |
195 | |
196 bool HTMLImportChild::ownsLoader() const | |
197 { | |
198 return m_loader && m_loader->isOwnedBy(this); | |
199 } | |
200 | |
201 bool HTMLImportChild::loaderHasError() const | 179 bool HTMLImportChild::loaderHasError() const |
202 { | 180 { |
203 return m_loader && m_loader->hasError(); | 181 return m_loader && m_loader->hasError(); |
204 } | 182 } |
205 | 183 |
206 | 184 |
207 void HTMLImportChild::setClient(HTMLImportChildClient* client) | 185 void HTMLImportChild::setClient(HTMLImportChildClient* client) |
208 { | 186 { |
209 ASSERT(client); | 187 ASSERT(client); |
210 ASSERT(!m_client); | 188 ASSERT(!m_client); |
(...skipping 11 matching lines...) Expand all Loading... | |
222 { | 200 { |
223 if (!m_client) | 201 if (!m_client) |
224 return 0; | 202 return 0; |
225 return m_client->link(); | 203 return m_client->link(); |
226 } | 204 } |
227 | 205 |
228 #if !defined(NDEBUG) | 206 #if !defined(NDEBUG) |
229 void HTMLImportChild::showThis() | 207 void HTMLImportChild::showThis() |
230 { | 208 { |
231 HTMLImport::showThis(); | 209 HTMLImport::showThis(); |
232 fprintf(stderr, " loader=%p own=%s async=%s url=%s", | 210 fprintf(stderr, " loader=%p sync=%s url=%s", |
233 m_loader, | 211 m_loader, |
234 hasLoader() && ownsLoader() ? "Y" : "N", | |
235 isSync() ? "Y" : "N", | 212 isSync() ? "Y" : "N", |
236 url().string().utf8().data()); | 213 url().string().utf8().data()); |
237 } | 214 } |
238 #endif | 215 #endif |
239 | 216 |
240 } // namespace WebCore | 217 } // namespace WebCore |
OLD | NEW |