| 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 "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/download/download_request_limiter.h" | 13 #include "chrome/browser/download/download_request_limiter.h" |
| 14 #include "chrome/browser/download/download_resource_throttle.h" | 14 #include "chrome/browser/download/download_resource_throttle.h" |
| 15 #include "chrome/browser/download/download_util.h" | 15 #include "chrome/browser/download/download_util.h" |
| 16 #include "chrome/browser/extensions/user_script_listener.h" | 16 #include "chrome/browser/extensions/user_script_listener.h" |
| 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 18 #include "chrome/browser/google/google_util.h" | 18 #include "chrome/browser/google/google_util.h" |
| 19 #include "chrome/browser/instant/instant_loader.h" | 19 #include "chrome/browser/instant/instant_loader.h" |
| 20 #include "chrome/browser/net/load_timing_observer.h" | 20 #include "chrome/browser/net/load_timing_observer.h" |
| 21 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 21 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 22 #include "chrome/browser/prerender/prerender_manager.h" | 22 #include "chrome/browser/prerender/prerender_manager.h" |
| 23 #include "chrome/browser/prerender/prerender_tracker.h" | 23 #include "chrome/browser/prerender/prerender_tracker.h" |
| 24 #include "chrome/browser/profiles/profile_io_data.h" | 24 #include "chrome/browser/profiles/profile_io_data.h" |
| 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" | 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" |
| 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" | 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" |
| 27 #include "chrome/browser/renderer_host/test_navigation_listener.h" |
| 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 28 #include "chrome/browser/ui/auto_login_prompter.h" | 29 #include "chrome/browser/ui/auto_login_prompter.h" |
| 29 #include "chrome/browser/ui/login/login_prompt.h" | 30 #include "chrome/browser/ui/login/login_prompt.h" |
| 30 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 31 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/extensions/user_script.h" | 33 #include "chrome/common/extensions/user_script.h" |
| 33 #include "chrome/common/metrics/experiments_helper.h" | 34 #include "chrome/common/metrics/experiments_helper.h" |
| 34 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" | 35 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" |
| 35 #include "chrome/common/render_messages.h" | 36 #include "chrome/common/render_messages.h" |
| 36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 : download_request_limiter_(g_browser_process->download_request_limiter()), | 76 : download_request_limiter_(g_browser_process->download_request_limiter()), |
| 76 safe_browsing_(g_browser_process->safe_browsing_service()), | 77 safe_browsing_(g_browser_process->safe_browsing_service()), |
| 77 user_script_listener_(new extensions::UserScriptListener()), | 78 user_script_listener_(new extensions::UserScriptListener()), |
| 78 prerender_tracker_(prerender_tracker), | 79 prerender_tracker_(prerender_tracker), |
| 79 variation_ids_cache_initialized_(false) { | 80 variation_ids_cache_initialized_(false) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { | 83 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { |
| 83 } | 84 } |
| 84 | 85 |
| 86 void ChromeResourceDispatcherHostDelegate::SetTestNavigationListener( |
| 87 TestNavigationListener* test_navigation_listener) { |
| 88 test_navigation_listener_ = test_navigation_listener; |
| 89 } |
| 90 |
| 85 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( | 91 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( |
| 86 int child_id, | 92 int child_id, |
| 87 int route_id, | 93 int route_id, |
| 88 const std::string& method, | 94 const std::string& method, |
| 89 const GURL& url, | 95 const GURL& url, |
| 90 ResourceType::Type resource_type, | 96 ResourceType::Type resource_type, |
| 91 content::ResourceContext* resource_context, | 97 content::ResourceContext* resource_context, |
| 92 const content::Referrer& referrer) { | 98 const content::Referrer& referrer) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 94 | 100 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 throttles->push_back(SafeBrowsingResourceThrottle::Create( | 278 throttles->push_back(SafeBrowsingResourceThrottle::Create( |
| 273 request, child_id, route_id, is_subresource_request, safe_browsing_)); | 279 request, child_id, route_id, is_subresource_request, safe_browsing_)); |
| 274 } | 280 } |
| 275 #endif | 281 #endif |
| 276 | 282 |
| 277 content::ResourceThrottle* throttle = | 283 content::ResourceThrottle* throttle = |
| 278 user_script_listener_->CreateResourceThrottle(request->url(), | 284 user_script_listener_->CreateResourceThrottle(request->url(), |
| 279 resource_type); | 285 resource_type); |
| 280 if (throttle) | 286 if (throttle) |
| 281 throttles->push_back(throttle); | 287 throttles->push_back(throttle); |
| 288 |
| 289 if (test_navigation_listener_.get()) { |
| 290 throttle = test_navigation_listener_->CreateResourceThrottle(request->url(), |
| 291 resource_type); |
| 292 if (throttle) |
| 293 throttles->push_back(throttle); |
| 294 } |
| 282 } | 295 } |
| 283 | 296 |
| 284 void ChromeResourceDispatcherHostDelegate::AppendChromeMetricsHeaders( | 297 void ChromeResourceDispatcherHostDelegate::AppendChromeMetricsHeaders( |
| 285 net::URLRequest* request, | 298 net::URLRequest* request, |
| 286 content::ResourceContext* resource_context, | 299 content::ResourceContext* resource_context, |
| 287 ResourceType::Type resource_type) { | 300 ResourceType::Type resource_type) { |
| 288 // Don't attempt to append headers to requests that have already started. | 301 // Don't attempt to append headers to requests that have already started. |
| 289 // TODO(stevet): Remove this once we've resolved the request ordering issues | 302 // TODO(stevet): Remove this once we've resolved the request ordering issues |
| 290 // in crbug.com/128048. | 303 // in crbug.com/128048. |
| 291 if (request->is_pending()) | 304 if (request->is_pending()) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (base::Base64Encode(serialized, &hashed)) { | 449 if (base::Base64Encode(serialized, &hashed)) { |
| 437 // If successful, swap the header value with the new one. | 450 // If successful, swap the header value with the new one. |
| 438 // Note that the list of IDs and the header could be temporarily out of sync | 451 // Note that the list of IDs and the header could be temporarily out of sync |
| 439 // if IDs are added as we are recreating the header, but we're OK with those | 452 // if IDs are added as we are recreating the header, but we're OK with those |
| 440 // descrepancies. | 453 // descrepancies. |
| 441 variation_ids_header_ = hashed; | 454 variation_ids_header_ = hashed; |
| 442 } else { | 455 } else { |
| 443 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized; | 456 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized; |
| 444 } | 457 } |
| 445 } | 458 } |
| OLD | NEW |