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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/component_updater/component_updater_service.h" | 15 #include "chrome/browser/component_updater/component_updater_service.h" |
16 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" | 16 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
18 #include "chrome/browser/download/download_request_limiter.h" | 18 #include "chrome/browser/download/download_request_limiter.h" |
19 #include "chrome/browser/download/download_resource_throttle.h" | 19 #include "chrome/browser/download/download_resource_throttle.h" |
20 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" | |
21 #include "chrome/browser/extensions/user_script_listener.h" | |
22 #include "chrome/browser/prefetch/prefetch.h" | 20 #include "chrome/browser/prefetch/prefetch.h" |
23 #include "chrome/browser/prerender/prerender_manager.h" | 21 #include "chrome/browser/prerender/prerender_manager.h" |
24 #include "chrome/browser/prerender/prerender_manager_factory.h" | 22 #include "chrome/browser/prerender/prerender_manager_factory.h" |
25 #include "chrome/browser/prerender/prerender_pending_swap_throttle.h" | 23 #include "chrome/browser/prerender/prerender_pending_swap_throttle.h" |
26 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 24 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
27 #include "chrome/browser/prerender/prerender_tracker.h" | 25 #include "chrome/browser/prerender/prerender_tracker.h" |
28 #include "chrome/browser/prerender/prerender_util.h" | 26 #include "chrome/browser/prerender/prerender_util.h" |
29 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/profiles/profile_io_data.h" | 28 #include "chrome/browser/profiles/profile_io_data.h" |
31 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" | 29 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h
" |
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
33 #include "chrome/browser/signin/signin_header_helper.h" | 31 #include "chrome/browser/signin/signin_header_helper.h" |
34 #include "chrome/browser/tab_contents/tab_util.h" | 32 #include "chrome/browser/tab_contents/tab_util.h" |
35 #include "chrome/browser/ui/login/login_prompt.h" | 33 #include "chrome/browser/ui/login/login_prompt.h" |
36 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 34 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
37 #include "chrome/common/extensions/extension_constants.h" | 35 #include "chrome/common/extensions/extension_constants.h" |
38 #include "chrome/common/extensions/manifest_handlers/mime_types_handler.h" | |
39 #include "chrome/common/render_messages.h" | 36 #include "chrome/common/render_messages.h" |
40 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
41 #include "components/google/core/browser/google_util.h" | 38 #include "components/google/core/browser/google_util.h" |
42 #include "components/variations/variations_http_header_provider.h" | 39 #include "components/variations/variations_http_header_provider.h" |
43 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
44 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
46 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
47 #include "content/public/browser/resource_context.h" | 44 #include "content/public/browser/resource_context.h" |
48 #include "content/public/browser/resource_dispatcher_host.h" | 45 #include "content/public/browser/resource_dispatcher_host.h" |
49 #include "content/public/browser/resource_request_info.h" | 46 #include "content/public/browser/resource_request_info.h" |
50 #include "content/public/browser/stream_handle.h" | 47 #include "content/public/browser/stream_handle.h" |
51 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
52 #include "content/public/common/resource_response.h" | 49 #include "content/public/common/resource_response.h" |
53 #include "extensions/browser/info_map.h" | |
54 #include "extensions/common/constants.h" | |
55 #include "extensions/common/user_script.h" | |
56 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
57 #include "net/base/load_timing_info.h" | 51 #include "net/base/load_timing_info.h" |
58 #include "net/base/request_priority.h" | 52 #include "net/base/request_priority.h" |
59 #include "net/http/http_response_headers.h" | 53 #include "net/http/http_response_headers.h" |
60 #include "net/url_request/url_request.h" | 54 #include "net/url_request/url_request.h" |
61 | 55 |
62 #if defined(ENABLE_EXTENSIONS) | 56 #if defined(ENABLE_EXTENSIONS) |
| 57 #include "chrome/browser/apps/app_url_redirector.h" |
| 58 #include "chrome/browser/apps/ephemeral_app_throttle.h" |
| 59 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" |
| 60 #include "chrome/browser/extensions/user_script_listener.h" |
63 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | 61 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
| 62 #include "chrome/common/extensions/manifest_handlers/mime_types_handler.h" |
| 63 #include "extensions/browser/info_map.h" |
| 64 #include "extensions/common/constants.h" |
| 65 #include "extensions/common/user_script.h" |
64 #endif | 66 #endif |
65 | 67 |
66 #if defined(ENABLE_CONFIGURATION_POLICY) | 68 #if defined(ENABLE_CONFIGURATION_POLICY) |
67 #include "components/policy/core/common/cloud/policy_header_io_helper.h" | 69 #include "components/policy/core/common/cloud/policy_header_io_helper.h" |
68 #endif | 70 #endif |
69 | 71 |
70 #if defined(ENABLE_MANAGED_USERS) | 72 #if defined(ENABLE_MANAGED_USERS) |
71 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" | 73 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" |
72 #endif | 74 #endif |
73 | 75 |
74 #if defined(USE_SYSTEM_PROTOBUF) | 76 #if defined(USE_SYSTEM_PROTOBUF) |
75 #include <google/protobuf/repeated_field.h> | 77 #include <google/protobuf/repeated_field.h> |
76 #else | 78 #else |
77 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | 79 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
78 #endif | 80 #endif |
79 | 81 |
80 #if defined(OS_ANDROID) | 82 #if defined(OS_ANDROID) |
81 #include "chrome/browser/android/intercept_download_resource_throttle.h" | 83 #include "chrome/browser/android/intercept_download_resource_throttle.h" |
82 #include "chrome/browser/ui/android/infobars/auto_login_prompter.h" | 84 #include "chrome/browser/ui/android/infobars/auto_login_prompter.h" |
83 #include "components/navigation_interception/intercept_navigation_delegate.h" | 85 #include "components/navigation_interception/intercept_navigation_delegate.h" |
84 #else | |
85 #include "chrome/browser/apps/app_url_redirector.h" | |
86 #include "chrome/browser/apps/ephemeral_app_throttle.h" | |
87 #endif | 86 #endif |
88 | 87 |
89 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
90 #include "chrome/browser/chromeos/login/signin/merge_session_throttle.h" | 89 #include "chrome/browser/chromeos/login/signin/merge_session_throttle.h" |
91 // TODO(oshima): Enable this for other platforms. | 90 // TODO(oshima): Enable this for other platforms. |
92 #include "chrome/browser/renderer_host/offline_resource_throttle.h" | 91 #include "chrome/browser/renderer_host/offline_resource_throttle.h" |
93 #endif | 92 #endif |
94 | 93 |
95 using content::BrowserThread; | 94 using content::BrowserThread; |
96 using content::RenderViewHost; | 95 using content::RenderViewHost; |
97 using content::ResourceDispatcherHostLoginDelegate; | 96 using content::ResourceDispatcherHostLoginDelegate; |
98 using content::ResourceRequestInfo; | 97 using content::ResourceRequestInfo; |
99 using content::ResourceType; | 98 using content::ResourceType; |
| 99 |
| 100 #if defined(ENABLE_EXTENSIONS) |
100 using extensions::Extension; | 101 using extensions::Extension; |
101 using extensions::StreamsPrivateAPI; | 102 using extensions::StreamsPrivateAPI; |
| 103 #endif |
102 | 104 |
103 #if defined(OS_ANDROID) | 105 #if defined(OS_ANDROID) |
104 using navigation_interception::InterceptNavigationDelegate; | 106 using navigation_interception::InterceptNavigationDelegate; |
105 #endif | 107 #endif |
106 | 108 |
107 namespace { | 109 namespace { |
108 | 110 |
109 ExternalProtocolHandler::Delegate* g_external_protocol_handler_delegate = NULL; | 111 ExternalProtocolHandler::Delegate* g_external_protocol_handler_delegate = NULL; |
110 | 112 |
111 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { | 113 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 cus->GetOnDemandUpdater().GetOnDemandResourceThrottle(request, crx_id)); | 249 cus->GetOnDemandUpdater().GetOnDemandResourceThrottle(request, crx_id)); |
248 } | 250 } |
249 } | 251 } |
250 | 252 |
251 } // end namespace | 253 } // end namespace |
252 | 254 |
253 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( | 255 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( |
254 prerender::PrerenderTracker* prerender_tracker) | 256 prerender::PrerenderTracker* prerender_tracker) |
255 : download_request_limiter_(g_browser_process->download_request_limiter()), | 257 : download_request_limiter_(g_browser_process->download_request_limiter()), |
256 safe_browsing_(g_browser_process->safe_browsing_service()), | 258 safe_browsing_(g_browser_process->safe_browsing_service()), |
| 259 #if defined(ENABLE_EXTENSIONS) |
257 user_script_listener_(new extensions::UserScriptListener()), | 260 user_script_listener_(new extensions::UserScriptListener()), |
| 261 #endif |
258 prerender_tracker_(prerender_tracker) { | 262 prerender_tracker_(prerender_tracker) { |
259 } | 263 } |
260 | 264 |
261 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { | 265 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { |
| 266 #if defined(ENABLE_EXTENSIONS) |
262 CHECK(stream_target_info_.empty()); | 267 CHECK(stream_target_info_.empty()); |
| 268 #endif |
263 } | 269 } |
264 | 270 |
265 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( | 271 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( |
266 int child_id, | 272 int child_id, |
267 int route_id, | 273 int route_id, |
268 const std::string& method, | 274 const std::string& method, |
269 const GURL& url, | 275 const GURL& url, |
270 ResourceType::Type resource_type, | 276 ResourceType::Type resource_type, |
271 content::ResourceContext* resource_context) { | 277 content::ResourceContext* resource_context) { |
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 } | 502 } |
497 #endif | 503 #endif |
498 | 504 |
499 #if defined(ENABLE_MANAGED_USERS) | 505 #if defined(ENABLE_MANAGED_USERS) |
500 bool is_subresource_request = resource_type != ResourceType::MAIN_FRAME; | 506 bool is_subresource_request = resource_type != ResourceType::MAIN_FRAME; |
501 throttles->push_back(new SupervisedUserResourceThrottle( | 507 throttles->push_back(new SupervisedUserResourceThrottle( |
502 request, !is_subresource_request, | 508 request, !is_subresource_request, |
503 io_data->supervised_user_url_filter())); | 509 io_data->supervised_user_url_filter())); |
504 #endif | 510 #endif |
505 | 511 |
| 512 #if defined(ENABLE_EXTENSIONS) |
506 content::ResourceThrottle* throttle = | 513 content::ResourceThrottle* throttle = |
507 user_script_listener_->CreateResourceThrottle(request->url(), | 514 user_script_listener_->CreateResourceThrottle(request->url(), |
508 resource_type); | 515 resource_type); |
509 if (throttle) | 516 if (throttle) |
510 throttles->push_back(throttle); | 517 throttles->push_back(throttle); |
| 518 #endif |
511 | 519 |
512 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 520 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
513 if (info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender) { | 521 if (info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender) { |
514 throttles->push_back(new prerender::PrerenderResourceThrottle(request)); | 522 throttles->push_back(new prerender::PrerenderResourceThrottle(request)); |
515 } | 523 } |
516 if (prerender_tracker_->IsPendingSwapRequestOnIOThread( | 524 if (prerender_tracker_->IsPendingSwapRequestOnIOThread( |
517 info->GetChildID(), info->GetRenderFrameID(), request->url())) { | 525 info->GetChildID(), info->GetRenderFrameID(), request->url())) { |
518 throttles->push_back(new prerender::PrerenderPendingSwapThrottle( | 526 throttles->push_back(new prerender::PrerenderPendingSwapThrottle( |
519 request, prerender_tracker_)); | 527 request, prerender_tracker_)); |
520 } | 528 } |
(...skipping 16 matching lines...) Expand all Loading... |
537 request->RemoveRequestHeaderByName(kAllowChromeSignIn); | 545 request->RemoveRequestHeaderByName(kAllowChromeSignIn); |
538 break; | 546 break; |
539 case OneClickSigninHelper::IGNORE_REQUEST: | 547 case OneClickSigninHelper::IGNORE_REQUEST: |
540 break; | 548 break; |
541 } | 549 } |
542 } | 550 } |
543 #endif | 551 #endif |
544 | 552 |
545 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( | 553 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( |
546 const GURL& url, const std::string& mime_type) { | 554 const GURL& url, const std::string& mime_type) { |
| 555 #if defined(ENABLE_EXTENSIONS) |
547 // Special-case user scripts to get downloaded instead of viewed. | 556 // Special-case user scripts to get downloaded instead of viewed. |
548 return extensions::UserScript::IsURLUserScript(url, mime_type); | 557 return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 558 #else |
| 559 return false; |
| 560 #endif |
549 } | 561 } |
550 | 562 |
551 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 563 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
552 net::URLRequest* request, | 564 net::URLRequest* request, |
553 const std::string& mime_type, | 565 const std::string& mime_type, |
554 GURL* origin, | 566 GURL* origin, |
555 std::string* payload) { | 567 std::string* payload) { |
556 #if !defined(OS_ANDROID) | 568 #if !defined(OS_ANDROID) |
557 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 569 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
558 ProfileIOData* io_data = | 570 ProfileIOData* io_data = |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 url_request->GetTotalReceivedBytes())); | 731 url_request->GetTotalReceivedBytes())); |
720 } | 732 } |
721 } | 733 } |
722 | 734 |
723 // static | 735 // static |
724 void ChromeResourceDispatcherHostDelegate:: | 736 void ChromeResourceDispatcherHostDelegate:: |
725 SetExternalProtocolHandlerDelegateForTesting( | 737 SetExternalProtocolHandlerDelegateForTesting( |
726 ExternalProtocolHandler::Delegate* delegate) { | 738 ExternalProtocolHandler::Delegate* delegate) { |
727 g_external_protocol_handler_delegate = delegate; | 739 g_external_protocol_handler_delegate = delegate; |
728 } | 740 } |
OLD | NEW |