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

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

Issue 1839473002: Centralize the setting of Accept headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again Created 4 years, 8 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) 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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return toImageResource(fetcher->requestResource(request, ImageResourceFactor y())); 58 return toImageResource(fetcher->requestResource(request, ImageResourceFactor y()));
59 } 59 }
60 60
61 ImageResource::ImageResource(const ResourceRequest& resourceRequest, const Resou rceLoaderOptions& options) 61 ImageResource::ImageResource(const ResourceRequest& resourceRequest, const Resou rceLoaderOptions& options)
62 : Resource(resourceRequest, Image, options) 62 : Resource(resourceRequest, Image, options)
63 , m_devicePixelRatioHeaderValue(1.0) 63 , m_devicePixelRatioHeaderValue(1.0)
64 , m_image(nullptr) 64 , m_image(nullptr)
65 , m_hasDevicePixelRatioHeaderValue(false) 65 , m_hasDevicePixelRatioHeaderValue(false)
66 { 66 {
67 WTF_LOG(Timers, "new ImageResource(ResourceRequest) %p", this); 67 WTF_LOG(Timers, "new ImageResource(ResourceRequest) %p", this);
68 setCustomAcceptHeader();
69 } 68 }
70 69
71 ImageResource::ImageResource(blink::Image* image, const ResourceLoaderOptions& o ptions) 70 ImageResource::ImageResource(blink::Image* image, const ResourceLoaderOptions& o ptions)
72 : Resource(ResourceRequest(""), Image, options) 71 : Resource(ResourceRequest(""), Image, options)
73 , m_devicePixelRatioHeaderValue(1.0) 72 , m_devicePixelRatioHeaderValue(1.0)
74 , m_image(image) 73 , m_image(image)
75 , m_hasDevicePixelRatioHeaderValue(false) 74 , m_hasDevicePixelRatioHeaderValue(false)
76 { 75 {
77 WTF_LOG(Timers, "new ImageResource(Image) %p", this); 76 WTF_LOG(Timers, "new ImageResource(Image) %p", this);
78 setStatus(Cached); 77 setStatus(Cached);
79 setCustomAcceptHeader();
80 } 78 }
81 79
82 ImageResource::ImageResource(const ResourceRequest& resourceRequest, blink::Imag e* image, const ResourceLoaderOptions& options) 80 ImageResource::ImageResource(const ResourceRequest& resourceRequest, blink::Imag e* image, const ResourceLoaderOptions& options)
83 : Resource(resourceRequest, Image, options) 81 : Resource(resourceRequest, Image, options)
84 , m_image(image) 82 , m_image(image)
85 { 83 {
86 WTF_LOG(Timers, "new ImageResource(ResourceRequest, Image) %p", this); 84 WTF_LOG(Timers, "new ImageResource(ResourceRequest, Image) %p", this);
87 setStatus(Cached); 85 setStatus(Cached);
88 setCustomAcceptHeader();
89 } 86 }
90 87
91 ImageResource::~ImageResource() 88 ImageResource::~ImageResource()
92 { 89 {
93 WTF_LOG(Timers, "~ImageResource %p", this); 90 WTF_LOG(Timers, "~ImageResource %p", this);
94 clearImage(); 91 clearImage();
95 } 92 }
96 93
97 DEFINE_TRACE(ImageResource) 94 DEFINE_TRACE(ImageResource)
98 { 95 {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 303 }
307 } 304 }
308 305
309 void ImageResource::clear() 306 void ImageResource::clear()
310 { 307 {
311 prune(); 308 prune();
312 clearImage(); 309 clearImage();
313 setEncodedSize(0); 310 setEncodedSize(0);
314 } 311 }
315 312
316 void ImageResource::setCustomAcceptHeader()
317 {
318 DEFINE_STATIC_LOCAL(const AtomicString, acceptImages, ("image/webp,image/*,* /*;q=0.8"));
319 setAccept(acceptImages);
320 }
321
322 inline void ImageResource::createImage() 313 inline void ImageResource::createImage()
323 { 314 {
324 // Create the image if it doesn't yet exist. 315 // Create the image if it doesn't yet exist.
325 if (m_image) 316 if (m_image)
326 return; 317 return;
327 318
328 if (m_response.mimeType() == "image/svg+xml") { 319 if (m_response.mimeType() == "image/svg+xml") {
329 m_image = SVGImage::create(this); 320 m_image = SVGImage::create(this);
330 } else { 321 } else {
331 m_image = BitmapImage::create(this); 322 m_image = BitmapImage::create(this);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (response().wasFetchedViaServiceWorker()) 535 if (response().wasFetchedViaServiceWorker())
545 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; 536 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque;
546 if (!getImage()->currentFrameHasSingleSecurityOrigin()) 537 if (!getImage()->currentFrameHasSingleSecurityOrigin())
547 return false; 538 return false;
548 if (passesAccessControlCheck(securityOrigin)) 539 if (passesAccessControlCheck(securityOrigin))
549 return true; 540 return true;
550 return !securityOrigin->taintsCanvas(response().url()); 541 return !securityOrigin->taintsCanvas(response().url());
551 } 542 }
552 543
553 } // namespace blink 544 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.h ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698