Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 ASSERT(loader); | 65 ASSERT(loader); |
| 66 ASSERT(loader->element()); | 66 ASSERT(loader->element()); |
| 67 ASSERT(loader->element()->document().frame()); | 67 ASSERT(loader->element()->document().frame()); |
| 68 if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP ()) | 68 if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP ()) |
| 69 return ImageLoader::BypassMainWorldCSP; | 69 return ImageLoader::BypassMainWorldCSP; |
| 70 return ImageLoader::DoNotBypassMainWorldCSP; | 70 return ImageLoader::DoNotBypassMainWorldCSP; |
| 71 } | 71 } |
| 72 | 72 |
| 73 class ImageLoader::Task : public blink::WebThread::Task { | 73 class ImageLoader::Task : public blink::WebThread::Task { |
| 74 public: | 74 public: |
| 75 static PassOwnPtr<Task> create(ImageLoader* loader) | 75 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio r updateBehavior) |
| 76 { | 76 { |
| 77 return adoptPtr(new Task(loader)); | 77 return adoptPtr(new Task(loader, updateBehavior)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 Task(ImageLoader* loader) | 80 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior) |
| 81 : m_loader(loader) | 81 : m_loader(loader) |
| 82 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) | 82 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) |
| 83 , m_weakFactory(this) | 83 , m_weakFactory(this) |
| 84 , m_updateBehavior(updateBehavior) | |
| 84 { | 85 { |
| 85 } | 86 } |
| 86 | 87 |
| 87 virtual void run() OVERRIDE | 88 virtual void run() OVERRIDE |
| 88 { | 89 { |
| 89 if (m_loader) { | 90 if (m_loader) { |
| 90 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP); | 91 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 void clearLoader() | 95 void clearLoader() |
| 95 { | 96 { |
| 96 m_loader = 0; | 97 m_loader = 0; |
| 97 } | 98 } |
| 98 | 99 |
| 99 WeakPtr<Task> createWeakPtr() | 100 WeakPtr<Task> createWeakPtr() |
| 100 { | 101 { |
| 101 return m_weakFactory.createWeakPtr(); | 102 return m_weakFactory.createWeakPtr(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 private: | 105 private: |
| 105 ImageLoader* m_loader; | 106 ImageLoader* m_loader; |
| 106 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; | 107 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; |
| 107 WeakPtrFactory<Task> m_weakFactory; | 108 WeakPtrFactory<Task> m_weakFactory; |
| 109 UpdateFromElementBehavior m_updateBehavior; | |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 ImageLoader::ImageLoader(Element* element) | 112 ImageLoader::ImageLoader(Element* element) |
| 111 : m_element(element) | 113 : m_element(element) |
| 112 , m_image(0) | 114 , m_image(0) |
| 113 , m_derefElementTimer(this, &ImageLoader::timerFired) | 115 , m_derefElementTimer(this, &ImageLoader::timerFired) |
| 114 , m_hasPendingLoadEvent(false) | 116 , m_hasPendingLoadEvent(false) |
| 115 , m_hasPendingErrorEvent(false) | 117 , m_hasPendingErrorEvent(false) |
| 116 , m_imageComplete(true) | 118 , m_imageComplete(true) |
| 117 , m_loadingImageDocument(false) | 119 , m_loadingImageDocument(false) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 m_failedLoadURL = imageSourceURL; | 205 m_failedLoadURL = imageSourceURL; |
| 204 m_hasPendingErrorEvent = true; | 206 m_hasPendingErrorEvent = true; |
| 205 errorEventSender().dispatchEventSoon(this); | 207 errorEventSender().dispatchEventSoon(this); |
| 206 } | 208 } |
| 207 | 209 |
| 208 inline void ImageLoader::clearFailedLoadURL() | 210 inline void ImageLoader::clearFailedLoadURL() |
| 209 { | 211 { |
| 210 m_failedLoadURL = AtomicString(); | 212 m_failedLoadURL = AtomicString(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 inline void ImageLoader::enqueueImageLoadingMicroTask() | 215 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior updateBehavior) |
| 214 { | 216 { |
| 215 OwnPtr<Task> task = Task::create(this); | 217 OwnPtr<Task> task = Task::create(this, updateBehavior); |
| 216 m_pendingTask = task->createWeakPtr(); | 218 m_pendingTask = task->createWeakPtr(); |
| 217 Microtask::enqueueMicrotask(task.release()); | 219 Microtask::enqueueMicrotask(task.release()); |
| 218 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen t()); | 220 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen t()); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior) | 223 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up dateFromElementBehavior updateBehavior) |
| 222 { | 224 { |
| 223 // We don't need to call clearLoader here: Either we were called from the | 225 // We don't need to call clearLoader here: Either we were called from the |
| 224 // task, or our caller updateFromElement cleared the task's loader (and set | 226 // task, or our caller updateFromElement cleared the task's loader (and set |
| 225 // m_pendingTask to null). | 227 // m_pendingTask to null). |
| 226 m_pendingTask.clear(); | 228 m_pendingTask.clear(); |
| 227 // Make sure to only decrement the count when we exit this function | 229 // Make sure to only decrement the count when we exit this function |
| 228 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter; | 230 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter; |
| 229 loadDelayCounter.swap(m_loadDelayCounter); | 231 loadDelayCounter.swap(m_loadDelayCounter); |
| 230 | 232 |
| 231 Document& document = m_element->document(); | 233 Document& document = m_element->document(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 m_imageComplete = !newImage; | 283 m_imageComplete = !newImage; |
| 282 | 284 |
| 283 updateRenderer(); | 285 updateRenderer(); |
| 284 // If newImage exists and is cached, addClient() will result in the load event | 286 // If newImage exists and is cached, addClient() will result in the load event |
| 285 // being queued to fire. Ensure this happens after beforeload is dispatc hed. | 287 // being queued to fire. Ensure this happens after beforeload is dispatc hed. |
| 286 if (newImage) | 288 if (newImage) |
| 287 newImage->addClient(this); | 289 newImage->addClient(this); |
| 288 | 290 |
| 289 if (oldImage) | 291 if (oldImage) |
| 290 oldImage->removeClient(this); | 292 oldImage->removeClient(this); |
| 293 } else if (updateBehavior == UpdateForce) { | |
| 294 if (m_element->renderer() && m_element->renderer()->isImage()) | |
|
esprehn
2014/07/25 23:51:56
combine with the other ifs?
if (updateBehavior ==
| |
| 295 toRenderImage(m_element->renderer())->intrinsicSizeChanged(); | |
| 291 } | 296 } |
| 292 | 297 |
| 293 if (RenderImageResource* imageResource = renderImageResource()) | 298 if (RenderImageResource* imageResource = renderImageResource()) |
| 294 imageResource->resetAnimation(); | 299 imageResource->resetAnimation(); |
| 295 | 300 |
| 296 // Only consider updating the protection ref-count of the Element immediatel y before returning | 301 // Only consider updating the protection ref-count of the Element immediatel y before returning |
| 297 // from this function as doing so might result in the destruction of this Im ageLoader. | 302 // from this function as doing so might result in the destruction of this Im ageLoader. |
| 298 updatedHasPendingEvent(); | 303 updatedHasPendingEvent(); |
| 299 } | 304 } |
| 300 | 305 |
| 301 void ImageLoader::updateFromElement(UpdateFromElementBehavior behavior, LoadType loadType) | 306 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo adType loadType) |
| 302 { | 307 { |
| 303 AtomicString imageSourceURL = m_element->imageSourceURL(); | 308 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 304 | 309 |
| 305 if (behavior == UpdateIgnorePreviousError) | 310 if (updateBehavior == UpdateIgnorePreviousError) |
| 306 clearFailedLoadURL(); | 311 clearFailedLoadURL(); |
| 307 | 312 |
| 308 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 313 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 309 return; | 314 return; |
| 310 | 315 |
| 311 // If we have a pending task, we have to clear it -- either we're | 316 // If we have a pending task, we have to clear it -- either we're |
| 312 // now loading immediately, or we need to reset the task's state. | 317 // now loading immediately, or we need to reset the task's state. |
| 313 if (m_pendingTask) { | 318 if (m_pendingTask) { |
| 314 m_pendingTask->clearLoader(); | 319 m_pendingTask->clearLoader(); |
| 315 m_pendingTask.clear(); | 320 m_pendingTask.clear(); |
| 316 } | 321 } |
| 317 | 322 |
| 318 KURL url = imageSourceToKURL(imageSourceURL); | 323 KURL url = imageSourceToKURL(imageSourceURL); |
| 319 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo adType)) { | 324 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo adType)) { |
| 320 doUpdateFromElement(DoNotBypassMainWorldCSP); | 325 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); |
| 321 return; | 326 return; |
| 322 } | 327 } |
| 323 enqueueImageLoadingMicroTask(); | 328 enqueueImageLoadingMicroTask(updateBehavior); |
| 324 } | 329 } |
| 325 | 330 |
| 326 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const | 331 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const |
| 327 { | 332 { |
| 328 KURL url; | 333 KURL url; |
| 329 | 334 |
| 330 // Don't load images for inactive documents. We don't want to slow down the | 335 // Don't load images for inactive documents. We don't want to slow down the |
| 331 // raw HTML parsing case by loading images we don't intend to display. | 336 // raw HTML parsing case by loading images we don't intend to display. |
| 332 Document& document = m_element->document(); | 337 Document& document = m_element->document(); |
| 333 if (!document.isActive()) | 338 if (!document.isActive()) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 } | 554 } |
| 550 | 555 |
| 551 #if ENABLE(OILPAN) | 556 #if ENABLE(OILPAN) |
| 552 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() | 557 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() |
| 553 { | 558 { |
| 554 m_loader.willRemoveClient(m_client); | 559 m_loader.willRemoveClient(m_client); |
| 555 } | 560 } |
| 556 #endif | 561 #endif |
| 557 | 562 |
| 558 } | 563 } |
| OLD | NEW |