| 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::ensureImage() | 122 void ImageResource::ensureImage() |
| 119 { | 123 { |
| 120 if (m_data && !m_image && !errorOccurred()) { | 124 if (m_data && !m_image && !errorOccurred()) { |
| 121 createImage(); | 125 createImage(); |
| 122 m_image->setData(m_data, true); | 126 m_image->setData(m_data, true); |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 | 129 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 if (isCacheValidator()) | 142 if (isCacheValidator()) |
| 139 return; | 143 return; |
| 140 | 144 |
| 141 ensureImage(); | 145 ensureImage(); |
| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; | 555 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; |
| 555 return; | 556 return; |
| 556 } | 557 } |
| 557 updateImageAndClearBuffer(); | 558 updateImageAndClearBuffer(); |
| 558 | 559 |
| 559 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { | 560 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { |
| 560 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPar
t; | 561 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPar
t; |
| 561 // Notify finished when the first part ends. | 562 // Notify finished when the first part ends. |
| 562 if (!errorOccurred()) | 563 if (!errorOccurred()) |
| 563 setStatus(Cached); | 564 setStatus(Cached); |
| 564 checkNotify(); | 565 // We will also notify clients/observers of the finish in |
| 566 // Resource::finish()/error() so we don't mark them finished here. |
| 567 notifyObserversInternal(MarkFinishedOption::DoNotMarkFinished); |
| 568 notifyClientsInternal(MarkFinishedOption::DoNotMarkFinished); |
| 565 if (m_loader) | 569 if (m_loader) |
| 566 m_loader->didFinishLoadingFirstPartInMultipart(); | 570 m_loader->didFinishLoadingFirstPartInMultipart(); |
| 567 } | 571 } |
| 568 } | 572 } |
| 569 | 573 |
| 570 void ImageResource::multipartDataReceived(const char* bytes, size_t size) | 574 void ImageResource::multipartDataReceived(const char* bytes, size_t size) |
| 571 { | 575 { |
| 572 ASSERT(m_multipartParser); | 576 ASSERT(m_multipartParser); |
| 573 Resource::appendData(bytes, size); | 577 Resource::appendData(bytes, size); |
| 574 } | 578 } |
| 575 | 579 |
| 576 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) | 580 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) |
| 577 { | 581 { |
| 578 if (response().wasFetchedViaServiceWorker()) | 582 if (response().wasFetchedViaServiceWorker()) |
| 579 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 583 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
| 580 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 584 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 581 return false; | 585 return false; |
| 582 if (passesAccessControlCheck(securityOrigin)) | 586 if (passesAccessControlCheck(securityOrigin)) |
| 583 return true; | 587 return true; |
| 584 return !securityOrigin->taintsCanvas(response().url()); | 588 return !securityOrigin->taintsCanvas(response().url()); |
| 585 } | 589 } |
| 586 | 590 |
| 587 } // namespace blink | 591 } // namespace blink |
| OLD | NEW |