Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: Source/core/fetch/ImageResource.cpp

Issue 1291883002: Use precaching for more data: urls than just images. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tweak determineRevalidationPolicy ordering Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/ImageResource.h ('k') | Source/core/fetch/RawResource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 #include "platform/RuntimeEnabledFeatures.h" 38 #include "platform/RuntimeEnabledFeatures.h"
39 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
40 #include "platform/TraceEvent.h" 40 #include "platform/TraceEvent.h"
41 #include "platform/graphics/BitmapImage.h" 41 #include "platform/graphics/BitmapImage.h"
42 #include "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
43 #include "wtf/CurrentTime.h" 43 #include "wtf/CurrentTime.h"
44 #include "wtf/StdLibExtras.h" 44 #include "wtf/StdLibExtras.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 void ImageResource::preCacheDataURIImage(const FetchRequest& request, ResourceFe tcher* fetcher)
49 {
50 const KURL& url = request.resourceRequest().url();
51 ASSERT(url.protocolIsData());
52
53 const String cacheIdentifier = fetcher->getCacheIdentifier();
54 if (memoryCache()->resourceForURL(url, cacheIdentifier))
55 return;
56
57 WebString mimetype;
58 WebString charset;
59 RefPtr<SharedBuffer> data = PassRefPtr<SharedBuffer>(Platform::current()->pa rseDataURL(url, mimetype, charset));
60 if (!data)
61 return;
62 ResourceResponse response(url, mimetype, data->size(), charset, String());
63
64 Resource* resource = new ImageResource(request.resourceRequest());
65 resource->setOptions(request.options());
66 // FIXME: We should provide a body stream here.
67 resource->responseReceived(response, nullptr);
68 if (data->size())
69 resource->setResourceBuffer(data);
70 resource->setCacheIdentifier(cacheIdentifier);
71 resource->finish();
72 memoryCache()->add(resource);
73 fetcher->scheduleDocumentResourcesGC();
74 }
75
76 ResourcePtr<ImageResource> ImageResource::fetch(FetchRequest& request, ResourceF etcher* fetcher) 48 ResourcePtr<ImageResource> ImageResource::fetch(FetchRequest& request, ResourceF etcher* fetcher)
77 { 49 {
78 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) 50 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified)
79 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); 51 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage);
80 if (fetcher->context().pageDismissalEventBeingDispatched()) { 52 if (fetcher->context().pageDismissalEventBeingDispatched()) {
81 KURL requestURL = request.resourceRequest().url(); 53 KURL requestURL = request.resourceRequest().url();
82 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.originRestriction())) 54 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.originRestriction()))
83 fetcher->context().sendImagePing(requestURL); 55 fetcher->context().sendImagePing(requestURL);
84 return 0; 56 return 0;
85 } 57 }
86 58
87 if (request.resourceRequest().url().protocolIsData())
88 ImageResource::preCacheDataURIImage(request, fetcher);
89
90 if (fetcher->clientDefersImage(request.resourceRequest().url())) 59 if (fetcher->clientDefersImage(request.resourceRequest().url()))
91 request.setDefer(FetchRequest::DeferredByClient); 60 request.setDefer(FetchRequest::DeferredByClient);
92 61
93 return toImageResource(fetcher->requestResource(request, ImageResourceFactor y())); 62 return toImageResource(fetcher->requestResource(request, ImageResourceFactor y()));
94 } 63 }
95 64
96 ImageResource::ImageResource(const ResourceRequest& resourceRequest) 65 ImageResource::ImageResource(const ResourceRequest& resourceRequest)
97 : Resource(resourceRequest, Image) 66 : Resource(resourceRequest, Image)
98 , m_devicePixelRatioHeaderValue(1.0) 67 , m_devicePixelRatioHeaderValue(1.0)
99 , m_image(nullptr) 68 , m_image(nullptr)
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 534
566 return imageForContainer.get(); 535 return imageForContainer.get();
567 } 536 }
568 537
569 bool ImageResource::loadingMultipartContent() const 538 bool ImageResource::loadingMultipartContent() const
570 { 539 {
571 return m_loader && m_loader->loadingMultipartContent(); 540 return m_loader && m_loader->loadingMultipartContent();
572 } 541 }
573 542
574 } // namespace blink 543 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/fetch/ImageResource.h ('k') | Source/core/fetch/RawResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698