| 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/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/loader/cross_site_resource_handler.h" | 14 #include "content/browser/loader/cross_site_resource_handler.h" |
| 15 #include "content/browser/loader/resource_loader_delegate.h" | 15 #include "content/browser/loader/resource_loader_delegate.h" |
| 16 #include "content/browser/loader/resource_request_info_impl.h" | 16 #include "content/browser/loader/resource_request_info_impl.h" |
| 17 #include "content/browser/ssl/ssl_client_auth_handler.h" | 17 #include "content/browser/ssl/ssl_client_auth_handler.h" |
| 18 #include "content/browser/ssl/ssl_manager.h" | 18 #include "content/browser/ssl/ssl_manager.h" |
| 19 #include "content/common/ssl_status_serialization.h" | 19 #include "content/common/ssl_status_serialization.h" |
| 20 #include "content/public/browser/cert_store.h" | 20 #include "content/public/browser/cert_store.h" |
| 21 #include "content/public/browser/resource_context.h" | 21 #include "content/public/browser/resource_context.h" |
| 22 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 22 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 23 #include "content/public/browser/site_instance.h" | |
| 24 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 25 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/process_type.h" | 25 #include "content/public/common/process_type.h" |
| 27 #include "content/public/common/resource_response.h" | 26 #include "content/public/common/resource_response.h" |
| 28 #include "content/public/common/url_constants.h" | |
| 29 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
| 30 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 31 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
| 32 #include "net/ssl/client_cert_store.h" | 30 #include "net/ssl/client_cert_store.h" |
| 33 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
| 34 #include "webkit/browser/appcache/appcache_interceptor.h" | 32 #include "webkit/browser/appcache/appcache_interceptor.h" |
| 35 | 33 |
| 36 using base::TimeDelta; | 34 using base::TimeDelta; |
| 37 using base::TimeTicks; | 35 using base::TimeTicks; |
| 38 | 36 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 weak_ptr_factory_.GetWeakPtr())); | 491 weak_ptr_factory_.GetWeakPtr())); |
| 494 } | 492 } |
| 495 } | 493 } |
| 496 | 494 |
| 497 void ResourceLoader::CompleteResponseStarted() { | 495 void ResourceLoader::CompleteResponseStarted() { |
| 498 ResourceRequestInfoImpl* info = GetRequestInfo(); | 496 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 499 | 497 |
| 500 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 498 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 501 PopulateResourceResponse(request_.get(), response.get()); | 499 PopulateResourceResponse(request_.get(), response.get()); |
| 502 | 500 |
| 503 // The --site-per-process flag enables an out-of-process iframes | |
| 504 // prototype. It works by changing the MIME type of cross-site subframe | |
| 505 // responses to a Chrome specific one. This new type causes the subframe | |
| 506 // to be replaced by a <webview> tag with the same URL, which results in | |
| 507 // using a renderer in a different process. | |
| 508 // | |
| 509 // For prototyping purposes, we will use a small hack to ensure same site | |
| 510 // iframes are not changed. We can compare the URL for the subframe | |
| 511 // request with the referrer. If the two don't match, then it should be a | |
| 512 // cross-site iframe. | |
| 513 // Also, we don't do the MIME type change for chrome:// URLs, as those | |
| 514 // require different privileges and are not allowed in regular renderers. | |
| 515 // | |
| 516 // The usage of SiteInstance::IsSameWebSite is safe on the IO thread, | |
| 517 // if the browser_context parameter is NULL. This does not work for hosted | |
| 518 // apps, but should be fine for prototyping. | |
| 519 // TODO(nasko): Once the SiteInstance check is fixed, ensure we do the | |
| 520 // right thing here. http://crbug.com/160576 | |
| 521 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 522 if (command_line.HasSwitch(switches::kSitePerProcess) && | |
| 523 GetRequestInfo()->GetResourceType() == ResourceType::SUB_FRAME && | |
| 524 response->head.mime_type == "text/html" && | |
| 525 !request_->url().SchemeIs(chrome::kChromeUIScheme) && | |
| 526 !SiteInstance::IsSameWebSite(NULL, request_->url(), | |
| 527 GURL(request_->referrer()))) { | |
| 528 response->head.mime_type = "application/browser-plugin"; | |
| 529 } | |
| 530 | |
| 531 if (request_->ssl_info().cert.get()) { | 501 if (request_->ssl_info().cert.get()) { |
| 532 int cert_id = CertStore::GetInstance()->StoreCert( | 502 int cert_id = CertStore::GetInstance()->StoreCert( |
| 533 request_->ssl_info().cert.get(), info->GetChildID()); | 503 request_->ssl_info().cert.get(), info->GetChildID()); |
| 534 response->head.security_info = SerializeSecurityInfo( | 504 response->head.security_info = SerializeSecurityInfo( |
| 535 cert_id, | 505 cert_id, |
| 536 request_->ssl_info().cert_status, | 506 request_->ssl_info().cert_status, |
| 537 request_->ssl_info().security_bits, | 507 request_->ssl_info().security_bits, |
| 538 request_->ssl_info().connection_status); | 508 request_->ssl_info().connection_status); |
| 539 } else { | 509 } else { |
| 540 // We should not have any SSL state. | 510 // We should not have any SSL state. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 case net::URLRequestStatus::FAILED: | 656 case net::URLRequestStatus::FAILED: |
| 687 status = STATUS_UNDEFINED; | 657 status = STATUS_UNDEFINED; |
| 688 break; | 658 break; |
| 689 } | 659 } |
| 690 | 660 |
| 691 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 661 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 692 } | 662 } |
| 693 } | 663 } |
| 694 | 664 |
| 695 } // namespace content | 665 } // namespace content |
| OLD | NEW |