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