Chromium Code Reviews| 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/render_process_host.h" | |
| 32 #include "content/public/browser/resource_request_info.h" | |
| 31 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
| 32 #include "googleurl/src/url_util.h" | 34 #include "googleurl/src/url_util.h" |
| 33 #include "net/base/io_buffer.h" | 35 #include "net/base/io_buffer.h" |
| 34 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
| 35 #include "net/http/http_response_headers.h" | 37 #include "net/http/http_response_headers.h" |
| 36 #include "net/http/http_status_code.h" | 38 #include "net/http/http_status_code.h" |
| 37 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
| 38 #include "net/url_request/url_request_context.h" | 40 #include "net/url_request/url_request_context.h" |
| 39 #include "net/url_request/url_request_job.h" | 41 #include "net/url_request/url_request_job.h" |
| 40 #include "net/url_request/url_request_job_factory.h" | 42 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 job->set_allow_caching(source->source()->AllowCaching()); | 502 job->set_allow_caching(source->source()->AllowCaching()); |
| 501 job->set_add_content_security_policy( | 503 job->set_add_content_security_policy( |
| 502 source->source()->ShouldAddContentSecurityPolicy()); | 504 source->source()->ShouldAddContentSecurityPolicy()); |
| 503 job->set_content_security_policy_object_source( | 505 job->set_content_security_policy_object_source( |
| 504 source->source()->GetContentSecurityPolicyObjectSrc()); | 506 source->source()->GetContentSecurityPolicyObjectSrc()); |
| 505 job->set_content_security_policy_frame_source( | 507 job->set_content_security_policy_frame_source( |
| 506 source->source()->GetContentSecurityPolicyFrameSrc()); | 508 source->source()->GetContentSecurityPolicyFrameSrc()); |
| 507 job->set_deny_xframe_options( | 509 job->set_deny_xframe_options( |
| 508 source->source()->ShouldDenyXFrameOptions()); | 510 source->source()->ShouldDenyXFrameOptions()); |
| 509 | 511 |
| 512 // Look up additional request info to pass down. | |
| 513 int render_process_id = -1; | |
| 514 int render_view_id = -1; | |
| 515 ResourceRequestInfo::GetRenderViewForRequest(request, | |
| 516 &render_process_id, | |
| 517 &render_view_id); | |
| 518 | |
| 510 // Forward along the request to the data source. | 519 // Forward along the request to the data source. |
| 511 MessageLoop* target_message_loop = | 520 MessageLoop* target_message_loop = |
| 512 source->source()->MessageLoopForRequestPath(path); | 521 source->source()->MessageLoopForRequestPath(path); |
| 513 if (!target_message_loop) { | 522 if (!target_message_loop) { |
| 514 bool is_incognito = job->is_incognito(); | |
| 515 job->MimeTypeAvailable(source->source()->GetMimeType(path)); | 523 job->MimeTypeAvailable(source->source()->GetMimeType(path)); |
| 516 // Eliminate potentially dangling pointer to avoid future use. | 524 // Eliminate potentially dangling pointer to avoid future use. |
| 517 job = NULL; | 525 job = NULL; |
| 518 | 526 |
| 519 // The DataSource is agnostic to which thread StartDataRequest is called | 527 // The DataSource is agnostic to which thread StartDataRequest is called |
| 520 // on for this path. Call directly into it from this thread, the IO | 528 // on for this path. Call directly into it from this thread, the IO |
| 521 // thread. | 529 // thread. |
| 522 source->source()->StartDataRequest( | 530 source->source()->StartDataRequest( |
| 523 path, is_incognito, | 531 path, render_process_id, render_view_id, |
| 524 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 532 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
| 525 } else { | 533 } else { |
| 526 // URLRequestChromeJob should receive mime type before data. This | 534 // URLRequestChromeJob should receive mime type before data. This |
| 527 // is guaranteed because request for mime type is placed in the | 535 // is guaranteed because request for mime type is placed in the |
| 528 // message loop before request for data. And correspondingly their | 536 // message loop before request for data. And correspondingly their |
| 529 // replies are put on the IO thread in the same order. | 537 // replies are put on the IO thread in the same order. |
| 530 target_message_loop->PostTask( | 538 target_message_loop->PostTask( |
| 531 FROM_HERE, | 539 FROM_HERE, |
| 532 base::Bind(&GetMimeTypeOnUI, | 540 base::Bind(&GetMimeTypeOnUI, |
| 533 scoped_refptr<URLDataSourceImpl>(source), | 541 scoped_refptr<URLDataSourceImpl>(source), |
| 534 path, job->AsWeakPtr())); | 542 path, job->AsWeakPtr())); |
| 535 | 543 |
| 536 // The DataSource wants StartDataRequest to be called on a specific thread, | 544 // The DataSource wants StartDataRequest to be called on a specific thread, |
| 537 // usually the UI thread, for this path. | 545 // usually the UI thread, for this path. |
| 538 target_message_loop->PostTask( | 546 target_message_loop->PostTask( |
| 539 FROM_HERE, | 547 FROM_HERE, |
| 540 base::Bind(&URLDataManagerBackend::CallStartRequest, | 548 base::Bind(&URLDataManagerBackend::CallStartRequest, |
| 541 make_scoped_refptr(source), path, job->is_incognito(), | 549 make_scoped_refptr(source), path, render_process_id, |
| 542 request_id)); | 550 render_view_id, request_id)); |
| 543 } | 551 } |
| 544 return true; | 552 return true; |
| 545 } | 553 } |
| 546 | 554 |
| 547 void URLDataManagerBackend::CallStartRequest( | 555 void URLDataManagerBackend::CallStartRequest( |
| 548 scoped_refptr<URLDataSourceImpl> source, | 556 scoped_refptr<URLDataSourceImpl> source, |
| 549 const std::string& path, | 557 const std::string& path, |
| 550 bool is_incognito, | 558 int render_process_id, |
| 559 int render_view_id, | |
| 551 int request_id) { | 560 int request_id) { |
| 561 if (content::RenderProcessHost::FromID(render_process_id) == NULL) { | |
|
jam
2013/04/22 18:17:10
this is called on whatever target message loop the
Jered
2013/04/22 20:46:54
Done.
| |
| 562 // Make the request fail if its initiating renderer is no longer valid. | |
| 563 // This can happen when the IO thread posts this task just before the | |
| 564 // renderder shuts down. | |
| 565 source->SendResponse(request_id, NULL); | |
| 566 return; | |
| 567 } | |
| 552 source->source()->StartDataRequest( | 568 source->source()->StartDataRequest( |
| 553 path, | 569 path, |
| 554 is_incognito, | 570 render_process_id, |
| 571 render_view_id, | |
| 555 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); | 572 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); |
| 556 } | 573 } |
| 557 | 574 |
| 558 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { | 575 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { |
| 559 // Remove the request from our list of pending requests. | 576 // Remove the request from our list of pending requests. |
| 560 // If/when the source sends the data that was requested, the data will just | 577 // If/when the source sends the data that was requested, the data will just |
| 561 // be thrown away. | 578 // be thrown away. |
| 562 for (PendingRequestMap::iterator i = pending_requests_.begin(); | 579 for (PendingRequestMap::iterator i = pending_requests_.begin(); |
| 563 i != pending_requests_.end(); ++i) { | 580 i != pending_requests_.end(); ++i) { |
| 564 if (i->second == job) { | 581 if (i->second == job) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 | 641 |
| 625 } // namespace | 642 } // namespace |
| 626 | 643 |
| 627 net::URLRequestJobFactory::ProtocolHandler* | 644 net::URLRequestJobFactory::ProtocolHandler* |
| 628 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 645 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
| 629 bool is_incognito) { | 646 bool is_incognito) { |
| 630 return new DevToolsJobFactory(resource_context, is_incognito); | 647 return new DevToolsJobFactory(resource_context, is_incognito); |
| 631 } | 648 } |
| 632 | 649 |
| 633 } // namespace content | 650 } // namespace content |
| OLD | NEW |