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

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

Issue 1112513005: Reload image bypassing the cache (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: WebNode instead of WebPoint Created 5 years, 7 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // loader has been GCed, but not yet lazily swept & finalized 93 // loader has been GCed, but not yet lazily swept & finalized
94 // (when this task's loader reference will be cleared.) 94 // (when this task's loader reference will be cleared.)
95 // 95 //
96 // Handle this transient condition by explicitly checking here 96 // Handle this transient condition by explicitly checking here
97 // before going ahead with the update operation. Unsafe to do it 97 // before going ahead with the update operation. Unsafe to do it
98 // if so, as the objects that the loader refers to may have been 98 // if so, as the objects that the loader refers to may have been
99 // finalized by this time. 99 // finalized by this time.
100 if (Heap::willObjectBeLazilySwept(m_loader)) 100 if (Heap::willObjectBeLazilySwept(m_loader))
101 return; 101 return;
102 #endif 102 #endif
103 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior); 103 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior, false);
104 } 104 }
105 } 105 }
106 106
107 void clearLoader() 107 void clearLoader()
108 { 108 {
109 m_loader = 0; 109 m_loader = 0;
110 } 110 }
111 111
112 WeakPtr<Task> createWeakPtr() 112 WeakPtr<Task> createWeakPtr()
113 { 113 {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 231
232 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior updateBehavior) 232 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior updateBehavior)
233 { 233 {
234 OwnPtr<Task> task = Task::create(this, updateBehavior); 234 OwnPtr<Task> task = Task::create(this, updateBehavior);
235 m_pendingTask = task->createWeakPtr(); 235 m_pendingTask = task->createWeakPtr();
236 Microtask::enqueueMicrotask(task.release()); 236 Microtask::enqueueMicrotask(task.release());
237 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen t()); 237 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen t());
238 } 238 }
239 239
240 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up dateFromElementBehavior updateBehavior) 240 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up dateFromElementBehavior updateBehavior, bool bypassCache)
241 { 241 {
242 // FIXME: According to 242 // FIXME: According to
243 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont ent.html#the-img-element:the-img-element-55 243 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont ent.html#the-img-element:the-img-element-55
244 // When "update image" is called due to environment changes and the load fai ls, onerror should not be called. 244 // When "update image" is called due to environment changes and the load fai ls, onerror should not be called.
245 // That is currently not the case. 245 // That is currently not the case.
246 // 246 //
247 // We don't need to call clearLoader here: Either we were called from the 247 // We don't need to call clearLoader here: Either we were called from the
248 // task, or our caller updateFromElement cleared the task's loader (and set 248 // task, or our caller updateFromElement cleared the task's loader (and set
249 // m_pendingTask to null). 249 // m_pendingTask to null).
250 m_pendingTask.clear(); 250 m_pendingTask.clear();
251 // Make sure to only decrement the count when we exit this function 251 // Make sure to only decrement the count when we exit this function
252 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter; 252 OwnPtr<IncrementLoadEventDelayCount> loadDelayCounter;
253 loadDelayCounter.swap(m_loadDelayCounter); 253 loadDelayCounter.swap(m_loadDelayCounter);
254 254
255 Document& document = m_element->document(); 255 Document& document = m_element->document();
256 if (!document.isActive()) 256 if (!document.isActive())
257 return; 257 return;
258 258
259 AtomicString imageSourceURL = m_element->imageSourceURL(); 259 AtomicString imageSourceURL = m_element->imageSourceURL();
260 KURL url = imageSourceToKURL(imageSourceURL); 260 KURL url = imageSourceToKURL(imageSourceURL);
261 ResourcePtr<ImageResource> newImage = 0; 261 ResourcePtr<ImageResource> newImage = 0;
262 RefPtrWillBeRawPtr<Element> protectElement(m_element.get()); 262 RefPtrWillBeRawPtr<Element> protectElement(m_element.get());
263 if (!url.isNull()) { 263 if (!url.isNull()) {
264 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>. 264 // Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>.
265 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions(); 265 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe sourceOptions();
266 ResourceRequest resourceRequest(url); 266 ResourceRequest resourceRequest(url);
267 resourceRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsM odeSameOrigin); 267 resourceRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsM odeSameOrigin);
268 if (bypassCache)
269 resourceRequest.setCachePolicy(ResourceRequestCachePolicy::ReloadByp assingCache);
268 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull()) 270 if (isHTMLPictureElement(element()->parentNode()) || !element()->fastGet Attribute(HTMLNames::srcsetAttr).isNull())
269 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set); 271 resourceRequest.setRequestContext(WebURLRequest::RequestContextImage Set);
270 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions); 272 FetchRequest request(resourceRequest, element()->localName(), resourceLo aderOptions);
271 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences()); 273 configureRequest(request, bypassBehavior, *m_element, document.clientHin tsPreferences());
272 274
273 // Prevent the immediate creation of a ResourceLoader (and therefore a n etwork 275 // Prevent the immediate creation of a ResourceLoader (and therefore a n etwork
274 // request) for ImageDocument loads. In this case, the image contents ha ve already 276 // request) for ImageDocument loads. In this case, the image contents ha ve already
275 // been requested as a main resource and ImageDocumentParser will take c are of 277 // been requested as a main resource and ImageDocumentParser will take c are of
276 // funneling the main resource bytes into the ImageResource. 278 // funneling the main resource bytes into the ImageResource.
277 if (m_loadingImageDocument) { 279 if (m_loadingImageDocument) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 335 }
334 336
335 if (LayoutImageResource* imageResource = layoutImageResource()) 337 if (LayoutImageResource* imageResource = layoutImageResource())
336 imageResource->resetAnimation(); 338 imageResource->resetAnimation();
337 339
338 // Only consider updating the protection ref-count of the Element immediatel y before returning 340 // Only consider updating the protection ref-count of the Element immediatel y before returning
339 // from this function as doing so might result in the destruction of this Im ageLoader. 341 // from this function as doing so might result in the destruction of this Im ageLoader.
340 updatedHasPendingEvent(); 342 updatedHasPendingEvent();
341 } 343 }
342 344
343 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior) 345 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, bo ol bypassCache)
344 { 346 {
345 AtomicString imageSourceURL = m_element->imageSourceURL(); 347 AtomicString imageSourceURL = m_element->imageSourceURL();
346 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); 348 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged);
347 349
348 if (updateBehavior == UpdateIgnorePreviousError) 350 if (updateBehavior == UpdateIgnorePreviousError)
349 clearFailedLoadURL(); 351 clearFailedLoadURL();
350 352
351 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) 353 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL)
352 return; 354 return;
353 355
354 // If we have a pending task, we have to clear it -- either we're 356 // If we have a pending task, we have to clear it -- either we're
355 // now loading immediately, or we need to reset the task's state. 357 // now loading immediately, or we need to reset the task's state.
356 if (m_pendingTask) { 358 if (m_pendingTask) {
357 m_pendingTask->clearLoader(); 359 m_pendingTask->clearLoader();
358 m_pendingTask.clear(); 360 m_pendingTask.clear();
359 } 361 }
360 362
361 KURL url = imageSourceToKURL(imageSourceURL); 363 KURL url = imageSourceToKURL(imageSourceURL);
362 if (shouldLoadImmediately(url)) { 364 if (shouldLoadImmediately(url)) {
363 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); 365 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, bypassCache );
364 return; 366 return;
365 } 367 }
366 // Allow the idiom "img.src=''; img.src='.." to clear down the image before 368 // Allow the idiom "img.src=''; img.src='.." to clear down the image before
367 // an asynchronous load completes. 369 // an asynchronous load completes.
368 if (imageSourceURL.isEmpty()) { 370 if (imageSourceURL.isEmpty()) {
369 ImageResource* image = m_image.get(); 371 ImageResource* image = m_image.get();
370 if (image) 372 if (image)
371 image->removeClient(this); 373 image->removeClient(this);
372 m_image = nullptr; 374 m_image = nullptr;
373 } 375 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 #endif 614 #endif
613 } 615 }
614 616
615 #if ENABLE(OILPAN) 617 #if ENABLE(OILPAN)
616 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() 618 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
617 { 619 {
618 m_loader.willRemoveClient(m_client); 620 m_loader.willRemoveClient(m_client);
619 } 621 }
620 #endif 622 #endif
621 } 623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698