| 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" | 
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  173   // Returns true when job was generated from an incognito profile. |  173   // Returns true when job was generated from an incognito profile. | 
|  174   bool is_incognito() const { |  174   bool is_incognito() const { | 
|  175     return is_incognito_; |  175     return is_incognito_; | 
|  176   } |  176   } | 
|  177  |  177  | 
|  178  private: |  178  private: | 
|  179   ~URLRequestChromeJob() override; |  179   ~URLRequestChromeJob() override; | 
|  180  |  180  | 
|  181   // Helper for Start(), to let us start asynchronously. |  181   // Helper for Start(), to let us start asynchronously. | 
|  182   // (This pattern is shared by most net::URLRequestJob implementations.) |  182   // (This pattern is shared by most net::URLRequestJob implementations.) | 
|  183   void StartAsync(); |  183   void StartAsync(bool allowed); | 
 |  184  | 
 |  185   // Called on the UI thread to check if this request is allowed. | 
 |  186   static void CheckStoragePartitionMatches( | 
 |  187       int render_process_id, | 
 |  188       const GURL& url, | 
 |  189       const base::WeakPtr<URLRequestChromeJob>& job); | 
|  184  |  190  | 
|  185   // Specific resources require unsafe-eval in the Content Security Policy. |  191   // Specific resources require unsafe-eval in the Content Security Policy. | 
|  186   bool RequiresUnsafeEval() const; |  192   bool RequiresUnsafeEval() const; | 
|  187  |  193  | 
|  188   // Do the actual copy from data_ (the data we're serving) into |buf|. |  194   // Do the actual copy from data_ (the data we're serving) into |buf|. | 
|  189   // Separate from ReadRawData so we can handle async I/O. Returns the number of |  195   // Separate from ReadRawData so we can handle async I/O. Returns the number of | 
|  190   // bytes read. |  196   // bytes read. | 
|  191   int CompleteRead(net::IOBuffer* buf, int buf_size); |  197   int CompleteRead(net::IOBuffer* buf, int buf_size); | 
|  192  |  198  | 
|  193   // The actual data we're serving.  NULL until it's been fetched. |  199   // The actual data we're serving.  NULL until it's been fetched. | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  250       backend_(backend), |  256       backend_(backend), | 
|  251       weak_factory_(this) { |  257       weak_factory_(this) { | 
|  252   DCHECK(backend); |  258   DCHECK(backend); | 
|  253 } |  259 } | 
|  254  |  260  | 
|  255 URLRequestChromeJob::~URLRequestChromeJob() { |  261 URLRequestChromeJob::~URLRequestChromeJob() { | 
|  256   CHECK(!backend_->HasPendingJob(this)); |  262   CHECK(!backend_->HasPendingJob(this)); | 
|  257 } |  263 } | 
|  258  |  264  | 
|  259 void URLRequestChromeJob::Start() { |  265 void URLRequestChromeJob::Start() { | 
|  260   // Start reading asynchronously so that all error reporting and data |  266   const GURL url = request_->url(); | 
|  261   // callbacks happen as they would for network requests. |  | 
|  262   base::MessageLoop::current()->PostTask( |  | 
|  263       FROM_HERE, |  | 
|  264       base::Bind(&URLRequestChromeJob::StartAsync, weak_factory_.GetWeakPtr())); |  | 
|  265  |  267  | 
|  266   TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", |  268   TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", | 
|  267       request_->url().possibly_invalid_spec()); |  269       url.possibly_invalid_spec()); | 
 |  270  | 
 |  271   int render_process_id, unused; | 
 |  272   bool is_renderer_request = ResourceRequestInfo::GetRenderFrameForRequest( | 
 |  273       request_, &render_process_id, &unused); | 
 |  274  | 
 |  275   if (!is_renderer_request) { | 
 |  276     StartAsync(true); | 
 |  277     return; | 
 |  278   } | 
 |  279  | 
 |  280   if (url.SchemeIs(kChromeUIScheme)) { | 
 |  281     // TODO(dbeam): it's not clear that partition checking is needed or used. It | 
 |  282     // was added for iframe-based signin (http://crbug.com/338127), which has | 
 |  283     // since changed. We should remove if no longer necessary. | 
 |  284     std::vector<std::string> hosts; | 
 |  285     hosts.push_back(content::kChromeUIResourcesHost); | 
 |  286     GetContentClient()-> | 
 |  287         browser()->GetAdditionalWebUIHostsToIgnoreParititionCheck(&hosts); | 
 |  288     if (std::find(hosts.begin(), hosts.end(), url.host()) != hosts.end()) { | 
 |  289       StartAsync(true); | 
 |  290       return; | 
 |  291     } | 
 |  292   } | 
 |  293  | 
 |  294   BrowserThread::PostTask( | 
 |  295       BrowserThread::UI, | 
 |  296       FROM_HERE, | 
 |  297       base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches, | 
 |  298                  render_process_id, url, | 
 |  299                  weak_factory_.GetWeakPtr())); | 
