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

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

Issue 2468883003: [ImageResource 0b] Decouple ImageResourceObserver::imageNotifyFinished() from notifyFinished() (Closed)
Patch Set: Rebase Created 4 years 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 DEFINE_TRACE(ImageResource) { 142 DEFINE_TRACE(ImageResource) {
143 visitor->trace(m_multipartParser); 143 visitor->trace(m_multipartParser);
144 Resource::trace(visitor); 144 Resource::trace(visitor);
145 ImageObserver::trace(visitor); 145 ImageObserver::trace(visitor);
146 MultipartImageResourceParser::Client::trace(visitor); 146 MultipartImageResourceParser::Client::trace(visitor);
147 } 147 }
148 148
149 void ImageResource::checkNotify() { 149 void ImageResource::checkNotify() {
150 // Don't notify observers and clients of completion if this ImageResource is 150 // Don't notify clients of completion if this ImageResource is
151 // about to be reloaded. 151 // about to be reloaded.
152 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) 152 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder())
153 return; 153 return;
154 154
155 notifyObserversInternal();
156 Resource::checkNotify(); 155 Resource::checkNotify();
157 } 156 }
158 157
159 void ImageResource::notifyObserversInternal() {
160 if (isLoading())
161 return;
162
163 for (auto* observer : m_observers.asVector()) {
164 if (m_observers.contains(observer)) {
165 markObserverFinished(observer);
166 observer->imageNotifyFinished(this);
167 }
168 }
169 }
170
171 void ImageResource::markObserverFinished(ImageResourceObserver* observer) { 158 void ImageResource::markObserverFinished(ImageResourceObserver* observer) {
172 if (m_observers.contains(observer)) { 159 if (m_observers.contains(observer)) {
173 m_finishedObservers.add(observer); 160 m_finishedObservers.add(observer);
174 m_observers.remove(observer); 161 m_observers.remove(observer);
175 } 162 }
176 } 163 }
177 164
178 void ImageResource::didAddClient(ResourceClient* client) { 165 void ImageResource::didAddClient(ResourceClient* client) {
179 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); 166 DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
180 167
(...skipping 20 matching lines...) Expand all
201 // On the other hand, when the response is multipart, |updateImage()| is not 188 // On the other hand, when the response is multipart, |updateImage()| is not
202 // called in |appendData()|, which means |m_image| might not be created even 189 // called in |appendData()|, which means |m_image| might not be created even
203 // when |data()| exists. This is intentional since creating a |m_image| on 190 // when |data()| exists. This is intentional since creating a |m_image| on
204 // receiving data might destroy an existing image in a previous part. 191 // receiving data might destroy an existing image in a previous part.
205 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); 192 DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
206 193
207 if (m_image && !m_image->isNull()) { 194 if (m_image && !m_image->isNull()) {
208 observer->imageChanged(this); 195 observer->imageChanged(this);
209 } 196 }
210 197
211 if (isLoaded() && !m_isSchedulingReload && !shouldReloadBrokenPlaceholder()) { 198 if (isLoaded() && m_observers.contains(observer) && !m_isSchedulingReload &&
199 !shouldReloadBrokenPlaceholder()) {
212 markObserverFinished(observer); 200 markObserverFinished(observer);
213 observer->imageNotifyFinished(this); 201 observer->imageNotifyFinished(this);
214 } 202 }
215 } 203 }
216 204
217 void ImageResource::removeObserver(ImageResourceObserver* observer) { 205 void ImageResource::removeObserver(ImageResourceObserver* observer) {
218 DCHECK(observer); 206 DCHECK(observer);
219 207
220 if (m_observers.contains(observer)) 208 if (m_observers.contains(observer))
221 m_observers.remove(observer); 209 m_observers.remove(observer);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 404
417 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed. 405 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
418 LayoutSize minimumSize( 406 LayoutSize minimumSize(
419 size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(), 407 size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
420 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit())); 408 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()));
421 size.scale(multiplier); 409 size.scale(multiplier);
422 size.clampToMinimumSize(minimumSize); 410 size.clampToMinimumSize(minimumSize);
423 return size; 411 return size;
424 } 412 }
425 413
426 void ImageResource::notifyObservers(const IntRect* changeRect) { 414 void ImageResource::notifyObservers(bool isNotifyingFinish,
415 const IntRect* changeRect) {
427 for (auto* observer : m_finishedObservers.asVector()) { 416 for (auto* observer : m_finishedObservers.asVector()) {
428 if (m_finishedObservers.contains(observer)) 417 if (m_finishedObservers.contains(observer))
429 observer->imageChanged(this, changeRect); 418 observer->imageChanged(this, changeRect);
430 } 419 }
431 for (auto* observer : m_observers.asVector()) { 420 for (auto* observer : m_observers.asVector()) {
432 if (m_observers.contains(observer)) 421 if (m_observers.contains(observer)) {
433 observer->imageChanged(this, changeRect); 422 observer->imageChanged(this, changeRect);
423 if (isNotifyingFinish && m_observers.contains(observer) &&
424 !m_isSchedulingReload && !shouldReloadBrokenPlaceholder()) {
425 markObserverFinished(observer);
426 observer->imageNotifyFinished(this);
427 }
428 }
434 } 429 }
435 } 430 }
436 431
437 void ImageResource::clear() { 432 void ImageResource::clear() {
438 clearImage(); 433 clearImage();
439 clearData(); 434 clearData();
440 setEncodedSize(0); 435 setEncodedSize(0);
441 } 436 }
442 437
443 inline void ImageResource::createImage() { 438 inline void ImageResource::createImage() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 setStatus(DecodeError); 502 setStatus(DecodeError);
508 if (!allDataReceived && loader()) { 503 if (!allDataReceived && loader()) {
509 loader()->didFinishLoading(nullptr, monotonicallyIncreasingTime(), size, 504 loader()->didFinishLoading(nullptr, monotonicallyIncreasingTime(), size,
510 size); 505 size);
511 } 506 }
512 memoryCache()->remove(this); 507 memoryCache()->remove(this);
513 } 508 }
514 509
515 // It would be nice to only redraw the decoded band of the image, but with the 510 // It would be nice to only redraw the decoded band of the image, but with the
516 // current design (decoding delayed until painting) that seems hard. 511 // current design (decoding delayed until painting) that seems hard.
517 notifyObservers(); 512 notifyObservers(allDataReceived);
518 } 513 }
519 514
520 void ImageResource::updateImageAndClearBuffer() { 515 void ImageResource::updateImageAndClearBuffer() {
521 clearImage(); 516 clearImage();
522 updateImage(true); 517 updateImage(true);
523 clearData(); 518 clearData();
524 } 519 }
525 520
526 void ImageResource::finish(double loadFinishTime) { 521 void ImageResource::finish(double loadFinishTime) {
527 if (m_multipartParser) { 522 if (m_multipartParser) {
(...skipping 10 matching lines...) Expand all
538 clearData(); 533 clearData();
539 } 534 }
540 Resource::finish(loadFinishTime); 535 Resource::finish(loadFinishTime);
541 } 536 }
542 537
543 void ImageResource::error(const ResourceError& error) { 538 void ImageResource::error(const ResourceError& error) {
544 if (m_multipartParser) 539 if (m_multipartParser)
545 m_multipartParser->cancel(); 540 m_multipartParser->cancel();
546 clear(); 541 clear();
547 Resource::error(error); 542 Resource::error(error);
548 notifyObservers(); 543 notifyObservers(true);
549 } 544 }
550 545
551 void ImageResource::responseReceived( 546 void ImageResource::responseReceived(
552 const ResourceResponse& response, 547 const ResourceResponse& response,
553 std::unique_ptr<WebDataConsumerHandle> handle) { 548 std::unique_ptr<WebDataConsumerHandle> handle) {
554 DCHECK(!handle); 549 DCHECK(!handle);
555 DCHECK(!m_multipartParser); 550 DCHECK(!m_multipartParser);
556 // If there's no boundary, just handle the request normally. 551 // If there's no boundary, just handle the request normally.
557 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { 552 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) {
558 m_multipartParser = new MultipartImageResourceParser( 553 m_multipartParser = new MultipartImageResourceParser(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 if (m_observers.contains(observer) && observer->willRenderImage()) 588 if (m_observers.contains(observer) && observer->willRenderImage())
594 return false; 589 return false;
595 } 590 }
596 591
597 return true; 592 return true;
598 } 593 }
599 594
600 void ImageResource::animationAdvanced(const blink::Image* image) { 595 void ImageResource::animationAdvanced(const blink::Image* image) {
601 if (!image || image != m_image) 596 if (!image || image != m_image)
602 return; 597 return;
603 notifyObservers(); 598 notifyObservers(false);
604 } 599 }
605 600
606 void ImageResource::updateImageAnimationPolicy() { 601 void ImageResource::updateImageAnimationPolicy() {
607 if (!m_image) 602 if (!m_image)
608 return; 603 return;
609 604
610 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; 605 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed;
611 for (auto* observer : m_finishedObservers.asVector()) { 606 for (auto* observer : m_finishedObservers.asVector()) {
612 if (m_finishedObservers.contains(observer) && 607 if (m_finishedObservers.contains(observer) &&
613 observer->getImageAnimationPolicy(newPolicy)) 608 observer->getImageAnimationPolicy(newPolicy))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 clearRangeRequestHeader(); 651 clearRangeRequestHeader();
657 } 652 }
658 653
659 if (isLoading()) { 654 if (isLoading()) {
660 loader()->cancel(); 655 loader()->cancel();
661 // Canceling the loader causes error() to be called, which in turn calls 656 // Canceling the loader causes error() to be called, which in turn calls
662 // clear() and notifyObservers(), so there's no need to call these again 657 // clear() and notifyObservers(), so there's no need to call these again
663 // here. 658 // here.
664 } else { 659 } else {
665 clear(); 660 clear();
666 notifyObservers(); 661 notifyObservers(false);
667 } 662 }
668 663
669 setStatus(NotStarted); 664 setStatus(NotStarted);
670 665
671 DCHECK(m_isSchedulingReload); 666 DCHECK(m_isSchedulingReload);
672 m_isSchedulingReload = false; 667 m_isSchedulingReload = false;
673 668
674 fetcher->startLoad(this); 669 fetcher->startLoad(this);
675 } 670 }
676 671
677 void ImageResource::changedInRect(const blink::Image* image, 672 void ImageResource::changedInRect(const blink::Image* image,
678 const IntRect& rect) { 673 const IntRect& rect) {
679 if (!image || image != m_image) 674 if (!image || image != m_image)
680 return; 675 return;
681 notifyObservers(&rect); 676 notifyObservers(false, &rect);
682 } 677 }
683 678
684 void ImageResource::onePartInMultipartReceived( 679 void ImageResource::onePartInMultipartReceived(
685 const ResourceResponse& response) { 680 const ResourceResponse& response) {
686 DCHECK(m_multipartParser); 681 DCHECK(m_multipartParser);
687 682
688 setResponse(response); 683 setResponse(response);
689 if (m_multipartParsingState == MultipartParsingState::WaitingForFirstPart) { 684 if (m_multipartParsingState == MultipartParsingState::WaitingForFirstPart) {
690 // We have nothing to do because we don't have any data. 685 // We have nothing to do because we don't have any data.
691 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; 686 m_multipartParsingState = MultipartParsingState::ParsingFirstPart;
(...skipping 25 matching lines...) Expand all
717 WebServiceWorkerResponseTypeOpaque; 712 WebServiceWorkerResponseTypeOpaque;
718 } 713 }
719 if (!getImage()->currentFrameHasSingleSecurityOrigin()) 714 if (!getImage()->currentFrameHasSingleSecurityOrigin())
720 return false; 715 return false;
721 if (passesAccessControlCheck(securityOrigin)) 716 if (passesAccessControlCheck(securityOrigin))
722 return true; 717 return true;
723 return !securityOrigin->taintsCanvas(response().url()); 718 return !securityOrigin->taintsCanvas(response().url());
724 } 719 }
725 720
726 } // namespace blink 721 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698