OLD | NEW |
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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #include "webkit/browser/blob/blob_data_handle.h" | 91 #include "webkit/browser/blob/blob_data_handle.h" |
92 #include "webkit/browser/blob/blob_storage_context.h" | 92 #include "webkit/browser/blob/blob_storage_context.h" |
93 #include "webkit/browser/blob/blob_url_request_job_factory.h" | 93 #include "webkit/browser/blob/blob_url_request_job_factory.h" |
94 #include "webkit/browser/fileapi/file_permission_policy.h" | 94 #include "webkit/browser/fileapi/file_permission_policy.h" |
95 #include "webkit/browser/fileapi/file_system_context.h" | 95 #include "webkit/browser/fileapi/file_system_context.h" |
96 #include "webkit/common/blob/shareable_file_reference.h" | 96 #include "webkit/common/blob/shareable_file_reference.h" |
97 | 97 |
98 using base::Time; | 98 using base::Time; |
99 using base::TimeDelta; | 99 using base::TimeDelta; |
100 using base::TimeTicks; | 100 using base::TimeTicks; |
101 using webkit_blob::ShareableFileReference; | 101 using storage::ShareableFileReference; |
102 | 102 |
103 // ---------------------------------------------------------------------------- | 103 // ---------------------------------------------------------------------------- |
104 | 104 |
105 namespace content { | 105 namespace content { |
106 | 106 |
107 namespace { | 107 namespace { |
108 | 108 |
109 static ResourceDispatcherHostImpl* g_resource_dispatcher_host; | 109 static ResourceDispatcherHostImpl* g_resource_dispatcher_host; |
110 | 110 |
111 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates | 111 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 request->set_referrer_policy(net_referrer_policy); | 193 request->set_referrer_policy(net_referrer_policy); |
194 } | 194 } |
195 | 195 |
196 // Consults the RendererSecurity policy to determine whether the | 196 // Consults the RendererSecurity policy to determine whether the |
197 // ResourceDispatcherHostImpl should service this request. A request might be | 197 // ResourceDispatcherHostImpl should service this request. A request might be |
198 // disallowed if the renderer is not authorized to retrieve the request URL or | 198 // disallowed if the renderer is not authorized to retrieve the request URL or |
199 // if the renderer is attempting to upload an unauthorized file. | 199 // if the renderer is attempting to upload an unauthorized file. |
200 bool ShouldServiceRequest(int process_type, | 200 bool ShouldServiceRequest(int process_type, |
201 int child_id, | 201 int child_id, |
202 const ResourceHostMsg_Request& request_data, | 202 const ResourceHostMsg_Request& request_data, |
203 fileapi::FileSystemContext* file_system_context) { | 203 storage::FileSystemContext* file_system_context) { |
204 if (process_type == PROCESS_TYPE_PLUGIN) | 204 if (process_type == PROCESS_TYPE_PLUGIN) |
205 return true; | 205 return true; |
206 | 206 |
207 ChildProcessSecurityPolicyImpl* policy = | 207 ChildProcessSecurityPolicyImpl* policy = |
208 ChildProcessSecurityPolicyImpl::GetInstance(); | 208 ChildProcessSecurityPolicyImpl::GetInstance(); |
209 | 209 |
210 // Check if the renderer is permitted to request the requested URL. | 210 // Check if the renderer is permitted to request the requested URL. |
211 if (!policy->CanRequestURL(child_id, request_data.url)) { | 211 if (!policy->CanRequestURL(child_id, request_data.url)) { |
212 VLOG(1) << "Denied unauthorized request for " | 212 VLOG(1) << "Denied unauthorized request for " |
213 << request_data.url.possibly_invalid_spec(); | 213 << request_data.url.possibly_invalid_spec(); |
214 return false; | 214 return false; |
215 } | 215 } |
216 | 216 |
217 // Check if the renderer is permitted to upload the requested files. | 217 // Check if the renderer is permitted to upload the requested files. |
218 if (request_data.request_body.get()) { | 218 if (request_data.request_body.get()) { |
219 const std::vector<ResourceRequestBody::Element>* uploads = | 219 const std::vector<ResourceRequestBody::Element>* uploads = |
220 request_data.request_body->elements(); | 220 request_data.request_body->elements(); |
221 std::vector<ResourceRequestBody::Element>::const_iterator iter; | 221 std::vector<ResourceRequestBody::Element>::const_iterator iter; |
222 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { | 222 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { |
223 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE && | 223 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE && |
224 !policy->CanReadFile(child_id, iter->path())) { | 224 !policy->CanReadFile(child_id, iter->path())) { |
225 NOTREACHED() << "Denied unauthorized upload of " | 225 NOTREACHED() << "Denied unauthorized upload of " |
226 << iter->path().value(); | 226 << iter->path().value(); |
227 return false; | 227 return false; |
228 } | 228 } |
229 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) { | 229 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) { |
230 fileapi::FileSystemURL url = | 230 storage::FileSystemURL url = |
231 file_system_context->CrackURL(iter->filesystem_url()); | 231 file_system_context->CrackURL(iter->filesystem_url()); |
232 if (!policy->CanReadFileSystemFile(child_id, url)) { | 232 if (!policy->CanReadFileSystemFile(child_id, url)) { |
233 NOTREACHED() << "Denied unauthorized upload of " | 233 NOTREACHED() << "Denied unauthorized upload of " |
234 << iter->filesystem_url().spec(); | 234 << iter->filesystem_url().spec(); |
235 return false; | 235 return false; |
236 } | 236 } |
237 } | 237 } |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (!web_contents) | 292 if (!web_contents) |
293 return; | 293 return; |
294 web_contents->DidGetResourceResponseStart(*details.get()); | 294 web_contents->DidGetResourceResponseStart(*details.get()); |
295 } | 295 } |
296 | 296 |
297 bool IsValidatedSCT( | 297 bool IsValidatedSCT( |
298 const net::SignedCertificateTimestampAndStatus& sct_status) { | 298 const net::SignedCertificateTimestampAndStatus& sct_status) { |
299 return sct_status.status == net::ct::SCT_STATUS_OK; | 299 return sct_status.status == net::ct::SCT_STATUS_OK; |
300 } | 300 } |
301 | 301 |
302 webkit_blob::BlobStorageContext* GetBlobStorageContext( | 302 storage::BlobStorageContext* GetBlobStorageContext( |
303 ResourceMessageFilter* filter) { | 303 ResourceMessageFilter* filter) { |
304 if (!filter->blob_storage_context()) | 304 if (!filter->blob_storage_context()) |
305 return NULL; | 305 return NULL; |
306 return filter->blob_storage_context()->context(); | 306 return filter->blob_storage_context()->context(); |
307 } | 307 } |
308 | 308 |
309 } // namespace | 309 } // namespace |
310 | 310 |
311 // static | 311 // static |
312 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 312 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST); | 545 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST); |
546 } | 546 } |
547 | 547 |
548 ResourceRequestInfoImpl* extra_info = | 548 ResourceRequestInfoImpl* extra_info = |
549 CreateRequestInfo(child_id, route_id, true, context); | 549 CreateRequestInfo(child_id, route_id, true, context); |
550 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 550 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
551 | 551 |
552 if (request->url().SchemeIs(url::kBlobScheme)) { | 552 if (request->url().SchemeIs(url::kBlobScheme)) { |
553 ChromeBlobStorageContext* blob_context = | 553 ChromeBlobStorageContext* blob_context = |
554 GetChromeBlobStorageContextForResourceContext(context); | 554 GetChromeBlobStorageContextForResourceContext(context); |
555 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle( | 555 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
556 request.get(), | 556 request.get(), |
557 blob_context->context()->GetBlobDataFromPublicURL(request->url())); | 557 blob_context->context()->GetBlobDataFromPublicURL(request->url())); |
558 } | 558 } |
559 | 559 |
560 // From this point forward, the |DownloadResourceHandler| is responsible for | 560 // From this point forward, the |DownloadResourceHandler| is responsible for |
561 // |started_callback|. | 561 // |started_callback|. |
562 scoped_ptr<ResourceHandler> handler( | 562 scoped_ptr<ResourceHandler> handler( |
563 CreateResourceHandlerForDownload(request.get(), is_content_initiated, | 563 CreateResourceHandlerForDownload(request.get(), is_content_initiated, |
564 true, download_id, save_info.Pass(), | 564 true, download_id, save_info.Pass(), |
565 started_callback)); | 565 started_callback)); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 request_data.visiblity_state, | 1094 request_data.visiblity_state, |
1095 resource_context, | 1095 resource_context, |
1096 filter_->GetWeakPtr(), | 1096 filter_->GetWeakPtr(), |
1097 !is_sync_load); | 1097 !is_sync_load); |
1098 // Request takes ownership. | 1098 // Request takes ownership. |
1099 extra_info->AssociateWithRequest(new_request.get()); | 1099 extra_info->AssociateWithRequest(new_request.get()); |
1100 | 1100 |
1101 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1101 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1102 // Hang on to a reference to ensure the blob is not released prior | 1102 // Hang on to a reference to ensure the blob is not released prior |
1103 // to the job being started. | 1103 // to the job being started. |
1104 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1104 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1105 new_request.get(), | 1105 new_request.get(), |
1106 filter_->blob_storage_context()->context()-> | 1106 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( |
1107 GetBlobDataFromPublicURL(new_request->url())); | 1107 new_request->url())); |
1108 } | 1108 } |
1109 | 1109 |
1110 // Initialize the service worker handler for the request. | 1110 // Initialize the service worker handler for the request. |
1111 ServiceWorkerRequestHandler::InitializeHandler( | 1111 ServiceWorkerRequestHandler::InitializeHandler( |
1112 new_request.get(), | 1112 new_request.get(), |
1113 filter_->service_worker_context(), | 1113 filter_->service_worker_context(), |
1114 GetBlobStorageContext(filter_), | 1114 GetBlobStorageContext(filter_), |
1115 child_id, | 1115 child_id, |
1116 request_data.service_worker_provider_id, | 1116 request_data.service_worker_provider_id, |
1117 request_data.resource_type, | 1117 request_data.resource_type, |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 | 1991 |
1992 // Add a flag to selectively bypass the data reduction proxy if the resource | 1992 // Add a flag to selectively bypass the data reduction proxy if the resource |
1993 // type is not an image. | 1993 // type is not an image. |
1994 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 1994 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
1995 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 1995 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
1996 | 1996 |
1997 return load_flags; | 1997 return load_flags; |
1998 } | 1998 } |
1999 | 1999 |
2000 } // namespace content | 2000 } // namespace content |
OLD | NEW |