| 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 ASSERT(loader->element()->document().frame()); | 69 if (loader->element()->document().frame() && loader->element()->document().f
rame()->script().shouldBypassMainWorldCSP()) |
| 70 if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP
()) | |
| 71 return ImageLoader::BypassMainWorldCSP; | 70 return ImageLoader::BypassMainWorldCSP; |
| 72 return ImageLoader::DoNotBypassMainWorldCSP; | 71 return ImageLoader::DoNotBypassMainWorldCSP; |
| 73 } | 72 } |
| 74 | 73 |
| 75 class ImageLoader::Task : public blink::WebThread::Task { | 74 class ImageLoader::Task : public blink::WebThread::Task { |
| 76 public: | 75 public: |
| 77 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio
r updateBehavior) | 76 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio
r updateBehavior) |
| 78 { | 77 { |
| 79 return adoptPtr(new Task(loader, updateBehavior)); | 78 return adoptPtr(new Task(loader, updateBehavior)); |
| 80 } | 79 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 newImage = createImageResourceForImageDocument(document, request); | 268 newImage = createImageResourceForImageDocument(document, request); |
| 270 else | 269 else |
| 271 newImage = document.fetcher()->fetchImage(request); | 270 newImage = document.fetcher()->fetchImage(request); |
| 272 | 271 |
| 273 if (!newImage && !pageIsBeingDismissed(&document)) { | 272 if (!newImage && !pageIsBeingDismissed(&document)) { |
| 274 crossSiteOrCSPViolationOccurred(imageSourceURL); | 273 crossSiteOrCSPViolationOccurred(imageSourceURL); |
| 275 dispatchErrorEvent(); | 274 dispatchErrorEvent(); |
| 276 } else { | 275 } else { |
| 277 clearFailedLoadURL(); | 276 clearFailedLoadURL(); |
| 278 } | 277 } |
| 279 } else if (!imageSourceURL.isNull()) { | 278 } else { |
| 280 // Fire an error event if the url string is not empty, but the KURL is. | 279 if (!imageSourceURL.isNull()) { |
| 281 dispatchErrorEvent(); | 280 // Fire an error event if the url string is not empty, but the KURL
is. |
| 281 dispatchErrorEvent(); |
| 282 } |
| 283 noImageResourceToLoad(); |
| 282 } | 284 } |
| 283 | 285 |
| 284 ImageResource* oldImage = m_image.get(); | 286 ImageResource* oldImage = m_image.get(); |
| 285 if (newImage != oldImage) { | 287 if (newImage != oldImage) { |
| 286 sourceImageChanged(); | 288 sourceImageChanged(); |
| 287 | 289 |
| 288 if (m_hasPendingLoadEvent) { | 290 if (m_hasPendingLoadEvent) { |
| 289 loadEventSender().cancelEvent(this); | 291 loadEventSender().cancelEvent(this); |
| 290 m_hasPendingLoadEvent = false; | 292 m_hasPendingLoadEvent = false; |
| 291 } | 293 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 316 } | 318 } |
| 317 | 319 |
| 318 if (RenderImageResource* imageResource = renderImageResource()) | 320 if (RenderImageResource* imageResource = renderImageResource()) |
| 319 imageResource->resetAnimation(); | 321 imageResource->resetAnimation(); |
| 320 | 322 |
| 321 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 323 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
| 322 // from this function as doing so might result in the destruction of this Im
ageLoader. | 324 // from this function as doing so might result in the destruction of this Im
ageLoader. |
| 323 updatedHasPendingEvent(); | 325 updatedHasPendingEvent(); |
| 324 } | 326 } |
| 325 | 327 |
| 326 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
adType loadType) | 328 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior) |
| 327 { | 329 { |
| 328 AtomicString imageSourceURL = m_element->imageSourceURL(); | 330 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 329 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); | 331 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); |
| 330 | 332 |
| 331 if (updateBehavior == UpdateIgnorePreviousError) | 333 if (updateBehavior == UpdateIgnorePreviousError) |
| 332 clearFailedLoadURL(); | 334 clearFailedLoadURL(); |
| 333 | 335 |
| 334 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 336 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 335 return; | 337 return; |
| 336 | 338 |
| 337 // If we have a pending task, we have to clear it -- either we're | 339 // If we have a pending task, we have to clear it -- either we're |
| 338 // now loading immediately, or we need to reset the task's state. | 340 // now loading immediately, or we need to reset the task's state. |
| 339 if (m_pendingTask) { | 341 if (m_pendingTask) { |
| 340 m_pendingTask->clearLoader(); | 342 m_pendingTask->clearLoader(); |
| 341 m_pendingTask.clear(); | 343 m_pendingTask.clear(); |
| 342 } | 344 } |
| 343 | 345 |
| 344 KURL url = imageSourceToKURL(imageSourceURL); | 346 KURL url = imageSourceToKURL(imageSourceURL); |
| 345 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo
adType)) { | 347 if (shouldLoadImmediately(url)) { |
| 346 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); | 348 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); |
| 347 return; | 349 return; |
| 348 } | 350 } |
| 349 enqueueImageLoadingMicroTask(updateBehavior); | 351 enqueueImageLoadingMicroTask(updateBehavior); |
| 350 } | 352 } |
| 351 | 353 |
| 352 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const | 354 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const |
| 353 { | 355 { |
| 354 KURL url; | 356 KURL url; |
| 355 | 357 |
| 356 // Don't load images for inactive documents. We don't want to slow down the | 358 // Don't load images for inactive documents. We don't want to slow down the |
| 357 // raw HTML parsing case by loading images we don't intend to display. | 359 // raw HTML parsing case by loading images we don't intend to display. |
| 358 Document& document = m_element->document(); | 360 Document& document = m_element->document(); |
| 359 if (!document.isActive()) | 361 if (!document.isActive()) |
| 360 return url; | 362 return url; |
| 361 | 363 |
| 362 // Do not load any image if the 'src' attribute is missing or if it is | 364 // Do not load any image if the 'src' attribute is missing or if it is |
| 363 // an empty string. | 365 // an empty string. |
| 364 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) | 366 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) |
| 365 url = document.completeURL(sourceURI(imageSourceURL)); | 367 url = document.completeURL(sourceURI(imageSourceURL)); |
| 366 return url; | 368 return url; |
| 367 } | 369 } |
| 368 | 370 |
| 369 bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) cons
t | 371 bool ImageLoader::shouldLoadImmediately(const KURL& url) const |
| 370 { | 372 { |
| 371 return (m_loadingImageDocument | 373 // We force any image loads which might require alt content through the asyn
chronous path so that we can add the shadow DOM |
| 372 || isHTMLObjectElement(m_element) | 374 // for the alt-text content when style recalc is over and DOM mutation is al
lowed again. |
| 373 || isHTMLEmbedElement(m_element) | 375 if (!url.isNull()) { |
| 374 || url.protocolIsData() | 376 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum
ent().fetcher()->getCacheIdentifier()); |
| 375 || memoryCache()->resourceForURL(url, m_element->document().fetcher()->g
etCacheIdentifier()) | 377 if (resource && !resource->errorOccurred()) |
| 376 || loadType == ForceLoadImmediately); | 378 return true; |
| 379 } |
| 380 return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEm
bedElement(m_element) || url.protocolIsData()); |
| 377 } | 381 } |
| 378 | 382 |
| 379 void ImageLoader::notifyFinished(Resource* resource) | 383 void ImageLoader::notifyFinished(Resource* resource) |
| 380 { | 384 { |
| 381 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", | 385 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", |
| 382 this, m_hasPendingLoadEvent); | 386 this, m_hasPendingLoadEvent); |
| 383 | 387 |
| 384 ASSERT(m_failedLoadURL.isEmpty()); | 388 ASSERT(m_failedLoadURL.isEmpty()); |
| 385 ASSERT(resource == m_image.get()); | 389 ASSERT(resource == m_image.get()); |
| 386 | 390 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 } | 586 } |
| 583 #endif | 587 #endif |
| 584 } | 588 } |
| 585 | 589 |
| 586 #if ENABLE(OILPAN) | 590 #if ENABLE(OILPAN) |
| 587 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() | 591 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() |
| 588 { | 592 { |
| 589 m_loader.willRemoveClient(m_client); | 593 m_loader.willRemoveClient(m_client); |
| 590 } | 594 } |
| 591 #endif | 595 #endif |
| 592 | |
| 593 } | 596 } |
| OLD | NEW |