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

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

Issue 11896113: Add chrome-search: access from Instant overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Charlie's comments. Created 7 years, 9 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
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/file_util.h" 14 #include "base/file_util.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "content/browser/resource_context_impl.h" 21 #include "content/browser/resource_context_impl.h"
22 #include "content/browser/webui/shared_resources_data_source.h" 22 #include "content/browser/webui/shared_resources_data_source.h"
23 #include "content/browser/webui/url_data_source_impl.h" 23 #include "content/browser/webui/url_data_source_impl.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
26 #include "googleurl/src/url_util.h" 27 #include "googleurl/src/url_util.h"
27 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
28 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_job.h" 33 #include "net/url_request/url_request_job.h"
33 #include "net/url_request/url_request_job_factory.h" 34 #include "net/url_request/url_request_job_factory.h"
34 35
35 namespace content { 36 namespace content {
36 37
37 namespace { 38 namespace {
38 39
39 // TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed. 40 // TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed.
40 const char kChromeURLContentSecurityPolicyHeaderBase[] = 41 const char kChromeURLContentSecurityPolicyHeaderBase[] =
41 "Content-Security-Policy: script-src chrome://resources " 42 "Content-Security-Policy: script-src chrome://resources "
42 "'self' 'unsafe-eval'; "; 43 "'self' 'unsafe-eval'; ";
43 44
44 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; 45 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY";
45 46
47 bool SchemeIsInSchemes(const std::string& scheme,
48 const std::vector<std::string>& schemes) {
49 return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end();
50 }
51
46 // Parse a URL into the components used to resolve its request. |source_name| 52 // Parse a URL into the components used to resolve its request. |source_name|
47 // is the hostname and |path| is the remaining portion of the URL. 53 // is the hostname and |path| is the remaining portion of the URL.
48 void URLToRequest(const GURL& url, std::string* source_name, 54 void URLToRequest(const GURL& url, std::string* source_name,
49 std::string* path) { 55 std::string* path) {
50 DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) || 56 DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) ||
51 url.SchemeIs(chrome::kChromeUIScheme)); 57 url.SchemeIs(chrome::kChromeUIScheme) ||
58 SchemeIsInSchemes(
59 url.scheme(),
60 GetContentClient()->browser()->GetAdditionalWebUISchemes()));
52 61
53 if (!url.is_valid()) { 62 if (!url.is_valid()) {
54 NOTREACHED(); 63 NOTREACHED();
55 return; 64 return;
56 } 65 }
57 66
58 // Our input looks like: chrome://source_name/extra_bits?foo . 67 // Our input looks like: chrome://source_name/extra_bits?foo .
59 // So the url's "host" is our source, and everything after the host is 68 // So the url's "host" is our source, and everything after the host is
60 // the path. 69 // the path.
61 source_name->assign(url.host()); 70 source_name->assign(url.host());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 memcpy(buf->data(), data_->front() + data_offset_, buf_size); 306 memcpy(buf->data(), data_->front() + data_offset_, buf_size);
298 data_offset_ += buf_size; 307 data_offset_ += buf_size;
299 } 308 }
300 *bytes_read = buf_size; 309 *bytes_read = buf_size;
301 } 310 }
302 311
303 void URLRequestChromeJob::StartAsync() { 312 void URLRequestChromeJob::StartAsync() {
304 if (!request_) 313 if (!request_)
305 return; 314 return;
306 315
307 if (!backend_->StartRequest(request_->url(), this)) { 316 if (!backend_->StartRequest(request_, this)) {
308 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 317 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
309 net::ERR_INVALID_URL)); 318 net::ERR_INVALID_URL));
310 } 319 }
311 } 320 }
312 321
313 namespace { 322 namespace {
314 323
315 // Gets mime type for data that is available from |source| by |path|. 324 // Gets mime type for data that is available from |source| by |path|.
316 // After that, notifies |job| that mime type is available. This method 325 // After that, notifies |job| that mime type is available. This method
317 // should be called on the UI thread, but notification is performed on 326 // should be called on the UI thread, but notification is performed on
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 bool URLDataManagerBackend::HasPendingJob( 419 bool URLDataManagerBackend::HasPendingJob(
411 URLRequestChromeJob* job) const { 420 URLRequestChromeJob* job) const {
412 for (PendingRequestMap::const_iterator i = pending_requests_.begin(); 421 for (PendingRequestMap::const_iterator i = pending_requests_.begin();
413 i != pending_requests_.end(); ++i) { 422 i != pending_requests_.end(); ++i) {
414 if (i->second == job) 423 if (i->second == job)
415 return true; 424 return true;
416 } 425 }
417 return false; 426 return false;
418 } 427 }
419 428
420 bool URLDataManagerBackend::StartRequest(const GURL& url, 429 bool URLDataManagerBackend::StartRequest(const net::URLRequest* request,
421 URLRequestChromeJob* job) { 430 URLRequestChromeJob* job) {
422 // Parse the URL into a request for a source and path. 431 // Parse the URL into a request for a source and path.
423 std::string source_name; 432 std::string source_name;
424 std::string path; 433 std::string path;
425 URLToRequest(url, &source_name, &path); 434 URLToRequest(request->url(), &source_name, &path);
426 435
427 // Look up the data source for the request. 436 // Look up the data source for the request.
428 DataSourceMap::iterator i = data_sources_.find(source_name); 437 DataSourceMap::iterator i = data_sources_.find(source_name);
429 if (i == data_sources_.end()) 438 if (i == data_sources_.end())
430 return false; 439 return false;
431 440
432 URLDataSourceImpl* source = i->second; 441 URLDataSourceImpl* source = i->second;
433 442
443 if (!source->source()->ShouldServiceRequest(request))
444 return false;
445
434 // Save this request so we know where to send the data. 446 // Save this request so we know where to send the data.
435 RequestID request_id = next_request_id_++; 447 RequestID request_id = next_request_id_++;
436 pending_requests_.insert(std::make_pair(request_id, job)); 448 pending_requests_.insert(std::make_pair(request_id, job));
437 449
438 job->set_allow_caching(source->source()->AllowCaching()); 450 job->set_allow_caching(source->source()->AllowCaching());
439 job->set_add_content_security_policy( 451 job->set_add_content_security_policy(
440 source->source()->ShouldAddContentSecurityPolicy()); 452 source->source()->ShouldAddContentSecurityPolicy());
441 job->set_content_security_policy_object_source( 453 job->set_content_security_policy_object_source(
442 source->source()->GetContentSecurityPolicyObjectSrc()); 454 source->source()->GetContentSecurityPolicyObjectSrc());
443 job->set_content_security_policy_frame_source( 455 job->set_content_security_policy_frame_source(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 574
563 } // namespace 575 } // namespace
564 576
565 net::URLRequestJobFactory::ProtocolHandler* 577 net::URLRequestJobFactory::ProtocolHandler*
566 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 578 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
567 bool is_incognito) { 579 bool is_incognito) {
568 return new DevToolsJobFactory(resource_context, is_incognito); 580 return new DevToolsJobFactory(resource_context, is_incognito);
569 } 581 }
570 582
571 } // namespace content 583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698