OLD | NEW |
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" |
(...skipping 10 matching lines...) Expand all Loading... |
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_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/resource_request_info.h" |
31 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
32 #include "googleurl/src/url_util.h" | 33 #include "googleurl/src/url_util.h" |
33 #include "net/base/io_buffer.h" | 34 #include "net/base/io_buffer.h" |
34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
35 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
36 #include "net/http/http_status_code.h" | 37 #include "net/http/http_status_code.h" |
37 #include "net/url_request/url_request.h" | 38 #include "net/url_request/url_request.h" |
38 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
39 #include "net/url_request/url_request_job.h" | 40 #include "net/url_request/url_request_job.h" |
40 #include "net/url_request/url_request_job_factory.h" | 41 #include "net/url_request/url_request_job_factory.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 const std::string& spec = url.possibly_invalid_spec(); | 82 const std::string& spec = url.possibly_invalid_spec(); |
82 const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); | 83 const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); |
83 // + 1 to skip the slash at the beginning of the path. | 84 // + 1 to skip the slash at the beginning of the path. |
84 int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false) + 1; | 85 int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false) + 1; |
85 | 86 |
86 if (offset < static_cast<int>(spec.size())) | 87 if (offset < static_cast<int>(spec.size())) |
87 path->assign(spec.substr(offset)); | 88 path->assign(spec.substr(offset)); |
88 } | 89 } |
89 | 90 |
| 91 // Fills extra request fields struct from |request|. |
| 92 void FillExtraRequestInfo( |
| 93 bool is_incognito, |
| 94 const net::URLRequest* request, |
| 95 URLDataSource::ExtraRequestInfo* request_info) { |
| 96 request_info->is_incognito = is_incognito; |
| 97 request_info->render_process_id = -1; |
| 98 request_info->render_view_id = -1; |
| 99 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 100 if (info) { |
| 101 info->GetAssociatedRenderView(&request_info->render_process_id, |
| 102 &request_info->render_view_id); |
| 103 } |
| 104 } |
| 105 |
90 } // namespace | 106 } // namespace |
91 | 107 |
92 // URLRequestChromeJob is a net::URLRequestJob that manages running | 108 // URLRequestChromeJob is a net::URLRequestJob that manages running |
93 // chrome-internal resource requests asynchronously. | 109 // chrome-internal resource requests asynchronously. |
94 // It hands off URL requests to ChromeURLDataManager, which asynchronously | 110 // It hands off URL requests to ChromeURLDataManager, which asynchronously |
95 // calls back once the data is available. | 111 // calls back once the data is available. |
96 class URLRequestChromeJob : public net::URLRequestJob, | 112 class URLRequestChromeJob : public net::URLRequestJob, |
97 public base::SupportsWeakPtr<URLRequestChromeJob> { | 113 public base::SupportsWeakPtr<URLRequestChromeJob> { |
98 public: | 114 public: |
99 // |is_incognito| set when job is generated from an incognito profile. | 115 // |is_incognito| set when job is generated from an incognito profile. |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 job->set_allow_caching(source->source()->AllowCaching()); | 515 job->set_allow_caching(source->source()->AllowCaching()); |
500 job->set_add_content_security_policy( | 516 job->set_add_content_security_policy( |
501 source->source()->ShouldAddContentSecurityPolicy()); | 517 source->source()->ShouldAddContentSecurityPolicy()); |
502 job->set_content_security_policy_object_source( | 518 job->set_content_security_policy_object_source( |
503 source->source()->GetContentSecurityPolicyObjectSrc()); | 519 source->source()->GetContentSecurityPolicyObjectSrc()); |
504 job->set_content_security_policy_frame_source( | 520 job->set_content_security_policy_frame_source( |
505 source->source()->GetContentSecurityPolicyFrameSrc()); | 521 source->source()->GetContentSecurityPolicyFrameSrc()); |
506 job->set_deny_xframe_options( | 522 job->set_deny_xframe_options( |
507 source->source()->ShouldDenyXFrameOptions()); | 523 source->source()->ShouldDenyXFrameOptions()); |
508 | 524 |
| 525 // Add extra info for the request. |
| 526 URLDataSource::ExtraRequestInfo request_info; |
| 527 FillExtraRequestInfo(job->is_incognito(), request, &request_info); |
| 528 |
509 // Forward along the request to the data source. | 529 // Forward along the request to the data source. |
510 MessageLoop* target_message_loop = | 530 MessageLoop* target_message_loop = |
511 source->source()->MessageLoopForRequestPath(path); | 531 source->source()->MessageLoopForRequestPath(path); |
512 if (!target_message_loop) { | 532 if (!target_message_loop) { |
513 bool is_incognito = job->is_incognito(); | |
514 job->MimeTypeAvailable(source->source()->GetMimeType(path)); | 533 job->MimeTypeAvailable(source->source()->GetMimeType(path)); |
515 // Eliminate potentially dangling pointer to avoid future use. | 534 // Eliminate potentially dangling pointer to avoid future use. |
516 job = NULL; | 535 job = NULL; |
517 | 536 |
518 // The DataSource is agnostic to which thread StartDataRequest is called | 537 // The DataSource is agnostic to which thread StartDataRequest is called |
519 // on for this path. Call directly into it from this thread, the IO | 538 // on for this path. Call directly into it from this thread, the IO |
520 // thread. | 539 // thread. |
521 source->source()->StartDataRequest( | 540 source->source()->StartDataRequest( |
522 path, is_incognito, | 541 path, request_info, |
523 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 542 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
524 } else { | 543 } else { |
525 // URLRequestChromeJob should receive mime type before data. This | 544 // URLRequestChromeJob should receive mime type before data. This |
526 // is guaranteed because request for mime type is placed in the | 545 // is guaranteed because request for mime type is placed in the |
527 // message loop before request for data. And correspondingly their | 546 // message loop before request for data. And correspondingly their |
528 // replies are put on the IO thread in the same order. | 547 // replies are put on the IO thread in the same order. |
529 target_message_loop->PostTask( | 548 target_message_loop->PostTask( |
530 FROM_HERE, | 549 FROM_HERE, |
531 base::Bind(&GetMimeTypeOnUI, | 550 base::Bind(&GetMimeTypeOnUI, |
532 scoped_refptr<URLDataSourceImpl>(source), | 551 scoped_refptr<URLDataSourceImpl>(source), |
533 path, job->AsWeakPtr())); | 552 path, job->AsWeakPtr())); |
534 | 553 |
535 // The DataSource wants StartDataRequest to be called on a specific thread, | 554 // The DataSource wants StartDataRequest to be called on a specific thread, |
536 // usually the UI thread, for this path. | 555 // usually the UI thread, for this path. |
537 target_message_loop->PostTask( | 556 target_message_loop->PostTask( |
538 FROM_HERE, | 557 FROM_HERE, |
539 base::Bind(&URLDataManagerBackend::CallStartRequest, | 558 base::Bind(&URLDataManagerBackend::CallStartRequest, |
540 make_scoped_refptr(source), path, job->is_incognito(), | 559 make_scoped_refptr(source), path, request_info, |
541 request_id)); | 560 request_id)); |
542 } | 561 } |
543 return true; | 562 return true; |
544 } | 563 } |
545 | 564 |
546 void URLDataManagerBackend::CallStartRequest( | 565 void URLDataManagerBackend::CallStartRequest( |
547 scoped_refptr<URLDataSourceImpl> source, | 566 scoped_refptr<URLDataSourceImpl> source, |
548 const std::string& path, | 567 const std::string& path, |
549 bool is_incognito, | 568 const URLDataSource::ExtraRequestInfo& info, |
550 int request_id) { | 569 int request_id) { |
551 source->source()->StartDataRequest( | 570 source->source()->StartDataRequest( |
552 path, | 571 path, |
553 is_incognito, | 572 info, |
554 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 573 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
555 } | 574 } |
556 | 575 |
557 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { | 576 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { |
558 // Remove the request from our list of pending requests. | 577 // Remove the request from our list of pending requests. |
559 // If/when the source sends the data that was requested, the data will just | 578 // If/when the source sends the data that was requested, the data will just |
560 // be thrown away. | 579 // be thrown away. |
561 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 580 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
562 i != pending_requests_.end(); ++i) { | 581 i != pending_requests_.end(); ++i) { |
563 if (i->second == job) { | 582 if (i->second == job) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 642 |
624 } // namespace | 643 } // namespace |
625 | 644 |
626 net::URLRequestJobFactory::ProtocolHandler* | 645 net::URLRequestJobFactory::ProtocolHandler* |
627 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 646 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
628 bool is_incognito) { | 647 bool is_incognito) { |
629 return new DevToolsJobFactory(resource_context, is_incognito); | 648 return new DevToolsJobFactory(resource_context, is_incognito); |
630 } | 649 } |
631 | 650 |
632 } // namespace content | 651 } // namespace content |
OLD | NEW |