Chromium Code Reviews| 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 #include "content/browser/webui/url_data_manager_backend.h" | 5 #include "content/browser/webui/url_data_manager_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/profiler/scoped_tracker.h" | 20 #include "base/profiler/scoped_tracker.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 26 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 26 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 27 #include "content/browser/frame_host/frame_tree_node.h" | |
| 28 #include "content/browser/frame_host/navigation_request.h" | |
| 29 #include "content/browser/frame_host/navigator.h" | |
| 27 #include "content/browser/histogram_internals_request_job.h" | 30 #include "content/browser/histogram_internals_request_job.h" |
| 31 #include "content/browser/loader/resource_request_info_impl.h" | |
| 28 #include "content/browser/net/view_blob_internals_job_factory.h" | 32 #include "content/browser/net/view_blob_internals_job_factory.h" |
| 29 #include "content/browser/net/view_http_cache_job_factory.h" | 33 #include "content/browser/net/view_http_cache_job_factory.h" |
| 30 #include "content/browser/resource_context_impl.h" | 34 #include "content/browser/resource_context_impl.h" |
| 31 #include "content/browser/webui/shared_resources_data_source.h" | 35 #include "content/browser/webui/shared_resources_data_source.h" |
| 32 #include "content/browser/webui/url_data_source_impl.h" | 36 #include "content/browser/webui/url_data_source_impl.h" |
| 33 #include "content/public/browser/browser_context.h" | 37 #include "content/public/browser/browser_context.h" |
| 34 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
| 36 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/resource_request_info.h" | 41 #include "content/public/browser/resource_request_info.h" |
| 42 #include "content/public/common/browser_side_navigation_policy.h" | |
| 38 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 39 #include "net/base/io_buffer.h" | 44 #include "net/base/io_buffer.h" |
| 40 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 41 #include "net/http/http_response_headers.h" | 46 #include "net/http/http_response_headers.h" |
| 42 #include "net/http/http_status_code.h" | 47 #include "net/http/http_status_code.h" |
| 43 #include "net/log/net_log_util.h" | 48 #include "net/log/net_log_util.h" |
| 44 #include "net/url_request/url_request.h" | 49 #include "net/url_request/url_request.h" |
| 45 #include "net/url_request/url_request_context.h" | 50 #include "net/url_request/url_request_context.h" |
| 46 #include "net/url_request/url_request_error_job.h" | 51 #include "net/url_request/url_request_error_job.h" |
| 47 #include "net/url_request/url_request_job.h" | 52 #include "net/url_request/url_request_job.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 private: | 183 private: |
| 179 ~URLRequestChromeJob() override; | 184 ~URLRequestChromeJob() override; |
| 180 | 185 |
| 181 // Helper for Start(), to let us start asynchronously. | 186 // Helper for Start(), to let us start asynchronously. |
| 182 // (This pattern is shared by most net::URLRequestJob implementations.) | 187 // (This pattern is shared by most net::URLRequestJob implementations.) |
| 183 void StartAsync(bool allowed); | 188 void StartAsync(bool allowed); |
| 184 | 189 |
| 185 // Called on the UI thread to check if this request is allowed. | 190 // Called on the UI thread to check if this request is allowed. |
| 186 static void CheckStoragePartitionMatches( | 191 static void CheckStoragePartitionMatches( |
| 187 int render_process_id, | 192 int render_process_id, |
| 193 int frame_tree_node_id, | |
| 188 const GURL& url, | 194 const GURL& url, |
| 189 const base::WeakPtr<URLRequestChromeJob>& job); | 195 const base::WeakPtr<URLRequestChromeJob>& job); |
| 190 | 196 |
| 191 // Specific resources require unsafe-eval in the Content Security Policy. | 197 // Specific resources require unsafe-eval in the Content Security Policy. |
| 192 bool RequiresUnsafeEval() const; | 198 bool RequiresUnsafeEval() const; |
| 193 | 199 |
| 194 // Do the actual copy from data_ (the data we're serving) into |buf|. | 200 // Do the actual copy from data_ (the data we're serving) into |buf|. |
| 195 // Separate from ReadRawData so we can handle async I/O. Returns the number of | 201 // Separate from ReadRawData so we can handle async I/O. Returns the number of |
| 196 // bytes read. | 202 // bytes read. |
| 197 int CompleteRead(net::IOBuffer* buf, int buf_size); | 203 int CompleteRead(net::IOBuffer* buf, int buf_size); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 std::vector<std::string> hosts; | 290 std::vector<std::string> hosts; |
| 285 hosts.push_back(content::kChromeUIResourcesHost); | 291 hosts.push_back(content::kChromeUIResourcesHost); |
| 286 GetContentClient()-> | 292 GetContentClient()-> |
| 287 browser()->GetAdditionalWebUIHostsToIgnoreParititionCheck(&hosts); | 293 browser()->GetAdditionalWebUIHostsToIgnoreParititionCheck(&hosts); |
| 288 if (std::find(hosts.begin(), hosts.end(), url.host()) != hosts.end()) { | 294 if (std::find(hosts.begin(), hosts.end(), url.host()) != hosts.end()) { |
| 289 StartAsync(true); | 295 StartAsync(true); |
| 290 return; | 296 return; |
| 291 } | 297 } |
| 292 } | 298 } |
| 293 | 299 |
| 300 const ResourceRequestInfoImpl* info = | |
| 301 ResourceRequestInfoImpl::ForRequest(request_); | |
| 302 DCHECK(info); | |
| 294 BrowserThread::PostTask( | 303 BrowserThread::PostTask( |
| 295 BrowserThread::UI, | 304 BrowserThread::UI, FROM_HERE, |
| 296 FROM_HERE, | |
| 297 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches, | 305 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches, |
| 298 render_process_id, url, | 306 render_process_id, info->frame_tree_node_id(), request_->url(), |
| 299 weak_factory_.GetWeakPtr())); | 307 weak_factory_.GetWeakPtr())); |
| 300 } | 308 } |
| 301 | 309 |
| 302 void URLRequestChromeJob::Kill() { | 310 void URLRequestChromeJob::Kill() { |
| 303 weak_factory_.InvalidateWeakPtrs(); | 311 weak_factory_.InvalidateWeakPtrs(); |
| 304 backend_->RemoveRequest(this); | 312 backend_->RemoveRequest(this); |
| 305 URLRequestJob::Kill(); | 313 URLRequestJob::Kill(); |
| 306 } | 314 } |
| 307 | 315 |
| 308 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 316 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 409 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 402 "455423 URLRequestChromeJob::CompleteRead memcpy")); | 410 "455423 URLRequestChromeJob::CompleteRead memcpy")); |
| 403 memcpy(buf->data(), data_->front() + data_offset_, buf_size); | 411 memcpy(buf->data(), data_->front() + data_offset_, buf_size); |
| 404 data_offset_ += buf_size; | 412 data_offset_ += buf_size; |
| 405 } | 413 } |
| 406 return buf_size; | 414 return buf_size; |
| 407 } | 415 } |
| 408 | 416 |
| 409 void URLRequestChromeJob::CheckStoragePartitionMatches( | 417 void URLRequestChromeJob::CheckStoragePartitionMatches( |
| 410 int render_process_id, | 418 int render_process_id, |
| 419 int frame_tree_node_id, | |
| 411 const GURL& url, | 420 const GURL& url, |
| 412 const base::WeakPtr<URLRequestChromeJob>& job) { | 421 const base::WeakPtr<URLRequestChromeJob>& job) { |
| 413 // The embedder could put some webui pages in separate storage partition. | 422 // The embedder could put some webui pages in separate storage partition. |
| 414 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages | 423 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages |
| 415 // being in the same process. We do an extra check to guard against an | 424 // being in the same process. We do an extra check to guard against an |
| 416 // exploited renderer pretending to add them as a subframe. We skip this check | 425 // exploited renderer pretending to add them as a subframe. We skip this check |
| 417 // for resources. | 426 // for resources. |
| 418 bool allowed = false; | 427 bool allowed = false; |
| 419 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); | 428 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
| 420 if (process) { | 429 if (process) { |
| 421 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( | 430 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 422 process->GetBrowserContext(), url); | 431 process->GetBrowserContext(), url); |
| 423 allowed = partition == process->GetStoragePartition(); | 432 allowed = partition == process->GetStoragePartition(); |
| 433 } else if (render_process_id == -1 && IsBrowserSideNavigationEnabled()) { | |
|
Dan Beam
2016/05/23 19:02:58
when will render_process_id be -1 here?
Charlie Reis
2016/05/23 19:11:16
With PlzNavigate, the renderer process may not be
Dan Beam
2016/05/23 19:17:09
are you saying that ResourceRequestInfo::GetRender
Charlie Reis
2016/05/23 19:50:10
That's what patch set 1 implies. I agree that see
Dan Beam
2016/05/23 20:41:09
I removed a constant in my previous CL that might
clamy
2016/05/24 11:18:32
PlzNavigate does indeed creates a URLRequestUserDa
Charlie Reis
2016/05/24 22:14:32
Yeah, we could reintroduce that old path for allow
clamy
2016/05/25 14:30:11
I'm a bit wary of changing the behavior of Resourc
| |
| 434 // PlzNavigate: there should be no process associated to the navigation. | |
| 435 // Instead, lookup the FrameTreeNode to access the NavigationRequest. | |
| 436 FrameTreeNode* frame_tree_node = | |
| 437 FrameTreeNode::GloballyFindByID(frame_tree_node_id); | |
| 438 if (frame_tree_node) { | |
| 439 NavigationRequest* request = frame_tree_node->navigation_request(); | |
| 440 if (request) { | |
| 441 StoragePartition* partition = | |
| 442 BrowserContext::GetStoragePartitionForSite( | |
| 443 frame_tree_node->navigator() | |
| 444 ->GetController() | |
| 445 ->GetBrowserContext(), | |
| 446 url); | |
| 447 allowed = partition == request->GetStoragePartitionForNavigation(); | |
| 448 } | |
| 449 } | |
| 424 } | 450 } |
| 425 BrowserThread::PostTask( | 451 BrowserThread::PostTask( |
| 426 BrowserThread::IO, | 452 BrowserThread::IO, |
| 427 FROM_HERE, | 453 FROM_HERE, |
| 428 base::Bind(&URLRequestChromeJob::StartAsync, job, allowed)); | 454 base::Bind(&URLRequestChromeJob::StartAsync, job, allowed)); |
| 429 } | 455 } |
| 430 | 456 |
| 431 void URLRequestChromeJob::StartAsync(bool allowed) { | 457 void URLRequestChromeJob::StartAsync(bool allowed) { |
| 432 if (!request_) | 458 if (!request_) |
| 433 return; | 459 return; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 | 829 |
| 804 } // namespace | 830 } // namespace |
| 805 | 831 |
| 806 net::URLRequestJobFactory::ProtocolHandler* | 832 net::URLRequestJobFactory::ProtocolHandler* |
| 807 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 833 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
| 808 bool is_incognito) { | 834 bool is_incognito) { |
| 809 return new DevToolsJobFactory(resource_context, is_incognito); | 835 return new DevToolsJobFactory(resource_context, is_incognito); |
| 810 } | 836 } |
| 811 | 837 |
| 812 } // namespace content | 838 } // namespace content |
| OLD | NEW |