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

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

Issue 757583002: Revert of Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/paint/ImagePainter.cpp » ('j') | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 static inline bool pageIsBeingDismissed(Document* document) 60 static inline bool pageIsBeingDismissed(Document* document)
61 { 61 {
62 return document->pageDismissalEventBeingDispatched() != Document::NoDismissa l; 62 return document->pageDismissalEventBeingDispatched() != Document::NoDismissa l;
63 } 63 }
64 64
65 static ImageLoader::BypassMainWorldBehavior shouldBypassMainWorldCSP(ImageLoader * loader) 65 static ImageLoader::BypassMainWorldBehavior shouldBypassMainWorldCSP(ImageLoader * loader)
66 { 66 {
67 ASSERT(loader); 67 ASSERT(loader);
68 ASSERT(loader->element()); 68 ASSERT(loader->element());
69 if (loader->element()->document().frame() && loader->element()->document().f rame()->script().shouldBypassMainWorldCSP()) 69 ASSERT(loader->element()->document().frame());
70 if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP ())
70 return ImageLoader::BypassMainWorldCSP; 71 return ImageLoader::BypassMainWorldCSP;
71 return ImageLoader::DoNotBypassMainWorldCSP; 72 return ImageLoader::DoNotBypassMainWorldCSP;
72 } 73 }
73 74
74 class ImageLoader::Task : public blink::WebThread::Task { 75 class ImageLoader::Task : public blink::WebThread::Task {
75 public: 76 public:
76 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio r updateBehavior) 77 static PassOwnPtr<Task> create(ImageLoader* loader, UpdateFromElementBehavio r updateBehavior)
77 { 78 {
78 return adoptPtr(new Task(loader, updateBehavior)); 79 return adoptPtr(new Task(loader, updateBehavior));
79 } 80 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 263
263 if (m_loadingImageDocument) 264 if (m_loadingImageDocument)
264 newImage = createImageResourceForImageDocument(document, request); 265 newImage = createImageResourceForImageDocument(document, request);
265 else 266 else
266 newImage = document.fetcher()->fetchImage(request); 267 newImage = document.fetcher()->fetchImage(request);
267 268
268 if (!newImage && !pageIsBeingDismissed(&document)) 269 if (!newImage && !pageIsBeingDismissed(&document))
269 crossSiteOrCSPViolationOccured(imageSourceURL); 270 crossSiteOrCSPViolationOccured(imageSourceURL);
270 else 271 else
271 clearFailedLoadURL(); 272 clearFailedLoadURL();
272 } else { 273 } else if (!imageSourceURL.isNull()) {
273 if (!imageSourceURL.isNull()) { 274 // Fire an error event if the url string is not empty, but the KURL is.
274 // Fire an error event if the url string is not empty, but the KURL is. 275 m_hasPendingErrorEvent = true;
275 m_hasPendingErrorEvent = true; 276 errorEventSender().dispatchEventSoon(this);
276 errorEventSender().dispatchEventSoon(this);
277 }
278 noImageResourceToLoad();
279 } 277 }
280 278
281 ImageResource* oldImage = m_image.get(); 279 ImageResource* oldImage = m_image.get();
282 if (newImage != oldImage) { 280 if (newImage != oldImage) {
283 sourceImageChanged(); 281 sourceImageChanged();
284 282
285 if (m_hasPendingLoadEvent) { 283 if (m_hasPendingLoadEvent) {
286 loadEventSender().cancelEvent(this); 284 loadEventSender().cancelEvent(this);
287 m_hasPendingLoadEvent = false; 285 m_hasPendingLoadEvent = false;
288 } 286 }
(...skipping 24 matching lines...) Expand all
313 } 311 }
314 312
315 if (RenderImageResource* imageResource = renderImageResource()) 313 if (RenderImageResource* imageResource = renderImageResource())
316 imageResource->resetAnimation(); 314 imageResource->resetAnimation();
317 315
318 // Only consider updating the protection ref-count of the Element immediatel y before returning 316 // Only consider updating the protection ref-count of the Element immediatel y before returning
319 // from this function as doing so might result in the destruction of this Im ageLoader. 317 // from this function as doing so might result in the destruction of this Im ageLoader.
320 updatedHasPendingEvent(); 318 updatedHasPendingEvent();
321 } 319 }
322 320
323 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior) 321 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo adType loadType)
324 { 322 {
325 AtomicString imageSourceURL = m_element->imageSourceURL(); 323 AtomicString imageSourceURL = m_element->imageSourceURL();
326 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged); 324 m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged);
327 325
328 if (updateBehavior == UpdateIgnorePreviousError) 326 if (updateBehavior == UpdateIgnorePreviousError)
329 clearFailedLoadURL(); 327 clearFailedLoadURL();
330 328
331 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL) 329 if (!m_failedLoadURL.isEmpty() && imageSourceURL == m_failedLoadURL)
332 return; 330 return;
333 331
334 // If we have a pending task, we have to clear it -- either we're 332 // If we have a pending task, we have to clear it -- either we're
335 // now loading immediately, or we need to reset the task's state. 333 // now loading immediately, or we need to reset the task's state.
336 if (m_pendingTask) { 334 if (m_pendingTask) {
337 m_pendingTask->clearLoader(); 335 m_pendingTask->clearLoader();
338 m_pendingTask.clear(); 336 m_pendingTask.clear();
339 } 337 }
340 338
341 KURL url = imageSourceToKURL(imageSourceURL); 339 KURL url = imageSourceToKURL(imageSourceURL);
342 if (shouldLoadImmediately(url)) { 340 if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, lo adType)) {
343 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior); 341 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior);
344 return; 342 return;
345 } 343 }
346 enqueueImageLoadingMicroTask(updateBehavior); 344 enqueueImageLoadingMicroTask(updateBehavior);
347 } 345 }
348 346
349 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const 347 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const
350 { 348 {
351 KURL url; 349 KURL url;
352 350
353 // Don't load images for inactive documents. We don't want to slow down the 351 // Don't load images for inactive documents. We don't want to slow down the
354 // raw HTML parsing case by loading images we don't intend to display. 352 // raw HTML parsing case by loading images we don't intend to display.
355 Document& document = m_element->document(); 353 Document& document = m_element->document();
356 if (!document.isActive()) 354 if (!document.isActive())
357 return url; 355 return url;
358 356
359 // Do not load any image if the 'src' attribute is missing or if it is 357 // Do not load any image if the 'src' attribute is missing or if it is
360 // an empty string. 358 // an empty string.
361 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour ceURL).isEmpty()) 359 if (!imageSourceURL.isNull() && !stripLeadingAndTrailingHTMLSpaces(imageSour ceURL).isEmpty())
362 url = document.completeURL(sourceURI(imageSourceURL)); 360 url = document.completeURL(sourceURI(imageSourceURL));
363 return url; 361 return url;
364 } 362 }
365 363
366 bool ImageLoader::shouldLoadImmediately(const KURL& url) const 364 bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) cons t
367 { 365 {
368 // We force any image loads which might require alt content through the asyn chronous path so that we can add the shadow DOM 366 return (m_loadingImageDocument
369 // for the alt-text content when style recalc is over and DOM mutation is al lowed again. 367 || isHTMLObjectElement(m_element)
370 if (!url.isNull()) { 368 || isHTMLEmbedElement(m_element)
371 Resource* resource = memoryCache()->resourceForURL(url, m_element->docum ent().fetcher()->getCacheIdentifier()); 369 || url.protocolIsData()
372 if (resource && !resource->errorOccurred()) 370 || memoryCache()->resourceForURL(url, m_element->document().fetcher()->g etCacheIdentifier())
373 return true; 371 || loadType == ForceLoadImmediately);
374 }
375 return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEm bedElement(m_element) || url.protocolIsData());
376 } 372 }
377 373
378 void ImageLoader::notifyFinished(Resource* resource) 374 void ImageLoader::notifyFinished(Resource* resource)
379 { 375 {
380 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d", 376 WTF_LOG(Timers, "ImageLoader::notifyFinished %p; m_hasPendingLoadEvent=%d",
381 this, m_hasPendingLoadEvent); 377 this, m_hasPendingLoadEvent);
382 378
383 ASSERT(m_failedLoadURL.isEmpty()); 379 ASSERT(m_failedLoadURL.isEmpty());
384 ASSERT(resource == m_image.get()); 380 ASSERT(resource == m_image.get());
385 381
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 576 }
581 #endif 577 #endif
582 } 578 }
583 579
584 #if ENABLE(OILPAN) 580 #if ENABLE(OILPAN)
585 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() 581 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
586 { 582 {
587 m_loader.willRemoveClient(m_client); 583 m_loader.willRemoveClient(m_client);
588 } 584 }
589 #endif 585 #endif
586
590 } 587 }
OLDNEW
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/paint/ImagePainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698