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