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

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

Issue 2650113002: Phase II Step 2: Remove setIsPlaceholder() in updateImage() (Closed)
Patch Set: compile fix Created 3 years, 10 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/loader/resource/ImageResourceContent.h" 5 #include "core/loader/resource/ImageResourceContent.h"
6 6
7 #include "core/loader/resource/ImageResource.h" 7 #include "core/loader/resource/ImageResource.h"
8 #include "core/loader/resource/ImageResourceInfo.h" 8 #include "core/loader/resource/ImageResourceInfo.h"
9 #include "core/loader/resource/ImageResourceObserver.h" 9 #include "core/loader/resource/ImageResourceObserver.h"
10 #include "core/svg/graphics/SVGImage.h" 10 #include "core/svg/graphics/SVGImage.h"
(...skipping 21 matching lines...) Expand all
32 32
33 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); } 33 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); }
34 34
35 private: 35 private:
36 const KURL& url() const override { return m_url; } 36 const KURL& url() const override { return m_url; }
37 bool isSchedulingReload() const override { return false; } 37 bool isSchedulingReload() const override { return false; }
38 bool hasDevicePixelRatioHeaderValue() const override { return false; } 38 bool hasDevicePixelRatioHeaderValue() const override { return false; }
39 float devicePixelRatioHeaderValue() const override { return 1.0; } 39 float devicePixelRatioHeaderValue() const override { return 1.0; }
40 const ResourceResponse& response() const override { return m_response; } 40 const ResourceResponse& response() const override { return m_response; }
41 ResourceStatus getStatus() const override { return ResourceStatus::Cached; } 41 ResourceStatus getStatus() const override { return ResourceStatus::Cached; }
42 bool isPlaceholder() const override { return false; } 42 bool shouldShowPlaceholder() const override { return false; }
43 bool isCacheValidator() const override { return false; } 43 bool isCacheValidator() const override { return false; }
44 bool schedulingReloadOrShouldReloadBrokenPlaceholder() const override { 44 bool schedulingReloadOrShouldReloadBrokenPlaceholder() const override {
45 return false; 45 return false;
46 } 46 }
47 bool isAccessAllowed( 47 bool isAccessAllowed(
48 SecurityOrigin*, 48 SecurityOrigin*,
49 DoesCurrentFrameHaveSingleSecurityOrigin) const override { 49 DoesCurrentFrameHaveSingleSecurityOrigin) const override {
50 return true; 50 return true;
51 } 51 }
52 bool hasCacheControlNoStoreHeader() const override { return false; } 52 bool hasCacheControlNoStoreHeader() const override { return false; }
53 const ResourceError& resourceError() const override { return m_error; } 53 const ResourceError& resourceError() const override { return m_error; }
54 54
55 void setDecodedSize(size_t) override {} 55 void setDecodedSize(size_t) override {}
56 void setIsPlaceholder(bool) override {}
57 void willAddClientOrObserver() override {} 56 void willAddClientOrObserver() override {}
58 void didRemoveClientOrObserver() override {} 57 void didRemoveClientOrObserver() override {}
59 void emulateLoadStartedForInspector( 58 void emulateLoadStartedForInspector(
60 ResourceFetcher*, 59 ResourceFetcher*,
61 const KURL&, 60 const KURL&,
62 const AtomicString& initiatorName) override {} 61 const AtomicString& initiatorName) override {}
63 62
64 const KURL m_url; 63 const KURL m_url;
65 const ResourceResponse m_response; 64 const ResourceResponse m_response;
66 const ResourceError m_error; 65 const ResourceError m_error;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 int64_t length = m_image->data() ? m_image->data()->size() : 0; 289 int64_t length = m_image->data() ? m_image->data()->size() : 0;
291 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); 290 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length);
292 291
293 // If our Image has an observer, it's always us so we need to clear the back 292 // If our Image has an observer, it's always us so we need to clear the back
294 // pointer before dropping our reference. 293 // pointer before dropping our reference.
295 m_image->clearImageObserver(); 294 m_image->clearImageObserver();
296 m_image.clear(); 295 m_image.clear();
297 m_sizeAvailable = Image::SizeUnavailable; 296 m_sizeAvailable = Image::SizeUnavailable;
298 } 297 }
299 298
300 // Determines if |response| likely contains the entire resource for the purposes
301 // of determining whether or not to show a placeholder, e.g. if the server
302 // responded with a full 200 response or if the full image is smaller than the
303 // requested range.
304 static bool isEntireResource(const ResourceResponse& response) {
305 if (response.httpStatusCode() != 206)
306 return true;
307
308 int64_t firstBytePosition = -1, lastBytePosition = -1, instanceLength = -1;
309 return parseContentRangeHeaderFor206(
310 response.httpHeaderField("Content-Range"), &firstBytePosition,
311 &lastBytePosition, &instanceLength) &&
312 firstBytePosition == 0 && lastBytePosition + 1 == instanceLength;
313 }
314
315 static bool shouldShowFullImageInsteadOfPlaceholder(
316 const ResourceResponse& response,
317 const Image* image) {
318 if (!isEntireResource(response))
319 return false;
320 if (image && !image->isNull())
321 return true;
322
323 // Don't treat a complete and broken image as a placeholder if the response
324 // code is something other than a 4xx or 5xx error. This is done to prevent
325 // reissuing the request in cases like "204 No Content" responses to tracking
326 // requests triggered by <img> tags, and <img> tags used to preload non-image
327 // resources.
328 return response.httpStatusCode() < 400 || response.httpStatusCode() >= 600;
329 }
330
331 ImageResourceContent::UpdateImageResult ImageResourceContent::updateImage( 299 ImageResourceContent::UpdateImageResult ImageResourceContent::updateImage(
332 PassRefPtr<SharedBuffer> data, 300 PassRefPtr<SharedBuffer> data,
333 UpdateImageOption updateImageOption, 301 UpdateImageOption updateImageOption,
334 bool allDataReceived) { 302 bool allDataReceived) {
335 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); 303 TRACE_EVENT0("blink", "ImageResourceContent::updateImage");
336 304
337 #if DCHECK_IS_ON() 305 #if DCHECK_IS_ON()
338 DCHECK(!m_isUpdateImageBeingCalled); 306 DCHECK(!m_isUpdateImageBeingCalled);
339 AutoReset<bool> scope(&m_isUpdateImageBeingCalled, true); 307 AutoReset<bool> scope(&m_isUpdateImageBeingCalled, true);
340 #endif 308 #endif
(...skipping 25 matching lines...) Expand all
366 DCHECK(m_image); 334 DCHECK(m_image);
367 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived); 335 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived);
368 } 336 }
369 337
370 // Go ahead and tell our observers to try to draw if we have either 338 // Go ahead and tell our observers to try to draw if we have either
371 // received all the data or the size is known. Each chunk from the network 339 // received all the data or the size is known. Each chunk from the network
372 // causes observers to repaint, which will force that chunk to decode. 340 // causes observers to repaint, which will force that chunk to decode.
373 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived) 341 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived)
374 return UpdateImageResult::NoDecodeError; 342 return UpdateImageResult::NoDecodeError;
375 343
376 if (m_info->isPlaceholder() && allDataReceived) { 344 if (m_info->shouldShowPlaceholder() && allDataReceived) {
377 if (shouldShowFullImageInsteadOfPlaceholder(response(), 345 if (m_image && !m_image->isNull()) {
378 m_image.get())) {
379 m_info->setIsPlaceholder(false);
380 } else if (m_image && !m_image->isNull()) {
381 IntSize dimensions = m_image->size(); 346 IntSize dimensions = m_image->size();
382 clearImage(); 347 clearImage();
383 m_image = PlaceholderImage::create(this, dimensions); 348 m_image = PlaceholderImage::create(this, dimensions);
384 } 349 }
385 } 350 }
386 351
387 if (!m_image || m_image->isNull()) { 352 if (!m_image || m_image->isNull()) {
388 clearImage(); 353 clearImage();
389 return UpdateImageResult::ShouldDecodeError; 354 return UpdateImageResult::ShouldDecodeError;
390 } 355 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 476
512 const ResourceResponse& ImageResourceContent::response() const { 477 const ResourceResponse& ImageResourceContent::response() const {
513 return m_info->response(); 478 return m_info->response();
514 } 479 }
515 480
516 const ResourceError& ImageResourceContent::resourceError() const { 481 const ResourceError& ImageResourceContent::resourceError() const {
517 return m_info->resourceError(); 482 return m_info->resourceError();
518 } 483 }
519 484
520 } // namespace blink 485 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698