OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/browser/appcache/appcache_url_loader_factory.h" | 5 #include "content/browser/appcache/appcache_url_loader_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/appcache/appcache_entry.h" | 9 #include "content/browser/appcache/appcache_backend_impl.h" |
10 #include "content/browser/appcache/appcache_policy.h" | 10 #include "content/browser/appcache/appcache_host.h" |
11 #include "content/browser/appcache/appcache_navigation_handle_core.h" | |
11 #include "content/browser/appcache/appcache_request.h" | 12 #include "content/browser/appcache/appcache_request.h" |
13 #include "content/browser/appcache/appcache_request_handler.h" | |
12 #include "content/browser/appcache/appcache_storage.h" | 14 #include "content/browser/appcache/appcache_storage.h" |
15 #include "content/browser/appcache/appcache_url_loader_job.h" | |
16 #include "content/browser/appcache/appcache_url_loader_request.h" | |
13 #include "content/browser/appcache/chrome_appcache_service.h" | 17 #include "content/browser/appcache/chrome_appcache_service.h" |
18 #include "content/browser/loader/url_loader_request_handler.h" | |
14 #include "content/browser/url_loader_factory_getter.h" | 19 #include "content/browser/url_loader_factory_getter.h" |
15 #include "content/common/network_service.mojom.h" | |
16 #include "content/common/resource_request.h" | 20 #include "content/common/resource_request.h" |
17 #include "content/common/url_loader.mojom.h" | 21 #include "content/common/url_loader.mojom.h" |
18 #include "content/common/url_loader_factory.mojom.h" | 22 #include "content/common/url_loader_factory.mojom.h" |
19 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
20 #include "mojo/public/cpp/bindings/binding.h" | 24 #include "mojo/public/cpp/bindings/binding.h" |
21 #include "mojo/public/cpp/bindings/binding_set.h" | 25 #include "mojo/public/cpp/bindings/binding_set.h" |
22 #include "mojo/public/cpp/bindings/interface_ptr.h" | 26 #include "mojo/public/cpp/bindings/interface_ptr.h" |
27 #include "mojo/public/cpp/system/data_pipe.h" | |
28 #include "net/base/io_buffer.h" | |
29 #include "net/http/http_response_headers.h" | |
23 | 30 |
24 namespace content { | 31 namespace content { |
25 | 32 |
26 namespace { | 33 // This class implements the URLLoader mojom which provides functionality to |
34 // service URL loads from the AppCache. It is also invoked for navigation | |
35 // requests to check if they can be serviced from the AppCache. If yes then | |
36 // it creates an instance of the AppCacheURLLoaderFactory class and passes it | |
37 // to the LoaderFactoryCallback callback. If not it invokes the | |
38 // LoaderFactoryCallback with a null factory pointer which passes the request | |
39 // to the next handler. | |
40 class AppCacheURLLoader : public mojom::URLLoader, | |
41 public AppCacheURLLoaderJob::Delegate { | |
42 public: | |
43 // Creates an instance of the AppCacheURLLoader class which checks if the | |
44 // navigation |request| can be served via AppCache. If yes it creates an | |
45 // instance of the AppCacheURLLoaderFactory class and passes it to the | |
46 // |callback|. If not it invokes the callback with a null factory which | |
47 // indicates that the next handler should be invoked. | |
48 static AppCacheURLLoader* CreateForNavigationRequest( | |
49 const ResourceRequest& request, | |
50 ChromeAppCacheService* appcache_service, | |
51 LoaderFactoryCallback callback, | |
52 URLLoaderFactoryGetter* factory_getter) { | |
53 AppCacheURLLoader* loader = new AppCacheURLLoader( | |
54 request, appcache_service, std::move(callback), factory_getter); | |
55 return loader; | |
56 } | |
27 | 57 |
28 // Handles AppCache URL loads for the network service. | 58 // Creates an instance of the AppCacheURLLoader class which is used to handle |
29 class AppCacheURLLoader : public AppCacheStorage::Delegate, | 59 // URL requests from the client. We expect this function to be called for |
30 public mojom::URLLoader { | 60 // handling subresource requests. |
31 public: | 61 static AppCacheURLLoader* CreateForURLLoads( |
32 AppCacheURLLoader(const ResourceRequest& request, | 62 const ResourceRequest& request, |
33 mojom::URLLoaderRequest url_loader_request, | 63 mojom::URLLoaderRequest url_loader_request, |
34 int32_t routing_id, | 64 int32_t routing_id, |
35 int32_t request_id, | 65 int32_t request_id, |
36 mojom::URLLoaderClientPtr client_info, | 66 mojom::URLLoaderClientPtr client_info, |
37 ChromeAppCacheService* appcache_service, | 67 ChromeAppCacheService* appcache_service, |
38 URLLoaderFactoryGetter* factory_getter) | 68 URLLoaderFactoryGetter* factory_getter) { |
39 : request_(request), | 69 AppCacheURLLoader* loader = new AppCacheURLLoader( |
40 routing_id_(routing_id), | 70 request, std::move(url_loader_request), routing_id, request_id, |
41 request_id_(request_id), | 71 std::move(client_info), appcache_service, factory_getter); |
42 client_info_(std::move(client_info)), | 72 return loader; |
43 appcache_service_(appcache_service), | |
44 factory_getter_(factory_getter), | |
45 binding_(this, std::move(url_loader_request)) { | |
46 binding_.set_connection_error_handler(base::Bind( | |
47 &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); | |
48 } | 73 } |
49 | 74 |
50 ~AppCacheURLLoader() override {} | 75 ~AppCacheURLLoader() override {} |
51 | 76 |
52 void Start() { | 77 // Starts the process of checking if the request can be served from the |
78 // AppCache. | |
79 void Start(AppCacheHost* host) { | |
80 DCHECK(host); | |
53 // If the origin does not exist in the AppCache usage map, then we can | 81 // If the origin does not exist in the AppCache usage map, then we can |
54 // safely call the network service here. | 82 // safely call the network service or pass it to the next handler. |
55 if (appcache_service_->storage()->usage_map()->find( | 83 if (appcache_service_->storage()->IsInitialized() && |
84 appcache_service_->storage()->usage_map()->find( | |
56 request_.url.GetOrigin()) == | 85 request_.url.GetOrigin()) == |
michaeln
2017/06/02 01:17:59
This test is only valid for navigations, cross-ori
ananta
2017/06/02 03:19:57
Done.
| |
57 appcache_service_->storage()->usage_map()->end()) { | 86 appcache_service_->storage()->usage_map()->end()) { |
58 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | 87 SendNetworkResponse(); |
59 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, | |
60 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); | |
61 return; | 88 return; |
62 } | 89 } |
63 | 90 |
64 appcache_service_->storage()->FindResponseForMainRequest(request_.url, | 91 if (IsResourceTypeFrame(request_.resource_type)) { |
65 GURL(), this); | 92 handler_ = host->CreateRequestHandler( |
93 AppCacheURLLoaderRequest::Create(request_), request_.resource_type, | |
94 request_.should_reset_appcache); | |
95 | |
96 AppCacheJob* job = handler_->MaybeLoadResource(nullptr); | |
97 if (!job) { | |
98 SendNetworkResponse(); | |
99 return; | |
100 } | |
101 | |
102 job_.reset(job->AsURLLoaderJob()); | |
103 job_->set_delegate(this); | |
104 } else { | |
105 // We should not be hitting this yet. We have to plumb the AppCache | |
106 // response through to the renderer before we receive requests for sub | |
107 // resources. | |
108 DCHECK(false); | |
109 } | |
110 } | |
111 | |
112 // Binds the client end point with this instance. | |
113 void BindEndpoints(const ResourceRequest& request, | |
114 mojom::URLLoaderRequest url_loader_request, | |
115 int32_t routing_id, | |
116 int32_t request_id, | |
117 mojom::URLLoaderClientPtrInfo client_info) { | |
118 request_ = request; | |
119 | |
120 binding_.reset(new mojo::Binding<mojom::URLLoader>( | |
121 this, std::move(url_loader_request))); | |
122 binding_->set_connection_error_handler(base::Bind( | |
123 &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); | |
124 | |
125 routing_id_ = routing_id; | |
126 request_id_ = request_id; | |
127 | |
128 client_info_.Bind(std::move(client_info)); | |
129 | |
130 // We pass the cached AppCache response and the data to the client for | |
131 // navigation requests. | |
132 if (IsNavigationRequest()) { | |
133 DCHECK(cached_response_info_.get()); | |
134 HandleAppCacheResponseInternal(cached_response_info_.get()); | |
135 cached_response_info_ = nullptr; | |
136 | |
137 if (cached_buffer_.get()) { | |
138 HandleAppCacheDataInternal(cached_buffer_.get(), cached_buffer_size_); | |
139 cached_buffer_ = nullptr; | |
140 cached_buffer_size_ = 0; | |
141 } | |
142 } | |
66 } | 143 } |
67 | 144 |
68 // mojom::URLLoader implementation: | 145 // mojom::URLLoader implementation: |
69 void FollowRedirect() override { network_loader_request_->FollowRedirect(); } | 146 void FollowRedirect() override { network_loader_request_->FollowRedirect(); } |
70 | 147 |
71 void SetPriority(net::RequestPriority priority, | 148 void SetPriority(net::RequestPriority priority, |
72 int32_t intra_priority_value) override { | 149 int32_t intra_priority_value) override { |
73 DCHECK(false); | 150 DCHECK(false); |
74 } | 151 } |
75 | 152 |
76 private: | 153 // AppCacheURLLoaderJob::Delegate overrides. |
77 // AppCacheStorage::Delegate methods. | 154 void SendNetworkResponse() override { |
78 void OnMainResponseFound(const GURL& url, | 155 // For a navigation request we invoke the LoaderFactoryCallback with null to |
79 const AppCacheEntry& entry, | 156 // ensure that the next handler gets a stab at the request. |
80 const GURL& fallback_url, | 157 if (IsNavigationRequest()) { |
81 const AppCacheEntry& fallback_entry, | 158 std::move(callback_).Run(nullptr); |
82 int64_t cache_id, | 159 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
83 int64_t group_id, | |
84 const GURL& manifest_url) override { | |
85 AppCachePolicy* policy = appcache_service_->appcache_policy(); | |
86 bool was_blocked_by_policy = | |
87 !manifest_url.is_empty() && policy && | |
88 !policy->CanLoadAppCache(manifest_url, | |
89 request_.first_party_for_cookies); | |
90 | |
91 if (was_blocked_by_policy || !entry.has_response_id() || | |
92 cache_id == kAppCacheNoCacheId) { | |
93 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | |
94 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, | |
95 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); | |
96 } else { | 160 } else { |
97 DLOG(WARNING) << "AppCache found for url " << url | |
98 << " Returning AppCache factory\n"; | |
99 // TODO(ananta) | 161 // TODO(ananta) |
100 // Provide the plumbing to initiate AppCache requests here. | 162 // We probably need to chain to the next factory instead of always |
163 // passing the request to the network factory. | |
101 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | 164 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
102 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, | 165 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, |
103 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); | 166 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); |
104 } | 167 } |
105 } | 168 } |
106 | 169 |
170 void SendErrorResponse() { | |
171 DLOG(WARNING) << "Sending error response for URL: " << request_.url; | |
172 } | |
173 | |
174 void HandleAppCacheResponseStart(AppCacheResponseInfo* response_info) { | |
175 DCHECK(response_info); | |
176 DCHECK(response_info->http_response_info()); | |
177 | |
178 // For a navigation request, we create an instance of the | |
179 // AppCacheURLLoaderFactory class which implements the URLLoaderFactory | |
180 // interface and pass it to the LoaderFactoryCallback. | |
181 if (IsNavigationRequest()) { | |
182 // Cache the response here to be passed to the client when it connects to | |
183 // us. | |
184 cached_response_info_ = response_info; | |
185 mojom::URLLoaderFactoryPtr appcache_factory; | |
186 AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
187 mojo::MakeRequest(&appcache_factory), appcache_service_.get(), | |
188 factory_getter_.get(), this, 0); | |
189 std::move(callback_).Run(appcache_factory.get()); | |
190 return; | |
191 } | |
192 | |
193 HandleAppCacheResponseInternal(response_info); | |
194 } | |
195 | |
196 void HandleAppCacheData(net::IOBuffer* buffer, int buffer_size) { | |
197 DLOG(WARNING) << "Received AppCache data for URL: " << request_.url; | |
198 | |
199 // Cache the buffer and the size. We will use it later when the client | |
200 // connects to us via URLLoaderFactory::CreateLoaderAndStart(). | |
201 | |
202 // If the cached AppCacheResponseInfo member is null, it means that the | |
203 // client has already connected to us. It is safe to forward the buffer | |
204 // directly to the client. | |
205 if (IsNavigationRequest() && cached_response_info_.get()) { | |
206 cached_buffer_ = buffer; | |
207 cached_buffer_size_ = buffer_size; | |
208 return; | |
209 } | |
210 | |
211 HandleAppCacheDataInternal(buffer, buffer_size); | |
212 } | |
213 | |
214 private: | |
215 // This ctor is used for checking if navigation requests can be served from | |
216 // the AppCache. | |
217 AppCacheURLLoader(const ResourceRequest& request, | |
218 ChromeAppCacheService* appcache_service, | |
219 LoaderFactoryCallback callback, | |
220 URLLoaderFactoryGetter* factory_getter) | |
221 : request_(request), | |
222 routing_id_(-1), | |
223 request_id_(-1), | |
224 appcache_service_(appcache_service), | |
225 factory_getter_(factory_getter), | |
226 callback_(std::move(callback)), | |
227 cached_buffer_size_(0), | |
228 navigation_request_(true) {} | |
229 | |
230 // This ctor is used for handling URL load requests. | |
231 AppCacheURLLoader(const ResourceRequest& request, | |
232 mojom::URLLoaderRequest url_loader_request, | |
233 int32_t routing_id, | |
234 int32_t request_id, | |
235 mojom::URLLoaderClientPtr client_info, | |
236 ChromeAppCacheService* appcache_service, | |
237 URLLoaderFactoryGetter* factory_getter) | |
238 : appcache_service_(appcache_service), | |
239 factory_getter_(factory_getter), | |
240 cached_buffer_size_(0), | |
241 navigation_request_(false) { | |
242 BindEndpoints(request, std::move(url_loader_request), routing_id, | |
243 request_id, client_info.PassInterface()); | |
244 } | |
245 | |
107 void OnConnectionError() { delete this; } | 246 void OnConnectionError() { delete this; } |
108 | 247 |
248 bool IsNavigationRequest() const { return navigation_request_; } | |
249 | |
250 void HandleAppCacheResponseInternal(AppCacheResponseInfo* response_info) { | |
251 DLOG(WARNING) << "Received AppCache response for URL: " << request_.url; | |
252 | |
253 const net::HttpResponseInfo* http_info = | |
254 response_info->http_response_info(); | |
255 | |
256 ResourceResponseHead response_head; | |
257 response_head.headers = new net::HttpResponseHeaders(""); | |
258 | |
259 std::string name; | |
260 std::string value; | |
261 | |
262 for (size_t it = 0; | |
263 http_info->headers->EnumerateHeaderLines(&it, &name, &value);) { | |
264 response_head.headers->AddHeader(name + ": " + value); | |
265 } | |
266 | |
267 // TODO(ananta) | |
268 // Copy more fields. | |
269 http_info->headers->GetMimeType(&response_head.mime_type); | |
270 http_info->headers->GetCharset(&response_head.charset); | |
271 | |
272 response_head.request_time = http_info->request_time; | |
273 response_head.response_time = http_info->response_time; | |
274 response_head.content_length = response_info->response_data_size(); | |
275 | |
276 client_info_->OnReceiveResponse(response_head, http_info->ssl_info, | |
277 mojom::DownloadedTempFilePtr()); | |
278 } | |
279 | |
280 void HandleAppCacheDataInternal(net::IOBuffer* buffer, int buffer_size) { | |
281 uint32_t bytes_written = static_cast<uint32_t>(buffer_size); | |
282 mojo::WriteDataRaw(data_pipe_.producer_handle.get(), buffer->data(), | |
283 &bytes_written, MOJO_WRITE_DATA_FLAG_NONE); | |
284 client_info_->OnStartLoadingResponseBody( | |
285 std::move(data_pipe_.consumer_handle)); | |
286 } | |
287 | |
288 // Used to query AppCacheStorage to see if a request can be served out of the | |
289 /// AppCache. | |
290 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
291 | |
292 // Used to retrieve the network service factory to pass requests to the | |
293 // network service. | |
294 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | |
295 | |
109 // The current request. | 296 // The current request. |
110 ResourceRequest request_; | 297 ResourceRequest request_; |
111 | 298 |
112 // URLLoader proxy for the network service. | 299 // URLLoader proxy for the network service. |
113 mojom::URLLoaderPtr network_loader_request_; | 300 mojom::URLLoaderPtr network_loader_request_; |
114 | 301 |
115 // Routing id of the request. This is 0 for navigation requests. For | 302 // Routing id of the request. This is 0 for navigation requests. For |
116 // subresource requests it is non zero. | 303 // subresource requests it is non zero. |
117 int routing_id_; | 304 int routing_id_; |
118 | 305 |
119 // Request id. | 306 // Request id. |
120 int request_id_; | 307 int request_id_; |
121 | 308 |
122 // The URLLoaderClient pointer. We call this interface with notifications | 309 // The URLLoaderClient pointer. We call this interface with notifications |
123 // about the URL load | 310 // about the URL load |
124 mojom::URLLoaderClientPtr client_info_; | 311 mojom::URLLoaderClientPtr client_info_; |
125 | 312 |
126 // Used to query AppCacheStorage to see if a request can be served out of the | 313 // Binds the URLLoaderClient with us. |
127 /// AppCache. | 314 std::unique_ptr<mojo::Binding<mojom::URLLoader>> binding_; |
128 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
129 | 315 |
316 // The handler for the AppCache request. | |
317 std::unique_ptr<AppCacheRequestHandler> handler_; | |
318 | |
319 // The job which gets invoked by the handler to deliver the responses to the | |
320 // client. | |
321 std::unique_ptr<AppCacheURLLoaderJob> job_; | |
322 | |
323 // The data pipe used to transfer AppCache data to the client. | |
324 mojo::DataPipe data_pipe_; | |
325 | |
326 // Callback to be invoked with the AppCache factory or null to fall through | |
327 // to the next handler in the chain. | |
328 LoaderFactoryCallback callback_; | |
329 | |
330 // Cached AppCache response to be used later when we are initialized with | |
331 // the connection end point. | |
332 scoped_refptr<AppCacheResponseInfo> cached_response_info_; | |
333 | |
334 // Cached IOBuffer to be used later when we are initialized with the | |
335 // connection end point. | |
336 scoped_refptr<net::IOBuffer> cached_buffer_; | |
337 | |
338 // Cached buffer size to be used later when we are initialized with the | |
339 // connection end point. | |
340 int cached_buffer_size_; | |
341 | |
342 // Set to true for navigation requests. | |
343 bool navigation_request_; | |
344 | |
345 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); | |
346 }; | |
347 | |
348 // This class is instantiated for navigation requests. It initiates checks on | |
349 // whether the request can be serviced via the AppCache. | |
350 // It uses the AppCacheURLLoader class defined above for this. If the request | |
351 // cannot be serviced via AppCache, the AppCacheURLLoader class calls | |
352 // the LoaderFactoryCallback with a null factory which ensures that the request | |
353 // goes to the next handler in the chain. | |
354 // If the request can be serviced with AppCache the AppCacheURLLoader class | |
355 // creates an instance of the AppCacheURLLoaderFactory class and passes it to | |
356 // the LoaderFactoryCallback function. | |
357 class AppCacheNavigationRequestHandler : public URLLoaderRequestHandler { | |
358 public: | |
359 explicit AppCacheNavigationRequestHandler( | |
360 AppCacheNavigationHandleCore* appcache_handle_core, | |
361 URLLoaderFactoryGetter* url_loader_factory_getter) | |
362 : appcache_core_(appcache_handle_core), | |
363 factory_getter_(url_loader_factory_getter) {} | |
364 | |
365 void MaybeCreateLoaderFactory(const ResourceRequest& resource_request, | |
366 ResourceContext* resource_context, | |
367 LoaderFactoryCallback callback) override { | |
368 // The AppCacheURLLoader instance will be deleted when the URL load request | |
369 // completes. It can complete in the following ways: | |
370 // 1. The request is serviced via AppCache. In this case it is deleted when | |
371 // the connection is dropped by the client. | |
372 // 2. The request is serviced by the next handler. | |
373 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForNavigationRequest( | |
374 resource_request, appcache_core_->GetAppCacheService(), | |
375 std::move(callback), factory_getter_.get()); | |
376 loader->Start(appcache_core_->host()); | |
377 } | |
378 | |
379 private: | |
380 AppCacheNavigationHandleCore* appcache_core_; | |
130 // Used to retrieve the network service factory to pass requests to the | 381 // Used to retrieve the network service factory to pass requests to the |
131 // network service. | 382 // network service. |
132 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | 383 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; |
133 | 384 |
134 // Binds the URLLoaderClient with us. | 385 DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationRequestHandler); |
135 mojo::Binding<mojom::URLLoader> binding_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); | |
138 }; | 386 }; |
139 | 387 |
140 } // namespace | |
141 | |
142 // Implements the URLLoaderFactory mojom for AppCache requests. | 388 // Implements the URLLoaderFactory mojom for AppCache requests. |
143 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( | 389 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( |
144 ChromeAppCacheService* appcache_service, | 390 ChromeAppCacheService* appcache_service, |
145 URLLoaderFactoryGetter* factory_getter) | 391 URLLoaderFactoryGetter* factory_getter, |
146 : appcache_service_(appcache_service), factory_getter_(factory_getter) {} | 392 AppCacheURLLoader* navigation_url_loader, |
393 int process_id) | |
394 : appcache_service_(appcache_service), | |
395 factory_getter_(factory_getter), | |
396 navigation_url_loader_(navigation_url_loader), | |
397 process_id_(process_id) {} | |
147 | 398 |
148 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} | 399 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} |
149 | 400 |
150 // static | 401 // static |
151 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( | 402 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
152 mojom::URLLoaderFactoryRequest request, | 403 mojom::URLLoaderFactoryRequest request, |
153 ChromeAppCacheService* appcache_service, | 404 ChromeAppCacheService* appcache_service, |
154 URLLoaderFactoryGetter* factory_getter) { | 405 URLLoaderFactoryGetter* factory_getter, |
406 AppCacheURLLoader* navigation_url_loader, | |
407 int process_id) { | |
155 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( | 408 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( |
156 new AppCacheURLLoaderFactory(appcache_service, factory_getter)); | 409 new AppCacheURLLoaderFactory(appcache_service, factory_getter, |
410 navigation_url_loader, process_id)); | |
157 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); | 411 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); |
158 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), | 412 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), |
159 std::move(request)); | 413 std::move(request)); |
160 } | 414 } |
161 | 415 |
416 // static | |
417 std::unique_ptr<URLLoaderRequestHandler> | |
418 AppCacheURLLoaderFactory::CreateRequestHandler( | |
419 AppCacheNavigationHandleCore* appcache_handle_core, | |
420 URLLoaderFactoryGetter* url_loader_factory_getter) { | |
421 std::unique_ptr<URLLoaderRequestHandler> handler( | |
422 new AppCacheNavigationRequestHandler(appcache_handle_core, | |
423 url_loader_factory_getter)); | |
424 return handler; | |
425 } | |
426 | |
162 void AppCacheURLLoaderFactory::CreateLoaderAndStart( | 427 void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
163 mojom::URLLoaderRequest url_loader_request, | 428 mojom::URLLoaderRequest url_loader_request, |
164 int32_t routing_id, | 429 int32_t routing_id, |
165 int32_t request_id, | 430 int32_t request_id, |
166 uint32_t options, | 431 uint32_t options, |
167 const ResourceRequest& request, | 432 const ResourceRequest& request, |
168 mojom::URLLoaderClientPtr client) { | 433 mojom::URLLoaderClientPtr client) { |
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 434 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
170 | 435 |
436 AppCacheHost* host = nullptr; | |
437 // If we have an ongoing navigation, bind the endpoints here. | |
438 if (navigation_url_loader_) { | |
439 navigation_url_loader_->BindEndpoints( | |
440 request, std::move(url_loader_request), routing_id, request_id, | |
441 client.PassInterface()); | |
442 return; | |
443 } else { | |
444 AppCacheBackendImpl* backend = appcache_service_->GetBackend(process_id_); | |
445 DCHECK(backend); | |
446 host = backend->GetHost(request.appcache_host_id); | |
447 DCHECK(host); | |
448 } | |
449 | |
171 // This will get deleted when the connection is dropped by the client. | 450 // This will get deleted when the connection is dropped by the client. |
172 AppCacheURLLoader* loader = new AppCacheURLLoader( | 451 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForURLLoads( |
173 request, std::move(url_loader_request), routing_id, request_id, | 452 request, std::move(url_loader_request), routing_id, request_id, |
174 std::move(client), appcache_service_.get(), factory_getter_.get()); | 453 std::move(client), appcache_service_.get(), factory_getter_.get()); |
175 loader->Start(); | 454 loader->Start(host); |
176 } | 455 } |
177 | 456 |
178 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, | 457 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, |
179 int32_t request_id, | 458 int32_t request_id, |
180 const ResourceRequest& request, | 459 const ResourceRequest& request, |
181 SyncLoadCallback callback) { | 460 SyncLoadCallback callback) { |
182 NOTREACHED(); | 461 NOTREACHED(); |
183 } | 462 } |
184 | 463 |
185 } // namespace content | 464 } // namespace content |
OLD | NEW |