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 | |
jam
2017/06/01 15:00:46
I'm finding it hard to read that this class is bot
ananta
2017/06/01 17:28:01
This class holds on the AppCacheRequestHandler cla
ananta
2017/06/01 17:37:16
During navigation the class calls the callback wit
michaeln
2017/06/02 01:17:59
I had some trouble reading thru too and have some
| |
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()) == |
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 |
jam
2017/06/01 15:00:46
can you explain this some more to me? Isn't this g
ananta
2017/06/01 17:28:01
Yes. I was wondering about chain of factories with
| |
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() override { | |
171 DLOG(WARNING) << "Sending error response for URL: " << request_.url; | |
172 } | |
173 | |
174 void HandleAppCacheResponseStart(AppCacheResponseInfo* response_info) | |
175 override { | |
176 DCHECK(response_info); | |
177 DCHECK(response_info->http_response_info()); | |
178 | |
179 // For a navigation request, we create an instance of the | |
180 // AppCacheURLLoaderFactory class which implements the URLLoaderFactory | |
181 // interface and pass it to the LoaderFactoryCallback. | |
182 if (IsNavigationRequest()) { | |
183 // Cache the response here to be passed to the client when it connects to | |
184 // us. | |
185 cached_response_info_ = response_info; | |
186 mojom::URLLoaderFactoryPtr appcache_factory; | |
187 AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
188 mojo::MakeRequest(&appcache_factory), appcache_service_.get(), | |
189 factory_getter_.get(), this, 0); | |
190 std::move(callback_).Run(appcache_factory.get()); | |
191 return; | |
192 } | |
193 | |
194 HandleAppCacheResponseInternal(response_info); | |
195 } | |
196 | |
197 void HandleAppCacheData(net::IOBuffer* buffer, int buffer_size) override { | |
198 DLOG(WARNING) << "Received AppCache data for URL: " << request_.url; | |
199 | |
200 // Cache the buffer and the size. We will use it later when the client | |
201 // connects to us via URLLoaderFactory::CreateLoaderAndStart(). | |
202 | |
203 // If the cached AppCacheResponseInfo member is null, it means that the | |
204 // client has already connected to us. It is safe to forward the buffer | |
205 // directly to the client. | |
206 if (IsNavigationRequest() && cached_response_info_.get()) { | |
207 cached_buffer_ = buffer; | |
208 cached_buffer_size_ = buffer_size; | |
209 return; | |
210 } | |
211 | |
212 HandleAppCacheDataInternal(buffer, buffer_size); | |
213 } | |
214 | |
215 private: | |
216 // This ctor is used for checking if navigation requests can be served from | |
217 // the AppCache. | |
218 AppCacheURLLoader(const ResourceRequest& request, | |
219 ChromeAppCacheService* appcache_service, | |
220 LoaderFactoryCallback callback, | |
221 URLLoaderFactoryGetter* factory_getter) | |
222 : appcache_service_(appcache_service), | |
223 factory_getter_(factory_getter), | |
224 request_(request), | |
225 routing_id_(-1), | |
226 request_id_(-1), | |
227 callback_(std::move(callback)), | |
228 cached_buffer_size_(0), | |
229 navigation_request_(true) {} | |
230 | |
231 // This ctor is used for handling URL load requests. | |
232 AppCacheURLLoader(const ResourceRequest& request, | |
233 mojom::URLLoaderRequest url_loader_request, | |
234 int32_t routing_id, | |
235 int32_t request_id, | |
236 mojom::URLLoaderClientPtr client_info, | |
237 ChromeAppCacheService* appcache_service, | |
238 URLLoaderFactoryGetter* factory_getter) | |
239 : appcache_service_(appcache_service), | |
240 factory_getter_(factory_getter), | |
241 cached_buffer_size_(0), | |
242 navigation_request_(false) { | |
243 BindEndpoints(request, std::move(url_loader_request), routing_id, | |
244 request_id, client_info.PassInterface()); | |
245 } | |
246 | |
107 void OnConnectionError() { delete this; } | 247 void OnConnectionError() { delete this; } |
108 | 248 |
249 bool IsNavigationRequest() const { return navigation_request_; } | |
jam
2017/06/01 15:00:46
nit: no need for this helper method to look up a m
ananta
2017/06/01 17:28:01
Done.
| |
250 | |
251 void HandleAppCacheResponseInternal(AppCacheResponseInfo* response_info) { | |
252 DLOG(WARNING) << "Received AppCache response for URL: " << request_.url; | |
253 | |
254 const net::HttpResponseInfo* http_info = | |
255 response_info->http_response_info(); | |
256 | |
257 ResourceResponseHead response_head; | |
258 response_head.headers = new net::HttpResponseHeaders(""); | |
259 | |
260 std::string name; | |
261 std::string value; | |
262 | |
263 for (size_t it = 0; | |
264 http_info->headers->EnumerateHeaderLines(&it, &name, &value);) { | |
265 response_head.headers->AddHeader(name + ": " + value); | |
266 } | |
267 | |
268 // TODO(ananta) | |
269 // Copy more fields. | |
270 http_info->headers->GetMimeType(&response_head.mime_type); | |
271 http_info->headers->GetCharset(&response_head.charset); | |
272 | |
273 response_head.request_time = http_info->request_time; | |
274 response_head.response_time = http_info->response_time; | |
275 response_head.content_length = response_info->response_data_size(); | |
276 | |
277 client_info_->OnReceiveResponse(response_head, http_info->ssl_info, | |
278 mojom::DownloadedTempFilePtr()); | |
279 } | |
280 | |
281 void HandleAppCacheDataInternal(net::IOBuffer* buffer, int buffer_size) { | |
282 uint32_t bytes_written = static_cast<uint32_t>(buffer_size); | |
283 mojo::WriteDataRaw(data_pipe_.producer_handle.get(), buffer->data(), | |
284 &bytes_written, MOJO_WRITE_DATA_FLAG_NONE); | |
285 client_info_->OnStartLoadingResponseBody( | |
286 std::move(data_pipe_.consumer_handle)); | |
287 } | |
288 | |
289 // Used to query AppCacheStorage to see if a request can be served out of the | |
290 /// AppCache. | |
291 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
292 | |
293 // Used to retrieve the network service factory to pass requests to the | |
294 // network service. | |
295 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | |
296 | |
109 // The current request. | 297 // The current request. |
110 ResourceRequest request_; | 298 ResourceRequest request_; |
111 | 299 |
112 // URLLoader proxy for the network service. | 300 // URLLoader proxy for the network service. |
113 mojom::URLLoaderPtr network_loader_request_; | 301 mojom::URLLoaderPtr network_loader_request_; |
114 | 302 |
115 // Routing id of the request. This is 0 for navigation requests. For | 303 // Routing id of the request. This is 0 for navigation requests. For |
116 // subresource requests it is non zero. | 304 // subresource requests it is non zero. |
117 int routing_id_; | 305 int routing_id_; |
118 | 306 |
119 // Request id. | 307 // Request id. |
120 int request_id_; | 308 int request_id_; |
121 | 309 |
122 // The URLLoaderClient pointer. We call this interface with notifications | 310 // The URLLoaderClient pointer. We call this interface with notifications |
123 // about the URL load | 311 // about the URL load |
124 mojom::URLLoaderClientPtr client_info_; | 312 mojom::URLLoaderClientPtr client_info_; |
125 | 313 |
126 // Used to query AppCacheStorage to see if a request can be served out of the | 314 // Binds the URLLoaderClient with us. |
127 /// AppCache. | 315 std::unique_ptr<mojo::Binding<mojom::URLLoader>> binding_; |
128 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
129 | 316 |
317 // The handler for the AppCache request. | |
318 std::unique_ptr<AppCacheRequestHandler> handler_; | |
319 | |
320 // The job which gets invoked by the handler to deliver the responses to the | |
321 // client. | |
322 std::unique_ptr<AppCacheURLLoaderJob> job_; | |
323 | |
324 // The data pipe used to transfer AppCache data to the client. | |
325 mojo::DataPipe data_pipe_; | |
326 | |
327 // Callback to be invoked with the AppCache factory or null to fall through | |
328 // to the next handler in the chain. | |
329 LoaderFactoryCallback callback_; | |
330 | |
331 // Cached AppCache response to be used later when we are initialized with | |
332 // the connection end point. | |
333 scoped_refptr<AppCacheResponseInfo> cached_response_info_; | |
334 | |
335 // Cached IOBuffer to be used later when we are initialized with the | |
336 // connection end point. | |
337 scoped_refptr<net::IOBuffer> cached_buffer_; | |
338 | |
339 // Cached buffer size to be used later when we are initialized with the | |
340 // connection end point. | |
341 int cached_buffer_size_; | |
342 | |
343 // Set to true for navigation requests. | |
344 bool navigation_request_; | |
345 | |
346 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); | |
347 }; | |
348 | |
349 // This class is instantiated for navigation requests. It initiates checks on | |
350 // whether the request can be serviced via the AppCache. | |
351 // It uses the AppCacheURLLoader class defined above for this. If the request | |
352 // cannot be serviced via AppCache, the AppCacheURLLoader class calls | |
353 // the LoaderFactoryCallback with a null factory which ensures that the request | |
354 // goes to the next handler in the chain. | |
355 // If the request can be serviced with AppCache the AppCacheURLLoader class | |
356 // creates an instance of the AppCacheURLLoaderFactory class and passes it to | |
357 // the LoaderFactoryCallback function. | |
358 class AppCacheNavigationRequestHandler : public URLLoaderRequestHandler { | |
359 public: | |
360 explicit AppCacheNavigationRequestHandler( | |
jam
2017/06/01 15:00:46
nit: explicit not needed
ananta
2017/06/01 17:28:01
Done.
| |
361 AppCacheNavigationHandleCore* appcache_handle_core, | |
362 URLLoaderFactoryGetter* url_loader_factory_getter) | |
363 : appcache_core_(appcache_handle_core), | |
364 factory_getter_(url_loader_factory_getter) {} | |
365 | |
366 void MaybeCreateLoaderFactory(const ResourceRequest& resource_request, | |
367 ResourceContext* resource_context, | |
368 LoaderFactoryCallback callback) override { | |
369 // The AppCacheURLLoader instance will be deleted when the URL load request | |
370 // completes. It can complete in the following ways: | |
371 // 1. The request is serviced via AppCache. In this case it is deleted when | |
372 // the connection is dropped by the client. | |
373 // 2. The request is serviced by the next handler. | |
374 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForNavigationRequest( | |
375 resource_request, appcache_core_->GetAppCacheService(), | |
376 std::move(callback), factory_getter_.get()); | |
377 loader->Start(appcache_core_->host()); | |
378 } | |
379 | |
380 private: | |
381 AppCacheNavigationHandleCore* appcache_core_; | |
130 // Used to retrieve the network service factory to pass requests to the | 382 // Used to retrieve the network service factory to pass requests to the |
131 // network service. | 383 // network service. |
132 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | 384 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; |
133 | 385 |
134 // Binds the URLLoaderClient with us. | 386 DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationRequestHandler); |
135 mojo::Binding<mojom::URLLoader> binding_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); | |
138 }; | 387 }; |
139 | 388 |
140 } // namespace | |
141 | |
142 // Implements the URLLoaderFactory mojom for AppCache requests. | 389 // Implements the URLLoaderFactory mojom for AppCache requests. |
143 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( | 390 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( |
144 ChromeAppCacheService* appcache_service, | 391 ChromeAppCacheService* appcache_service, |
145 URLLoaderFactoryGetter* factory_getter) | 392 URLLoaderFactoryGetter* factory_getter, |
146 : appcache_service_(appcache_service), factory_getter_(factory_getter) {} | 393 AppCacheURLLoader* navigation_url_loader, |
394 int process_id) | |
395 : appcache_service_(appcache_service), | |
396 factory_getter_(factory_getter), | |
397 navigation_url_loader_(navigation_url_loader), | |
398 process_id_(process_id) {} | |
147 | 399 |
148 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} | 400 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} |
149 | 401 |
150 // static | 402 // static |
151 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( | 403 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
152 mojom::URLLoaderFactoryRequest request, | 404 mojom::URLLoaderFactoryRequest request, |
153 ChromeAppCacheService* appcache_service, | 405 ChromeAppCacheService* appcache_service, |
154 URLLoaderFactoryGetter* factory_getter) { | 406 URLLoaderFactoryGetter* factory_getter, |
407 AppCacheURLLoader* navigation_url_loader, | |
408 int process_id) { | |
155 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( | 409 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( |
156 new AppCacheURLLoaderFactory(appcache_service, factory_getter)); | 410 new AppCacheURLLoaderFactory(appcache_service, factory_getter, |
411 navigation_url_loader, process_id)); | |
157 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); | 412 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); |
158 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), | 413 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), |
159 std::move(request)); | 414 std::move(request)); |
160 } | 415 } |
161 | 416 |
417 // static | |
418 std::unique_ptr<URLLoaderRequestHandler> | |
419 AppCacheURLLoaderFactory::CreateRequestHandler( | |
420 AppCacheNavigationHandleCore* appcache_handle_core, | |
421 URLLoaderFactoryGetter* url_loader_factory_getter) { | |
422 std::unique_ptr<URLLoaderRequestHandler> handler( | |
423 new AppCacheNavigationRequestHandler(appcache_handle_core, | |
424 url_loader_factory_getter)); | |
425 return handler; | |
426 } | |
427 | |
162 void AppCacheURLLoaderFactory::CreateLoaderAndStart( | 428 void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
163 mojom::URLLoaderRequest url_loader_request, | 429 mojom::URLLoaderRequest url_loader_request, |
164 int32_t routing_id, | 430 int32_t routing_id, |
165 int32_t request_id, | 431 int32_t request_id, |
166 uint32_t options, | 432 uint32_t options, |
167 const ResourceRequest& request, | 433 const ResourceRequest& request, |
168 mojom::URLLoaderClientPtr client) { | 434 mojom::URLLoaderClientPtr client) { |
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 435 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
170 | 436 |
437 AppCacheHost* host = nullptr; | |
438 // If we have an ongoing navigation, bind the endpoints here. | |
439 if (navigation_url_loader_) { | |
440 navigation_url_loader_->BindEndpoints( | |
441 request, std::move(url_loader_request), routing_id, request_id, | |
442 client.PassInterface()); | |
443 return; | |
444 } else { | |
445 AppCacheBackendImpl* backend = appcache_service_->GetBackend(process_id_); | |
446 DCHECK(backend); | |
447 host = backend->GetHost(request.appcache_host_id); | |
448 DCHECK(host); | |
449 } | |
450 | |
171 // This will get deleted when the connection is dropped by the client. | 451 // This will get deleted when the connection is dropped by the client. |
172 AppCacheURLLoader* loader = new AppCacheURLLoader( | 452 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForURLLoads( |
173 request, std::move(url_loader_request), routing_id, request_id, | 453 request, std::move(url_loader_request), routing_id, request_id, |
174 std::move(client), appcache_service_.get(), factory_getter_.get()); | 454 std::move(client), appcache_service_.get(), factory_getter_.get()); |
175 loader->Start(); | 455 loader->Start(host); |
176 } | 456 } |
177 | 457 |
178 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, | 458 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, |
179 int32_t request_id, | 459 int32_t request_id, |
180 const ResourceRequest& request, | 460 const ResourceRequest& request, |
181 SyncLoadCallback callback) { | 461 SyncLoadCallback callback) { |
182 NOTREACHED(); | 462 NOTREACHED(); |
183 } | 463 } |
184 | 464 |
185 } // namespace content | 465 } // namespace content |
OLD | NEW |