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 21 matching lines...) Expand all Loading... | |
| 32 #include "core/events/Event.h" | 32 #include "core/events/Event.h" |
| 33 #include "core/events/EventSender.h" | 33 #include "core/events/EventSender.h" |
| 34 #include "core/fetch/FetchRequest.h" | 34 #include "core/fetch/FetchRequest.h" |
| 35 #include "core/fetch/MemoryCache.h" | 35 #include "core/fetch/MemoryCache.h" |
| 36 #include "core/fetch/ResourceFetcher.h" | 36 #include "core/fetch/ResourceFetcher.h" |
| 37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
| 39 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 40 #include "core/html/CrossOriginAttribute.h" | 40 #include "core/html/CrossOriginAttribute.h" |
| 41 #include "core/html/HTMLImageElement.h" | 41 #include "core/html/HTMLImageElement.h" |
| 42 #include "core/html/ImageDocument.h" | |
| 42 #include "core/html/parser/HTMLParserIdioms.h" | 43 #include "core/html/parser/HTMLParserIdioms.h" |
| 43 #include "core/inspector/InspectorInstrumentation.h" | 44 #include "core/inspector/InspectorInstrumentation.h" |
| 44 #include "core/layout/LayoutImage.h" | 45 #include "core/layout/LayoutImage.h" |
| 45 #include "core/layout/LayoutVideo.h" | 46 #include "core/layout/LayoutVideo.h" |
| 46 #include "core/layout/svg/LayoutSVGImage.h" | 47 #include "core/layout/svg/LayoutSVGImage.h" |
| 47 #include "core/svg/graphics/SVGImage.h" | 48 #include "core/svg/graphics/SVGImage.h" |
| 48 #include "platform/Logging.h" | 49 #include "platform/Logging.h" |
| 49 #include "platform/weborigin/SecurityOrigin.h" | 50 #include "platform/weborigin/SecurityOrigin.h" |
| 50 #include "platform/weborigin/SecurityPolicy.h" | 51 #include "platform/weborigin/SecurityPolicy.h" |
| 51 #include "public/platform/WebCachePolicy.h" | 52 #include "public/platform/WebCachePolicy.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 WeakPtrFactory<Task> m_weakFactory; | 145 WeakPtrFactory<Task> m_weakFactory; |
| 145 ReferrerPolicy m_referrerPolicy; | 146 ReferrerPolicy m_referrerPolicy; |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 ImageLoader::ImageLoader(Element* element) | 149 ImageLoader::ImageLoader(Element* element) |
| 149 : m_element(element) | 150 : m_element(element) |
| 150 , m_derefElementTimer(this, &ImageLoader::timerFired) | 151 , m_derefElementTimer(this, &ImageLoader::timerFired) |
| 151 , m_hasPendingLoadEvent(false) | 152 , m_hasPendingLoadEvent(false) |
| 152 , m_hasPendingErrorEvent(false) | 153 , m_hasPendingErrorEvent(false) |
| 153 , m_imageComplete(true) | 154 , m_imageComplete(true) |
| 154 , m_loadingImageDocument(false) | |
|
yhirano
2016/04/20 08:42:41
Can you tell me why you deleted this statement?
Nate Chapin
2016/04/21 18:52:46
It's a mistake. My first pass deleted this variabl
| |
| 155 , m_elementIsProtected(false) | 155 , m_elementIsProtected(false) |
| 156 , m_suppressErrorEvents(false) | 156 , m_suppressErrorEvents(false) |
| 157 { | 157 { |
| 158 WTF_LOG(Timers, "new ImageLoader %p", this); | 158 WTF_LOG(Timers, "new ImageLoader %p", this); |
| 159 ThreadState::current()->registerPreFinalizer(this); | 159 ThreadState::current()->registerPreFinalizer(this); |
| 160 } | 160 } |
| 161 | 161 |
| 162 ImageLoader::~ImageLoader() | 162 ImageLoader::~ImageLoader() |
| 163 { | 163 { |
| 164 } | 164 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 AtomicString imageSourceURL = m_element->imageSourceURL(); | 275 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 276 KURL url = imageSourceToKURL(imageSourceURL); | 276 KURL url = imageSourceToKURL(imageSourceURL); |
| 277 ImageResource* newImage = nullptr; | 277 ImageResource* newImage = nullptr; |
| 278 if (!url.isNull()) { | 278 if (!url.isNull()) { |
| 279 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>. | 279 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>. |
| 280 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions(); | 280 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions(); |
| 281 ResourceRequest resourceRequest(url); | 281 ResourceRequest resourceRequest(url); |
| 282 if (updateBehavior == UpdateForcedReload) { | 282 if (updateBehavior == UpdateForcedReload) { |
| 283 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 283 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
| 284 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 284 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
| 285 // ImageLoader defers the load of images when in an ImageDocument. | |
| 286 // Don't defer this load on a forced reload. | |
| 287 m_loadingImageDocument = false; | |
| 288 } | 285 } |
| 289 | 286 |
| 290 if (referrerPolicy != ReferrerPolicyDefault) | 287 if (referrerPolicy != ReferrerPolicyDefault) |
| 291 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref errerPolicy, url, document.outgoingReferrer())); | 288 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref errerPolicy, url, document.outgoingReferrer())); |
| 292 | 289 |
| 293 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull()) | 290 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull()) |
| 294 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set); | 291 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set); |
| 295 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions); | 292 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions); |
| 296 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences()); | 293 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences()); |
| 297 | 294 |
| 298 // Prevent the immediate creation of a ResourceLoader (and therefore a n etwork | |
| 299 // request) for ImageDocument loads. In this case, the image contents ha ve already | |
| 300 // been requested as a main resource and ImageDocumentParser will take c are of | |
| 301 // funneling the main resource bytes into the ImageResource. | |
| 302 if (m_loadingImageDocument) { | |
| 303 request.setDefer(FetchRequest::DeferredByClient); | |
| 304 request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy); | |
| 305 } | |
| 306 | |
| 307 newImage = ImageResource::fetch(request, document.fetcher()); | 295 newImage = ImageResource::fetch(request, document.fetcher()); |
| 308 if (m_loadingImageDocument && newImage) | |
| 309 newImage->setStatus(Resource::Pending); | |
| 310 | 296 |
| 311 if (!newImage && !pageIsBeingDismissed(&document)) { | 297 if (!newImage && !pageIsBeingDismissed(&document)) { |
| 312 crossSiteOrCSPViolationOccurred(imageSourceURL); | 298 crossSiteOrCSPViolationOccurred(imageSourceURL); |
| 313 dispatchErrorEvent(); | 299 dispatchErrorEvent(); |
| 314 } else { | 300 } else { |
| 315 clearFailedLoadURL(); | 301 clearFailedLoadURL(); |
| 316 } | 302 } |
| 317 } else { | 303 } else { |
| 318 if (!imageSourceURL.isNull()) { | 304 if (!imageSourceURL.isNull()) { |
| 319 // Fire an error event if the url string is not empty, but the KURL is. | 305 // Fire an error event if the url string is not empty, but the KURL is. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 { | 353 { |
| 368 AtomicString imageSourceURL = m_element->imageSourceURL(); | 354 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 369 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); | 355 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); |
| 370 | 356 |
| 371 if (updateBehavior == UpdateIgnorePreviousError) | 357 if (updateBehavior == UpdateIgnorePreviousError) |
| 372 clearFailedLoadURL(); | 358 clearFailedLoadURL(); |
| 373 | 359 |
| 374 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) | 360 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) |
| 375 return; | 361 return; |
| 376 | 362 |
| 363 // Prevent the creation of a ResourceLoader (and therefore a network | |
| 364 // 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 | |
| 366 // funneling the main resource bytes into m_image, so just create an ImageRe source | |
| 367 // to be populated later. | |
| 368 if (m_loadingImageDocument) { | |
| 369 setImage(ImageResource::create(imageSourceToKURL(m_element->imageSourceU RL()))); | |
|
yhirano
2016/04/20 08:42:41
ImageResource::create(const ResourceRequest&) is e
Nate Chapin
2016/04/21 18:52:46
It's safe to use, it's mostly a question of whethe
| |
| 370 return; | |
| 371 } | |
| 372 | |
| 377 // If we have a pending task, we have to clear it -- either we're | 373 // If we have a pending task, we have to clear it -- either we're |
| 378 // now loading immediately, or we need to reset the task's state. | 374 // now loading immediately, or we need to reset the task's state. |
| 379 if (m_pendingTask) { | 375 if (m_pendingTask) { |
| 380 m_pendingTask->clearLoader(); | 376 m_pendingTask->clearLoader(); |
| 381 m_pendingTask.clear(); | 377 m_pendingTask.clear(); |
| 382 } | 378 } |
| 383 | 379 |
| 384 KURL url = imageSourceToKURL(imageSourceURL); | 380 KURL url = imageSourceToKURL(imageSourceURL); |
| 385 if (shouldLoadImmediately(url)) { | 381 if (shouldLoadImmediately(url)) { |
| 386 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy); | 382 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 | 421 |
| 426 bool ImageLoader::shouldLoadImmediately(const KURL& url) const | 422 bool ImageLoader::shouldLoadImmediately(const KURL& url) const |
| 427 { | 423 { |
| 428 // We force any image loads which might require alt content through the asyn chronous path so that we can add the shadow DOM | 424 // We force any image loads which might require alt content through the asyn chronous path so that we can add the shadow DOM |
| 429 // for the alt-text content when style recalc is over and DOM mutation is al lowed again. | 425 // for the alt-text content when style recalc is over and DOM mutation is al lowed again. |
| 430 if (!url.isNull()) { | 426 if (!url.isNull()) { |
| 431 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum ent().fetcher()->getCacheIdentifier()); | 427 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum ent().fetcher()->getCacheIdentifier()); |
| 432 if (resource && !resource->errorOccurred()) | 428 if (resource && !resource->errorOccurred()) |
| 433 return true; | 429 return true; |
| 434 } | 430 } |
| 435 return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEm bedElement(m_element) || url.protocolIsData()); | 431 return (isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element) || u rl.protocolIsData()); |
| 436 } | 432 } |
| 437 | 433 |
| 438 void ImageLoader::imageNotifyFinished(ImageResource* resource) | 434 void ImageLoader::imageNotifyFinished(ImageResource* resource) |
| 439 { | 435 { |
| 440 WTF_LOG(Timers, "ImageLoader::imageNotifyFinished %p; m_hasPendingLoadEvent= %d", | 436 WTF_LOG(Timers, "ImageLoader::imageNotifyFinished %p; m_hasPendingLoadEvent= %d", |
| 441 this, m_hasPendingLoadEvent); | 437 this, m_hasPendingLoadEvent); |
| 442 | 438 |
| 443 ASSERT(m_failedLoadURL.isEmpty()); | 439 ASSERT(m_failedLoadURL.isEmpty()); |
| 444 ASSERT(resource == m_image.get()); | 440 ASSERT(resource == m_image.get()); |
| 445 | 441 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 | 604 |
| 609 void ImageLoader::elementDidMoveToNewDocument() | 605 void ImageLoader::elementDidMoveToNewDocument() |
| 610 { | 606 { |
| 611 if (m_loadDelayCounter) | 607 if (m_loadDelayCounter) |
| 612 m_loadDelayCounter->documentChanged(m_element->document()); | 608 m_loadDelayCounter->documentChanged(m_element->document()); |
| 613 clearFailedLoadURL(); | 609 clearFailedLoadURL(); |
| 614 setImage(0); | 610 setImage(0); |
| 615 } | 611 } |
| 616 | 612 |
| 617 } // namespace blink | 613 } // namespace blink |
| OLD | NEW |