Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 1692503002: Functionality to allow blacklist and whitelist of custom schemes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compile error Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 extension_id, web_contents, std::move(stream), view_id, 212 extension_id, web_contents, std::move(stream), view_id,
213 expected_content_size, embedded, render_process_id, render_frame_id); 213 expected_content_size, embedded, render_process_id, render_frame_id);
214 } 214 }
215 #endif // !defined(ENABLE_EXTENSIONS) 215 #endif // !defined(ENABLE_EXTENSIONS)
216 216
217 void LaunchURL( 217 void LaunchURL(
218 const GURL& url, 218 const GURL& url,
219 int render_process_id, 219 int render_process_id,
220 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, 220 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
221 ui::PageTransition page_transition, 221 ui::PageTransition page_transition,
222 bool has_user_gesture) { 222 bool has_user_gesture,
223 bool is_whitelisted) {
223 // If there is no longer a WebContents, the request may have raced with tab 224 // If there is no longer a WebContents, the request may have raced with tab
224 // closing. Don't fire the external request. (It may have been a prerender.) 225 // closing. Don't fire the external request. (It may have been a prerender.)
225 content::WebContents* web_contents = web_contents_getter.Run(); 226 content::WebContents* web_contents = web_contents_getter.Run();
226 if (!web_contents) 227 if (!web_contents)
227 return; 228 return;
228 229
229 // Do not launch external requests attached to unswapped prerenders. 230 // Do not launch external requests attached to unswapped prerenders.
230 prerender::PrerenderContents* prerender_contents = 231 prerender::PrerenderContents* prerender_contents =
231 prerender::PrerenderContents::FromWebContents(web_contents); 232 prerender::PrerenderContents::FromWebContents(web_contents);
232 if (prerender_contents) { 233 if (prerender_contents) {
233 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); 234 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
234 prerender::ReportPrerenderExternalURL(); 235 prerender::ReportPrerenderExternalURL();
235 return; 236 return;
236 } 237 }
237 238
238 ExternalProtocolHandler::LaunchUrlWithDelegate( 239 // If the URL is in whitelist, we launch it without asking the user and
239 url, render_process_id, web_contents->GetRoutingID(), page_transition, 240 // without any additional security checks. Since the URL is whitelisted,
240 has_user_gesture, g_external_protocol_handler_delegate); 241 // we assume it can be executed.
242 if (is_whitelisted) {
243 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
244 url, render_process_id, web_contents->GetRoutingID());
245 } else {
246 ExternalProtocolHandler::LaunchUrlWithDelegate(
247 url, render_process_id, web_contents->GetRoutingID(), page_transition,
248 has_user_gesture, g_external_protocol_handler_delegate);
249 }
241 } 250 }
242 251
243 #if !defined(DISABLE_NACL) 252 #if !defined(DISABLE_NACL)
244 void AppendComponentUpdaterThrottles( 253 void AppendComponentUpdaterThrottles(
245 net::URLRequest* request, 254 net::URLRequest* request,
246 content::ResourceContext* resource_context, 255 content::ResourceContext* resource_context,
247 ResourceType resource_type, 256 ResourceType resource_type,
248 ScopedVector<content::ResourceThrottle>* throttles) { 257 ScopedVector<content::ResourceThrottle>* throttles) {
249 const char* crx_id = NULL; 258 const char* crx_id = NULL;
250 component_updater::ComponentUpdateService* cus = 259 component_updater::ComponentUpdateService* cus =
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 net::AuthChallengeInfo* auth_info, net::URLRequest* request) { 515 net::AuthChallengeInfo* auth_info, net::URLRequest* request) {
507 return CreateLoginPrompt(auth_info, request); 516 return CreateLoginPrompt(auth_info, request);
508 } 517 }
509 518
510 bool ChromeResourceDispatcherHostDelegate::HandleExternalProtocol( 519 bool ChromeResourceDispatcherHostDelegate::HandleExternalProtocol(
511 const GURL& url, 520 const GURL& url,
512 int child_id, 521 int child_id,
513 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, 522 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
514 bool is_main_frame, 523 bool is_main_frame,
515 ui::PageTransition page_transition, 524 ui::PageTransition page_transition,
516 bool has_user_gesture) { 525 bool has_user_gesture,
526 content::ResourceContext* resource_context) {
527 // Get the state, if |url| is in blacklist, whitelist or in none of those.
528 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
529 const policy::URLBlacklist::URLBlacklistState url_state =
530 io_data->GetURLBlacklistState(url);
531 if (url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_BLACKLIST) {
532 // It's a link with custom scheme and it's blacklisted. We return false here
533 // and let it process as a normal URL. Eventually chrome_network_delegate
534 // will see it's in the blacklist and the user will be shown the blocked
535 // content page.
536 return false;
537 }
517 #if defined(ENABLE_EXTENSIONS) 538 #if defined(ENABLE_EXTENSIONS)
518 // External protocols are disabled for guests. An exception is made for the 539 // External protocols are disabled for guests. An exception is made for the
519 // "mailto" protocol, so that pages that utilize it work properly in a 540 // "mailto" protocol, so that pages that utilize it work properly in a
520 // WebView. 541 // WebView.
521 if (extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) && 542 if (extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) &&
522 !url.SchemeIs(url::kMailToScheme)) { 543 !url.SchemeIs(url::kMailToScheme)) {
523 return false; 544 return false;
524 } 545 }
525 #endif // defined(ENABLE_EXTENSIONS) 546 #endif // defined(ENABLE_EXTENSIONS)
526 547
527 #if defined(OS_ANDROID) 548 #if defined(OS_ANDROID)
528 // Main frame external protocols are handled by 549 // Main frame external protocols are handled by
529 // InterceptNavigationResourceThrottle. 550 // InterceptNavigationResourceThrottle.
530 if (is_main_frame) 551 if (is_main_frame)
531 return false; 552 return false;
532 #endif // defined(ANDROID) 553 #endif // defined(ANDROID)
533 554
555 const bool is_whitelisted =
556 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
534 BrowserThread::PostTask( 557 BrowserThread::PostTask(
535 BrowserThread::UI, FROM_HERE, 558 BrowserThread::UI, FROM_HERE,
536 base::Bind(&LaunchURL, url, child_id, web_contents_getter, 559 base::Bind(&LaunchURL, url, child_id, web_contents_getter,
537 page_transition, has_user_gesture)); 560 page_transition, has_user_gesture, is_whitelisted));
538 return true; 561 return true;
539 } 562 }
540 563
541 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( 564 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
542 net::URLRequest* request, 565 net::URLRequest* request,
543 content::ResourceContext* resource_context, 566 content::ResourceContext* resource_context,
544 ResourceType resource_type, 567 ResourceType resource_type,
545 ScopedVector<content::ResourceThrottle>* throttles) { 568 ScopedVector<content::ResourceThrottle>* throttles) {
546 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 569 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
547 570
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data = 837 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data =
815 data_reduction_proxy::DataReductionProxyData::GetData(*request); 838 data_reduction_proxy::DataReductionProxyData::GetData(*request);
816 // DeepCopy the DataReductionProxyData from the URLRequest to prevent the 839 // DeepCopy the DataReductionProxyData from the URLRequest to prevent the
817 // URLRequest and DataReductionProxyData from both having ownership of the 840 // URLRequest and DataReductionProxyData from both having ownership of the
818 // same object. This copy will be shortlived as it will be deep copied again 841 // same object. This copy will be shortlived as it will be deep copied again
819 // when content makes a clone of NavigationData for the UI thread. 842 // when content makes a clone of NavigationData for the UI thread.
820 if (data_reduction_proxy_data) 843 if (data_reduction_proxy_data)
821 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy()); 844 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy());
822 return data; 845 return data;
823 } 846 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698