Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/Source/core/loader/ImageLoader.cpp

Issue 1879793003: Remove DeferredByClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Resource_load
Patch Set: Address yhirano's comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
yhirano 2016/04/22 04:12:13 Do we need to include this header?
Nate Chapin 2016/04/25 22:13:03 No, removed.
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 AtomicString imageSourceURL = m_element->imageSourceURL(); 276 AtomicString imageSourceURL = m_element->imageSourceURL();
276 KURL url = imageSourceToKURL(imageSourceURL); 277 KURL url = imageSourceToKURL(imageSourceURL);
277 ImageResource* newImage = nullptr; 278 ImageResource* newImage = nullptr;
278 if (!url.isNull()) { 279 if (!url.isNull()) {
279 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>. 280 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>.
280 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions(); 281 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions();
281 ResourceRequest resourceRequest(url); 282 ResourceRequest resourceRequest(url);
282 if (updateBehavior == UpdateForcedReload) { 283 if (updateBehavior == UpdateForcedReload) {
283 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); 284 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache);
284 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); 285 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 } 286 }
289 287
290 if (referrerPolicy != ReferrerPolicyDefault) 288 if (referrerPolicy != ReferrerPolicyDefault)
291 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref errerPolicy, url, document.outgoingReferrer())); 289 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(ref errerPolicy, url, document.outgoingReferrer()));
292 290
293 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull()) 291 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull())
294 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set); 292 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set);
295 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions); 293 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions);
296 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences()); 294 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences());
297 295
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()); 296 newImage = ImageResource::fetch(request, document.fetcher());
308 if (m_loadingImageDocument && newImage)
309 newImage->setStatus(Resource::Pending);
310 297
311 if (!newImage && !pageIsBeingDismissed(&document)) { 298 if (!newImage && !pageIsBeingDismissed(&document)) {
312 crossSiteOrCSPViolationOccurred(imageSourceURL); 299 crossSiteOrCSPViolationOccurred(imageSourceURL);
313 dispatchErrorEvent(); 300 dispatchErrorEvent();
314 } else { 301 } else {
315 clearFailedLoadURL(); 302 clearFailedLoadURL();
316 } 303 }
317 } else { 304 } else {
318 if (!imageSourceURL.isNull()) { 305 if (!imageSourceURL.isNull()) {
319 // Fire an error event if the url string is not empty, but the KURL is. 306 // 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
367 { 354 {
368 AtomicString imageSourceURL = m_element->imageSourceURL(); 355 AtomicString imageSourceURL = m_element->imageSourceURL();
369 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); 356 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged);
370 357
371 if (updateBehavior == UpdateIgnorePreviousError) 358 if (updateBehavior == UpdateIgnorePreviousError)
372 clearFailedLoadURL(); 359 clearFailedLoadURL();
373 360
374 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) 361 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL)
375 return; 362 return;
376 363
364 // Prevent the creation of a ResourceLoader (and therefore a network
365 // request) for ImageDocument loads. In this case, the image contents have a lready
366 // been requested as a main resource and ImageDocumentParser will take care of
367 // funneling the main resource bytes into m_image, so just create an ImageRe source
368 // to be populated later.
369 if (m_loadingImageDocument) {
370 setImage(ImageResource::create(imageSourceToKURL(m_element->imageSourceU RL())));
yhirano 2016/04/22 04:12:13 imageResource->setStatus(Pending) needed?
Nate Chapin 2016/04/25 22:13:03 "Need", not as the code currently works. But it's
371 return;
372 }
373
377 // If we have a pending task, we have to clear it -- either we're 374 // 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. 375 // now loading immediately, or we need to reset the task's state.
379 if (m_pendingTask) { 376 if (m_pendingTask) {
380 m_pendingTask->clearLoader(); 377 m_pendingTask->clearLoader();
381 m_pendingTask.clear(); 378 m_pendingTask.clear();
382 } 379 }
383 380
384 KURL url = imageSourceToKURL(imageSourceURL); 381 KURL url = imageSourceToKURL(imageSourceURL);
385 if (shouldLoadImmediately(url)) { 382 if (shouldLoadImmediately(url)) {
386 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy); 383 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 422
426 bool ImageLoader::shouldLoadImmediately(const KURL& url) const 423 bool ImageLoader::shouldLoadImmediately(const KURL& url) const
427 { 424 {
428 // We force any image loads which might require alt content through the asyn chronous path so that we can add the shadow DOM 425 // 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. 426 // for the alt-text content when style recalc is over and DOM mutation is al lowed again.
430 if (!url.isNull()) { 427 if (!url.isNull()) {
431 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum ent().fetcher()->getCacheIdentifier()); 428 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum ent().fetcher()->getCacheIdentifier());
432 if (resource && !resource->errorOccurred()) 429 if (resource && !resource->errorOccurred())
433 return true; 430 return true;
434 } 431 }
435 return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEm bedElement(m_element) || url.protocolIsData()); 432 return (isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element) || u rl.protocolIsData());
436 } 433 }
437 434
438 void ImageLoader::imageNotifyFinished(ImageResource* resource) 435 void ImageLoader::imageNotifyFinished(ImageResource* resource)
439 { 436 {
440 WTF_LOG(Timers, "ImageLoader::imageNotifyFinished %p; m_hasPendingLoadEvent= %d", 437 WTF_LOG(Timers, "ImageLoader::imageNotifyFinished %p; m_hasPendingLoadEvent= %d",
441 this, m_hasPendingLoadEvent); 438 this, m_hasPendingLoadEvent);
442 439
443 ASSERT(m_failedLoadURL.isEmpty()); 440 ASSERT(m_failedLoadURL.isEmpty());
444 ASSERT(resource == m_image.get()); 441 ASSERT(resource == m_image.get());
445 442
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 605
609 void ImageLoader::elementDidMoveToNewDocument() 606 void ImageLoader::elementDidMoveToNewDocument()
610 { 607 {
611 if (m_loadDelayCounter) 608 if (m_loadDelayCounter)
612 m_loadDelayCounter->documentChanged(m_element->document()); 609 m_loadDelayCounter->documentChanged(m_element->document());
613 clearFailedLoadURL(); 610 clearFailedLoadURL();
614 setImage(0); 611 setImage(0);
615 } 612 }
616 613
617 } // namespace blink 614 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698