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

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

Issue 134263005: Implement inline signin with iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't check title1.html ids Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('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/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "content/browser/fileapi/chrome_blob_storage_context.h" 21 #include "content/browser/fileapi/chrome_blob_storage_context.h"
22 #include "content/browser/histogram_internals_request_job.h" 22 #include "content/browser/histogram_internals_request_job.h"
23 #include "content/browser/net/view_blob_internals_job_factory.h" 23 #include "content/browser/net/view_blob_internals_job_factory.h"
24 #include "content/browser/net/view_http_cache_job_factory.h" 24 #include "content/browser/net/view_http_cache_job_factory.h"
25 #include "content/browser/resource_context_impl.h" 25 #include "content/browser/resource_context_impl.h"
26 #include "content/browser/tcmalloc_internals_request_job.h" 26 #include "content/browser/tcmalloc_internals_request_job.h"
27 #include "content/browser/webui/shared_resources_data_source.h" 27 #include "content/browser/webui/shared_resources_data_source.h"
28 #include "content/browser/webui/url_data_source_impl.h" 28 #include "content/browser/webui/url_data_source_impl.h"
29 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
31 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/resource_request_info.h" 33 #include "content/public/browser/resource_request_info.h"
33 #include "content/public/common/url_constants.h" 34 #include "content/public/common/url_constants.h"
34 #include "net/base/io_buffer.h" 35 #include "net/base/io_buffer.h"
35 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
36 #include "net/http/http_response_headers.h" 37 #include "net/http/http_response_headers.h"
37 #include "net/http/http_status_code.h" 38 #include "net/http/http_status_code.h"
38 #include "net/url_request/url_request.h" 39 #include "net/url_request/url_request.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Returns true when job was generated from an incognito profile. 155 // Returns true when job was generated from an incognito profile.
155 bool is_incognito() const { 156 bool is_incognito() const {
156 return is_incognito_; 157 return is_incognito_;
157 } 158 }
158 159
159 private: 160 private:
160 virtual ~URLRequestChromeJob(); 161 virtual ~URLRequestChromeJob();
161 162
162 // Helper for Start(), to let us start asynchronously. 163 // Helper for Start(), to let us start asynchronously.
163 // (This pattern is shared by most net::URLRequestJob implementations.) 164 // (This pattern is shared by most net::URLRequestJob implementations.)
164 void StartAsync(); 165 void StartAsync(bool allowed);
166
167 // Called on the UI thread to check if this request is allowed.
168 static void CheckStoragePartitionMatches(
169 int render_process_id,
170 const GURL& url,
171 const base::WeakPtr<URLRequestChromeJob>& job);
165 172
166 // Do the actual copy from data_ (the data we're serving) into |buf|. 173 // Do the actual copy from data_ (the data we're serving) into |buf|.
167 // Separate from ReadRawData so we can handle async I/O. 174 // Separate from ReadRawData so we can handle async I/O.
168 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); 175 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read);
169 176
170 // The actual data we're serving. NULL until it's been fetched. 177 // The actual data we're serving. NULL until it's been fetched.
171 scoped_refptr<base::RefCountedMemory> data_; 178 scoped_refptr<base::RefCountedMemory> data_;
172 // The current offset into the data that we're handing off to our 179 // The current offset into the data that we're handing off to our
173 // callers via the Read interfaces. 180 // callers via the Read interfaces.
174 int data_offset_; 181 int data_offset_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 backend_(backend), 230 backend_(backend),
224 weak_factory_(this) { 231 weak_factory_(this) {
225 DCHECK(backend); 232 DCHECK(backend);
226 } 233 }
227 234
228 URLRequestChromeJob::~URLRequestChromeJob() { 235 URLRequestChromeJob::~URLRequestChromeJob() {
229 CHECK(!backend_->HasPendingJob(this)); 236 CHECK(!backend_->HasPendingJob(this));
230 } 237 }
231 238
232 void URLRequestChromeJob::Start() { 239 void URLRequestChromeJob::Start() {
233 // Start reading asynchronously so that all error reporting and data 240 int render_process_id, unused;
234 // callbacks happen as they would for network requests. 241 ResourceRequestInfo::GetRenderFrameForRequest(
235 base::MessageLoop::current()->PostTask( 242 request_, &render_process_id, &unused);
243 BrowserThread::PostTask(
244 BrowserThread::UI,
236 FROM_HERE, 245 FROM_HERE,
237 base::Bind(&URLRequestChromeJob::StartAsync, weak_factory_.GetWeakPtr())); 246 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches,
238 247 render_process_id, request_->url(), AsWeakPtr()));
239 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", 248 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL",
240 request_->url().possibly_invalid_spec()); 249 request_->url().possibly_invalid_spec());
241 } 250 }
242 251
243 void URLRequestChromeJob::Kill() { 252 void URLRequestChromeJob::Kill() {
244 backend_->RemoveRequest(this); 253 backend_->RemoveRequest(this);
245 } 254 }
246 255
247 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { 256 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const {
248 *mime_type = mime_type_; 257 *mime_type = mime_type_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 int remaining = static_cast<int>(data_->size()) - data_offset_; 341 int remaining = static_cast<int>(data_->size()) - data_offset_;
333 if (buf_size > remaining) 342 if (buf_size > remaining)
334 buf_size = remaining; 343 buf_size = remaining;
335 if (buf_size > 0) { 344 if (buf_size > 0) {
336 memcpy(buf->data(), data_->front() + data_offset_, buf_size); 345 memcpy(buf->data(), data_->front() + data_offset_, buf_size);
337 data_offset_ += buf_size; 346 data_offset_ += buf_size;
338 } 347 }
339 *bytes_read = buf_size; 348 *bytes_read = buf_size;
340 } 349 }
341 350
342 void URLRequestChromeJob::StartAsync() { 351 void URLRequestChromeJob::CheckStoragePartitionMatches(
352 int render_process_id,
353 const GURL& url,
354 const base::WeakPtr<URLRequestChromeJob>& job) {
355 // The embedder could put some webui pages in separate storage partition.
356 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages
357 // being in the same process. We do an extra check to guard against an
358 // exploited renderer pretending to add them as a subframe. We skip this check
359 // for resources.
360 bool allowed = false;
361 if (url.SchemeIs(kChromeUIScheme) && url.host() == kChromeUIResourcesHost) {
362 allowed = true;
guohui 2014/02/19 15:38:36 Caused crbug/344355. Suspect we need to whitelist
363 } else {
364 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
365 if (process) {
366 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
367 process->GetBrowserContext(), url);
368 allowed = partition == process->GetStoragePartition();
369 }
370 }
371
372 BrowserThread::PostTask(
373 BrowserThread::IO,
374 FROM_HERE,
375 base::Bind(&URLRequestChromeJob::StartAsync, job, allowed));
376 }
377
378 void URLRequestChromeJob::StartAsync(bool allowed) {
343 if (!request_) 379 if (!request_)
344 return; 380 return;
345 381
346 if (!backend_->StartRequest(request_, this)) { 382 if (!allowed || !backend_->StartRequest(request_, this)) {
347 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 383 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
348 net::ERR_INVALID_URL)); 384 net::ERR_INVALID_URL));
349 } 385 }
350 } 386 }
351 387
352 namespace { 388 namespace {
353 389
354 // Gets mime type for data that is available from |source| by |path|. 390 // Gets mime type for data that is available from |source| by |path|.
355 // After that, notifies |job| that mime type is available. This method 391 // After that, notifies |job| that mime type is available. This method
356 // should be called on the UI thread, but notification is performed on 392 // should be called on the UI thread, but notification is performed on
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 715
680 } // namespace 716 } // namespace
681 717
682 net::URLRequestJobFactory::ProtocolHandler* 718 net::URLRequestJobFactory::ProtocolHandler*
683 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 719 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
684 bool is_incognito) { 720 bool is_incognito) {
685 return new DevToolsJobFactory(resource_context, is_incognito); 721 return new DevToolsJobFactory(resource_context, is_incognito);
686 } 722 }
687 723
688 } // namespace content 724 } // namespace content
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698