OLD | NEW |
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 DEFINE_TRACE(ImageResource) | 88 DEFINE_TRACE(ImageResource) |
89 { | 89 { |
90 visitor->trace(m_multipartParser); | 90 visitor->trace(m_multipartParser); |
91 Resource::trace(visitor); | 91 Resource::trace(visitor); |
92 ImageObserver::trace(visitor); | 92 ImageObserver::trace(visitor); |
93 MultipartImageResourceParser::Client::trace(visitor); | 93 MultipartImageResourceParser::Client::trace(visitor); |
94 } | 94 } |
95 | 95 |
96 void ImageResource::checkNotify() | 96 void ImageResource::checkNotify() |
97 { | 97 { |
| 98 notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished); |
| 99 Resource::checkNotify(); |
| 100 } |
| 101 |
| 102 void ImageResource::notifyObserversInternal(MarkFinishedOption markFinishedOptio
n) |
| 103 { |
98 if (isLoading()) | 104 if (isLoading()) |
99 return; | 105 return; |
100 | 106 |
101 ImageResourceObserverWalker walker(m_observers); | 107 ImageResourceObserverWalker walker(m_observers); |
102 while (auto* observer = walker.next()) { | 108 while (auto* observer = walker.next()) { |
| 109 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished) |
| 110 markObserverFinished(observer); |
103 observer->imageNotifyFinished(this); | 111 observer->imageNotifyFinished(this); |
104 } | 112 } |
105 | |
106 Resource::checkNotify(); | |
107 } | 113 } |
108 | 114 |
109 void ImageResource::markClientsAndObserversFinished() | 115 void ImageResource::markObserverFinished(ImageResourceObserver* observer) |
110 { | 116 { |
111 HashCountedSet<ImageResourceObserver*> observers; | 117 if (m_observers.contains(observer)) { |
112 m_observers.swap(observers); | 118 m_finishedObservers.add(observer); |
113 for (const auto& it : observers) | 119 m_observers.remove(observer); |
114 m_finishedObservers.add(it.key, it.value); | 120 } |
115 | |
116 Resource::markClientsAndObserversFinished(); | |
117 } | 121 } |
118 | 122 |
119 void ImageResource::didAddClient(ResourceClient* client) | 123 void ImageResource::didAddClient(ResourceClient* client) |
120 { | 124 { |
121 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); | 125 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); |
122 Resource::didAddClient(client); | 126 Resource::didAddClient(client); |
123 } | 127 } |
124 | 128 |
125 void ImageResource::addObserver(ImageResourceObserver* observer) | 129 void ImageResource::addObserver(ImageResourceObserver* observer) |
126 { | 130 { |
(...skipping 12 matching lines...) Expand all Loading... |
139 // not called in |appendData()|, which means |m_image| might not be created | 143 // not called in |appendData()|, which means |m_image| might not be created |
140 // even when |data()| exists. This is intentional since creating a |m_image| | 144 // even when |data()| exists. This is intentional since creating a |m_image| |
141 // on receiving data might destroy an existing image in a previous part. | 145 // on receiving data might destroy an existing image in a previous part. |
142 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); | 146 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); |
143 | 147 |
144 if (m_image && !m_image->isNull()) { | 148 if (m_image && !m_image->isNull()) { |
145 observer->imageChanged(this); | 149 observer->imageChanged(this); |
146 } | 150 } |
147 | 151 |
148 if (isLoaded()) { | 152 if (isLoaded()) { |
| 153 markObserverFinished(observer); |
149 observer->imageNotifyFinished(this); | 154 observer->imageNotifyFinished(this); |
150 if (m_observers.contains(observer)) { | |
151 m_finishedObservers.add(observer); | |
152 m_observers.remove(observer); | |
153 } | |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 void ImageResource::removeObserver(ImageResourceObserver* observer) | 158 void ImageResource::removeObserver(ImageResourceObserver* observer) |
158 { | 159 { |
159 ASSERT(observer); | 160 ASSERT(observer); |
160 | 161 |
161 if (m_observers.contains(observer)) | 162 if (m_observers.contains(observer)) |
162 m_observers.remove(observer); | 163 m_observers.remove(observer); |
163 else if (m_finishedObservers.contains(observer)) | 164 else if (m_finishedObservers.contains(observer)) |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; | 575 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; |
575 return; | 576 return; |
576 } | 577 } |
577 updateImageAndClearBuffer(); | 578 updateImageAndClearBuffer(); |
578 | 579 |
579 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { | 580 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { |
580 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPar
t; | 581 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPar
t; |
581 // Notify finished when the first part ends. | 582 // Notify finished when the first part ends. |
582 if (!errorOccurred()) | 583 if (!errorOccurred()) |
583 setStatus(Cached); | 584 setStatus(Cached); |
584 checkNotify(); | 585 // We will also notify clients/observers of the finish in |
| 586 // Resource::finish()/error() so we don't mark them finished here. |
| 587 notifyObserversInternal(MarkFinishedOption::DoNotMarkFinished); |
| 588 notifyClientsInternal(MarkFinishedOption::DoNotMarkFinished); |
585 if (loader()) | 589 if (loader()) |
586 loader()->didFinishLoadingFirstPartInMultipart(); | 590 loader()->didFinishLoadingFirstPartInMultipart(); |
587 } | 591 } |
588 } | 592 } |
589 | 593 |
590 void ImageResource::multipartDataReceived(const char* bytes, size_t size) | 594 void ImageResource::multipartDataReceived(const char* bytes, size_t size) |
591 { | 595 { |
592 ASSERT(m_multipartParser); | 596 ASSERT(m_multipartParser); |
593 Resource::appendData(bytes, size); | 597 Resource::appendData(bytes, size); |
594 } | 598 } |
595 | 599 |
596 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) | 600 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) |
597 { | 601 { |
598 if (response().wasFetchedViaServiceWorker()) | 602 if (response().wasFetchedViaServiceWorker()) |
599 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 603 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
600 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 604 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
601 return false; | 605 return false; |
602 if (passesAccessControlCheck(securityOrigin)) | 606 if (passesAccessControlCheck(securityOrigin)) |
603 return true; | 607 return true; |
604 return !securityOrigin->taintsCanvas(response().url()); | 608 return !securityOrigin->taintsCanvas(response().url()); |
605 } | 609 } |
606 | 610 |
607 } // namespace blink | 611 } // namespace blink |
OLD | NEW |