| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 ImageLoader::ImageLoader(Element* element) | 148 ImageLoader::ImageLoader(Element* element) |
| 149 : m_element(element) | 149 : m_element(element) |
| 150 , m_derefElementTimer(this, &ImageLoader::timerFired) | 150 , m_derefElementTimer(this, &ImageLoader::timerFired) |
| 151 , m_hasPendingLoadEvent(false) | 151 , m_hasPendingLoadEvent(false) |
| 152 , m_hasPendingErrorEvent(false) | 152 , m_hasPendingErrorEvent(false) |
| 153 , m_imageComplete(true) | 153 , m_imageComplete(true) |
| 154 , m_loadingImageDocument(false) | 154 , m_loadingImageDocument(false) |
| 155 , m_elementIsProtected(false) | 155 , m_elementIsProtected(false) |
| 156 , m_suppressErrorEvents(false) | 156 , m_suppressErrorEvents(false) |
| 157 , m_suppressEvents(false) |
| 157 { | 158 { |
| 158 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; | 159 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; |
| 159 ThreadState::current()->registerPreFinalizer(this); | 160 ThreadState::current()->registerPreFinalizer(this); |
| 160 } | 161 } |
| 161 | 162 |
| 162 ImageLoader::~ImageLoader() | 163 ImageLoader::~ImageLoader() |
| 163 { | 164 { |
| 164 } | 165 } |
| 165 | 166 |
| 166 void ImageLoader::dispose() | 167 void ImageLoader::dispose() |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(element.fa
stGetAttribute(HTMLNames::crossoriginAttr)); | 226 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(element.fa
stGetAttribute(HTMLNames::crossoriginAttr)); |
| 226 if (crossOrigin != CrossOriginAttributeNotSet) | 227 if (crossOrigin != CrossOriginAttributeNotSet) |
| 227 request.setCrossOriginAccessControl(element.document().getSecurityOrigin
(), crossOrigin); | 228 request.setCrossOriginAccessControl(element.document().getSecurityOrigin
(), crossOrigin); |
| 228 | 229 |
| 229 if (clientHintsPreferences.shouldSendResourceWidth() && isHTMLImageElement(e
lement)) | 230 if (clientHintsPreferences.shouldSendResourceWidth() && isHTMLImageElement(e
lement)) |
| 230 request.setResourceWidth(toHTMLImageElement(element).getResourceWidth())
; | 231 request.setResourceWidth(toHTMLImageElement(element).getResourceWidth())
; |
| 231 } | 232 } |
| 232 | 233 |
| 233 inline void ImageLoader::dispatchErrorEvent() | 234 inline void ImageLoader::dispatchErrorEvent() |
| 234 { | 235 { |
| 236 if (m_suppressEvents) { |
| 237 return; |
| 238 } |
| 235 m_hasPendingErrorEvent = true; | 239 m_hasPendingErrorEvent = true; |
| 236 errorEventSender().dispatchEventSoon(this); | 240 errorEventSender().dispatchEventSoon(this); |
| 237 } | 241 } |
| 238 | 242 |
| 239 inline void ImageLoader::crossSiteOrCSPViolationOccurred(AtomicString imageSourc
eURL) | 243 inline void ImageLoader::crossSiteOrCSPViolationOccurred(AtomicString imageSourc
eURL) |
| 240 { | 244 { |
| 241 m_failedLoadURL = imageSourceURL; | 245 m_failedLoadURL = imageSourceURL; |
| 242 } | 246 } |
| 243 | 247 |
| 244 inline void ImageLoader::clearFailedLoadURL() | 248 inline void ImageLoader::clearFailedLoadURL() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 272 Document& document = m_element->document(); | 276 Document& document = m_element->document(); |
| 273 if (!document.isActive()) | 277 if (!document.isActive()) |
| 274 return; | 278 return; |
| 275 | 279 |
| 276 AtomicString imageSourceURL = m_element->imageSourceURL(); | 280 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 277 ImageResource* newImage = nullptr; | 281 ImageResource* newImage = nullptr; |
| 278 if (!url.isNull()) { | 282 if (!url.isNull()) { |
| 279 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. | 283 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. |
| 280 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); | 284 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); |
| 281 ResourceRequest resourceRequest(url); | 285 ResourceRequest resourceRequest(url); |
| 282 if (updateBehavior == UpdateForcedReload) { | 286 switch (updateBehavior) { |
| 287 case UpdateForcedReload: |
| 283 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 288 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
| 284 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 289 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
| 290 break; |
| 291 case UpdateMyReload: |
| 292 resourceRequest.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLo
ad); |
| 293 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
| 294 break; |
| 295 default: |
| 296 break; |
| 285 } | 297 } |
| 286 | 298 |
| 287 if (referrerPolicy != ReferrerPolicyDefault) | 299 if (referrerPolicy != ReferrerPolicyDefault) |
| 288 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref
errerPolicy, url, document.outgoingReferrer())); | 300 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref
errerPolicy, url, document.outgoingReferrer())); |
| 289 | 301 |
| 290 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet
Attribute(HTMLNames::srcsetAttr).isNull()) | 302 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet
Attribute(HTMLNames::srcsetAttr).isNull()) |
| 291 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage
Set); | 303 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage
Set); |
| 292 FetchRequest request(resourceRequest, element()->localName(), resourceLo
aderOptions); | 304 FetchRequest request(resourceRequest, element()->localName(), resourceLo
aderOptions); |
| 293 configureRequest(request, bypassBehavior, *m_element, document.clientHin
tsPreferences()); | 305 configureRequest(request, bypassBehavior, *m_element, document.clientHin
tsPreferences()); |
| 294 | 306 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 320 // Cancel error events that belong to the previous load, which is now ca
ncelled by changing the src attribute. | 332 // Cancel error events that belong to the previous load, which is now ca
ncelled by changing the src attribute. |
| 321 // If newImage is null and m_hasPendingErrorEvent is true, we know the e
rror event has been just posted by | 333 // If newImage is null and m_hasPendingErrorEvent is true, we know the e
rror event has been just posted by |
| 322 // this load and we should not cancel the event. | 334 // this load and we should not cancel the event. |
| 323 // FIXME: If both previous load and this one got blocked with an error,
we can receive one error event instead of two. | 335 // FIXME: If both previous load and this one got blocked with an error,
we can receive one error event instead of two. |
| 324 if (m_hasPendingErrorEvent && newImage) { | 336 if (m_hasPendingErrorEvent && newImage) { |
| 325 errorEventSender().cancelEvent(this); | 337 errorEventSender().cancelEvent(this); |
| 326 m_hasPendingErrorEvent = false; | 338 m_hasPendingErrorEvent = false; |
| 327 } | 339 } |
| 328 | 340 |
| 329 m_image = newImage; | 341 m_image = newImage; |
| 330 m_hasPendingLoadEvent = newImage; | 342 m_hasPendingLoadEvent = newImage && !m_suppressEvents; |
| 331 m_imageComplete = !newImage; | 343 m_imageComplete = !newImage; |
| 332 | 344 |
| 333 updateLayoutObject(); | 345 updateLayoutObject(); |
| 334 // If newImage exists and is cached, addObserver() will result in the lo
ad event | 346 // If newImage exists and is cached, addObserver() will result in the lo
ad event |
| 335 // being queued to fire. Ensure this happens after beforeload is dispatc
hed. | 347 // being queued to fire. Ensure this happens after beforeload is dispatc
hed. |
| 336 if (newImage) { | 348 if (newImage) { |
| 337 newImage->addObserver(this); | 349 newImage->addObserver(this); |
| 338 } | 350 } |
| 339 if (oldImage) { | 351 if (oldImage) { |
| 340 oldImage->removeObserver(this); | 352 oldImage->removeObserver(this); |
| 341 } | 353 } |
| 342 } | 354 } |
| 343 | 355 |
| 344 if (LayoutImageResource* imageResource = layoutImageResource()) | 356 if (LayoutImageResource* imageResource = layoutImageResource()) |
| 345 imageResource->resetAnimation(); | 357 imageResource->resetAnimation(); |
| 346 | 358 |
| 347 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 359 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
| 348 // from this function as doing so might result in the destruction of this Im
ageLoader. | 360 // from this function as doing so might result in the destruction of this Im
ageLoader. |
| 349 updatedHasPendingEvent(); | 361 updatedHasPendingEvent(); |
| 350 } | 362 } |
| 351 | 363 |
| 352 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Re
ferrerPolicy referrerPolicy) | 364 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Re
ferrerPolicy referrerPolicy) |
| 353 { | 365 { |
| 354 AtomicString imageSourceURL = m_element->imageSourceURL(); | 366 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 355 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); | 367 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); |
| 368 m_suppressEvents = (updateBehavior == UpdateMyReload); |
| 356 | 369 |
| 357 if (updateBehavior == UpdateIgnorePreviousError) | 370 if (updateBehavior == UpdateIgnorePreviousError) |
| 358 clearFailedLoadURL(); | 371 clearFailedLoadURL(); |
| 359 | 372 |
| 360 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 373 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 361 return; | 374 return; |
| 362 | 375 |
| 363 // Prevent the creation of a ResourceLoader (and therefore a network | 376 // Prevent the creation of a ResourceLoader (and therefore a network |
| 364 // request) for ImageDocument loads. In this case, the image contents have a
lready | 377 // request) for ImageDocument loads. In this case, the image contents have a
lready |
| 365 // been requested as a main resource and ImageDocumentParser will take care
of | 378 // been requested as a main resource and ImageDocumentParser will take care
of |
| 366 // funneling the main resource bytes into m_image, so just create an ImageRe
source | 379 // funneling the main resource bytes into m_image, so just create an ImageRe
source |
| 367 // to be populated later. | 380 // to be populated later. |
| 368 if (m_loadingImageDocument && updateBehavior != UpdateForcedReload) { | 381 if (m_loadingImageDocument && updateBehavior != UpdateForcedReload && update
Behavior != UpdateMyReload) { |
| 369 setImage(ImageResource::create(imageSourceToKURL(m_element->imageSourceU
RL()))); | 382 setImage(ImageResource::create(imageSourceToKURL(m_element->imageSourceU
RL()))); |
| 370 m_image->setStatus(Resource::Pending); | 383 m_image->setStatus(Resource::Pending); |
| 371 return; | 384 return; |
| 372 } | 385 } |
| 373 | 386 |
| 374 // If we have a pending task, we have to clear it -- either we're | 387 // If we have a pending task, we have to clear it -- either we're |
| 375 // now loading immediately, or we need to reset the task's state. | 388 // now loading immediately, or we need to reset the task's state. |
| 376 if (m_pendingTask) { | 389 if (m_pendingTask) { |
| 377 m_pendingTask->clearLoader(); | 390 m_pendingTask->clearLoader(); |
| 378 m_pendingTask.clear(); | 391 m_pendingTask.clear(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 599 |
| 587 bool ImageLoader::getImageAnimationPolicy(ImageAnimationPolicy& policy) | 600 bool ImageLoader::getImageAnimationPolicy(ImageAnimationPolicy& policy) |
| 588 { | 601 { |
| 589 if (!element()->document().settings()) | 602 if (!element()->document().settings()) |
| 590 return false; | 603 return false; |
| 591 | 604 |
| 592 policy = element()->document().settings()->imageAnimationPolicy(); | 605 policy = element()->document().settings()->imageAnimationPolicy(); |
| 593 return true; | 606 return true; |
| 594 } | 607 } |
| 595 | 608 |
| 609 void ImageLoader::requireReloading() |
| 610 { |
| 611 updateFromElement(UpdateMyReload); |
| 612 } |
| 613 |
| 596 void ImageLoader::dispatchPendingLoadEvents() | 614 void ImageLoader::dispatchPendingLoadEvents() |
| 597 { | 615 { |
| 598 loadEventSender().dispatchPendingEvents(); | 616 loadEventSender().dispatchPendingEvents(); |
| 599 } | 617 } |
| 600 | 618 |
| 601 void ImageLoader::dispatchPendingErrorEvents() | 619 void ImageLoader::dispatchPendingErrorEvents() |
| 602 { | 620 { |
| 603 errorEventSender().dispatchPendingEvents(); | 621 errorEventSender().dispatchPendingEvents(); |
| 604 } | 622 } |
| 605 | 623 |
| 606 void ImageLoader::elementDidMoveToNewDocument() | 624 void ImageLoader::elementDidMoveToNewDocument() |
| 607 { | 625 { |
| 608 if (m_loadDelayCounter) | 626 if (m_loadDelayCounter) |
| 609 m_loadDelayCounter->documentChanged(m_element->document()); | 627 m_loadDelayCounter->documentChanged(m_element->document()); |
| 610 clearFailedLoadURL(); | 628 clearFailedLoadURL(); |
| 611 setImage(0); | 629 setImage(0); |
| 612 } | 630 } |
| 613 | 631 |
| 614 } // namespace blink | 632 } // namespace blink |
| OLD | NEW |