Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/browser/webui/url_data_manager_backend.cc

Issue 2033563002: Remove obsolete StoragePartition check from old iframe signin path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add early return Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(bool allowed); 183 void StartAsync();
184 184
185 // Called on the UI thread to check if this request is allowed. 185 // Due to a race condition, DevTools relies on a legacy thread hop to the UI
186 static void CheckStoragePartitionMatches( 186 // thread before calling StartAsync.
187 int render_process_id, 187 // TODO(caseq): Fix the race condition and remove this thread hop in
188 const GURL& url, 188 // https://crbug.com/616641.
189 static void DelayStartForDevTools(
189 const base::WeakPtr<URLRequestChromeJob>& job); 190 const base::WeakPtr<URLRequestChromeJob>& job);
190 191
191 // Specific resources require unsafe-eval in the Content Security Policy. 192 // Specific resources require unsafe-eval in the Content Security Policy.
192 bool RequiresUnsafeEval() const; 193 bool RequiresUnsafeEval() const;
193 194
194 // Do the actual copy from data_ (the data we're serving) into |buf|. 195 // 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 196 // Separate from ReadRawData so we can handle async I/O. Returns the number of
196 // bytes read. 197 // bytes read.
197 int CompleteRead(net::IOBuffer* buf, int buf_size); 198 int CompleteRead(net::IOBuffer* buf, int buf_size);
198 199
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 DCHECK(backend); 259 DCHECK(backend);
259 } 260 }
260 261
261 URLRequestChromeJob::~URLRequestChromeJob() { 262 URLRequestChromeJob::~URLRequestChromeJob() {
262 CHECK(!backend_->HasPendingJob(this)); 263 CHECK(!backend_->HasPendingJob(this));
263 } 264 }
264 265
265 void URLRequestChromeJob::Start() { 266 void URLRequestChromeJob::Start() {
266 const GURL url = request_->url(); 267 const GURL url = request_->url();
267 268
268 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", 269 // Due to a race condition, DevTools relies on a legacy thread hop to the UI
269 url.possibly_invalid_spec()); 270 // thread before calling StartAsync.
270 271 // TODO(caseq): Fix the race condition and remove this thread hop in
271 int render_process_id, unused; 272 // https://crbug.com/616641.
272 bool is_renderer_request = ResourceRequestInfo::GetRenderFrameForRequest( 273 if (url.SchemeIs(kChromeDevToolsScheme)) {
273 request_, &render_process_id, &unused); 274 BrowserThread::PostTask(
274 275 BrowserThread::UI,
275 if (!is_renderer_request) { 276 FROM_HERE,
276 StartAsync(true); 277 base::Bind(&URLRequestChromeJob::DelayStartForDevTools,
278 weak_factory_.GetWeakPtr()));
277 return; 279 return;
278 } 280 }
279 281
280 if (url.SchemeIs(kChromeUIScheme)) { 282 // Start reading asynchronously so that all error reporting and data
281 // TODO(dbeam): it's not clear that partition checking is needed or used. It 283 // callbacks happen as they would for network requests.
282 // was added for iframe-based signin (http://crbug.com/338127), which has 284 base::MessageLoop::current()->PostTask(
283 // since changed. We should remove if no longer necessary. 285 FROM_HERE,
284 std::vector<std::string> hosts; 286 base::Bind(&URLRequestChromeJob::StartAsync, weak_factory_.GetWeakPtr()));
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 287
294 BrowserThread::PostTask( 288 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL",
295 BrowserThread::UI, 289 url.possibly_invalid_spec());
296 FROM_HERE,
297 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches,
298 render_process_id, url,
299 weak_factory_.GetWeakPtr()));
300 } 290 }
301 291
302 void URLRequestChromeJob::Kill() { 292 void URLRequestChromeJob::Kill() {
303 weak_factory_.InvalidateWeakPtrs(); 293 weak_factory_.InvalidateWeakPtrs();
304 backend_->RemoveRequest(this); 294 backend_->RemoveRequest(this);
305 URLRequestJob::Kill(); 295 URLRequestJob::Kill();
306 } 296 }
307 297
308 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { 298 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const {
309 *mime_type = mime_type_; 299 *mime_type = mime_type_;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // fixed. 389 // fixed.
400 tracked_objects::ScopedTracker tracking_profile( 390 tracked_objects::ScopedTracker tracking_profile(
401 FROM_HERE_WITH_EXPLICIT_FUNCTION( 391 FROM_HERE_WITH_EXPLICIT_FUNCTION(
402 "455423 URLRequestChromeJob::CompleteRead memcpy")); 392 "455423 URLRequestChromeJob::CompleteRead memcpy"));
403 memcpy(buf->data(), data_->front() + data_offset_, buf_size); 393 memcpy(buf->data(), data_->front() + data_offset_, buf_size);
404 data_offset_ += buf_size; 394 data_offset_ += buf_size;
405 } 395 }
406 return buf_size; 396 return buf_size;
407 } 397 }
408 398
409 void URLRequestChromeJob::CheckStoragePartitionMatches( 399 void URLRequestChromeJob::DelayStartForDevTools(
410 int render_process_id,
411 const GURL& url,
412 const base::WeakPtr<URLRequestChromeJob>& job) { 400 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( 401 BrowserThread::PostTask(
426 BrowserThread::IO, 402 BrowserThread::IO,
427 FROM_HERE, 403 FROM_HERE,
428 base::Bind(&URLRequestChromeJob::StartAsync, job, allowed)); 404 base::Bind(&URLRequestChromeJob::StartAsync, job));
429 } 405 }
430 406
431 void URLRequestChromeJob::StartAsync(bool allowed) { 407 void URLRequestChromeJob::StartAsync() {
432 if (!request_) 408 if (!request_)
433 return; 409 return;
434 410
435 if (!allowed || !backend_->StartRequest(request_, this)) { 411 if (!backend_->StartRequest(request_, this)) {
436 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 412 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
437 net::ERR_INVALID_URL)); 413 net::ERR_INVALID_URL));
438 } 414 }
439 } 415 }
440 416
441 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use 417 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use
442 // eval()/new Function(). http://crbug.com/525224 418 // eval()/new Function(). http://crbug.com/525224
443 bool URLRequestChromeJob::RequiresUnsafeEval() const { 419 bool URLRequestChromeJob::RequiresUnsafeEval() const {
444 return true; 420 return true;
445 } 421 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 779
804 } // namespace 780 } // namespace
805 781
806 net::URLRequestJobFactory::ProtocolHandler* 782 net::URLRequestJobFactory::ProtocolHandler*
807 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 783 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
808 bool is_incognito) { 784 bool is_incognito) {
809 return new DevToolsJobFactory(resource_context, is_incognito); 785 return new DevToolsJobFactory(resource_context, is_incognito);
810 } 786 }
811 787
812 } // namespace content 788 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | content/public/browser/content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698