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

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

Issue 2007223003: Remove obsolete StoragePartition check from old iframe signin path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inline Created 4 years, 7 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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);
190 184
191 // Specific resources require unsafe-eval in the Content Security Policy. 185 // Specific resources require unsafe-eval in the Content Security Policy.
192 bool RequiresUnsafeEval() const; 186 bool RequiresUnsafeEval() const;
193 187
194 // Do the actual copy from data_ (the data we're serving) into |buf|. 188 // 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 189 // Separate from ReadRawData so we can handle async I/O. Returns the number of
196 // bytes read. 190 // bytes read.
197 int CompleteRead(net::IOBuffer* buf, int buf_size); 191 int CompleteRead(net::IOBuffer* buf, int buf_size);
198 192
199 // The actual data we're serving. NULL until it's been fetched. 193 // The actual data we're serving. NULL until it's been fetched.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 backend_(backend), 250 backend_(backend),
257 weak_factory_(this) { 251 weak_factory_(this) {
258 DCHECK(backend); 252 DCHECK(backend);
259 } 253 }
260 254
261 URLRequestChromeJob::~URLRequestChromeJob() { 255 URLRequestChromeJob::~URLRequestChromeJob() {
262 CHECK(!backend_->HasPendingJob(this)); 256 CHECK(!backend_->HasPendingJob(this));
263 } 257 }
264 258
265 void URLRequestChromeJob::Start() { 259 void URLRequestChromeJob::Start() {
266 const GURL url = request_->url(); 260 // Start reading asynchronously so that all error reporting and data
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()));
267 265
268 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", 266 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL",
269 url.possibly_invalid_spec()); 267 request_->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 } 268 }
301 269
302 void URLRequestChromeJob::Kill() { 270 void URLRequestChromeJob::Kill() {
303 weak_factory_.InvalidateWeakPtrs(); 271 weak_factory_.InvalidateWeakPtrs();
304 backend_->RemoveRequest(this); 272 backend_->RemoveRequest(this);
305 URLRequestJob::Kill(); 273 URLRequestJob::Kill();
306 } 274 }
307 275
308 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { 276 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const {
309 *mime_type = mime_type_; 277 *mime_type = mime_type_;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // fixed. 367 // fixed.
400 tracked_objects::ScopedTracker tracking_profile( 368 tracked_objects::ScopedTracker tracking_profile(
401 FROM_HERE_WITH_EXPLICIT_FUNCTION( 369 FROM_HERE_WITH_EXPLICIT_FUNCTION(
402 "455423 URLRequestChromeJob::CompleteRead memcpy")); 370 "455423 URLRequestChromeJob::CompleteRead memcpy"));
403 memcpy(buf->data(), data_->front() + data_offset_, buf_size); 371 memcpy(buf->data(), data_->front() + data_offset_, buf_size);
404 data_offset_ += buf_size; 372 data_offset_ += buf_size;
405 } 373 }
406 return buf_size; 374 return buf_size;
407 } 375 }
408 376
409 void URLRequestChromeJob::CheckStoragePartitionMatches( 377 void URLRequestChromeJob::StartAsync() {
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) {
432 if (!request_) 378 if (!request_)
433 return; 379 return;
434 380
435 if (!allowed || !backend_->StartRequest(request_, this)) { 381 if (!backend_->StartRequest(request_, this)) {
436 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 382 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
437 net::ERR_INVALID_URL)); 383 net::ERR_INVALID_URL));
438 } 384 }
439 } 385 }
440 386
441 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use 387 // TODO(tsepez,mfoltz): Refine this method when tests have been fixed to not use
442 // eval()/new Function(). http://crbug.com/525224 388 // eval()/new Function(). http://crbug.com/525224
443 bool URLRequestChromeJob::RequiresUnsafeEval() const { 389 bool URLRequestChromeJob::RequiresUnsafeEval() const {
444 return true; 390 return true;
445 } 391 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 749
804 } // namespace 750 } // namespace
805 751
806 net::URLRequestJobFactory::ProtocolHandler* 752 net::URLRequestJobFactory::ProtocolHandler*
807 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 753 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
808 bool is_incognito) { 754 bool is_incognito) {
809 return new DevToolsJobFactory(resource_context, is_incognito); 755 return new DevToolsJobFactory(resource_context, is_incognito);
810 } 756 }
811 757
812 } // namespace content 758 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698