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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 260 |
262 if (m_loadingImageDocument) | 261 if (m_loadingImageDocument) |
263 newImage = createImageResourceForImageDocument(document, request); | 262 newImage = createImageResourceForImageDocument(document, request); |
264 else | 263 else |
265 newImage = document.fetcher()->fetchImage(request); | 264 newImage = document.fetcher()->fetchImage(request); |
266 | 265 |
267 if (!newImage && !pageIsBeingDismissed(&document)) | 266 if (!newImage && !pageIsBeingDismissed(&document)) |
268 crossSiteOrCSPViolationOccured(imageSourceURL); | 267 crossSiteOrCSPViolationOccured(imageSourceURL); |
269 else | 268 else |
270 clearFailedLoadURL(); | 269 clearFailedLoadURL(); |
271 } else if (!imageSourceURL.isNull()) { | 270 } else { |
272 // Fire an error event if the url string is not empty, but the KURL is. | 271 if (!imageSourceURL.isNull()) { |
273 m_hasPendingErrorEvent = true; | 272 // Fire an error event if the url string is not empty, but the KURL
is. |
274 errorEventSender().dispatchEventSoon(this); | 273 m_hasPendingErrorEvent = true; |
| 274 errorEventSender().dispatchEventSoon(this); |
| 275 } |
| 276 noImageResourceToLoad(); |
275 } | 277 } |
276 | 278 |
277 ImageResource* oldImage = m_image.get(); | 279 ImageResource* oldImage = m_image.get(); |
278 if (newImage != oldImage) { | 280 if (newImage != oldImage) { |
279 sourceImageChanged(); | 281 sourceImageChanged(); |
280 | 282 |
281 if (m_hasPendingLoadEvent) { | 283 if (m_hasPendingLoadEvent) { |
282 loadEventSender().cancelEvent(this); | 284 loadEventSender().cancelEvent(this); |
283 m_hasPendingLoadEvent = false; | 285 m_hasPendingLoadEvent = false; |
284 } | 286 } |
(...skipping 24 matching lines...) Expand all Loading... |
309 } | 311 } |
310 | 312 |
311 if (RenderImageResource* imageResource = renderImageResource()) | 313 if (RenderImageResource* imageResource = renderImageResource()) |
312 imageResource->resetAnimation(); | 314 imageResource->resetAnimation(); |
313 | 315 |
314 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 316 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
315 // from this function as doing so might result in the destruction of this Im
ageLoader. | 317 // from this function as doing so might result in the destruction of this Im
ageLoader. |
316 updatedHasPendingEvent(); | 318 updatedHasPendingEvent(); |
317 } | 319 } |
318 | 320 |
319 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
adType loadType) | 321 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior) |
320 { | 322 { |
321 AtomicString imageSourceURL = m_element->imageSourceURL(); | 323 AtomicString imageSourceURL = m_element->imageSourceURL(); |
322 | 324 |
323 if (updateBehavior == UpdateIgnorePreviousError) | 325 if (updateBehavior == UpdateIgnorePreviousError) |
324 clearFailedLoadURL(); | 326 clearFailedLoadURL(); |
325 | 327 |
326 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 328 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
327 return; | 329 return; |
328 | 330 |
329 // If we have a pending task, we have to clear it -- either we're | 331 // If we have a pending task, we have to clear it -- either we're |
330 // now loading immediately, or we need to reset the task's state. | 332 // now loading immediately, or we need to reset the task's state. |
331 if (m_pendingTask) { | 333 if (m_pendingTask) { |
332 m_pendingTask->clearLoader(); | 334 m_pendingTask->clearLoader(); |
333 m_pendingTask.clear(); | 335 m_pendingTask.clear(); |
334 } | 336 } |
335 | 337 |
336 KURL url = imageSourceToKURL(imageSourceURL); | 338 KURL url = imageSourceToKURL(imageSourceURL); |
337 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo
adType)) { | 339 if (shouldLoadImmediately(url)) { |
338 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); | 340 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); |
339 return; | 341 return; |
340 } | 342 } |
341 enqueueImageLoadingMicroTask(updateBehavior); | 343 enqueueImageLoadingMicroTask(updateBehavior); |
342 } | 344 } |
343 | 345 |
344 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const | 346 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const |
345 { | 347 { |
346 KURL url; | 348 KURL url; |
347 | 349 |
348 // Don't load images for inactive documents. We don't want to slow down the | 350 // Don't load images for inactive documents. We don't want to slow down the |
349 // raw HTML parsing case by loading images we don't intend to display. | 351 // raw HTML parsing case by loading images we don't intend to display. |
350 Document& document = m_element->document(); | 352 Document& document = m_element->document(); |
351 if (!document.isActive()) | 353 if (!document.isActive()) |
352 return url; | 354 return url; |
353 | 355 |
354 // Do not load any image if the 'src' attribute is missing or if it is | 356 // Do not load any image if the 'src' attribute is missing or if it is |
355 // an empty string. | 357 // an empty string. |
356 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) | 358 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour
ceURL).isEmpty()) |
357 url = document.completeURL(sourceURI(imageSourceURL)); | 359 url = document.completeURL(sourceURI(imageSourceURL)); |
358 return url; | 360 return url; |
359 } | 361 } |
360 | 362 |
361 bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) cons
t | 363 bool ImageLoader::shouldLoadImmediately(const KURL& url) const |
362 { | 364 { |
| 365 // We force failed image loads through the asynchronous path so that we can
add the shadow DOM |
| 366 // for the alt-text content when style recalc is over and DOM mutation is al
lowed again. |
| 367 if (!url.isNull()) { |
| 368 Resource* resource = memoryCache()->resourceForURL(url); |
| 369 if (resource && !resource->errorOccurred()) |
| 370 return true; |
| 371 } |
363 return (m_loadingImageDocument | 372 return (m_loadingImageDocument |
364 || isHTMLObjectElement(m_element) | 373 || isHTMLObjectElement(m_element) |
365 || isHTMLEmbedElement(m_element) | 374 || isHTMLEmbedElement(m_element) |
366 || url.protocolIsData() | 375 || url.protocolIsData()); |
367 || memoryCache()->resourceForURL(url) | |
368 || loadType == ForceLoadImmediately); | |
369 } | 376 } |
370 | 377 |
371 void ImageLoader::notifyFinished(Resource* resource) | 378 void ImageLoader::notifyFinished(Resource* resource) |
372 { | 379 { |
373 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", | 380 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", |
374 this, m_hasPendingLoadEvent); | 381 this, m_hasPendingLoadEvent); |
375 | 382 |
376 ASSERT(m_failedLoadURL.isEmpty()); | 383 ASSERT(m_failedLoadURL.isEmpty()); |
377 ASSERT(resource == m_image.get()); | 384 ASSERT(resource == m_image.get()); |
378 | 385 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 } | 578 } |
572 | 579 |
573 #if ENABLE(OILPAN) | 580 #if ENABLE(OILPAN) |
574 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() | 581 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() |
575 { | 582 { |
576 m_loader.willRemoveClient(m_client); | 583 m_loader.willRemoveClient(m_client); |
577 } | 584 } |
578 #endif | 585 #endif |
579 | 586 |
580 } | 587 } |
OLD | NEW |