|  268 } |  300 } | 
|  269  |  301  | 
|  270 void URLRequestChromeJob::Kill() { |  302 void URLRequestChromeJob::Kill() { | 
|  271   weak_factory_.InvalidateWeakPtrs(); |  303   weak_factory_.InvalidateWeakPtrs(); | 
|  272   backend_->RemoveRequest(this); |  304   backend_->RemoveRequest(this); | 
|  273   URLRequestJob::Kill(); |  305   URLRequestJob::Kill(); | 
|  274 } |  306 } | 
|  275  |  307  | 
|  276 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |  308 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 
|  277   *mime_type = mime_type_; |  309   *mime_type = mime_type_; | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  367     // fixed. |  399     // fixed. | 
|  368     tracked_objects::ScopedTracker tracking_profile( |  400     tracked_objects::ScopedTracker tracking_profile( | 
|  369         FROM_HERE_WITH_EXPLICIT_FUNCTION( |  401         FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
|  370             "455423 URLRequestChromeJob::CompleteRead memcpy")); |  402             "455423 URLRequestChromeJob::CompleteRead memcpy")); | 
|  371     memcpy(buf->data(), data_->front() + data_offset_, buf_size); |  403     memcpy(buf->data(), data_->front() + data_offset_, buf_size); | 
|  372     data_offset_ += buf_size; |  404     data_offset_ += buf_size; | 
|  373   } |  405   } | 
|  374   return buf_size; |  406   return buf_size; | 
|  375 } |  407 } | 
|  376  |  408  | 
|  377 void URLRequestChromeJob::StartAsync() { |  409 void URLRequestChromeJob::CheckStoragePartitionMatches( | 
 |  410     int render_process_id, | 
 |  411     const GURL& url, | 
 |  412     const base::WeakPtr<URLRequestChromeJob>& job) { | 
 |  413   // The embedder could put some webui pages in separate storage partition. | 
 |  414   // RenderProcessHostImpl::IsSuitableHost would guard against top level pages | 
 |  415   // 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 | 
 |  417   // for resources. | 
 |  418   bool allowed = false; | 
 |  419   RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); | 
 |  420   if (process) { | 
 |  421     StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( | 
 |  422         process->GetBrowserContext(), url); | 
 |  423     allowed = partition == process->GetStoragePartition(); | 
 |  424   } | 
 |  425   BrowserThread::PostTask( | 
 |  426       BrowserThread::IO, | 
 |  427       FROM_HERE, | 
 |  428       base::Bind(&URLRequestChromeJob::StartAsync, job, allowed)); | 
 |  429 } | 
 |  430  | 
 |  431 void URLRequestChromeJob::StartAsync(bool allowed) { | 
|  378   if (!request_) |  432   if (!request_) | 
|  379     return; |  433     return; | 
|  380  |  434  | 
|  381   if (!backend_->StartRequest(request_, this)) { |  435   if (!allowed || !backend_->StartRequest(request_, this)) { | 
|  382     NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |  436     NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 
|  383                                            net::ERR_INVALID_URL)); |  437                                            net::ERR_INVALID_URL)); | 
|  384   } |  438   } | 
|  385 } |  439 } | 
|  386  |  440  | 
|  387 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use |  441 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use | 
|  388 // eval()/new Function().  http://crbug.com/525224 |  442 // eval()/new Function().  http://crbug.com/525224 | 
|  389 bool URLRequestChromeJob::RequiresUnsafeEval() const { |  443 bool URLRequestChromeJob::RequiresUnsafeEval() const { | 
|  390   return true; |  444   return true; | 
|  391 } |  445 } | 
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  749  |  803  | 
|  750 }  // namespace |  804 }  // namespace | 
|  751  |  805  | 
|  752 net::URLRequestJobFactory::ProtocolHandler* |  806 net::URLRequestJobFactory::ProtocolHandler* | 
|  753 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |  807 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 
|  754                               bool is_incognito) { |  808                               bool is_incognito) { | 
|  755   return new DevToolsJobFactory(resource_context, is_incognito); |  809   return new DevToolsJobFactory(resource_context, is_incognito); | 
|  756 } |  810 } | 
|  757  |  811  | 
|  758 }  // namespace content |  812 }  // namespace content | 
| OLD | NEW |