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

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

Issue 2278953002: Revert of Fix ImageLoader::m_hasPendingLoadEvent/m_imageComplete in ImageDocument (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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/loader/ImageLoader.h ('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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 210 }
211 if (oldImage) { 211 if (oldImage) {
212 oldImage->removeObserver(this); 212 oldImage->removeObserver(this);
213 } 213 }
214 } 214 }
215 215
216 if (LayoutImageResource* imageResource = layoutImageResource()) 216 if (LayoutImageResource* imageResource = layoutImageResource())
217 imageResource->resetAnimation(); 217 imageResource->resetAnimation();
218 } 218 }
219 219
220 void ImageLoader::setImagePending(ImageResource* newImage)
221 {
222 ImageResource* oldImage = m_image.get();
223 if (m_hasPendingLoadEvent) {
224 loadEventSender().cancelEvent(this);
225 m_hasPendingLoadEvent = false;
226 }
227
228 // Cancel error events that belong to the previous load, which is now cancel led by changing the src attribute.
229 // If newImage is null and m_hasPendingErrorEvent is true, we know the error event has been just posted by
230 // this load and we should not cancel the event.
231 // FIXME: If both previous load and this one got blocked with an error, we c an receive one error event instead of two.
232 if (m_hasPendingErrorEvent && newImage) {
233 errorEventSender().cancelEvent(this);
234 m_hasPendingErrorEvent = false;
235 }
236
237 m_image = newImage;
238 m_hasPendingLoadEvent = newImage;
239 m_imageComplete = !newImage;
240
241 updateLayoutObject();
242 // If newImage exists and is cached, addObserver() will result in the load e vent
243 // being queued to fire. Ensure this happens after beforeload is dispatched.
244 if (newImage) {
245 newImage->addObserver(this);
246 }
247 if (oldImage) {
248 oldImage->removeObserver(this);
249 }
250 }
251
252 static void configureRequest(FetchRequest& request, ImageLoader::BypassMainWorld Behavior bypassBehavior, Element& element, const ClientHintsPreferences& clientH intsPreferences) 220 static void configureRequest(FetchRequest& request, ImageLoader::BypassMainWorld Behavior bypassBehavior, Element& element, const ClientHintsPreferences& clientH intsPreferences)
253 { 221 {
254 if (bypassBehavior == ImageLoader::BypassMainWorldCSP) 222 if (bypassBehavior == ImageLoader::BypassMainWorldCSP)
255 request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy); 223 request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy);
256 224
257 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(element.fa stGetAttribute(HTMLNames::crossoriginAttr)); 225 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(element.fa stGetAttribute(HTMLNames::crossoriginAttr));
258 if (crossOrigin != CrossOriginAttributeNotSet) 226 if (crossOrigin != CrossOriginAttributeNotSet)
259 request.setCrossOriginAccessControl(element.document().getSecurityOrigin (), crossOrigin); 227 request.setCrossOriginAccessControl(element.document().getSecurityOrigin (), crossOrigin);
260 228
261 if (clientHintsPreferences.shouldSendResourceWidth() && isHTMLImageElement(e lement)) 229 if (clientHintsPreferences.shouldSendResourceWidth() && isHTMLImageElement(e lement))
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // 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.
338 dispatchErrorEvent(); 306 dispatchErrorEvent();
339 } 307 }
340 noImageResourceToLoad(); 308 noImageResourceToLoad();
341 } 309 }
342 310
343 ImageResource* oldImage = m_image.get(); 311 ImageResource* oldImage = m_image.get();
344 if (updateBehavior == UpdateSizeChanged && m_element->layoutObject() && m_el ement->layoutObject()->isImage() && newImage == oldImage) { 312 if (updateBehavior == UpdateSizeChanged && m_element->layoutObject() && m_el ement->layoutObject()->isImage() && newImage == oldImage) {
345 toLayoutImage(m_element->layoutObject())->intrinsicSizeChanged(); 313 toLayoutImage(m_element->layoutObject())->intrinsicSizeChanged();
346 } else { 314 } else {
347 setImagePending(newImage); 315 if (m_hasPendingLoadEvent) {
316 loadEventSender().cancelEvent(this);
317 m_hasPendingLoadEvent = false;
318 }
319
320 // 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
322 // 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.
324 if (m_hasPendingErrorEvent && newImage) {
325 errorEventSender().cancelEvent(this);
326 m_hasPendingErrorEvent = false;
327 }
328
329 m_image = newImage;
330 m_hasPendingLoadEvent = newImage;
331 m_imageComplete = !newImage;
332
333 updateLayoutObject();
334 // 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.
336 if (newImage) {
337 newImage->addObserver(this);
338 }
339 if (oldImage) {
340 oldImage->removeObserver(this);
341 }
348 } 342 }
349 343
350 if (LayoutImageResource* imageResource = layoutImageResource()) 344 if (LayoutImageResource* imageResource = layoutImageResource())
351 imageResource->resetAnimation(); 345 imageResource->resetAnimation();
352 346
353 // Only consider updating the protection ref-count of the Element immediatel y before returning 347 // Only consider updating the protection ref-count of the Element immediatel y before returning
354 // from this function as doing so might result in the destruction of this Im ageLoader. 348 // from this function as doing so might result in the destruction of this Im ageLoader.
355 updatedHasPendingEvent(); 349 updatedHasPendingEvent();
356 } 350 }
357 351
358 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Re ferrerPolicy referrerPolicy) 352 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Re ferrerPolicy referrerPolicy)
359 { 353 {
360 AtomicString imageSourceURL = m_element->imageSourceURL(); 354 AtomicString imageSourceURL = m_element->imageSourceURL();
361 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); 355 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged);
362 356
363 if (updateBehavior == UpdateIgnorePreviousError) 357 if (updateBehavior == UpdateIgnorePreviousError)
364 clearFailedLoadURL(); 358 clearFailedLoadURL();
365 359
366 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) 360 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL)
367 return; 361 return;
368 362
369 // Prevent the creation of a ResourceLoader (and therefore a network 363 // Prevent the creation of a ResourceLoader (and therefore a network
370 // request) for ImageDocument loads. In this case, the image contents have a lready 364 // request) for ImageDocument loads. In this case, the image contents have a lready
371 // been requested as a main resource and ImageDocumentParser will take care of 365 // been requested as a main resource and ImageDocumentParser will take care of
372 // funneling the main resource bytes into m_image, so just create an ImageRe source 366 // funneling the main resource bytes into m_image, so just create an ImageRe source
373 // to be populated later. 367 // to be populated later.
374 if (m_loadingImageDocument && updateBehavior != UpdateForcedReload) { 368 if (m_loadingImageDocument && updateBehavior != UpdateForcedReload) {
375 setImagePending(ImageResource::create(imageSourceToKURL(m_element->image SourceURL()))); 369 setImage(ImageResource::create(imageSourceToKURL(m_element->imageSourceU RL())));
376 m_image->setStatus(Resource::Pending); 370 m_image->setStatus(Resource::Pending);
377 // Only consider updating the protection ref-count of the Element immedi ately before returning
378 // from this function as doing so might result in the destruction of thi s ImageLoader.
379 updatedHasPendingEvent();
380 return; 371 return;
381 } 372 }
382 373
383 // 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
384 // 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.
385 if (m_pendingTask) { 376 if (m_pendingTask) {
386 m_pendingTask->clearLoader(); 377 m_pendingTask->clearLoader();
387 m_pendingTask.clear(); 378 m_pendingTask.clear();
388 } 379 }
389 380
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 605
615 void ImageLoader::elementDidMoveToNewDocument() 606 void ImageLoader::elementDidMoveToNewDocument()
616 { 607 {
617 if (m_loadDelayCounter) 608 if (m_loadDelayCounter)
618 m_loadDelayCounter->documentChanged(m_element->document()); 609 m_loadDelayCounter->documentChanged(m_element->document());
619 clearFailedLoadURL(); 610 clearFailedLoadURL();
620 setImage(0); 611 setImage(0);
621 } 612 }
622 613
623 } // namespace blink 614 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/ImageLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698