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

Side by Side Diff: Source/core/fetch/ImageResource.cpp

Issue 46313002: Support the DPR header for client hints. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. 21 Boston, MA 02110-1301, USA.
22 */ 22 */
23 23
24 #include "config.h" 24 #include "config.h"
25 #include "core/fetch/ImageResource.h" 25 #include "core/fetch/ImageResource.h"
26 #include "RuntimeEnabledFeatures.h"
pdr. 2013/10/26 01:26:31 Nit: Can you put this include one line lower? ...
26 27
27 #include "core/fetch/ImageResourceClient.h" 28 #include "core/fetch/ImageResourceClient.h"
28 #include "core/fetch/MemoryCache.h" 29 #include "core/fetch/MemoryCache.h"
29 #include "core/fetch/ResourceClient.h" 30 #include "core/fetch/ResourceClient.h"
30 #include "core/fetch/ResourceClientWalker.h" 31 #include "core/fetch/ResourceClientWalker.h"
31 #include "core/fetch/ResourceFetcher.h" 32 #include "core/fetch/ResourceFetcher.h"
32 #include "core/frame/FrameView.h" 33 #include "core/frame/FrameView.h"
33 #include "core/platform/graphics/BitmapImage.h" 34 #include "core/platform/graphics/BitmapImage.h"
34 #include "core/rendering/RenderObject.h" 35 #include "core/rendering/RenderObject.h"
35 #include "core/svg/graphics/SVGImage.h" 36 #include "core/svg/graphics/SVGImage.h"
36 #include "platform/SharedBuffer.h" 37 #include "platform/SharedBuffer.h"
37 #include "wtf/CurrentTime.h" 38 #include "wtf/CurrentTime.h"
38 #include "wtf/StdLibExtras.h" 39 #include "wtf/StdLibExtras.h"
39 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
40 41
41 using namespace std; 42 using namespace std;
42 43
43 namespace WebCore { 44 namespace WebCore {
44 45
45 ImageResource::ImageResource(const ResourceRequest& resourceRequest) 46 ImageResource::ImageResource(const ResourceRequest& resourceRequest)
46 : Resource(resourceRequest, Image) 47 : Resource(resourceRequest, Image)
48 , m_dprHeaderValue(1.0)
47 , m_image(0) 49 , m_image(0)
48 , m_loadingMultipartContent(false) 50 , m_loadingMultipartContent(false)
51 , m_hasDprHeaderValue(false)
49 { 52 {
50 setStatus(Unknown); 53 setStatus(Unknown);
51 setCustomAcceptHeader(); 54 setCustomAcceptHeader();
52 } 55 }
53 56
54 ImageResource::ImageResource(WebCore::Image* image) 57 ImageResource::ImageResource(WebCore::Image* image)
55 : Resource(ResourceRequest(""), Image) 58 : Resource(ResourceRequest(""), Image)
56 , m_image(image) 59 , m_image(image)
57 { 60 {
58 setStatus(Cached); 61 setStatus(Cached);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 Resource::error(status); 373 Resource::error(status);
371 notifyObservers(); 374 notifyObservers();
372 } 375 }
373 376
374 void ImageResource::responseReceived(const ResourceResponse& response) 377 void ImageResource::responseReceived(const ResourceResponse& response)
375 { 378 {
376 if (m_loadingMultipartContent && m_data) 379 if (m_loadingMultipartContent && m_data)
377 finishOnePart(); 380 finishOnePart();
378 else if (response.isMultipart()) 381 else if (response.isMultipart())
379 m_loadingMultipartContent = true; 382 m_loadingMultipartContent = true;
383 if (RuntimeEnabledFeatures::clientHintsDprEnabled()) {
384 m_dprHeaderValue = response.httpHeaderField("DPR").toFloat(&m_hasDprHead erValue);
385 if (!m_hasDprHeaderValue || m_dprHeaderValue <= 0.0) {
386 m_dprHeaderValue = 1.0;
387 m_hasDprHeaderValue = false;
388 }
389 }
380 Resource::responseReceived(response); 390 Resource::responseReceived(response);
381 } 391 }
382 392
383 void ImageResource::destroyDecodedData() 393 void ImageResource::destroyDecodedData()
384 { 394 {
385 bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmap Image()); 395 bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmap Image());
386 if (isSafeToMakePurgeable() && canDeleteImage && !isLoading()) { 396 if (isSafeToMakePurgeable() && canDeleteImage && !isLoading()) {
387 // Image refs the data buffer so we should not make it purgeable while t he image is alive. 397 // Image refs the data buffer so we should not make it purgeable while t he image is alive.
388 // Invoking addClient() will reconstruct the image object. 398 // Invoking addClient() will reconstruct the image object.
389 m_image = 0; 399 m_image = 0;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 454
445 bool ImageResource::currentFrameKnownToBeOpaque(const RenderObject* renderer) 455 bool ImageResource::currentFrameKnownToBeOpaque(const RenderObject* renderer)
446 { 456 {
447 WebCore::Image* image = imageForRenderer(renderer); 457 WebCore::Image* image = imageForRenderer(renderer);
448 if (image->isBitmapImage()) 458 if (image->isBitmapImage())
449 image->nativeImageForCurrentFrame(); // force decode 459 image->nativeImageForCurrentFrame(); // force decode
450 return image->currentFrameKnownToBeOpaque(); 460 return image->currentFrameKnownToBeOpaque();
451 } 461 }
452 462
453 } // namespace WebCore 463 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698