Chromium Code Reviews| 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 |
| 11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
| 12 | 12 |
| 13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 Library General Public License for more details. | 16 Library General Public License for more details. |
| 17 | 17 |
| 18 You should have received a copy of the GNU Library General Public License | 18 You should have received a copy of the GNU Library General Public License |
| 19 along with this library; see the file COPYING.LIB. If not, write to | 19 along with this library; see the file COPYING.LIB. If not, write to |
| 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "core/fetch/ImageResource.h" | 24 #include "core/fetch/ImageResource.h" |
| 25 | 25 |
| 26 #include "core/fetch/ImageResourceClient.h" | 26 #include "core/fetch/ImageResourceObserver.h" |
| 27 #include "core/fetch/MemoryCache.h" | 27 #include "core/fetch/MemoryCache.h" |
| 28 #include "core/fetch/ResourceClient.h" | 28 #include "core/fetch/ResourceClient.h" |
| 29 #include "core/fetch/ResourceClientWalker.h" | 29 #include "core/fetch/ResourceClientWalker.h" |
| 30 #include "core/fetch/ResourceFetcher.h" | 30 #include "core/fetch/ResourceFetcher.h" |
| 31 #include "core/fetch/ResourceLoader.h" | 31 #include "core/fetch/ResourceLoader.h" |
| 32 #include "core/svg/graphics/SVGImage.h" | 32 #include "core/svg/graphics/SVGImage.h" |
| 33 #include "platform/Logging.h" | 33 #include "platform/Logging.h" |
| 34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
| 35 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
| 36 #include "platform/TraceEvent.h" | 36 #include "platform/TraceEvent.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
| 38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 39 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
| 40 #include "wtf/StdLibExtras.h" | 40 #include "wtf/StdLibExtras.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 namespace { | |
|
yhirano
2016/03/17 04:44:57
Is this unnamed namespace necessary? My (rough) un
hiroshige
2016/03/23 18:47:25
Done.
| |
| 45 | |
| 46 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource Observer, ImageResourceObserver>; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 44 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request , ResourceFetcher* fetcher) | 50 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request , ResourceFetcher* fetcher) |
| 45 { | 51 { |
| 46 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) | 52 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) |
| 47 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); | 53 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); |
| 48 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 54 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
| 49 KURL requestURL = request.resourceRequest().url(); | 55 KURL requestURL = request.resourceRequest().url(); |
| 50 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.getOriginRestriction())) | 56 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.getOriginRestriction())) |
| 51 fetcher->context().sendImagePing(requestURL); | 57 fetcher->context().sendImagePing(requestURL); |
| 52 return nullptr; | 58 return nullptr; |
| 53 } | 59 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } | 112 } |
| 107 | 113 |
| 108 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& options) | 114 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& options) |
| 109 { | 115 { |
| 110 if (!fetcher || fetcher->autoLoadImages()) | 116 if (!fetcher || fetcher->autoLoadImages()) |
| 111 Resource::load(fetcher, options); | 117 Resource::load(fetcher, options); |
| 112 else | 118 else |
| 113 setLoading(false); | 119 setLoading(false); |
| 114 } | 120 } |
| 115 | 121 |
| 116 void ImageResource::didAddClient(ResourceClient* c) | 122 void ImageResource::addObserver(ImageResourceObserver* observer) |
| 117 { | 123 { |
| 124 willAddClientOrObserver(); | |
| 125 | |
| 126 m_observers.add(observer); | |
| 127 | |
| 128 if (!m_revalidatingRequest.isNull()) | |
| 129 return; | |
| 130 | |
| 118 if (m_data && !m_image && !errorOccurred()) { | 131 if (m_data && !m_image && !errorOccurred()) { |
| 119 createImage(); | 132 createImage(); |
| 120 m_image->setData(m_data, true); | 133 m_image->setData(m_data, true); |
| 121 } | 134 } |
| 122 | 135 |
| 123 ASSERT(ImageResourceClient::isExpectedType(c)); | |
| 124 if (m_image && !m_image->isNull()) | 136 if (m_image && !m_image->isNull()) |
| 125 static_cast<ImageResourceClient*>(c)->imageChanged(this); | 137 observer->imageChanged(this); |
| 126 | |
| 127 Resource::didAddClient(c); | |
| 128 } | 138 } |
| 129 | 139 |
| 130 void ImageResource::didRemoveClient(ResourceClient* c) | 140 void ImageResource::removeObserver(ImageResourceObserver* observer) |
| 131 { | 141 { |
| 132 ASSERT(c); | 142 ASSERT(observer); |
| 133 ASSERT(ImageResourceClient::isExpectedType(c)); | 143 ASSERT(m_observers.contains(observer)); |
| 144 m_observers.remove(observer); | |
| 145 didRemoveClientOrObserver(); | |
| 146 } | |
| 134 | 147 |
| 135 Resource::didRemoveClient(c); | 148 ResourcePriority ImageResource::priorityFromObservers() |
| 149 { | |
| 150 ResourcePriority priority; | |
| 151 ImageResourceObserverWalker w(m_observers); | |
| 152 while (const auto* observer = w.next()) { | |
| 153 ResourcePriority nextPriority = observer->computeResourcePriority(); | |
| 154 if (nextPriority.visibility == ResourcePriority::NotVisible) | |
| 155 continue; | |
| 156 priority.visibility = ResourcePriority::Visible; | |
| 157 priority.intraPriorityValue += nextPriority.intraPriorityValue; | |
| 158 } | |
| 159 return priority; | |
| 136 } | 160 } |
| 137 | 161 |
| 138 bool ImageResource::isSafeToUnlock() const | 162 bool ImageResource::isSafeToUnlock() const |
| 139 { | 163 { |
| 140 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. | 164 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. |
| 141 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); | 165 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); |
| 142 } | 166 } |
| 143 | 167 |
| 144 void ImageResource::destroyDecodedDataForFailedRevalidation() | 168 void ImageResource::destroyDecodedDataForFailedRevalidation() |
| 145 { | 169 { |
| 146 m_image = nullptr; | 170 m_image = nullptr; |
| 147 setDecodedSize(0); | 171 setDecodedSize(0); |
| 148 } | 172 } |
| 149 | 173 |
| 150 void ImageResource::destroyDecodedDataIfPossible() | 174 void ImageResource::destroyDecodedDataIfPossible() |
| 151 { | 175 { |
| 152 if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m _image->isBitmapImage()))) { | 176 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn eRef() && m_image->isBitmapImage()))) { |
| 153 m_image = nullptr; | 177 m_image = nullptr; |
| 154 setDecodedSize(0); | 178 setDecodedSize(0); |
| 155 } else if (m_image && !errorOccurred()) { | 179 } else if (m_image && !errorOccurred()) { |
| 156 m_image->destroyDecodedData(true); | 180 m_image->destroyDecodedData(true); |
| 157 } | 181 } |
| 158 } | 182 } |
| 159 | 183 |
| 160 void ImageResource::allClientsRemoved() | 184 void ImageResource::allClientsAndObserversRemoved() |
| 161 { | 185 { |
| 162 if (m_image && !errorOccurred()) | 186 if (m_image && !errorOccurred()) |
| 163 m_image->resetAnimation(); | 187 m_image->resetAnimation(); |
| 164 if (m_multipartParser) | 188 if (m_multipartParser) |
| 165 m_multipartParser->cancel(); | 189 m_multipartParser->cancel(); |
| 166 Resource::allClientsRemoved(); | 190 Resource::allClientsAndObserversRemoved(); |
| 167 } | 191 } |
| 168 | 192 |
| 169 void ImageResource::appendData(const char* data, size_t length) | 193 void ImageResource::appendData(const char* data, size_t length) |
| 170 { | 194 { |
| 171 if (m_multipartParser) { | 195 if (m_multipartParser) { |
| 172 m_multipartParser->appendData(data, length); | 196 m_multipartParser->appendData(data, length); |
| 173 } else { | 197 } else { |
| 174 Resource::appendData(data, length); | 198 Resource::appendData(data, length); |
| 175 updateImage(false); | 199 updateImage(false); |
| 176 } | 200 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed . | 272 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed . |
| 249 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU nit(), | 273 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU nit(), |
| 250 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit())) ; | 274 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit())) ; |
| 251 size.scale(multiplier); | 275 size.scale(multiplier); |
| 252 size.clampToMinimumSize(minimumSize); | 276 size.clampToMinimumSize(minimumSize); |
| 253 return size; | 277 return size; |
| 254 } | 278 } |
| 255 | 279 |
| 256 void ImageResource::notifyObservers(const IntRect* changeRect) | 280 void ImageResource::notifyObservers(const IntRect* changeRect) |
| 257 { | 281 { |
| 258 ResourceClientWalker<ImageResourceClient> w(m_clients); | 282 ImageResourceObserverWalker w(m_observers); |
| 259 while (ImageResourceClient* c = w.next()) | 283 while (auto* observer = w.next()) { |
| 260 c->imageChanged(this, changeRect); | 284 observer->imageChanged(this, changeRect); |
| 261 | 285 } |
| 262 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
| 263 while (ImageResourceClient* c = w2.next()) | |
| 264 c->imageChanged(this, changeRect); | |
| 265 } | 286 } |
| 266 | 287 |
| 267 void ImageResource::clear() | 288 void ImageResource::clear() |
| 268 { | 289 { |
| 269 prune(); | 290 prune(); |
| 270 clearImage(); | 291 clearImage(); |
| 271 setEncodedSize(0); | 292 setEncodedSize(0); |
| 272 } | 293 } |
| 273 | 294 |
| 274 void ImageResource::setCustomAcceptHeader() | 295 void ImageResource::setCustomAcceptHeader() |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 // to update MemoryCache. | 416 // to update MemoryCache. |
| 396 if (decodedSize() != 0) | 417 if (decodedSize() != 0) |
| 397 Resource::didAccessDecodedData(); | 418 Resource::didAccessDecodedData(); |
| 398 } | 419 } |
| 399 | 420 |
| 400 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 421 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
| 401 { | 422 { |
| 402 if (!image || image != m_image) | 423 if (!image || image != m_image) |
| 403 return false; | 424 return false; |
| 404 | 425 |
| 405 ResourceClientWalker<ImageResourceClient> w(m_clients); | 426 ImageResourceObserverWalker w(m_observers); |
| 406 while (ImageResourceClient* c = w.next()) { | 427 while (auto* observer = w.next()) { |
| 407 if (c->willRenderImage(this)) | 428 if (observer->willRenderImage()) |
| 408 return false; | 429 return false; |
| 409 } | 430 } |
| 410 | |
| 411 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
| 412 while (ImageResourceClient* c = w2.next()) { | |
| 413 if (c->willRenderImage(this)) | |
| 414 return false; | |
| 415 } | |
| 416 | |
| 417 return true; | 431 return true; |
| 418 } | 432 } |
| 419 | 433 |
| 420 void ImageResource::animationAdvanced(const blink::Image* image) | 434 void ImageResource::animationAdvanced(const blink::Image* image) |
| 421 { | 435 { |
| 422 if (!image || image != m_image) | 436 if (!image || image != m_image) |
| 423 return; | 437 return; |
| 424 notifyObservers(); | 438 notifyObservers(); |
| 425 } | 439 } |
| 426 | 440 |
| 427 void ImageResource::updateImageAnimationPolicy() | 441 void ImageResource::updateImageAnimationPolicy() |
| 428 { | 442 { |
| 429 if (!m_image) | 443 if (!m_image) |
| 430 return; | 444 return; |
| 431 | 445 |
| 432 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 446 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
| 433 ResourceClientWalker<ImageResourceClient> w(m_clients); | 447 ImageResourceObserverWalker w(m_observers); |
| 434 while (ImageResourceClient* c = w.next()) { | 448 while (auto* observer = w.next()) { |
| 435 if (c->getImageAnimationPolicy(this, newPolicy)) | 449 if (observer->getImageAnimationPolicy(newPolicy)) |
| 436 break; | 450 break; |
| 437 } | 451 } |
| 438 | 452 |
| 439 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
| 440 while (ImageResourceClient* c = w2.next()) { | |
| 441 if (c->getImageAnimationPolicy(this, newPolicy)) | |
| 442 break; | |
| 443 } | |
| 444 | |
| 445 if (m_image->animationPolicy() != newPolicy) { | 453 if (m_image->animationPolicy() != newPolicy) { |
| 446 m_image->resetAnimation(); | 454 m_image->resetAnimation(); |
| 447 m_image->setAnimationPolicy(newPolicy); | 455 m_image->setAnimationPolicy(newPolicy); |
| 448 } | 456 } |
| 449 } | 457 } |
| 450 | 458 |
| 451 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 459 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| 452 { | 460 { |
| 453 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 461 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
| 454 return; | 462 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 if (response().wasFetchedViaServiceWorker()) | 499 if (response().wasFetchedViaServiceWorker()) |
| 492 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; | 500 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; |
| 493 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 501 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 494 return false; | 502 return false; |
| 495 if (passesAccessControlCheck(securityOrigin)) | 503 if (passesAccessControlCheck(securityOrigin)) |
| 496 return true; | 504 return true; |
| 497 return !securityOrigin->taintsCanvas(response().url()); | 505 return !securityOrigin->taintsCanvas(response().url()); |
| 498 } | 506 } |
| 499 | 507 |
| 500 } // namespace blink | 508 } // namespace blink |
| OLD | NEW |