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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 { | 122 { |
123 return client()->sourceElement()->document(); | 123 return client()->sourceElement()->document(); |
124 } | 124 } |
125 | 125 |
126 void ImageLoader::setImage(CachedImage* newImage) | 126 void ImageLoader::setImage(CachedImage* newImage) |
127 { | 127 { |
128 setImageWithoutConsideringPendingLoadEvent(newImage); | 128 setImageWithoutConsideringPendingLoadEvent(newImage); |
129 | 129 |
130 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 130 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
131 // from this function as doing so might result in the destruction of this Im
ageLoader. | 131 // from this function as doing so might result in the destruction of this Im
ageLoader. |
132 updatedHasPendingLoadEvent(); | 132 updatedHasPendingEvent(); |
133 } | 133 } |
134 | 134 |
135 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma
ge) | 135 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma
ge) |
136 { | 136 { |
137 ASSERT(m_failedLoadURL.isEmpty()); | 137 ASSERT(m_failedLoadURL.isEmpty()); |
138 CachedImage* oldImage = m_image.get(); | 138 CachedImage* oldImage = m_image.get(); |
139 if (newImage != oldImage) { | 139 if (newImage != oldImage) { |
140 m_image = newImage; | 140 m_image = newImage; |
141 if (m_hasPendingBeforeLoadEvent) { | 141 if (m_hasPendingBeforeLoadEvent) { |
142 beforeLoadEventSender().cancelEvent(this); | 142 beforeLoadEventSender().cancelEvent(this); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 241 } |
242 if (oldImage) | 242 if (oldImage) |
243 oldImage->removeClient(this); | 243 oldImage->removeClient(this); |
244 } | 244 } |
245 | 245 |
246 if (RenderImageResource* imageResource = renderImageResource()) | 246 if (RenderImageResource* imageResource = renderImageResource()) |
247 imageResource->resetAnimation(); | 247 imageResource->resetAnimation(); |
248 | 248 |
249 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 249 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
250 // from this function as doing so might result in the destruction of this Im
ageLoader. | 250 // from this function as doing so might result in the destruction of this Im
ageLoader. |
251 updatedHasPendingLoadEvent(); | 251 updatedHasPendingEvent(); |
252 } | 252 } |
253 | 253 |
254 void ImageLoader::updateFromElementIgnoringPreviousError() | 254 void ImageLoader::updateFromElementIgnoringPreviousError() |
255 { | 255 { |
256 // Clear previous error. | 256 // Clear previous error. |
257 m_failedLoadURL = AtomicString(); | 257 m_failedLoadURL = AtomicString(); |
258 updateFromElement(); | 258 updateFromElement(); |
259 } | 259 } |
260 | 260 |
261 void ImageLoader::notifyFinished(CachedResource* resource) | 261 void ImageLoader::notifyFinished(CachedResource* resource) |
(...skipping 17 matching lines...) Expand all Loading... |
279 m_hasPendingErrorEvent = true; | 279 m_hasPendingErrorEvent = true; |
280 errorEventSender().dispatchEventSoon(this); | 280 errorEventSender().dispatchEventSoon(this); |
281 | 281 |
282 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin
image load denied by Cross-Origin Resource Sharing policy."))); | 282 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin
image load denied by Cross-Origin Resource Sharing policy."))); |
283 document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMess
ageLevel, consoleMessage); | 283 document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMess
ageLevel, consoleMessage); |
284 | 284 |
285 ASSERT(!m_hasPendingLoadEvent); | 285 ASSERT(!m_hasPendingLoadEvent); |
286 | 286 |
287 // Only consider updating the protection ref-count of the Element immedi
ately before returning | 287 // Only consider updating the protection ref-count of the Element immedi
ately before returning |
288 // from this function as doing so might result in the destruction of thi
s ImageLoader. | 288 // from this function as doing so might result in the destruction of thi
s ImageLoader. |
289 updatedHasPendingLoadEvent(); | 289 updatedHasPendingEvent(); |
290 return; | 290 return; |
291 } | 291 } |
292 | 292 |
293 if (resource->wasCanceled()) { | 293 if (resource->wasCanceled()) { |
294 m_hasPendingLoadEvent = false; | 294 m_hasPendingLoadEvent = false; |
295 // Only consider updating the protection ref-count of the Element immedi
ately before returning | 295 // Only consider updating the protection ref-count of the Element immedi
ately before returning |
296 // from this function as doing so might result in the destruction of thi
s ImageLoader. | 296 // from this function as doing so might result in the destruction of thi
s ImageLoader. |
297 updatedHasPendingLoadEvent(); | 297 updatedHasPendingEvent(); |
298 return; | 298 return; |
299 } | 299 } |
300 | 300 |
301 loadEventSender().dispatchEventSoon(this); | 301 loadEventSender().dispatchEventSoon(this); |
302 } | 302 } |
303 | 303 |
304 RenderImageResource* ImageLoader::renderImageResource() | 304 RenderImageResource* ImageLoader::renderImageResource() |
305 { | 305 { |
306 RenderObject* renderer = client()->imageElement()->renderer(); | 306 RenderObject* renderer = client()->imageElement()->renderer(); |
307 | 307 |
(...skipping 26 matching lines...) Expand all Loading... |
334 return; | 334 return; |
335 | 335 |
336 // Only update the renderer if it doesn't have an image or if what we have | 336 // Only update the renderer if it doesn't have an image or if what we have |
337 // is a complete image. This prevents flickering in the case where a dynami
c | 337 // is a complete image. This prevents flickering in the case where a dynami
c |
338 // change is happening between two images. | 338 // change is happening between two images. |
339 CachedImage* cachedImage = imageResource->cachedImage(); | 339 CachedImage* cachedImage = imageResource->cachedImage(); |
340 if (m_image != cachedImage && (m_imageComplete || !cachedImage)) | 340 if (m_image != cachedImage && (m_imageComplete || !cachedImage)) |
341 imageResource->setCachedImage(m_image.get()); | 341 imageResource->setCachedImage(m_image.get()); |
342 } | 342 } |
343 | 343 |
344 void ImageLoader::updatedHasPendingLoadEvent() | 344 void ImageLoader::updatedHasPendingEvent() |
345 { | 345 { |
346 // If an Element that does image loading is removed from the DOM the load ev
ent for the image is still observable. | 346 // If an Element that does image loading is removed from the DOM the load/er
ror event for the image is still observable. |
347 // As long as the ImageLoader is actively loading, the Element itself needs
to be ref'ed to keep it from being | 347 // As long as the ImageLoader is actively loading, the Element itself needs
to be ref'ed to keep it from being |
348 // destroyed by DOM manipulation or garbage collection. | 348 // destroyed by DOM manipulation or garbage collection. |
349 // If such an Element wishes for the load to stop when removed from the DOM
it needs to stop the ImageLoader explicitly. | 349 // If such an Element wishes for the load to stop when removed from the DOM
it needs to stop the ImageLoader explicitly. |
350 | 350 bool wasProtected = m_elementIsProtected; |
351 if (m_hasPendingLoadEvent == m_elementIsProtected) | 351 m_elementIsProtected = m_hasPendingLoadEvent || m_hasPendingErrorEvent; |
| 352 if (wasProtected == m_elementIsProtected) |
352 return; | 353 return; |
353 | 354 |
354 m_elementIsProtected = m_hasPendingLoadEvent; | |
355 | |
356 if (m_elementIsProtected) | 355 if (m_elementIsProtected) |
357 client()->refSourceElement(); | 356 client()->refSourceElement(); |
358 else | 357 else |
359 client()->derefSourceElement(); | 358 client()->derefSourceElement(); |
360 } | 359 } |
361 | 360 |
362 void ImageLoader::dispatchPendingEvent(ImageEventSender* eventSender) | 361 void ImageLoader::dispatchPendingEvent(ImageEventSender* eventSender) |
363 { | 362 { |
364 ASSERT(eventSender == &beforeLoadEventSender() || eventSender == &loadEventS
ender() || eventSender == &errorEventSender()); | 363 ASSERT(eventSender == &beforeLoadEventSender() || eventSender == &loadEventS
ender() || eventSender == &errorEventSender()); |
365 const AtomicString& eventType = eventSender->eventType(); | 364 const AtomicString& eventType = eventSender->eventType(); |
(...skipping 24 matching lines...) Expand all Loading... |
390 } | 389 } |
391 | 390 |
392 loadEventSender().cancelEvent(this); | 391 loadEventSender().cancelEvent(this); |
393 m_hasPendingLoadEvent = false; | 392 m_hasPendingLoadEvent = false; |
394 | 393 |
395 if (client()->sourceElement()->hasTagName(HTMLNames::objectTag)) | 394 if (client()->sourceElement()->hasTagName(HTMLNames::objectTag)) |
396 static_cast<HTMLObjectElement*>(client()->sourceElement())->renderFallba
ckContent(); | 395 static_cast<HTMLObjectElement*>(client()->sourceElement())->renderFallba
ckContent(); |
397 | 396 |
398 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 397 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
399 // from this function as doing so might result in the destruction of this Im
ageLoader. | 398 // from this function as doing so might result in the destruction of this Im
ageLoader. |
400 updatedHasPendingLoadEvent(); | 399 updatedHasPendingEvent(); |
401 } | 400 } |
402 | 401 |
403 void ImageLoader::dispatchPendingLoadEvent() | 402 void ImageLoader::dispatchPendingLoadEvent() |
404 { | 403 { |
405 if (!m_hasPendingLoadEvent) | 404 if (!m_hasPendingLoadEvent) |
406 return; | 405 return; |
407 if (!m_image) | 406 if (!m_image) |
408 return; | 407 return; |
409 if (!document()->attached()) | 408 if (!document()->attached()) |
410 return; | 409 return; |
411 m_hasPendingLoadEvent = false; | 410 m_hasPendingLoadEvent = false; |
412 dispatchLoadEvent(); | 411 dispatchLoadEvent(); |
413 | 412 |
414 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 413 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
415 // from this function as doing so might result in the destruction of this Im
ageLoader. | 414 // from this function as doing so might result in the destruction of this Im
ageLoader. |
416 updatedHasPendingLoadEvent(); | 415 updatedHasPendingEvent(); |
417 } | 416 } |
418 | 417 |
419 void ImageLoader::dispatchPendingErrorEvent() | 418 void ImageLoader::dispatchPendingErrorEvent() |
420 { | 419 { |
421 if (!m_hasPendingErrorEvent) | 420 if (!m_hasPendingErrorEvent) |
422 return; | 421 return; |
423 if (!document()->attached()) | 422 if (!document()->attached()) |
424 return; | 423 return; |
425 m_hasPendingErrorEvent = false; | 424 m_hasPendingErrorEvent = false; |
426 client()->imageElement()->dispatchEvent(Event::create(eventNames().errorEven
t, false, false)); | 425 client()->imageElement()->dispatchEvent(Event::create(eventNames().errorEven
t, false, false)); |
(...skipping 13 matching lines...) Expand all Loading... |
440 { | 439 { |
441 errorEventSender().dispatchPendingEvents(); | 440 errorEventSender().dispatchPendingEvents(); |
442 } | 441 } |
443 | 442 |
444 void ImageLoader::elementDidMoveToNewDocument() | 443 void ImageLoader::elementDidMoveToNewDocument() |
445 { | 444 { |
446 setImage(0); | 445 setImage(0); |
447 } | 446 } |
448 | 447 |
449 } | 448 } |
OLD | NEW |