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

Side by Side Diff: content/renderer/fetchers/resource_fetcher_impl.cc

Issue 840553003: Use a FrameAssociatedLoader when downloading image resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bypass sw for favicons Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/fetchers/resource_fetcher_impl.h" 5 #include "content/renderer/fetchers/resource_fetcher_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "third_party/WebKit/public/platform/Platform.h" 10 #include "third_party/WebKit/public/platform/Platform.h"
11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 11 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
12 #include "third_party/WebKit/public/platform/WebURL.h" 12 #include "third_party/WebKit/public/platform/WebURL.h"
13 #include "third_party/WebKit/public/platform/WebURLError.h" 13 #include "third_party/WebKit/public/platform/WebURLError.h"
tyoshino (SeeGerritForStatus) 2015/01/14 04:09:41 [optional] remove this unused include using this o
mlamouri (slow - plz ping) 2015/01/14 14:31:17 Done.
14 #include "third_party/WebKit/public/platform/WebURLLoader.h" 14 #include "third_party/WebKit/public/platform/WebURLLoader.h"
15 #include "third_party/WebKit/public/platform/WebURLRequest.h" 15 #include "third_party/WebKit/public/platform/WebURLRequest.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebFrame.h" 17 #include "third_party/WebKit/public/web/WebFrame.h"
18 #include "third_party/WebKit/public/web/WebKit.h" 18 #include "third_party/WebKit/public/web/WebKit.h"
19 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 19 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
20 20
21 using base::TimeDelta; 21 using base::TimeDelta;
22 using blink::WebFrame; 22 using blink::WebFrame;
23 using blink::WebHTTPBody; 23 using blink::WebHTTPBody;
24 using blink::WebSecurityPolicy; 24 using blink::WebSecurityPolicy;
25 using blink::WebURLError; 25 using blink::WebURLError;
tyoshino (SeeGerritForStatus) 2015/01/14 04:09:41 [optional] remove this unused using using this opp
mlamouri (slow - plz ping) 2015/01/14 14:31:17 Done.
26 using blink::WebURLLoader; 26 using blink::WebURLLoader;
27 using blink::WebURLLoaderOptions;
tyoshino (SeeGerritForStatus) 2015/01/14 04:09:41 just one occurrence. maybe it's just fine to add b
mlamouri (slow - plz ping) 2015/01/14 14:31:17 I removed all the |using| while I was at it. Most
27 using blink::WebURLRequest; 28 using blink::WebURLRequest;
28 using blink::WebURLResponse; 29 using blink::WebURLResponse;
29 30
30 namespace content { 31 namespace content {
31 32
32 // static 33 // static
33 ResourceFetcher* ResourceFetcher::Create(const GURL& url) { 34 ResourceFetcher* ResourceFetcher::Create(const GURL& url) {
34 return new ResourceFetcherImpl(url); 35 return new ResourceFetcherImpl(url);
35 } 36 }
36 37
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 blink::WebReferrerPolicyDefault, 71 blink::WebReferrerPolicyDefault,
71 request_.url(), 72 request_.url(),
72 blink::WebString::fromUTF8(value)); 73 blink::WebString::fromUTF8(value));
73 request_.setHTTPReferrer(referrer, blink::WebReferrerPolicyDefault); 74 request_.setHTTPReferrer(referrer, blink::WebReferrerPolicyDefault);
74 } else { 75 } else {
75 request_.setHTTPHeaderField(blink::WebString::fromUTF8(header), 76 request_.setHTTPHeaderField(blink::WebString::fromUTF8(header),
76 blink::WebString::fromUTF8(value)); 77 blink::WebString::fromUTF8(value));
77 } 78 }
78 } 79 }
79 80
81 void ResourceFetcherImpl::SetSkipServiceWorker(bool skip_service_worker) {
82 DCHECK(!request_.isNull());
83 DCHECK(!loader_);
84
85 request_.setSkipServiceWorker(skip_service_worker);
86 }
87
88 void ResourceFetcherImpl::SetLoaderOptions(const WebURLLoaderOptions& options) {
89 DCHECK(!request_.isNull());
90 DCHECK(!loader_);
91
92 options_ = options;
93 }
94
80 void ResourceFetcherImpl::Start(WebFrame* frame, 95 void ResourceFetcherImpl::Start(WebFrame* frame,
81 WebURLRequest::RequestContext request_context, 96 WebURLRequest::RequestContext request_context,
82 WebURLRequest::FrameType frame_type, 97 WebURLRequest::FrameType frame_type,
83 LoaderType loader_type, 98 LoaderType loader_type,
84 const Callback& callback) { 99 const Callback& callback) {
85 DCHECK(!loader_); 100 DCHECK(!loader_);
86 DCHECK(!request_.isNull()); 101 DCHECK(!request_.isNull());
87 DCHECK(callback_.is_null()); 102 DCHECK(callback_.is_null());
88 DCHECK(!completed()); 103 DCHECK(!completed());
89 if (!request_.httpBody().isNull()) 104 if (!request_.httpBody().isNull())
90 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; 105 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies.";
91 106
92 callback_ = callback; 107 callback_ = callback;
93 108
94 request_.setRequestContext(request_context); 109 request_.setRequestContext(request_context);
95 request_.setFrameType(frame_type); 110 request_.setFrameType(frame_type);
96 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); 111 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies());
97 frame->dispatchWillSendRequest(request_); 112 frame->dispatchWillSendRequest(request_);
98 113
99 switch (loader_type) { 114 switch (loader_type) {
100 case PLATFORM_LOADER: 115 case PLATFORM_LOADER:
101 loader_.reset(blink::Platform::current()->createURLLoader()); 116 loader_.reset(blink::Platform::current()->createURLLoader());
102 break; 117 break;
103 case FRAME_ASSOCIATED_LOADER: 118 case FRAME_ASSOCIATED_LOADER:
104 loader_.reset(frame->createAssociatedURLLoader()); 119 loader_.reset(frame->createAssociatedURLLoader(options_));
105 break; 120 break;
106 } 121 }
107 loader_->loadAsynchronously(request_, this); 122 loader_->loadAsynchronously(request_, this);
108 123
109 // No need to hold on to the request. 124 // No need to hold on to the request.
110 request_.reset(); 125 request_.reset();
111 } 126 }
112 127
113 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { 128 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) {
114 DCHECK(loader_); 129 DCHECK(loader_);
(...skipping 13 matching lines...) Expand all
128 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), 143 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(),
129 status() == LOAD_FAILED ? std::string() : data()); 144 status() == LOAD_FAILED ? std::string() : data());
130 } 145 }
131 146
132 void ResourceFetcherImpl::Cancel() { 147 void ResourceFetcherImpl::Cancel() {
133 loader_->cancel(); 148 loader_->cancel();
134 WebURLLoaderClientImpl::Cancel(); 149 WebURLLoaderClientImpl::Cancel();
135 } 150 }
136 151
137 } // namespace content 152 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698