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

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

Issue 2407573002: Wait to notify completion until after a Lo-Fi image is reloaded. (Closed)
Patch Set: Created 4 years, 2 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 MultipartImageResourceParser::Client::trace(visitor); 97 MultipartImageResourceParser::Client::trace(visitor);
98 } 98 }
99 99
100 void ImageResource::checkNotify() { 100 void ImageResource::checkNotify() {
101 notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished); 101 notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished);
102 Resource::checkNotify(); 102 Resource::checkNotify();
103 } 103 }
104 104
105 void ImageResource::notifyObserversInternal( 105 void ImageResource::notifyObserversInternal(
106 MarkFinishedOption markFinishedOption) { 106 MarkFinishedOption markFinishedOption) {
107 if (isLoading()) 107 if (isLoading() || isNotifyClientsOfCompletionProhibited())
108 return; 108 return;
109 109
110 for (auto* observer : m_observers.asVector()) { 110 for (auto* observer : m_observers.asVector()) {
111 if (m_observers.contains(observer)) { 111 if (m_observers.contains(observer)) {
112 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished) 112 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished)
113 markObserverFinished(observer); 113 markObserverFinished(observer);
114 observer->imageNotifyFinished(this); 114 observer->imageNotifyFinished(this);
115 } 115 }
116 } 116 }
117 } 117 }
(...skipping 25 matching lines...) Expand all
143 // On the other hand, when the response is multipart, |updateImage()| is not 143 // On the other hand, when the response is multipart, |updateImage()| is not
144 // called in |appendData()|, which means |m_image| might not be created even 144 // called in |appendData()|, which means |m_image| might not be created even
145 // when |data()| exists. This is intentional since creating a |m_image| on 145 // when |data()| exists. This is intentional since creating a |m_image| on
146 // receiving data might destroy an existing image in a previous part. 146 // receiving data might destroy an existing image in a previous part.
147 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); 147 DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
148 148
149 if (m_image && !m_image->isNull()) { 149 if (m_image && !m_image->isNull()) {
150 observer->imageChanged(this); 150 observer->imageChanged(this);
151 } 151 }
152 152
153 if (isLoaded()) { 153 if (isLoaded() && !isNotifyClientsOfCompletionProhibited()) {
154 markObserverFinished(observer); 154 markObserverFinished(observer);
155 observer->imageNotifyFinished(this); 155 observer->imageNotifyFinished(this);
156 } 156 }
157 } 157 }
158 158
159 void ImageResource::removeObserver(ImageResourceObserver* observer) { 159 void ImageResource::removeObserver(ImageResourceObserver* observer) {
160 DCHECK(observer); 160 DCHECK(observer);
161 161
162 if (m_observers.contains(observer)) 162 if (m_observers.contains(observer))
163 m_observers.remove(observer); 163 m_observers.remove(observer);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 m_image->setAnimationPolicy(newPolicy); 525 m_image->setAnimationPolicy(newPolicy);
526 } 526 }
527 } 527 }
528 528
529 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) { 529 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) {
530 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) 530 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn)
531 return; 531 return;
532 if (isLoaded() && 532 if (isLoaded() &&
533 !response().httpHeaderField("chrome-proxy").contains("q=low")) 533 !response().httpHeaderField("chrome-proxy").contains("q=low"))
534 return; 534 return;
535 setCachePolicyBypassingCache();
536 setLoFiStateOff();
537 if (isLoading())
538 loader()->cancel();
539 clear();
540 notifyObservers();
541 535
542 setStatus(NotStarted); 536 {
Nate Chapin 2016/10/10 23:47:49 I don't think you need to force this to have a nar
sclittle 2016/10/11 02:56:56 AIUI we only want to prevent completion callbacks
Nate Chapin 2016/10/12 22:56:17 If startLoad() is someday allowed to complete the
sclittle 2016/10/12 23:38:16 Fair enough :) I've removed the dependency on Auto
537 // Prevent clients and observers from being notified of completion while the
538 // reload is being scheduled, so that e.g. canceling an existing load in
539 // progress doesn't cause clients and observers to be notified of completion
540 // prematurely.
541 Resource::ProhibitNotifyClientsOfCompletionInScope
Nate Chapin 2016/10/10 23:47:49 AutoReset<bool> instead of a custom helper?
sclittle 2016/10/11 02:56:56 I don't see an easy way to do that, unless we want
Nate Chapin 2016/10/12 22:56:17 Let's use AutoReset if and only if we settle on mo
sclittle 2016/10/12 23:38:16 I've removed the dependency on AutoReset and chang
542 scopedProhibitNotifyCompletion(this);
543
544 setCachePolicyBypassingCache();
545 setLoFiStateOff();
546 if (isLoading()) {
547 loader()->cancel();
Nate Chapin 2016/10/10 23:47:49 Is this the only case where you want to suppress c
sclittle 2016/10/11 02:56:56 loader()->cancel() is the main case I'm worried ab
Nate Chapin 2016/10/12 22:56:17 clear() is trivial, but notifyObservers() could ha
sclittle 2016/10/12 23:38:16 Acknowledged.
548 // Canceling the loader causes error() to be called, which in turn calls
549 // clear() and notifyObservers(), so there's no need to call these again
550 // here.
551 } else {
552 clear();
553 notifyObservers();
554 }
555
556 setStatus(NotStarted);
557 }
558
543 fetcher->startLoad(this); 559 fetcher->startLoad(this);
544 } 560 }
545 561
546 void ImageResource::changedInRect(const blink::Image* image, 562 void ImageResource::changedInRect(const blink::Image* image,
547 const IntRect& rect) { 563 const IntRect& rect) {
548 if (!image || image != m_image) 564 if (!image || image != m_image)
549 return; 565 return;
550 notifyObservers(&rect); 566 notifyObservers(&rect);
551 } 567 }
552 568
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 return response().serviceWorkerResponseType() != 602 return response().serviceWorkerResponseType() !=
587 WebServiceWorkerResponseTypeOpaque; 603 WebServiceWorkerResponseTypeOpaque;
588 if (!getImage()->currentFrameHasSingleSecurityOrigin()) 604 if (!getImage()->currentFrameHasSingleSecurityOrigin())
589 return false; 605 return false;
590 if (passesAccessControlCheck(securityOrigin)) 606 if (passesAccessControlCheck(securityOrigin))
591 return true; 607 return true;
592 return !securityOrigin->taintsCanvas(response().url()); 608 return !securityOrigin->taintsCanvas(response().url());
593 } 609 }
594 610
595 } // namespace blink 611 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698