| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 extension_id, web_contents, std::move(stream), view_id, | 204 extension_id, web_contents, std::move(stream), view_id, |
| 205 expected_content_size, embedded, render_process_id, render_frame_id); | 205 expected_content_size, embedded, render_process_id, render_frame_id); |
| 206 } | 206 } |
| 207 #endif // !defined(ENABLE_EXTENSIONS) | 207 #endif // !defined(ENABLE_EXTENSIONS) |
| 208 | 208 |
| 209 void LaunchURL( | 209 void LaunchURL( |
| 210 const GURL& url, | 210 const GURL& url, |
| 211 int render_process_id, | 211 int render_process_id, |
| 212 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 212 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 213 ui::PageTransition page_transition, | 213 ui::PageTransition page_transition, |
| 214 bool has_user_gesture) { | 214 bool has_user_gesture, |
| 215 bool is_whitelisted) { |
| 215 // If there is no longer a WebContents, the request may have raced with tab | 216 // If there is no longer a WebContents, the request may have raced with tab |
| 216 // closing. Don't fire the external request. (It may have been a prerender.) | 217 // closing. Don't fire the external request. (It may have been a prerender.) |
| 217 content::WebContents* web_contents = web_contents_getter.Run(); | 218 content::WebContents* web_contents = web_contents_getter.Run(); |
| 218 if (!web_contents) | 219 if (!web_contents) |
| 219 return; | 220 return; |
| 220 | 221 |
| 221 // Do not launch external requests attached to unswapped prerenders. | 222 // Do not launch external requests attached to unswapped prerenders. |
| 222 prerender::PrerenderContents* prerender_contents = | 223 prerender::PrerenderContents* prerender_contents = |
| 223 prerender::PrerenderContents::FromWebContents(web_contents); | 224 prerender::PrerenderContents::FromWebContents(web_contents); |
| 224 if (prerender_contents) { | 225 if (prerender_contents) { |
| 225 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 226 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 226 prerender::ReportPrerenderExternalURL(); | 227 prerender::ReportPrerenderExternalURL(); |
| 227 return; | 228 return; |
| 228 } | 229 } |
| 229 | 230 |
| 230 ExternalProtocolHandler::LaunchUrlWithDelegate( | 231 // If the URL is in whitelist, we launch it without asking the user and |
| 231 url, render_process_id, web_contents->GetRoutingID(), page_transition, | 232 // without any additional security checks. Since the URL is whitelisted, |
| 232 has_user_gesture, g_external_protocol_handler_delegate); | 233 // we assume it can be executed. |
| 234 if (is_whitelisted) { |
| 235 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
| 236 url, render_process_id, web_contents->GetRoutingID()); |
| 237 } else { |
| 238 ExternalProtocolHandler::LaunchUrlWithDelegate( |
| 239 url, render_process_id, web_contents->GetRoutingID(), page_transition, |
| 240 has_user_gesture, g_external_protocol_handler_delegate); |
| 241 } |
| 233 } | 242 } |
| 234 | 243 |
| 235 #if !defined(DISABLE_NACL) | 244 #if !defined(DISABLE_NACL) |
| 236 void AppendComponentUpdaterThrottles( | 245 void AppendComponentUpdaterThrottles( |
| 237 net::URLRequest* request, | 246 net::URLRequest* request, |
| 238 content::ResourceContext* resource_context, | 247 content::ResourceContext* resource_context, |
| 239 ResourceType resource_type, | 248 ResourceType resource_type, |
| 240 ScopedVector<content::ResourceThrottle>* throttles) { | 249 ScopedVector<content::ResourceThrottle>* throttles) { |
| 241 const char* crx_id = NULL; | 250 const char* crx_id = NULL; |
| 242 component_updater::ComponentUpdateService* cus = | 251 component_updater::ComponentUpdateService* cus = |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 net::AuthChallengeInfo* auth_info, net::URLRequest* request) { | 445 net::AuthChallengeInfo* auth_info, net::URLRequest* request) { |
| 437 return CreateLoginPrompt(auth_info, request); | 446 return CreateLoginPrompt(auth_info, request); |
| 438 } | 447 } |
| 439 | 448 |
| 440 bool ChromeResourceDispatcherHostDelegate::HandleExternalProtocol( | 449 bool ChromeResourceDispatcherHostDelegate::HandleExternalProtocol( |
| 441 const GURL& url, | 450 const GURL& url, |
| 442 int child_id, | 451 int child_id, |
| 443 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 452 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 444 bool is_main_frame, | 453 bool is_main_frame, |
| 445 ui::PageTransition page_transition, | 454 ui::PageTransition page_transition, |
| 446 bool has_user_gesture) { | 455 bool has_user_gesture, |
| 456 bool is_whitelisted) { |
| 447 #if defined(ENABLE_EXTENSIONS) | 457 #if defined(ENABLE_EXTENSIONS) |
| 448 // External protocols are disabled for guests. An exception is made for the | 458 // External protocols are disabled for guests. An exception is made for the |
| 449 // "mailto" protocol, so that pages that utilize it work properly in a | 459 // "mailto" protocol, so that pages that utilize it work properly in a |
| 450 // WebView. | 460 // WebView. |
| 451 if (extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) && | 461 if (extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) && |
| 452 !url.SchemeIs(url::kMailToScheme)) { | 462 !url.SchemeIs(url::kMailToScheme)) { |
| 453 return false; | 463 return false; |
| 454 } | 464 } |
| 455 #endif // defined(ENABLE_EXTENSIONS) | 465 #endif // defined(ENABLE_EXTENSIONS) |
| 456 | 466 |
| 457 #if defined(OS_ANDROID) | 467 #if defined(OS_ANDROID) |
| 458 // Main frame external protocols are handled by | 468 // Main frame external protocols are handled by |
| 459 // InterceptNavigationResourceThrottle. | 469 // InterceptNavigationResourceThrottle. |
| 460 if (is_main_frame) | 470 if (is_main_frame) |
| 461 return false; | 471 return false; |
| 462 #endif // defined(ANDROID) | 472 #endif // defined(ANDROID) |
| 463 | 473 |
| 464 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
| 465 BrowserThread::UI, FROM_HERE, | 475 BrowserThread::UI, FROM_HERE, |
| 466 base::Bind(&LaunchURL, url, child_id, web_contents_getter, | 476 base::Bind(&LaunchURL, url, child_id, web_contents_getter, |
| 467 page_transition, has_user_gesture)); | 477 page_transition, has_user_gesture, is_whitelisted)); |
| 468 return true; | 478 return true; |
| 469 } | 479 } |
| 470 | 480 |
| 471 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( | 481 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( |
| 472 net::URLRequest* request, | 482 net::URLRequest* request, |
| 473 content::ResourceContext* resource_context, | 483 content::ResourceContext* resource_context, |
| 474 ResourceType resource_type, | 484 ResourceType resource_type, |
| 475 ScopedVector<content::ResourceThrottle>* throttles) { | 485 ScopedVector<content::ResourceThrottle>* throttles) { |
| 476 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 486 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 477 | 487 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return data_reduction_proxy_io_data->ShouldEnableLoFiMode(url_request); | 725 return data_reduction_proxy_io_data->ShouldEnableLoFiMode(url_request); |
| 716 return false; | 726 return false; |
| 717 } | 727 } |
| 718 | 728 |
| 719 // static | 729 // static |
| 720 void ChromeResourceDispatcherHostDelegate:: | 730 void ChromeResourceDispatcherHostDelegate:: |
| 721 SetExternalProtocolHandlerDelegateForTesting( | 731 SetExternalProtocolHandlerDelegateForTesting( |
| 722 ExternalProtocolHandler::Delegate* delegate) { | 732 ExternalProtocolHandler::Delegate* delegate) { |
| 723 g_external_protocol_handler_delegate = delegate; | 733 g_external_protocol_handler_delegate = delegate; |
| 724 } | 734 } |
| OLD | NEW |