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

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

Issue 1706083002: Split ImageResourceClient into ResourceClient and ImageResourceObserver [1/2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More consistent Client/Observer Created 4 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 /* 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 "core/fetch/ImageResource.h" 24 #include "core/fetch/ImageResource.h"
25 25
26 #include "core/fetch/ImageResourceClient.h" 26 #include "core/fetch/ImageResourceObserver.h"
27 #include "core/fetch/MemoryCache.h" 27 #include "core/fetch/MemoryCache.h"
28 #include "core/fetch/ResourceClient.h" 28 #include "core/fetch/ResourceClient.h"
29 #include "core/fetch/ResourceClientWalker.h" 29 #include "core/fetch/ResourceClientWalker.h"
30 #include "core/fetch/ResourceFetcher.h" 30 #include "core/fetch/ResourceFetcher.h"
31 #include "core/fetch/ResourceLoader.h" 31 #include "core/fetch/ResourceLoader.h"
32 #include "core/svg/graphics/SVGImage.h" 32 #include "core/svg/graphics/SVGImage.h"
33 #include "platform/Logging.h" 33 #include "platform/Logging.h"
34 #include "platform/RuntimeEnabledFeatures.h" 34 #include "platform/RuntimeEnabledFeatures.h"
35 #include "platform/SharedBuffer.h" 35 #include "platform/SharedBuffer.h"
36 #include "platform/TraceEvent.h" 36 #include "platform/TraceEvent.h"
37 #include "platform/graphics/BitmapImage.h" 37 #include "platform/graphics/BitmapImage.h"
38 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
39 #include "wtf/CurrentTime.h" 39 #include "wtf/CurrentTime.h"
40 #include "wtf/StdLibExtras.h" 40 #include "wtf/StdLibExtras.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 namespace {
45
46 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource Observer, ImageResourceObserver>;
47
48 } // namespace
49
44 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request , ResourceFetcher* fetcher) 50 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request , ResourceFetcher* fetcher)
45 { 51 {
46 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) 52 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified)
47 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); 53 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage);
48 if (fetcher->context().pageDismissalEventBeingDispatched()) { 54 if (fetcher->context().pageDismissalEventBeingDispatched()) {
49 KURL requestURL = request.resourceRequest().url(); 55 KURL requestURL = request.resourceRequest().url();
50 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.originRestriction())) 56 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.originRestriction()))
51 fetcher->context().sendImagePing(requestURL); 57 fetcher->context().sendImagePing(requestURL);
52 return nullptr; 58 return nullptr;
53 } 59 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 110 }
105 111
106 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& options) 112 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& options)
107 { 113 {
108 if (!fetcher || fetcher->autoLoadImages()) 114 if (!fetcher || fetcher->autoLoadImages())
109 Resource::load(fetcher, options); 115 Resource::load(fetcher, options);
110 else 116 else
111 setLoading(false); 117 setLoading(false);
112 } 118 }
113 119
114 void ImageResource::didAddClient(ResourceClient* c) 120 void ImageResource::addObserver(ImageResourceObserver* observer)
115 { 121 {
122 willAddClient();
123
124 m_observers.add(observer);
125
126 if (!m_revalidatingRequest.isNull())
127 return;
128
116 if (m_data && !m_image && !errorOccurred()) { 129 if (m_data && !m_image && !errorOccurred()) {
117 createImage(); 130 createImage();
118 m_image->setData(m_data, true); 131 m_image->setData(m_data, true);
119 } 132 }
120 133
121 ASSERT(ImageResourceClient::isExpectedType(c));
122 if (m_image && !m_image->isNull()) 134 if (m_image && !m_image->isNull())
123 static_cast<ImageResourceClient*>(c)->imageChanged(this); 135 observer->imageChanged(this);
124
125 Resource::didAddClient(c);
126 } 136 }
127 137
128 void ImageResource::didRemoveClient(ResourceClient* c) 138 void ImageResource::removeObserver(ImageResourceObserver* observer)
129 { 139 {
130 ASSERT(c); 140 ASSERT(observer);
131 ASSERT(ImageResourceClient::isExpectedType(c)); 141 ASSERT(m_observers.contains(observer));
142 m_observers.remove(observer);
143 didRemoveClient();
144 }
132 145
133 Resource::didRemoveClient(c); 146 ResourcePriority ImageResource::priorityFromClients()
147 {
148 ResourcePriority priority;
149 ImageResourceObserverWalker w(m_observers);
150 while (const auto* observer = w.next()) {
151 ResourcePriority nextPriority = observer->computeResourcePriority();
152 if (nextPriority.visibility == ResourcePriority::NotVisible)
153 continue;
154 priority.visibility = ResourcePriority::Visible;
155 priority.intraPriorityValue += nextPriority.intraPriorityValue;
156 }
157 return priority;
134 } 158 }
135 159
136 bool ImageResource::isSafeToUnlock() const 160 bool ImageResource::isSafeToUnlock() const
137 { 161 {
138 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. 162 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class.
139 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); 163 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2);
140 } 164 }
141 165
142 void ImageResource::destroyDecodedDataForFailedRevalidation() 166 void ImageResource::destroyDecodedDataForFailedRevalidation()
143 { 167 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 264 }
241 265
242 void ImageResource::computeIntrinsicDimensions(Length& intrinsicWidth, Length& i ntrinsicHeight, FloatSize& intrinsicRatio) 266 void ImageResource::computeIntrinsicDimensions(Length& intrinsicWidth, Length& i ntrinsicHeight, FloatSize& intrinsicRatio)
243 { 267 {
244 if (m_image) 268 if (m_image)
245 m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int rinsicRatio); 269 m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int rinsicRatio);
246 } 270 }
247 271
248 void ImageResource::notifyObservers(const IntRect* changeRect) 272 void ImageResource::notifyObservers(const IntRect* changeRect)
249 { 273 {
250 ResourceClientWalker<ImageResourceClient> w(m_clients); 274 ImageResourceObserverWalker w(m_observers);
251 while (ImageResourceClient* c = w.next()) 275 while (auto* observer = w.next()) {
252 c->imageChanged(this, changeRect); 276 observer->imageChanged(this, changeRect);
253 277 }
254 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
255 while (ImageResourceClient* c = w2.next())
256 c->imageChanged(this, changeRect);
257 } 278 }
258 279
259 void ImageResource::clear() 280 void ImageResource::clear()
260 { 281 {
261 prune(); 282 prune();
262 clearImage(); 283 clearImage();
263 setEncodedSize(0); 284 setEncodedSize(0);
264 } 285 }
265 286
266 void ImageResource::setCustomAcceptHeader() 287 void ImageResource::setCustomAcceptHeader()
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // to update MemoryCache. 405 // to update MemoryCache.
385 if (decodedSize() != 0) 406 if (decodedSize() != 0)
386 Resource::didAccessDecodedData(); 407 Resource::didAccessDecodedData();
387 } 408 }
388 409
389 bool ImageResource::shouldPauseAnimation(const blink::Image* image) 410 bool ImageResource::shouldPauseAnimation(const blink::Image* image)
390 { 411 {
391 if (!image || image != m_image) 412 if (!image || image != m_image)
392 return false; 413 return false;
393 414
394 ResourceClientWalker<ImageResourceClient> w(m_clients); 415 ImageResourceObserverWalker w(m_observers);
395 while (ImageResourceClient* c = w.next()) { 416 while (auto* observer = w.next()) {
396 if (c->willRenderImage(this)) 417 if (observer->willRenderImage())
397 return false; 418 return false;
398 } 419 }
399
400 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
401 while (ImageResourceClient* c = w2.next()) {
402 if (c->willRenderImage(this))
403 return false;
404 }
405
406 return true; 420 return true;
407 } 421 }
408 422
409 void ImageResource::animationAdvanced(const blink::Image* image) 423 void ImageResource::animationAdvanced(const blink::Image* image)
410 { 424 {
411 if (!image || image != m_image) 425 if (!image || image != m_image)
412 return; 426 return;
413 notifyObservers(); 427 notifyObservers();
414 } 428 }
415 429
416 void ImageResource::updateImageAnimationPolicy() 430 void ImageResource::updateImageAnimationPolicy()
417 { 431 {
418 if (!m_image) 432 if (!m_image)
419 return; 433 return;
420 434
421 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; 435 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed;
422 ResourceClientWalker<ImageResourceClient> w(m_clients); 436 ImageResourceObserverWalker w(m_observers);
423 while (ImageResourceClient* c = w.next()) { 437 while (auto* observer = w.next()) {
424 if (c->getImageAnimationPolicy(this, newPolicy)) 438 if (observer->getImageAnimationPolicy(newPolicy))
425 break; 439 break;
426 } 440 }
427 441
428 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
429 while (ImageResourceClient* c = w2.next()) {
430 if (c->getImageAnimationPolicy(this, newPolicy))
431 break;
432 }
433
434 if (m_image->animationPolicy() != newPolicy) { 442 if (m_image->animationPolicy() != newPolicy) {
435 m_image->resetAnimation(); 443 m_image->resetAnimation();
436 m_image->setAnimationPolicy(newPolicy); 444 m_image->setAnimationPolicy(newPolicy);
437 } 445 }
438 } 446 }
439 447
440 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) 448 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher)
441 { 449 {
442 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) 450 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low"))
443 return; 451 return;
(...skipping 20 matching lines...) Expand all
464 return true; 472 return true;
465 return !securityOrigin->taintsCanvas(response().url()); 473 return !securityOrigin->taintsCanvas(response().url());
466 } 474 }
467 475
468 bool ImageResource::loadingMultipartContent() const 476 bool ImageResource::loadingMultipartContent() const
469 { 477 {
470 return m_loader && m_loader->loadingMultipartContent(); 478 return m_loader && m_loader->loadingMultipartContent();
471 } 479 }
472 480
473 } // namespace blink 481 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698