| 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 30 matching lines...) Expand all Loading... |
| 41 #include "wtf/StdLibExtras.h" | 41 #include "wtf/StdLibExtras.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include <memory> | 43 #include <memory> |
| 44 #include <v8.h> | 44 #include <v8.h> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 ImageResource* ImageResource::fetch(FetchRequest& request, | 48 ImageResource* ImageResource::fetch(FetchRequest& request, |
| 49 ResourceFetcher* fetcher) { | 49 ResourceFetcher* fetcher) { |
| 50 if (request.resourceRequest().requestContext() == | 50 if (request.resourceRequest().requestContext() == |
| 51 WebURLRequest::RequestContextUnspecified) | 51 WebURLRequest::RequestContextUnspecified) { |
| 52 request.mutableResourceRequest().setRequestContext( | 52 request.mutableResourceRequest().setRequestContext( |
| 53 WebURLRequest::RequestContextImage); | 53 WebURLRequest::RequestContextImage); |
| 54 } |
| 54 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 55 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
| 55 KURL requestURL = request.resourceRequest().url(); | 56 KURL requestURL = request.resourceRequest().url(); |
| 56 if (requestURL.isValid() && | 57 if (requestURL.isValid() && |
| 57 fetcher->context().canRequest(Resource::Image, | 58 fetcher->context().canRequest(Resource::Image, |
| 58 request.resourceRequest(), requestURL, | 59 request.resourceRequest(), requestURL, |
| 59 request.options(), request.forPreload(), | 60 request.options(), request.forPreload(), |
| 60 request.getOriginRestriction())) | 61 request.getOriginRestriction())) |
| 61 fetcher->context().sendImagePing(requestURL); | 62 fetcher->context().sendImagePing(requestURL); |
| 62 return nullptr; | 63 return nullptr; |
| 63 } | 64 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (m_image) | 223 if (m_image) |
| 223 m_image->resetAnimation(); | 224 m_image->resetAnimation(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void ImageResource::allClientsAndObserversRemoved() { | 227 void ImageResource::allClientsAndObserversRemoved() { |
| 227 if (m_image) { | 228 if (m_image) { |
| 228 CHECK(!errorOccurred()); | 229 CHECK(!errorOccurred()); |
| 229 // If possible, delay the resetting until back at the event loop. Doing so | 230 // If possible, delay the resetting until back at the event loop. Doing so |
| 230 // after a conservative GC prevents resetAnimation() from upsetting ongoing | 231 // after a conservative GC prevents resetAnimation() from upsetting ongoing |
| 231 // animation updates (crbug.com/613709) | 232 // animation updates (crbug.com/613709) |
| 232 if (!ThreadHeap::willObjectBeLazilySwept(this)) | 233 if (!ThreadHeap::willObjectBeLazilySwept(this)) { |
| 233 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | 234 Platform::current()->currentThread()->getWebTaskRunner()->postTask( |
| 234 BLINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, | 235 BLINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, |
| 235 wrapWeakPersistent(this))); | 236 wrapWeakPersistent(this))); |
| 236 else | 237 } else { |
| 237 m_image->resetAnimation(); | 238 m_image->resetAnimation(); |
| 239 } |
| 238 } | 240 } |
| 239 if (m_multipartParser) | 241 if (m_multipartParser) |
| 240 m_multipartParser->cancel(); | 242 m_multipartParser->cancel(); |
| 241 Resource::allClientsAndObserversRemoved(); | 243 Resource::allClientsAndObserversRemoved(); |
| 242 } | 244 } |
| 243 | 245 |
| 244 PassRefPtr<const SharedBuffer> ImageResource::resourceBuffer() const { | 246 PassRefPtr<const SharedBuffer> ImageResource::resourceBuffer() const { |
| 245 if (data()) | 247 if (data()) |
| 246 return data(); | 248 return data(); |
| 247 if (m_image) | 249 if (m_image) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 LayoutSize ImageResource::imageSize( | 310 LayoutSize ImageResource::imageSize( |
| 309 RespectImageOrientationEnum shouldRespectImageOrientation, | 311 RespectImageOrientationEnum shouldRespectImageOrientation, |
| 310 float multiplier, | 312 float multiplier, |
| 311 SizeType sizeType) { | 313 SizeType sizeType) { |
| 312 if (!m_image) | 314 if (!m_image) |
| 313 return LayoutSize(); | 315 return LayoutSize(); |
| 314 | 316 |
| 315 LayoutSize size; | 317 LayoutSize size; |
| 316 | 318 |
| 317 if (m_image->isBitmapImage() && | 319 if (m_image->isBitmapImage() && |
| 318 shouldRespectImageOrientation == RespectImageOrientation) | 320 shouldRespectImageOrientation == RespectImageOrientation) { |
| 319 size = | 321 size = |
| 320 LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrientation()); | 322 LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrientation()); |
| 321 else | 323 } else { |
| 322 size = LayoutSize(m_image->size()); | 324 size = LayoutSize(m_image->size()); |
| 325 } |
| 323 | 326 |
| 324 if (sizeType == IntrinsicCorrectedToDPR && m_hasDevicePixelRatioHeaderValue && | 327 if (sizeType == IntrinsicCorrectedToDPR && m_hasDevicePixelRatioHeaderValue && |
| 325 m_devicePixelRatioHeaderValue > 0) | 328 m_devicePixelRatioHeaderValue > 0) |
| 326 multiplier = 1 / m_devicePixelRatioHeaderValue; | 329 multiplier = 1 / m_devicePixelRatioHeaderValue; |
| 327 | 330 |
| 328 if (multiplier == 1 || m_image->hasRelativeSize()) | 331 if (multiplier == 1 || m_image->hasRelativeSize()) |
| 329 return size; | 332 return size; |
| 330 | 333 |
| 331 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed. | 334 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed. |
| 332 LayoutSize minimumSize( | 335 LayoutSize minimumSize( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 Resource::error(error); | 447 Resource::error(error); |
| 445 notifyObservers(); | 448 notifyObservers(); |
| 446 } | 449 } |
| 447 | 450 |
| 448 void ImageResource::responseReceived( | 451 void ImageResource::responseReceived( |
| 449 const ResourceResponse& response, | 452 const ResourceResponse& response, |
| 450 std::unique_ptr<WebDataConsumerHandle> handle) { | 453 std::unique_ptr<WebDataConsumerHandle> handle) { |
| 451 DCHECK(!handle); | 454 DCHECK(!handle); |
| 452 DCHECK(!m_multipartParser); | 455 DCHECK(!m_multipartParser); |
| 453 // If there's no boundary, just handle the request normally. | 456 // If there's no boundary, just handle the request normally. |
| 454 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) | 457 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { |
| 455 m_multipartParser = new MultipartImageResourceParser( | 458 m_multipartParser = new MultipartImageResourceParser( |
| 456 response, response.multipartBoundary(), this); | 459 response, response.multipartBoundary(), this); |
| 460 } |
| 457 Resource::responseReceived(response, std::move(handle)); | 461 Resource::responseReceived(response, std::move(handle)); |
| 458 if (RuntimeEnabledFeatures::clientHintsEnabled()) { | 462 if (RuntimeEnabledFeatures::clientHintsEnabled()) { |
| 459 m_devicePixelRatioHeaderValue = | 463 m_devicePixelRatioHeaderValue = |
| 460 this->response() | 464 this->response() |
| 461 .httpHeaderField(HTTPNames::Content_DPR) | 465 .httpHeaderField(HTTPNames::Content_DPR) |
| 462 .toFloat(&m_hasDevicePixelRatioHeaderValue); | 466 .toFloat(&m_hasDevicePixelRatioHeaderValue); |
| 463 if (!m_hasDevicePixelRatioHeaderValue || | 467 if (!m_hasDevicePixelRatioHeaderValue || |
| 464 m_devicePixelRatioHeaderValue <= 0.0) { | 468 m_devicePixelRatioHeaderValue <= 0.0) { |
| 465 m_devicePixelRatioHeaderValue = 1.0; | 469 m_devicePixelRatioHeaderValue = 1.0; |
| 466 m_hasDevicePixelRatioHeaderValue = false; | 470 m_hasDevicePixelRatioHeaderValue = false; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 loader()->didFinishLoadingFirstPartInMultipart(); | 601 loader()->didFinishLoadingFirstPartInMultipart(); |
| 598 } | 602 } |
| 599 } | 603 } |
| 600 | 604 |
| 601 void ImageResource::multipartDataReceived(const char* bytes, size_t size) { | 605 void ImageResource::multipartDataReceived(const char* bytes, size_t size) { |
| 602 DCHECK(m_multipartParser); | 606 DCHECK(m_multipartParser); |
| 603 Resource::appendData(bytes, size); | 607 Resource::appendData(bytes, size); |
| 604 } | 608 } |
| 605 | 609 |
| 606 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) { | 610 bool ImageResource::isAccessAllowed(SecurityOrigin* securityOrigin) { |
| 607 if (response().wasFetchedViaServiceWorker()) | 611 if (response().wasFetchedViaServiceWorker()) { |
| 608 return response().serviceWorkerResponseType() != | 612 return response().serviceWorkerResponseType() != |
| 609 WebServiceWorkerResponseTypeOpaque; | 613 WebServiceWorkerResponseTypeOpaque; |
| 614 } |
| 610 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 615 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 611 return false; | 616 return false; |
| 612 if (passesAccessControlCheck(securityOrigin)) | 617 if (passesAccessControlCheck(securityOrigin)) |
| 613 return true; | 618 return true; |
| 614 return !securityOrigin->taintsCanvas(response().url()); | 619 return !securityOrigin->taintsCanvas(response().url()); |
| 615 } | 620 } |
| 616 | 621 |
| 617 } // namespace blink | 622 } // namespace blink |
| OLD | NEW |