| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv
ed. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 static inline bool pageIsBeingDismissed(Document* document) | 60 static inline bool pageIsBeingDismissed(Document* document) |
| 61 { | 61 { |
| 62 return document->pageDismissalEventBeingDispatched() != Document::NoDismissa
l; | 62 return document->pageDismissalEventBeingDispatched() != Document::NoDismissa
l; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static ImageLoader::BypassMainWorldBehavior shouldBypassMainWorldCSP(ImageLoader
* loader) | 65 static ImageLoader::BypassMainWorldBehavior shouldBypassMainWorldCSP(ImageLoader
* loader) |
| 66 { | 66 { |
| 67 ASSERT(loader); | 67 ASSERT(loader); |
| 68 ASSERT(loader->element()); | 68 ASSERT(loader->element()); |
| 69 if (loader->element()->document().frame() && loader->element()->document().f
rame()->script().shouldBypassMainWorldCSP()) | 69 ASSERT(loader->element()->document().frame()); |
| 70 if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP
()) |
| 70 return ImageLoader::BypassMainWorldCSP; | 71 return ImageLoader::BypassMainWorldCSP; |
| 71 return ImageLoader::DoNotBypassMainWorldCSP; | 72 return ImageLoader::DoNotBypassMainWorldCSP; |
| 72 } | 73 } |
| 73 | 74 |
| 74 class ImageLoader::Task : public blink::WebThread::Task { | 75 class ImageLoader::Task : public blink::WebThread::Task { |
| 75 public: | 76 public: |
| 76 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio
r updateBehavior) | 77 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio
r updateBehavior) |
| 77 { | 78 { |
| 78 return adoptPtr(new Task(loader, updateBehavior)); | 79 return adoptPtr(new Task(loader, updateBehavior)); |
| 79 } | 80 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 262 |
| 262 if (m_loadingImageDocument) | 263 if (m_loadingImageDocument) |
| 263 newImage = createImageResourceForImageDocument(document, request); | 264 newImage = createImageResourceForImageDocument(document, request); |
| 264 else | 265 else |
| 265 newImage = document.fetcher()->fetchImage(request); | 266 newImage = document.fetcher()->fetchImage(request); |
| 266 | 267 |
| 267 if (!newImage && !pageIsBeingDismissed(&document)) | 268 if (!newImage && !pageIsBeingDismissed(&document)) |
| 268 crossSiteOrCSPViolationOccured(imageSourceURL); | 269 crossSiteOrCSPViolationOccured(imageSourceURL); |
| 269 else | 270 else |
| 270 clearFailedLoadURL(); | 271 clearFailedLoadURL(); |
| 271 } else { | 272 } else if (!imageSourceURL.isNull()) { |
| 272 if (!imageSourceURL.isNull()) { | 273 // Fire an error event if the url string is not empty, but the KURL is. |
| 273 // Fire an error event if the url string is not empty, but the KURL
is. | 274 m_hasPendingErrorEvent = true; |
| 274 m_hasPendingErrorEvent = true; | 275 errorEventSender().dispatchEventSoon(this); |
| 275 errorEventSender().dispatchEventSoon(this); | |
| 276 } | |
| 277 noImageResourceToLoad(); | |
| 278 } | 276 } |
| 279 | 277 |
| 280 ImageResource* oldImage = m_image.get(); | 278 ImageResource* oldImage = m_image.get(); |
| 281 if (newImage != oldImage) { | 279 if (newImage != oldImage) { |
| 282 sourceImageChanged(); | 280 sourceImageChanged(); |
| 283 | 281 |
| 284 if (m_hasPendingLoadEvent) { | 282 if (m_hasPendingLoadEvent) { |
| 285 loadEventSender().cancelEvent(this); | 283 loadEventSender().cancelEvent(this); |
| 286 m_hasPendingLoadEvent = false; | 284 m_hasPendingLoadEvent = false; |
| 287 } | 285 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 312 } | 310 } |
| 313 | 311 |
| 314 if (RenderImageResource* imageResource = renderImageResource()) | 312 if (RenderImageResource* imageResource = renderImageResource()) |
| 315 imageResource->resetAnimation(); | 313 imageResource->resetAnimation(); |
| 316 | 314 |
| 317 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 315 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
| 318 // from this function as doing so might result in the destruction of this Im
ageLoader. | 316 // from this function as doing so might result in the destruction of this Im
ageLoader. |
| 319 updatedHasPendingEvent(); | 317 updatedHasPendingEvent(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior) | 320 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
adType loadType) |
| 323 { | 321 { |
| 324 AtomicString imageSourceURL = m_element->imageSourceURL(); | 322 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 325 | 323 |
| 326 if (updateBehavior == UpdateIgnorePreviousError) | 324 if (updateBehavior == UpdateIgnorePreviousError) |
| 327 clearFailedLoadURL(); | 325 clearFailedLoadURL(); |
| 328 | 326 |
| 329 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 327 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 330 return; | 328 return; |
| 331 | 329 |
| 332 // If we have a pending task, we have to clear it -- either we're | 330 // If we have a pending task, we have to clear it -- either we're |
| 333 // now loading immediately, or we need to reset the task's state. | 331 // now loading immediately, or we need to reset the task's state. |
| 334 if (m_pendingTask) { | 332 if (m_pendingTask) { |
| 335 m_pendingTask->clearLoader(); | 333 m_pendingTask->clearLoader(); |
| 336 m_pendingTask.clear(); | 334 m_pendingTask.clear(); |
| 337 } | 335 } |
| 338 | 336 |
| 339 KURL url = imageSourceToKURL(imageSourceURL); | 337 KURL url = imageSourceToKURL(imageSourceURL); |
| 340 if (shouldLoadImmediately(url)) { | 338 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo
adType)) { |
| 341 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); | 339 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); |
| 342 return; | 340 return; |
| 343 } | 341 } |
| 344 enqueueImageLoadingMicroTask(updateBehavior); | 342 enqueueImageLoadingMicroTask(updateBehavior); |
| 345 } | 343 } |
| 346 | 344 |
| 347 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const | 345 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const |
| 348 { | 346 { |
| 349 KURL url; | 347 KURL url; |
| 350 | 348 |
| 351 // Don't load images for inactive documents. We don't want to slow down the | 349 // Don't load images for inactive documents. We don't want to slow down the |
| 352 // raw HTML parsing case by loading images we don't intend to display. | 350 // raw HTML parsing case by loading images we don't intend to display. |
| 353 Document& document = m_element->document(); | 351 Document& document = m_element->document(); |
| 354 if (!document.isActive()) | 352 if (!document.isActive()) |
| 355 return url; | 353 return url; |
| 356 | 354 |
| 357 // Do not load any image if the 'src' attribute is missing or if it is | 355 // Do not load any image if the 'src' attribute is missing or if it is |
| 358 // an empty string. | 356 // an empty string. |
| 359 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) | 357 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) |
| 360 url = document.completeURL(sourceURI(imageSourceURL)); | 358 url = document.completeURL(sourceURI(imageSourceURL)); |
| 361 return url; | 359 return url; |
| 362 } | 360 } |
| 363 | 361 |
| 364 bool ImageLoader::shouldLoadImmediately(const KURL& url) const | 362 bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) cons
t |
| 365 { | 363 { |
| 366 // We force failed image loads through the asynchronous path so that we can
add the shadow DOM | |
| 367 // for the alt-text content when style recalc is over and DOM mutation is al
lowed again. | |
| 368 if (!url.isNull()) { | |
| 369 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum
ent().fetcher()->getCacheIdentifier()); | |
| 370 if (resource && !resource->errorOccurred()) | |
| 371 return true; | |
| 372 } | |
| 373 return (m_loadingImageDocument | 364 return (m_loadingImageDocument |
| 374 || isHTMLObjectElement(m_element) | 365 || isHTMLObjectElement(m_element) |
| 375 || isHTMLEmbedElement(m_element) | 366 || isHTMLEmbedElement(m_element) |
| 376 || url.protocolIsData()); | 367 || url.protocolIsData() |
| 368 || memoryCache()->resourceForURL(url, m_element->document().fetcher()->g
etCacheIdentifier()) |
| 369 || loadType == ForceLoadImmediately); |
| 377 } | 370 } |
| 378 | 371 |
| 379 void ImageLoader::notifyFinished(Resource* resource) | 372 void ImageLoader::notifyFinished(Resource* resource) |
| 380 { | 373 { |
| 381 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", | 374 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", |
| 382 this, m_hasPendingLoadEvent); | 375 this, m_hasPendingLoadEvent); |
| 383 | 376 |
| 384 ASSERT(m_failedLoadURL.isEmpty()); | 377 ASSERT(m_failedLoadURL.isEmpty()); |
| 385 ASSERT(resource == m_image.get()); | 378 ASSERT(resource == m_image.get()); |
| 386 | 379 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 } | 572 } |
| 580 | 573 |
| 581 #if ENABLE(OILPAN) | 574 #if ENABLE(OILPAN) |
| 582 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() | 575 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() |
| 583 { | 576 { |
| 584 m_loader.willRemoveClient(m_client); | 577 m_loader.willRemoveClient(m_client); |
| 585 } | 578 } |
| 586 #endif | 579 #endif |
| 587 | 580 |
| 588 } | 581 } |
| OLD | NEW |