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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 job->set_allow_caching(source->source()->AllowCaching()); | 500 job->set_allow_caching(source->source()->AllowCaching()); |
500 job->set_add_content_security_policy( | 501 job->set_add_content_security_policy( |
501 source->source()->ShouldAddContentSecurityPolicy()); | 502 source->source()->ShouldAddContentSecurityPolicy()); |
502 job->set_content_security_policy_object_source( | 503 job->set_content_security_policy_object_source( |
503 source->source()->GetContentSecurityPolicyObjectSrc()); | 504 source->source()->GetContentSecurityPolicyObjectSrc()); |
504 job->set_content_security_policy_frame_source( | 505 job->set_content_security_policy_frame_source( |
505 source->source()->GetContentSecurityPolicyFrameSrc()); | 506 source->source()->GetContentSecurityPolicyFrameSrc()); |
506 job->set_deny_xframe_options( | 507 job->set_deny_xframe_options( |
507 source->source()->ShouldDenyXFrameOptions()); | 508 source->source()->ShouldDenyXFrameOptions()); |
508 | 509 |
510 // Look up additional request info to pass down. | |
511 int render_process_id = -1; | |
512 int render_view_id = -1; | |
513 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | |
514 if (info) | |
jam
2013/04/17 00:45:09
when could this be null?
I'm not sure this can ac
Jered
2013/04/17 01:03:08
How about this way? I think it's clearer anyway.
| |
515 info->GetAssociatedRenderView(&render_process_id, &render_view_id); | |
516 | |
509 // Forward along the request to the data source. | 517 // Forward along the request to the data source. |
510 MessageLoop* target_message_loop = | 518 MessageLoop* target_message_loop = |
511 source->source()->MessageLoopForRequestPath(path); | 519 source->source()->MessageLoopForRequestPath(path); |
512 if (!target_message_loop) { | 520 if (!target_message_loop) { |
513 bool is_incognito = job->is_incognito(); | |
514 job->MimeTypeAvailable(source->source()->GetMimeType(path)); | 521 job->MimeTypeAvailable(source->source()->GetMimeType(path)); |
515 // Eliminate potentially dangling pointer to avoid future use. | 522 // Eliminate potentially dangling pointer to avoid future use. |
516 job = NULL; | 523 job = NULL; |
517 | 524 |
518 // The DataSource is agnostic to which thread StartDataRequest is called | 525 // The DataSource is agnostic to which thread StartDataRequest is called |
519 // on for this path. Call directly into it from this thread, the IO | 526 // on for this path. Call directly into it from this thread, the IO |
520 // thread. | 527 // thread. |
521 source->source()->StartDataRequest( | 528 source->source()->StartDataRequest( |
522 path, is_incognito, | 529 path, render_process_id, render_view_id, |
523 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 530 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
524 } else { | 531 } else { |
525 // URLRequestChromeJob should receive mime type before data. This | 532 // URLRequestChromeJob should receive mime type before data. This |
526 // is guaranteed because request for mime type is placed in the | 533 // is guaranteed because request for mime type is placed in the |
527 // message loop before request for data. And correspondingly their | 534 // message loop before request for data. And correspondingly their |
528 // replies are put on the IO thread in the same order. | 535 // replies are put on the IO thread in the same order. |
529 target_message_loop->PostTask( | 536 target_message_loop->PostTask( |
530 FROM_HERE, | 537 FROM_HERE, |
531 base::Bind(&GetMimeTypeOnUI, | 538 base::Bind(&GetMimeTypeOnUI, |
532 scoped_refptr<URLDataSourceImpl>(source), | 539 scoped_refptr<URLDataSourceImpl>(source), |
533 path, job->AsWeakPtr())); | 540 path, job->AsWeakPtr())); |
534 | 541 |
535 // The DataSource wants StartDataRequest to be called on a specific thread, | 542 // The DataSource wants StartDataRequest to be called on a specific thread, |
536 // usually the UI thread, for this path. | 543 // usually the UI thread, for this path. |
537 target_message_loop->PostTask( | 544 target_message_loop->PostTask( |
538 FROM_HERE, | 545 FROM_HERE, |
539 base::Bind(&URLDataManagerBackend::CallStartRequest, | 546 base::Bind(&URLDataManagerBackend::CallStartRequest, |
540 make_scoped_refptr(source), path, job->is_incognito(), | 547 make_scoped_refptr(source), path, render_process_id, |
541 request_id)); | 548 render_view_id, request_id)); |
542 } | 549 } |
543 return true; | 550 return true; |
544 } | 551 } |
545 | 552 |
546 void URLDataManagerBackend::CallStartRequest( | 553 void URLDataManagerBackend::CallStartRequest( |
547 scoped_refptr<URLDataSourceImpl> source, | 554 scoped_refptr<URLDataSourceImpl> source, |
548 const std::string& path, | 555 const std::string& path, |
549 bool is_incognito, | 556 int render_process_id, |
557 int render_view_id, | |
550 int request_id) { | 558 int request_id) { |
551 source->source()->StartDataRequest( | 559 source->source()->StartDataRequest( |
552 path, | 560 path, |
553 is_incognito, | 561 render_process_id, |
562 render_view_id, | |
554 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 563 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
555 } | 564 } |
556 | 565 |
557 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { | 566 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { |
558 // Remove the request from our list of pending requests. | 567 // Remove the request from our list of pending requests. |
559 // If/when the source sends the data that was requested, the data will just | 568 // If/when the source sends the data that was requested, the data will just |
560 // be thrown away. | 569 // be thrown away. |
561 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 570 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
562 i != pending_requests_.end(); ++i) { | 571 i != pending_requests_.end(); ++i) { |
563 if (i->second == job) { | 572 if (i->second == job) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 | 632 |
624 } // namespace | 633 } // namespace |
625 | 634 |
626 net::URLRequestJobFactory::ProtocolHandler* | 635 net::URLRequestJobFactory::ProtocolHandler* |
627 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 636 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
628 bool is_incognito) { | 637 bool is_incognito) { |
629 return new DevToolsJobFactory(resource_context, is_incognito); | 638 return new DevToolsJobFactory(resource_context, is_incognito); |
630 } | 639 } |
631 | 640 |
632 } // namespace content | 641 } // namespace content |
OLD | NEW |