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

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 UI thread hop for DevTools 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
Charlie Reis 2016/06/02 16:42:11 caseq@: Note that the TODO(username) convention do
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
269 // Due to a race condition, DevTools relies on a legacy thread hop to the UI
270 // thread before calling StartAsync.
271 // TODO(caseq): Fix the race condition and remove this thread hop in
272 // https://crbug.com/616641.
273 if (url.SchemeIs(kChromeDevToolsScheme)) {
274 BrowserThread::PostTask(
275 BrowserThread::UI,
276 FROM_HERE,
277 base::Bind(&URLRequestChromeJob::DelayStartForDevTools,
278 weak_factory_.GetWeakPtr()));
Dan Beam 2016/06/02 18:58:07 did you meant to put a "return;" here?
Charlie Reis 2016/06/02 19:01:42 Yes! Good catch.
279 }
280
281 // Start reading asynchronously so that all error reporting and data
282 // callbacks happen as they would for network requests.
283 base::MessageLoop::current()->PostTask(
284 FROM_HERE,
285 base::Bind(&URLRequestChromeJob::StartAsync, weak_factory_.GetWeakPtr()));
286
268 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", 287 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL",
269 url.possibly_invalid_spec()); 288 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()));
300 } 289 }
301 290
302 void URLRequestChromeJob::Kill() { 291 void URLRequestChromeJob::Kill() {
303 weak_factory_.InvalidateWeakPtrs(); 292 weak_factory_.InvalidateWeakPtrs();
304 backend_->RemoveRequest(this); 293 backend_->RemoveRequest(this);
305 URLRequestJob::Kill(); 294 URLRequestJob::Kill();
306 } 295 }
307 296
308 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { 297 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const {
309 *mime_type = mime_type_; 298 *mime_type = mime_type_;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // fixed. 388 // fixed.
400 tracked_objects::ScopedTracker tracking_profile( 389 tracked_objects::ScopedTracker tracking_profile(
401 FROM_HERE_WITH_EXPLICIT_FUNCTION( 390 FROM_HERE_WITH_EXPLICIT_FUNCTION(
402 "455423 URLRequestChromeJob::CompleteRead memcpy")); 391 "455423 URLRequestChromeJob::CompleteRead memcpy"));
403 memcpy(buf->data(), data_->front() + data_offset_, buf_size); 392 memcpy(buf->data(), data_->front() + data_offset_, buf_size);
404 data_offset_ += buf_size; 393 data_offset_ += buf_size;
405 } 394 }
406 return buf_size; 395 return buf_size;
407 } 396 }
408 397
409 void URLRequestChromeJob::CheckStoragePartitionMatches( 398 void URLRequestChromeJob::DelayStartForDevTools(
410 int render_process_id,
411 const GURL& url,
412 const base::WeakPtr<URLRequestChromeJob>& job) { 399 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( 400 BrowserThread::PostTask(
426 BrowserThread::IO, 401 BrowserThread::IO,
427 FROM_HERE, 402 FROM_HERE,
428 base::Bind(&URLRequestChromeJob::StartAsync, job, allowed)); 403 base::Bind(&URLRequestChromeJob::StartAsync, job));
429 } 404 }
430 405
431 void URLRequestChromeJob::StartAsync(bool allowed) { 406 void URLRequestChromeJob::StartAsync() {
432 if (!request_) 407 if (!request_)
433 return; 408 return;
434 409
435 if (!allowed || !backend_->StartRequest(request_, this)) { 410 if (!backend_->StartRequest(request_, this)) {
436 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 411 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
437 net::ERR_INVALID_URL)); 412 net::ERR_INVALID_URL));
438 } 413 }
439 } 414 }
440 415
441 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use 416 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use
442 // eval()/new Function(). http://crbug.com/525224 417 // eval()/new Function(). http://crbug.com/525224
443 bool URLRequestChromeJob::RequiresUnsafeEval() const { 418 bool URLRequestChromeJob::RequiresUnsafeEval() const {
444 return true; 419 return true;
445 } 420 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 778
804 } // namespace 779 } // namespace
805 780
806 net::URLRequestJobFactory::ProtocolHandler* 781 net::URLRequestJobFactory::ProtocolHandler*
807 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 782 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
808 bool is_incognito) { 783 bool is_incognito) {
809 return new DevToolsJobFactory(resource_context, is_incognito); 784 return new DevToolsJobFactory(resource_context, is_incognito);
810 } 785 }
811 786
812 } // namespace content 787 } // 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