| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 { | 103 { |
| 104 m_owner = 0; | 104 m_owner = 0; |
| 105 m_loader.clear(); | 105 m_loader.clear(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 PassRefPtr<HTMLImportLoader> HTMLImportLoader::create(HTMLImport* parent, const
KURL& url, const ResourcePtr<CachedScript>& resource) | 109 PassRefPtr<HTMLImportLoader> HTMLImportLoader::create(HTMLImport* parent, const
KURL& url, const ResourcePtr<CachedScript>& resource) |
| 110 { | 110 { |
| 111 RefPtr<HTMLImportLoader> loader = adoptRef(new HTMLImportLoader(parent, url,
resource)); | 111 RefPtr<HTMLImportLoader> loader = adoptRef(new HTMLImportLoader(parent, url,
resource)); |
| 112 loader->controller()->addImport(loader); | 112 loader->controller()->addImport(loader); |
| 113 parent->appendChild(loader.get()); |
| 113 return loader.release(); | 114 return loader.release(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 HTMLImportLoader::HTMLImportLoader(HTMLImport* parent, const KURL& url, const Re
sourcePtr<CachedScript>& resource) | 117 HTMLImportLoader::HTMLImportLoader(HTMLImport* parent, const KURL& url, const Re
sourcePtr<CachedScript>& resource) |
| 117 : m_parent(parent) | 118 : m_parent(parent) |
| 118 , m_state(StateLoading) | 119 , m_state(StateLoading) |
| 119 , m_resource(resource) | 120 , m_resource(resource) |
| 120 , m_url(url) | 121 , m_url(url) |
| 121 { | 122 { |
| 122 m_resource->addClient(this); | 123 m_resource->addClient(this); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 dispose(); | 164 dispose(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void HTMLImportLoader::dispose() | 167 void HTMLImportLoader::dispose() |
| 167 { | 168 { |
| 168 if (m_resource) { | 169 if (m_resource) { |
| 169 m_resource->removeClient(this); | 170 m_resource->removeClient(this); |
| 170 m_resource = 0; | 171 m_resource = 0; |
| 171 } | 172 } |
| 172 | 173 |
| 173 if (HTMLImportsController* controller = this->controller()) | 174 ASSERT(!document() || !document()->parsing()); |
| 174 controller->didLoad(this); | 175 controller()->scheduleUnblock(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR
esponse& response) | 178 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR
esponse& response) |
| 178 { | 179 { |
| 179 // Current canAccess() implementation isn't sufficient for catching cross-do
main redirects: http://crbug.com/256976 | 180 // Current canAccess() implementation isn't sufficient for catching cross-do
main redirects: http://crbug.com/256976 |
| 180 if (!m_parent->document()->fetcher()->canAccess(m_resource.get())) | 181 if (!m_parent->document()->fetcher()->canAccess(m_resource.get())) |
| 181 return StateError; | 182 return StateError; |
| 182 | 183 |
| 183 m_importedDocument = HTMLDocument::create(DocumentInit(response.url(), 0, th
is).withRegistrationContext(controller()->document()->registrationContext())); | 184 m_importedDocument = HTMLDocument::create(DocumentInit(response.url(), 0, th
is).withRegistrationContext(controller()->document()->registrationContext())); |
| 184 m_importedDocument->initContentSecurityPolicy(ContentSecurityPolicyResponseH
eaders(response)); | 185 m_importedDocument->initContentSecurityPolicy(ContentSecurityPolicyResponseH
eaders(response)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 m_parent = 0; | 219 m_parent = 0; |
| 219 if (RefPtr<Document> document = m_importedDocument.release()) | 220 if (RefPtr<Document> document = m_importedDocument.release()) |
| 220 document->setImport(0); | 221 document->setImport(0); |
| 221 } | 222 } |
| 222 | 223 |
| 223 HTMLImportsController* HTMLImportLoader::controller() | 224 HTMLImportsController* HTMLImportLoader::controller() |
| 224 { | 225 { |
| 225 return m_parent ? m_parent->controller() : 0; | 226 return m_parent ? m_parent->controller() : 0; |
| 226 } | 227 } |
| 227 | 228 |
| 228 HTMLImport* HTMLImportLoader::parent() | 229 HTMLImport* HTMLImportLoader::parent() const |
| 229 { | 230 { |
| 230 return m_parent; | 231 return m_parent; |
| 231 } | 232 } |
| 232 | 233 |
| 233 Document* HTMLImportLoader::document() | 234 Document* HTMLImportLoader::document() const |
| 234 { | 235 { |
| 235 return m_importedDocument.get(); | 236 return m_importedDocument.get(); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void HTMLImportLoader::wasDetachedFromDocument() | 239 void HTMLImportLoader::wasDetachedFromDocument() |
| 239 { | 240 { |
| 240 // For imported documens this shouldn't be called because Document::m_import
is | 241 // For imported documens this shouldn't be called because Document::m_import
is |
| 241 // cleared before Document is destroyed by HTMLImportLoader::importDestroyed
(). | 242 // cleared before Document is destroyed by HTMLImportLoader::importDestroyed
(). |
| 242 ASSERT_NOT_REACHED(); | 243 ASSERT_NOT_REACHED(); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void HTMLImportLoader::didFinishParsing() | 246 void HTMLImportLoader::didFinishParsing() |
| 246 { | 247 { |
| 247 setState(finishParsing()); | 248 setState(finishParsing()); |
| 248 } | 249 } |
| 249 | 250 |
| 251 bool HTMLImportLoader::isProcessing() const |
| 252 { |
| 253 if (!m_importedDocument) |
| 254 return !isDone(); |
| 255 return m_importedDocument->parsing(); |
| 256 } |
| 250 | 257 |
| 251 void HTMLImportsController::provideTo(Document* master) | 258 void HTMLImportsController::provideTo(Document* master) |
| 252 { | 259 { |
| 253 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); | 260 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); |
| 254 OwnPtr<HTMLImportsController> controller = adoptPtr(new HTMLImportsControlle
r(master)); | 261 OwnPtr<HTMLImportsController> controller = adoptPtr(new HTMLImportsControlle
r(master)); |
| 255 master->setImport(controller.get()); | 262 master->setImport(controller.get()); |
| 256 Supplement<ScriptExecutionContext>::provideTo(master, name, controller.relea
se()); | 263 Supplement<ScriptExecutionContext>::provideTo(master, name, controller.relea
se()); |
| 257 } | 264 } |
| 258 | 265 |
| 259 HTMLImportsController::HTMLImportsController(Document* master) | 266 HTMLImportsController::HTMLImportsController(Document* master) |
| 260 : m_master(master) | 267 : m_master(master) |
| 268 , m_unblockTimer(this, &HTMLImportsController::unblockTimerFired) |
| 261 { | 269 { |
| 262 } | 270 } |
| 263 | 271 |
| 264 HTMLImportsController::~HTMLImportsController() | 272 HTMLImportsController::~HTMLImportsController() |
| 265 { | 273 { |
| 266 ASSERT(!m_master); | 274 ASSERT(!m_master); |
| 267 } | 275 } |
| 268 | 276 |
| 269 void HTMLImportsController::clear() | 277 void HTMLImportsController::clear() |
| 270 { | 278 { |
| 271 for (size_t i = 0; i < m_imports.size(); ++i) | 279 for (size_t i = 0; i < m_imports.size(); ++i) |
| 272 m_imports[i]->importDestroyed(); | 280 m_imports[i]->importDestroyed(); |
| 273 if (m_master) | 281 if (m_master) |
| 274 m_master->setImport(0); | 282 m_master->setImport(0); |
| 275 m_master = 0; | 283 m_master = 0; |
| 276 } | 284 } |
| 277 | 285 |
| 278 void HTMLImportsController::addImport(PassRefPtr<HTMLImportLoader> link) | 286 void HTMLImportsController::addImport(PassRefPtr<HTMLImportLoader> link) |
| 279 { | 287 { |
| 280 ASSERT(!link->url().isEmpty() && link->url().isValid()); | 288 ASSERT(!link->url().isEmpty() && link->url().isValid()); |
| 281 m_imports.append(link); | 289 m_imports.append(link); |
| 282 } | 290 } |
| 283 | 291 |
| 284 void HTMLImportsController::showSecurityErrorMessage(const String& message) | 292 void HTMLImportsController::showSecurityErrorMessage(const String& message) |
| 285 { | 293 { |
| 286 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); | 294 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); |
| 287 } | 295 } |
| 288 | 296 |
| 289 void HTMLImportsController::didLoad(HTMLImportLoader* loadedImport) | |
| 290 { | |
| 291 for (HTMLImport* ancestorToNotify = loadedImport->parent(); ancestorToNotify
; ancestorToNotify = ancestorToNotify->parent()) { | |
| 292 if (haveChildrenLoaded(ancestorToNotify)) | |
| 293 ancestorToNotify->document()->didLoadAllImports(); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 PassRefPtr<HTMLImportLoader> HTMLImportsController::findLinkFor(const KURL& url)
const | 297 PassRefPtr<HTMLImportLoader> HTMLImportsController::findLinkFor(const KURL& url)
const |
| 298 { | 298 { |
| 299 for (size_t i = 0; i < m_imports.size(); ++i) { | 299 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 300 if (equalIgnoringFragmentIdentifier(m_imports[i]->url(), url)) | 300 if (equalIgnoringFragmentIdentifier(m_imports[i]->url(), url)) |
| 301 return m_imports[i]; | 301 return m_imports[i]; |
| 302 } | 302 } |
| 303 | 303 |
| 304 return 0; | 304 return 0; |
| 305 } | 305 } |
| 306 | 306 |
| 307 SecurityOrigin* HTMLImportsController::securityOrigin() const | 307 SecurityOrigin* HTMLImportsController::securityOrigin() const |
| 308 { | 308 { |
| 309 return m_master->securityOrigin(); | 309 return m_master->securityOrigin(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 ResourceFetcher* HTMLImportsController::fetcher() const | 312 ResourceFetcher* HTMLImportsController::fetcher() const |
| 313 { | 313 { |
| 314 return m_master->fetcher(); | 314 return m_master->fetcher(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 bool HTMLImportsController::haveChildrenLoaded(HTMLImport* parent) const | |
| 318 { | |
| 319 for (size_t i = 0; i < m_imports.size(); ++i) { | |
| 320 if (!m_imports[i]->isDone()) { | |
| 321 for (HTMLImport* ancestor = m_imports[i]->parent(); ancestor; ancest
or = ancestor->parent()) { | |
| 322 if (ancestor == parent) | |
| 323 return false; | |
| 324 } | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 return true; | |
| 329 } | |
| 330 | |
| 331 HTMLImportsController* HTMLImportsController::controller() | 317 HTMLImportsController* HTMLImportsController::controller() |
| 332 { | 318 { |
| 333 return this; | 319 return this; |
| 334 } | 320 } |
| 335 | 321 |
| 336 HTMLImport* HTMLImportsController::parent() | 322 HTMLImport* HTMLImportsController::parent() const |
| 337 { | 323 { |
| 338 return 0; | 324 return 0; |
| 339 } | 325 } |
| 340 | 326 |
| 341 Document* HTMLImportsController::document() | 327 Document* HTMLImportsController::document() const |
| 342 { | 328 { |
| 343 return m_master; | 329 return m_master; |
| 344 } | 330 } |
| 345 | 331 |
| 346 void HTMLImportsController::wasDetachedFromDocument() | 332 void HTMLImportsController::wasDetachedFromDocument() |
| 347 { | 333 { |
| 348 clear(); | 334 clear(); |
| 349 } | 335 } |
| 350 | 336 |
| 351 void HTMLImportsController::didFinishParsing() | 337 void HTMLImportsController::didFinishParsing() |
| 352 { | 338 { |
| 353 } | 339 } |
| 354 | 340 |
| 341 bool HTMLImportsController::isProcessing() const |
| 342 { |
| 343 return m_master->parsing(); |
| 344 } |
| 345 |
| 346 void HTMLImportsController::scheduleUnblock() |
| 347 { |
| 348 if (m_unblockTimer.isActive()) |
| 349 return; |
| 350 m_unblockTimer.startOneShot(0); |
| 351 } |
| 352 |
| 353 void HTMLImportsController::unblockTimerFired(Timer<HTMLImportsController>*) |
| 354 { |
| 355 do { |
| 356 m_unblockTimer.stop(); |
| 357 HTMLImport::unblock(this); |
| 358 } while (m_unblockTimer.isActive()); |
| 359 } |
| 360 |
| 355 } // namespace WebCore | 361 } // namespace WebCore |
| OLD | NEW |