| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "core/layout/svg/LayoutSVGImage.h" | 45 #include "core/layout/svg/LayoutSVGImage.h" |
| 46 #include "core/svg/graphics/SVGImage.h" | 46 #include "core/svg/graphics/SVGImage.h" |
| 47 #include "platform/Logging.h" | 47 #include "platform/Logging.h" |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "platform/weborigin/SecurityOrigin.h" | 49 #include "platform/weborigin/SecurityOrigin.h" |
| 50 #include "platform/weborigin/SecurityPolicy.h" | 50 #include "platform/weborigin/SecurityPolicy.h" |
| 51 #include "public/platform/WebURLRequest.h" | 51 #include "public/platform/WebURLRequest.h" |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 namespace { |
| 56 |
| 57 class ExtraDataContainer : public ResourceRequest::ExtraData { |
| 58 public: |
| 59 static PassRefPtr<ExtraDataContainer> create(WebURLRequest::ExtraData* extra
Data) { return adoptRef(new ExtraDataContainer(extraData)); } |
| 60 |
| 61 ~ExtraDataContainer() override {} |
| 62 |
| 63 WebURLRequest::ExtraData* extraData() const { return m_extraData.get(); } |
| 64 |
| 65 private: |
| 66 explicit ExtraDataContainer(WebURLRequest::ExtraData* extraData) |
| 67 : m_extraData(adoptPtr(extraData)) |
| 68 { |
| 69 } |
| 70 |
| 71 OwnPtr<WebURLRequest::ExtraData> m_extraData; |
| 72 }; |
| 73 |
| 74 } // namespace |
| 75 |
| 55 static ImageEventSender& loadEventSender() | 76 static ImageEventSender& loadEventSender() |
| 56 { | 77 { |
| 57 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::load)); | 78 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::load)); |
| 58 return sender; | 79 return sender; |
| 59 } | 80 } |
| 60 | 81 |
| 61 static ImageEventSender& errorEventSender() | 82 static ImageEventSender& errorEventSender() |
| 62 { | 83 { |
| 63 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::error)); | 84 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::error)); |
| 64 return sender; | 85 return sender; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ~Task() override | 126 ~Task() override |
| 106 { | 127 { |
| 107 } | 128 } |
| 108 | 129 |
| 109 void run() override | 130 void run() override |
| 110 { | 131 { |
| 111 if (!m_loader) | 132 if (!m_loader) |
| 112 return; | 133 return; |
| 113 if (m_scriptState->contextIsValid()) { | 134 if (m_scriptState->contextIsValid()) { |
| 114 ScriptState::Scope scope(m_scriptState.get()); | 135 ScriptState::Scope scope(m_scriptState.get()); |
| 115 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 136 m_loader->doUpdateFromElement(0, m_shouldBypassMainWorldCSP, m_updat
eBehavior, m_referrerPolicy); |
| 116 } else { | 137 } else { |
| 117 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 138 m_loader->doUpdateFromElement(0, m_shouldBypassMainWorldCSP, m_updat
eBehavior, m_referrerPolicy); |
| 118 } | 139 } |
| 119 } | 140 } |
| 120 | 141 |
| 121 void clearLoader() | 142 void clearLoader() |
| 122 { | 143 { |
| 123 m_loader = nullptr; | 144 m_loader = nullptr; |
| 124 m_scriptState.clear(); | 145 m_scriptState.clear(); |
| 125 } | 146 } |
| 126 | 147 |
| 127 WeakPtr<Task> createWeakPtr() | 148 WeakPtr<Task> createWeakPtr() |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 299 } |
| 279 | 300 |
| 280 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) | 301 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) |
| 281 { | 302 { |
| 282 OwnPtr<Task> task = Task::create(this, updateBehavior, referrerPolicy); | 303 OwnPtr<Task> task = Task::create(this, updateBehavior, referrerPolicy); |
| 283 m_pendingTask = task->createWeakPtr(); | 304 m_pendingTask = task->createWeakPtr(); |
| 284 Microtask::enqueueMicrotask(task.release()); | 305 Microtask::enqueueMicrotask(task.release()); |
| 285 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); | 306 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); |
| 286 } | 307 } |
| 287 | 308 |
| 288 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
dateFromElementBehavior updateBehavior, ReferrerPolicy referrerPolicy) | 309 void ImageLoader::doUpdateFromElement(WebURLRequest::ExtraData* extraData, Bypas
sMainWorldBehavior bypassBehavior, UpdateFromElementBehavior updateBehavior, Ref
errerPolicy referrerPolicy) |
| 289 { | 310 { |
| 290 // FIXME: According to | 311 // FIXME: According to |
| 291 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont
ent.html#the-img-element:the-img-element-55 | 312 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont
ent.html#the-img-element:the-img-element-55 |
| 292 // When "update image" is called due to environment changes and the load fai
ls, onerror should not be called. | 313 // When "update image" is called due to environment changes and the load fai
ls, onerror should not be called. |
| 293 // That is currently not the case. | 314 // That is currently not the case. |
| 294 // | 315 // |
| 295 // We don't need to call clearLoader here: Either we were called from the | 316 // We don't need to call clearLoader here: Either we were called from the |
| 296 // task, or our caller updateFromElement cleared the task's loader (and set | 317 // task, or our caller updateFromElement cleared the task's loader (and set |
| 297 // m_pendingTask to null). | 318 // m_pendingTask to null). |
| 298 m_pendingTask.clear(); | 319 m_pendingTask.clear(); |
| 299 // Make sure to only decrement the count when we exit this function | 320 // Make sure to only decrement the count when we exit this function |
| 300 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter; | 321 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter; |
| 301 loadDelayCounter.swap(m_loadDelayCounter); | 322 loadDelayCounter.swap(m_loadDelayCounter); |
| 302 | 323 |
| 303 Document& document = m_element->document(); | 324 Document& document = m_element->document(); |
| 304 if (!document.isActive()) | 325 if (!document.isActive()) |
| 305 return; | 326 return; |
| 306 | 327 |
| 307 AtomicString imageSourceURL = m_element->imageSourceURL(); | 328 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 308 KURL url = imageSourceToKURL(imageSourceURL); | 329 KURL url = imageSourceToKURL(imageSourceURL); |
| 309 ResourcePtr<ImageResource> newImage = 0; | 330 ResourcePtr<ImageResource> newImage = 0; |
| 310 RefPtrWillBeRawPtr<Element> protectElement(m_element.get()); | 331 RefPtrWillBeRawPtr<Element> protectElement(m_element.get()); |
| 311 if (!url.isNull()) { | 332 if (!url.isNull()) { |
| 312 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. | 333 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. |
| 313 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); | 334 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); |
| 314 ResourceRequest resourceRequest(url); | 335 ResourceRequest resourceRequest(url); |
| 315 resourceRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsM
odeSameOrigin); | 336 resourceRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsM
odeSameOrigin); |
| 316 if (updateBehavior == UpdateForcedReload) { | 337 if (updateBehavior == UpdateForcedReload) { |
| 317 resourceRequest.setCachePolicy(ResourceRequestCachePolicy::ReloadByp
assingCache); | |
| 318 // ImageLoader defers the load of images when in an ImageDocument. D
on't defer this load on a forced reload. | 338 // ImageLoader defers the load of images when in an ImageDocument. D
on't defer this load on a forced reload. |
| 319 m_loadingImageDocument = false; | 339 m_loadingImageDocument = false; |
| 320 } | 340 } |
| 321 | 341 |
| 342 if (extraData) |
| 343 resourceRequest.setExtraData(ExtraDataContainer::create(extraData)); |
| 344 |
| 322 if (RuntimeEnabledFeatures::referrerPolicyAttributeEnabled() && referrer
Policy != ReferrerPolicyDefault) | 345 if (RuntimeEnabledFeatures::referrerPolicyAttributeEnabled() && referrer
Policy != ReferrerPolicyDefault) |
| 323 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref
errerPolicy, url, document.outgoingReferrer())); | 346 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref
errerPolicy, url, document.outgoingReferrer())); |
| 324 | 347 |
| 325 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet
Attribute(HTMLNames::srcsetAttr).isNull()) | 348 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet
Attribute(HTMLNames::srcsetAttr).isNull()) |
| 326 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage
Set); | 349 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage
Set); |
| 327 FetchRequest request(resourceRequest, element()->localName(), resourceLo
aderOptions); | 350 FetchRequest request(resourceRequest, element()->localName(), resourceLo
aderOptions); |
| 328 configureRequest(request, bypassBehavior, *m_element, document.clientHin
tsPreferences()); | 351 configureRequest(request, bypassBehavior, *m_element, document.clientHin
tsPreferences()); |
| 329 | 352 |
| 330 // Prevent the immediate creation of a ResourceLoader (and therefore a n
etwork | 353 // Prevent the immediate creation of a ResourceLoader (and therefore a n
etwork |
| 331 // request) for ImageDocument loads. In this case, the image contents ha
ve already | 354 // request) for ImageDocument loads. In this case, the image contents ha
ve already |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 413 } |
| 391 | 414 |
| 392 if (LayoutImageResource* imageResource = layoutImageResource()) | 415 if (LayoutImageResource* imageResource = layoutImageResource()) |
| 393 imageResource->resetAnimation(); | 416 imageResource->resetAnimation(); |
| 394 | 417 |
| 395 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 418 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
| 396 // from this function as doing so might result in the destruction of this Im
ageLoader. | 419 // from this function as doing so might result in the destruction of this Im
ageLoader. |
| 397 updatedHasPendingEvent(); | 420 updatedHasPendingEvent(); |
| 398 } | 421 } |
| 399 | 422 |
| 400 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Re
ferrerPolicy referrerPolicy) | 423 void ImageLoader::updateFromElement(WebURLRequest::ExtraData* extraData, UpdateF
romElementBehavior updateBehavior, ReferrerPolicy referrerPolicy) |
| 401 { | 424 { |
| 402 AtomicString imageSourceURL = m_element->imageSourceURL(); | 425 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 403 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); | 426 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); |
| 404 | 427 |
| 405 if (updateBehavior == UpdateIgnorePreviousError) | 428 if (updateBehavior == UpdateIgnorePreviousError) |
| 406 clearFailedLoadURL(); | 429 clearFailedLoadURL(); |
| 407 | 430 |
| 408 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 431 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 409 return; | 432 return; |
| 410 | 433 |
| 411 // If we have a pending task, we have to clear it -- either we're | 434 // If we have a pending task, we have to clear it -- either we're |
| 412 // now loading immediately, or we need to reset the task's state. | 435 // now loading immediately, or we need to reset the task's state. |
| 413 if (m_pendingTask) { | 436 if (m_pendingTask) { |
| 414 m_pendingTask->clearLoader(); | 437 m_pendingTask->clearLoader(); |
| 415 m_pendingTask.clear(); | 438 m_pendingTask.clear(); |
| 416 } | 439 } |
| 417 | 440 |
| 418 KURL url = imageSourceToKURL(imageSourceURL); | 441 KURL url = imageSourceToKURL(imageSourceURL); |
| 419 if (shouldLoadImmediately(url)) { | 442 if (shouldLoadImmediately(url)) { |
| 420 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol
icy); | 443 doUpdateFromElement(extraData, DoNotBypassMainWorldCSP, updateBehavior,
referrerPolicy); |
| 421 return; | 444 return; |
| 422 } | 445 } |
| 423 // Allow the idiom "img.src=''; img.src='.." to clear down the image before | 446 // Allow the idiom "img.src=''; img.src='.." to clear down the image before |
| 424 // an asynchronous load completes. | 447 // an asynchronous load completes. |
| 425 if (imageSourceURL.isEmpty()) { | 448 if (imageSourceURL.isEmpty()) { |
| 426 ImageResource* image = m_image.get(); | 449 ImageResource* image = m_image.get(); |
| 427 if (image) | 450 if (image) |
| 428 image->removeClient(this); | 451 image->removeClient(this); |
| 429 m_image = nullptr; | 452 m_image = nullptr; |
| 430 } | 453 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 697 |
| 675 void ImageLoader::sourceImageChanged() | 698 void ImageLoader::sourceImageChanged() |
| 676 { | 699 { |
| 677 for (auto& client : m_clients) { | 700 for (auto& client : m_clients) { |
| 678 ImageLoaderClient* handle = client; | 701 ImageLoaderClient* handle = client; |
| 679 handle->notifyImageSourceChanged(); | 702 handle->notifyImageSourceChanged(); |
| 680 } | 703 } |
| 681 } | 704 } |
| 682 | 705 |
| 683 } // namespace blink | 706 } // namespace blink |
| OLD | NEW |