blob: b9a17c03d379b2645afef76293dfd916a4f416b6 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
bmcquade5d2d9cf32015-06-19 17:42:287#include <map>
[email protected]7c3228a2011-11-11 21:35:228#include <set>
[email protected]1033acd2012-02-08 08:46:279#include <utility>
[email protected]7c3228a2011-11-11 21:35:2210#include <vector>
11
brettwf1958912015-10-07 19:43:1212#include "base/base_switches.h"
[email protected]317c58f02011-11-09 02:15:0313#include "base/bind.h"
estark3ba11132015-04-10 01:38:3314#include "base/bind_helpers.h"
[email protected]b80f68432011-05-02 17:22:3015#include "base/command_line.h"
Will Harrisc196ed942019-08-03 03:45:3016#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2417#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0018#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1519#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5820#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2521#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1422#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3323#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3924#include "base/path_service.h"
Avi Drissmand251e912018-12-26 15:46:3725#include "base/stl_util.h"
[email protected]e7463412013-06-10 22:53:4626#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0327#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2828#include "base/strings/string_util.h"
29#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2030#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0331#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2832#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3233#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4134#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1835#include "build/build_config.h"
Ken Rockot06fd2832019-05-24 17:24:4436#include "chrome/app/builtin_service_manifests.h"
Ken Rockot341089f2019-01-11 23:11:5837#include "chrome/app/chrome_content_browser_overlay_manifest.h"
38#include "chrome/app/chrome_content_gpu_overlay_manifest.h"
39#include "chrome/app/chrome_content_renderer_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4740#include "chrome/browser/accessibility/accessibility_labels_service.h"
41#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
michaeln96f887e22015-04-13 23:58:3142#include "chrome/browser/after_startup_task_utils.h"
[email protected]b8148ac2011-07-13 22:03:2543#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3044#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4745#include "chrome/browser/browsing_data/browsing_data_helper.h"
msramek1c2b3ca2017-03-14 17:57:5646#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
nigeltaobeff0a102017-04-29 09:30:3747#include "chrome/browser/cache_stats_recorder.h"
[email protected]d5a74be2014-08-08 01:01:2748#include "chrome/browser/chrome_content_browser_client_parts.h"
[email protected]317f96c92011-05-31 06:53:4149#include "chrome/browser/chrome_quota_permission_context.h"
drogerb1716972015-06-30 09:04:0950#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0851#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
[email protected]8093a542011-05-13 07:29:3252#include "chrome/browser/content_settings/tab_specific_content_settings.h"
Robbie McElrath1294d242019-05-31 20:46:2253#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
54#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3055#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
56#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0657#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0858#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4959#include "chrome/browser/download/download_prefs.h"
Maks Orlovich710d5e32019-07-09 20:16:4560#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0161#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1962#include "chrome/browser/font_family_cache.h"
Matt Reynolds93616f9b2019-06-07 01:28:5263#include "chrome/browser/hid/chrome_hid_delegate.h"
Anthony Vallee-Duboise2432137a2019-01-17 20:06:0164#include "chrome/browser/language/translate_frame_binder.h"
Avi Drissmand30927342018-05-22 15:04:2765#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2766#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3467#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4268#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
69#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1670#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3671#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Patrik Höglundb564859b2018-05-17 11:17:1672#include "chrome/browser/media/webrtc/webrtc_logging_handler_host.h"
[email protected]95132f52013-04-12 02:19:0473#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0574#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0775#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
Lu Chen5bec7a302018-06-26 18:52:3276#include "chrome/browser/navigation_predictor/navigation_predictor.h"
John Abd-El-Malek7577f262019-06-10 21:23:2377#include "chrome/browser/net/chrome_network_delegate.h"
Matt Menkeae4fdb12018-06-02 06:32:5478#include "chrome/browser/net/system_network_context_manager.h"
dvallet233f57ab2016-12-21 03:17:1079#include "chrome/browser/net_benchmarking.h"
Richard Knolld0eae962019-04-04 12:34:0280#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5981#include "chrome/browser/notifications/platform_notification_service_impl.h"
csharrison4bd8a192016-08-02 18:03:1582#include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h"
Charlie Harrison650e11422018-12-04 00:37:2683#include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
Matt Falkenhagen8479b202017-07-14 04:35:3184#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
leon.han952ea3252016-04-13 02:44:5685#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0686#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5487#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5188#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5689#include "chrome/browser/permissions/attestation_permission_request.h"
jyasskinc993ce8d2016-03-31 00:38:3490#include "chrome/browser/permissions/permission_context_base.h"
Adam Langley85339f62018-02-12 22:03:5691#include "chrome/browser/permissions/permission_request_manager.h"
[email protected]0609b17f2011-05-31 20:13:4292#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1193#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4894#include "chrome/browser/plugins/plugin_utils.h"
Alexandr Ilin4909ec82018-06-06 10:22:4895#include "chrome/browser/predictors/loading_predictor.h"
96#include "chrome/browser/predictors/loading_predictor_factory.h"
[email protected]190e5e22013-07-27 05:59:2397#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4198#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5099#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:07100#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:01101#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:19102#include "chrome/browser/previews/previews_content_util.h"
Robert Ogdenafd250b2018-07-25 22:21:03103#include "chrome/browser/previews/previews_lite_page_decider.h"
Robert Ogdene7fdca92018-10-12 17:53:06104#include "chrome/browser/previews/previews_lite_page_navigation_throttle.h"
Ryan Sturmaf523742019-01-16 00:15:45105#include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h"
Ryan Sturmaa05092f2018-10-21 03:56:54106#include "chrome/browser/previews/previews_service.h"
107#include "chrome/browser/previews/previews_service_factory.h"
108#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03109#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14110#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32111#include "chrome/browser/profiles/profile_io_data.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06112#include "chrome/browser/profiles/renderer_updater.h"
113#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56114#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
115#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44116#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]05fcf982011-04-19 00:44:14117#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:38118#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40119#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45120#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31121#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
122#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Carlos IL4ee307e2018-12-22 03:19:00123#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40124#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35125#include "chrome/browser/safe_browsing/ui_manager.h"
126#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43127#include "chrome/browser/search/search.h"
Jay Civelli2578ebe2018-06-05 18:44:31128#include "chrome/browser/sessions/session_tab_helper.h"
Reilly Grantcc22e602018-09-07 15:25:20129#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35130#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath127ad2b2019-07-22 22:38:11131#include "chrome/browser/signin/header_modification_delegate_on_io_thread_impl.h"
132#include "chrome/browser/signin/header_modification_delegate_on_ui_thread_impl.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28133#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02134#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48135#include "chrome/browser/speech/tts_controller_delegate_impl.h"
[email protected]7a06d282013-05-03 04:39:33136#include "chrome/browser/speech/tts_message_filter.h"
Eric Lawrenced0acf2a7c2017-07-20 18:02:48137#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
[email protected]848dd042011-06-04 18:24:03138#include "chrome/browser/ssl/ssl_blocking_page.h"
estark3ba11132015-04-10 01:38:33139#include "chrome/browser/ssl/ssl_cert_reporter.h"
Joe DeBlasio9b996292019-01-31 05:09:32140#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07141#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35142#include "chrome/browser/ssl/ssl_error_handler.h"
Lucas Garron94b16052017-11-11 01:58:12143#include "chrome/browser/ssl/ssl_error_navigation_throttle.h"
Christopher Thompson4137cec2017-12-19 05:34:23144#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10145#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35146#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45147#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52148#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19149#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44150#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38151#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51152#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08153#include "chrome/browser/ui/browser_navigator.h"
154#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43155#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39156#include "chrome/browser/ui/login/login_handler.h"
Makoto Shimazuc7502932018-08-15 02:12:56157#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25158#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44159#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58160#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50161#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01162#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25163#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53164#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25165#include "chrome/browser/web_applications/components/app_registrar.h"
166#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23167#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22168#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01169#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51170#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14171#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22172#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30173#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02174#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50175#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34176#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37177#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12178#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12179#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22180#include "chrome/common/prerender_util.h"
[email protected]3e69bc82011-05-26 23:22:38181#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28182#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02183#include "chrome/common/secure_origin_whitelist.h"
wittman832321f52016-10-10 18:18:38184#include "chrome/common/stack_sampling_configuration.h"
[email protected]c5dbef02011-05-13 05:06:09185#include "chrome/common/url_constants.h"
benc70c0e32016-09-22 03:50:37186#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18187#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30188#include "chrome/installer/util/google_update_settings.h"
leon.han04b276e2016-06-01 01:34:16189#include "components/autofill/content/browser/content_autofill_driver_factory.h"
brettwf1958912015-10-07 19:43:12190#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53191#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44192#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04193#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48194#include "components/cloud_devices/common/cloud_devices_switches.h"
Tao Bai02ab4dd42019-03-06 00:30:37195#include "components/content_capture/browser/content_capture_receiver_manager.h"
mukai8eaec822014-10-25 17:53:16196#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09197#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16198#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52199#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45200#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08201#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03202#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09203#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Ryan Sturmaa05092f2018-10-21 03:56:54204#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall92335842018-10-10 16:49:09205#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28206#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43207#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09208#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32209#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03210#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24211#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43212#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01213#include "components/feature_engagement/public/feature_constants.h"
214#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39215#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20216#include "components/language/core/browser/pref_names.h"
wittmane16da2782016-09-21 16:43:04217#include "components/metrics/call_stack_profile_collector.h"
[email protected]8e885de2014-07-22 23:36:53218#include "components/metrics/client_info.h"
Xiangjun Zhang45474842018-08-17 21:07:59219#include "components/mirroring/mojom/constants.mojom.h"
220#include "components/mirroring/service/features.h"
Scott Violet9ae82892018-03-01 18:38:12221#include "components/nacl/common/buildflags.h"
sammc2b0375b2016-12-22 01:26:17222#include "components/nacl/common/nacl_constants.h"
drogerc690e8802015-09-21 14:29:16223#include "components/net_log/chrome_net_log.h"
leon.han97e8f752016-09-06 06:13:20224#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06225#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53226#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54227#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18228#include "components/policy/core/common/policy_service.h"
229#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26230#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54231#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08232#include "components/prefs/pref_service.h"
233#include "components/prefs/scoped_user_pref_update.h"
Ryan Sturmaa05092f2018-10-21 03:56:54234#include "components/previews/content/previews_decider_impl.h"
235#include "components/previews/content/previews_ui_service.h"
236#include "components/previews/content/previews_user_data.h"
237#include "components/previews/core/previews_decider.h"
238#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45239#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43240#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56241#include "components/rappor/public/rappor_utils.h"
nigeltao2f673762016-10-14 03:27:28242#include "components/rappor/rappor_recorder_impl.h"
nzolghadrd87a308d2016-12-07 15:45:56243#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35244#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
245#include "components/safe_browsing/browser/mojo_safe_browsing_impl.h"
246#include "components/safe_browsing/browser/url_checker_delegate.h"
Nico Weberbc5b06f2019-07-26 14:00:13247#include "components/safe_browsing/buildflags.h"
timvolodine89cf11712017-05-15 18:05:07248#include "components/safe_browsing/common/safe_browsing_prefs.h"
Tim Volodinee45938472017-09-21 10:08:22249#include "components/safe_browsing/db/database_manager.h"
Yuzhu Shencb3011f62018-02-08 02:51:50250#include "components/safe_browsing/features.h"
Jialiu Linbdbb81d2017-10-11 21:29:09251#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14252#include "components/security_interstitials/content/origin_policy_ui.h"
Alexander Woolfed183c512019-05-17 01:18:03253#include "components/services/quarantine/public/mojom/quarantine.mojom.h"
254#include "components/services/quarantine/quarantine_service.h"
Colin Blundell3517170e2019-07-11 08:16:34255#include "components/signin/public/base/signin_pref_names.h"
Scott Violetd7983c52018-03-03 00:24:41256#include "components/spellcheck/spellcheck_buildflags.h"
Ken Rockot7c6275b2019-08-02 20:00:23257#include "components/startup_metric_utils/browser/startup_metric_host_impl.h"
csharrisone985ebc2017-04-04 17:05:03258#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17259#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21260#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28261#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33262#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46263#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22264#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43265#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30266#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38267#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28268#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03269#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31270#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41271#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09272#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03273#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59274#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19275#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31276#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35277#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47278#include "content/public/browser/navigation_handle.h"
279#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11280#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50281#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30282#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33283#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05284#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34285#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48286#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27287#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13288#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08289#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19290#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21291#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23292#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43293#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18294#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56295#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40296#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18297#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58298#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57299#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23300#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44301#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31302#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05303#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56304#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43305#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59306#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48307#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30308#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28309#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04310#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31311#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44312#include "media/media_buildflags.h"
313#include "media/mojo/buildflags.h"
Jay Civelli2578ebe2018-06-05 18:44:31314#include "mojo/public/cpp/bindings/binding_set.h"
Shimi Zhang6b72d292019-07-12 20:52:42315#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Ken Rockot40a1df792019-05-08 22:15:52316#include "mojo/public/cpp/bindings/pending_receiver.h"
317#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot0adc1e42019-05-24 08:20:08318#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53319#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51320#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58321#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23322#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46323#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57324#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14325#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38326#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19327#include "printing/buildflags/buildflags.h"
Andrew Moylan8ed9d83c82019-01-29 20:23:52328#include "services/image_annotation/public/mojom/constants.mojom.h"
329#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37330#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50331#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50332#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13333#include "services/service_manager/embedder/switches.h"
erikchena9db3a72018-04-12 16:24:00334#include "services/service_manager/public/cpp/connector.h"
Ken Rockot543f5e32018-02-04 02:13:50335#include "services/service_manager/public/mojom/connector.mojom.h"
Tom Sepez15d4e5202017-09-27 23:59:05336#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34337#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03338#include "services/strings/grit/services_strings.h"
pilgrime92c5fcd2014-09-10 23:31:23339#include "storage/browser/fileapi/external_mount_points.h"
John Delaneyac24e572019-04-30 19:47:02340#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02341#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Julie Jeongeun Kimd3d00a12019-03-25 01:46:25342#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h"
Leon Hanc819dc62019-01-28 04:30:19343#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17344#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Eric Willigers3eeae17c2019-03-13 17:32:10345#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21346#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26347#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18348#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39349#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08350#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35351#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21352#include "ui/base/ui_base_switches.h"
353#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49354#include "ui/native_theme/caption_style.h"
355#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57356#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45357#include "url/gurl.h"
358#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26359
Ken Rockot69aade02019-01-23 21:19:51360#if BUILDFLAG(ENABLE_NACL)
361#include "components/nacl/loader/nacl_loader_manifest.h"
362#if defined(OS_WIN) && defined(ARCH_CPU_X86)
363#include "components/nacl/broker/nacl_broker_manifest.h"
364#endif
365#endif
366
[email protected]b48c9182011-10-26 18:03:30367#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20368#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38369#include "chrome/browser/chrome_browser_main_win.h"
Patrick Monettebb543942019-05-17 17:45:32370#include "chrome/browser/win/conflicts/module_database.h"
371#include "chrome/browser/win/conflicts/module_event_sink_impl.h"
Jerry Lina0de7ce2018-06-22 15:18:36372#include "chrome/install_static/install_util.h"
Ken Rockotfba9e742018-02-10 16:36:20373#include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h"
Ken Rockot7c168502019-05-30 07:58:46374#include "components/services/quarantine/public/cpp/quarantine_features_win.h"
[email protected]34f48682013-03-20 00:30:18375#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38376#elif defined(OS_MACOSX)
377#include "chrome/browser/chrome_browser_main_mac.h"
Guido Urdaneta1a2917432018-05-10 18:32:32378#include "services/audio/public/mojom/constants.mojom.h"
[email protected]b48c9182011-10-26 18:03:30379#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42380#include "ash/public/cpp/tablet_mode.h"
Miyoung Shin7e1b1b12019-08-02 12:23:50381#include "ash/public/mojom/constants.mojom.h"
Scott Violet47f00e52018-05-04 22:50:31382#include "chrome/browser/ash_service_registry.h"
hashimotoa53e7e82016-10-26 06:30:47383#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17384#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30385#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24386#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18387#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]07fe2752014-01-29 11:21:55388#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08389#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48390#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41391#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32392#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58393#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00394#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
395#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44396#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39397#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31398#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33399#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44400#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10401#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36402#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27403#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31404#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10405#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21406#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10407#include "chromeos/constants/chromeos_switches.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21408#include "chromeos/services/cellular_setup/cellular_setup_service.h"
409#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
410#include "chromeos/services/cellular_setup/public/mojom/constants.mojom.h"
Leo Zhang84ce09e92018-08-25 01:55:36411#include "chromeos/services/ime/public/mojom/constants.mojom.h"
Steven Bennetts0c565d5b2019-04-24 23:52:45412#include "chromeos/services/network_config/network_config_service.h"
413#include "chromeos/services/network_config/public/mojom/constants.mojom.h"
Ryan Hansberry9a08623c2018-06-14 21:28:05414#include "chromeos/services/secure_channel/public/mojom/constants.mojom.h"
415#include "chromeos/services/secure_channel/secure_channel_service.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11416#include "components/crash/content/app/breakpad_linux.h"
[email protected]4d390782014-08-15 09:22:58417#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50418#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26419#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30420#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09421#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35422#include "base/android/application_status_listener.h"
zqzhang93e959d12017-03-16 13:10:20423#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36424#include "chrome/browser/android/chrome_context_util.h"
425#include "chrome/browser/android/devtools_manager_delegate_android.h"
Dan Harrington964d48c2018-08-03 15:52:24426#include "chrome/browser/android/download/available_offline_content_provider.h"
Min Qin0ab0e162017-11-14 21:57:19427#include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h"
Scott Violetef765b92017-06-09 21:26:36428#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
429#include "chrome/browser/android/service_tab_launcher.h"
430#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42431#include "chrome/browser/android/tab_web_contents_delegate_android.h"
Scott Violetef765b92017-06-09 21:26:36432#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09433#include "chrome/browser/chrome_browser_main_android.h"
Dan Harrington954c8822019-01-09 18:40:48434#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07435#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38436#include "chrome/common/chrome_descriptors.h"
Xing Liu302e0652018-04-27 18:23:08437#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Joshua Peraza934e5592018-07-18 23:43:11438#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07439#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47440#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36441#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54442#include "services/service_manager/public/cpp/interface_provider.h"
Han Leonabbe7c902018-08-30 02:08:10443#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Julie Jeongeun Kimb6a0a1f2019-03-21 05:08:26444#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
agrieve05398f52015-06-24 18:59:00445#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36446#include "ui/base/ui_base_paths.h"
[email protected]b48c9182011-10-26 18:03:30447#elif defined(OS_POSIX)
448#include "chrome/browser/chrome_browser_main_posix.h"
449#endif
450
tmartinofb341882017-02-10 19:36:53451#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40452#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36453#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54454#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59455#include "chrome/browser/media/unified_autoplay_config.h"
mathpf709499d2017-01-09 20:48:36456#include "chrome/browser/payments/payment_request_factory.h"
Marc Treib7895941d2017-11-28 12:37:02457#include "chrome/browser/search/instant_service.h"
458#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46459#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51460#include "chrome/browser/ui/browser.h"
461#include "chrome/browser/ui/browser_finder.h"
462#include "chrome/browser/ui/browser_list.h"
463#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20464#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51465#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39466#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
467#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43468#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27469#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28470#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36471
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33472#if defined(OS_WIN) || defined(OS_MACOSX) || \
473 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52474#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
475#endif
476
[email protected]a220b5932013-09-21 03:47:44477#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02478#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02479#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13480#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02481#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13482#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43483#endif
[email protected]b80f68432011-05-02 17:22:30484
Maggie Caia2f03f52019-04-02 02:13:28485// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
486// single navigation throttle to display the intent picker on all platforms.
487#if !defined(OS_ANDROID)
488#if defined(OS_CHROMEOS)
489#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
490#else
491#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
492#endif
493#endif
494
[email protected]e8b6ca02013-07-10 18:00:51495#if defined(TOOLKIT_VIEWS)
496#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
497#endif
498
estaded3aa0e82016-02-17 22:55:21499#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22500#if defined(USE_X11)
501#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
502#else
estaded3aa0e82016-02-17 22:55:21503#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22504#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51505#endif
506
Mohsen Izadif1958f22019-01-18 20:29:31507#if defined(USE_OZONE)
508#include "ui/ozone/public/ozone_platform.h"
509#endif
510
[email protected]e8b6ca02013-07-10 18:00:51511#if defined(USE_X11)
512#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
513#endif
514
brettwab78fef2016-10-12 02:56:05515#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19516#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
517#endif
518
Nico Weberaf3b00b2017-09-11 17:58:17519#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55520#include "components/nacl/browser/nacl_browser.h"
521#include "components/nacl/browser/nacl_host_message_filter.h"
522#include "components/nacl/browser/nacl_process_host.h"
523#include "components/nacl/common/nacl_process_type.h"
524#include "components/nacl/common/nacl_switches.h"
525#endif
526
brettw00899e62016-11-12 02:10:17527#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05528#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20529#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27530#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23531#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32532#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51533#include "chrome/browser/extensions/user_script_listener.h"
534#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28535#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:53536#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Ken Rockot551f7482018-02-10 11:18:46537#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Ken Rockot2ad4db32018-02-10 16:24:10538#include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h"
fsamuel8dfa19a2015-05-05 01:00:39539#include "components/guest_view/browser/guest_view_base.h"
540#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25541#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31542#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35543#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32544#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12545#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57546#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48547#include "extensions/browser/guest_view/web_view/web_view_guest.h"
548#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
549#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31550#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27551#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28552#include "extensions/common/extension.h"
553#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13554#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28555#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33556#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28557#include "extensions/common/permissions/permissions_data.h"
558#include "extensions/common/permissions/socket_permission.h"
559#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34560#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25561
brettw4b461082016-11-19 18:55:16562#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55563#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27564#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39565#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55566#endif
567
bauerb8f9c37742017-03-30 15:04:12568#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
569#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
570#endif
571
thakis678822e2017-04-20 17:20:34572#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38573#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09574#endif
575
weilifabbf7572017-05-22 19:05:16576#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21577#include "chrome/browser/printing/printing_message_filter.h"
Miyoung Shin0f25ee5402019-07-19 01:26:14578#include "components/services/pdf_compositor/public/mojom/pdf_compositor.mojom.h"
weilifabbf7572017-05-22 19:05:16579#endif
Lei Zhanga2fa14c2018-05-15 00:05:21580
581#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
582 (BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
Ken Rockoted7f41b2018-02-10 16:19:10583#include "chrome/services/printing/public/mojom/constants.mojom.h"
Jay Civelli9237eac2017-09-21 16:10:21584#endif
weilifabbf7572017-05-22 19:05:16585
Xiaohan Wanga4e41842018-06-26 18:45:10586#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49587#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wanga4e41842018-06-26 18:45:10588#include "chrome/browser/media/platform_verification_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26589#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10590#include "chrome/browser/media/widevine_hardware_caps_win.h"
591#include "third_party/widevine/cdm/widevine_cdm_common.h"
592#endif
593#endif
594
xhwangdb24d602017-05-20 06:32:24595#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
xhwang116acb92017-04-03 18:27:20596#include "chrome/browser/media/android/cdm/media_drm_storage_factory.h"
597#endif
xhwangc86d76e42016-03-14 23:38:49598
xhwangdb24d602017-05-20 06:32:24599#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
Miyoung Shin25bb8c092019-08-03 00:56:57600#include "media/mojo/mojom/constants.mojom.h" // nogncheck
xhwangb1d65fd2016-10-19 20:55:52601#include "media/mojo/services/media_service_factory.h" // nogncheck
alokp6ecb2382016-01-27 00:40:00602#endif
603
mmenkedb2637ff2017-03-30 23:59:42604#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
605#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
606#endif
607
Nico Weberbc5b06f2019-07-26 14:00:13608#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35609#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
610#endif
611
Jian Lide7b43792018-06-01 23:22:13612#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54613#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13614#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
615#endif
616
Ken Rockot80b08e92018-08-15 04:22:02617#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
618#include "services/content/simple_browser/public/mojom/constants.mojom.h"
619#include "services/content/simple_browser/simple_browser_service.h"
620#endif
621
622#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
Ken Rockot99c5bc742018-07-12 15:36:56623#include "services/content/simple_browser/public/mojom/constants.mojom.h"
624#endif
625
Will Cassella40837ba2019-07-01 21:32:00626#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43627#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
628#endif
629
Ken Rockotc185b2a2019-08-01 22:19:48630#if BUILDFLAG(ENABLE_SPELLCHECK)
631#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
632#include "components/spellcheck/common/spellcheck.mojom.h"
633#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
634#include "chrome/browser/spellchecker/spell_check_panel_host_impl.h"
635#endif
636#endif
637
Michael Thiessen909ba032019-03-26 23:47:43638#if defined(BROWSER_MEDIA_CONTROLS_MENU)
639#include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h"
640#endif
641
Michael Thiessen07c444c2019-04-26 03:53:11642#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
643#include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h"
644#endif
645
[email protected]c7abd422012-09-25 00:20:08646using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39647using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31648using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13649using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59650using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00651using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02652using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11653using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07654using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33655using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13656using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05657using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38658using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39659
[email protected]0daaebfe2014-03-15 00:09:05660#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20661using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05662#endif
663
brettw00899e62016-11-12 02:10:17664#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28665using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27666using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28667using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28668using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27669#endif
670
brettw4b461082016-11-19 18:55:16671#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55672using plugins::ChromeContentBrowserClientPluginsPart;
673#endif
674
[email protected]c5dbef02011-05-13 05:06:09675namespace {
676
michaeln10e5fc352017-02-07 02:07:58677const storage::QuotaSettings* g_default_quota_settings;
678
brettw4b461082016-11-19 18:55:16679#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42680// TODO(teravest): Add renderer-side API-specific checking for these APIs so
681// that blanket permission isn't granted to all dev channel APIs for these.
682// http://crbug.com/386743
683const char* const kPredefinedAllowedDevChannelOrigins[] = {
684 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
685 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
686};
687
[email protected]9de4da52014-05-24 12:26:50688const char* const kPredefinedAllowedFileHandleOrigins[] = {
[email protected]10c39222013-11-13 20:09:25689 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
690 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
691};
692
[email protected]9de4da52014-05-24 12:26:50693const char* const kPredefinedAllowedSocketOrigins[] = {
Mike Frysingera9864c6a2017-12-18 22:12:31694 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
695 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
696 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
697 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
[email protected]99132682012-04-24 19:00:45698 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
699 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
700 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
701 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35702 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54703 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
704 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
705 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
706 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
707 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
708 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38709 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58710 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29711 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42712 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42713 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
714 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
715 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40716};
[email protected]93f72062013-05-29 20:29:40717#endif
[email protected]e461da2f2012-02-16 19:06:40718
Will Harrisc196ed942019-08-03 03:45:30719#if defined(OS_WIN) && !defined(COMPONENT_BUILD)
720// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
721// running on Windows 10 1511 and above. See
722// https://blogs.windows.com/blog/tag/code-integrity-guard/.
723const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harris6dd1f842019-08-05 21:01:33724 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harrisc196ed942019-08-03 03:45:30725#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD)
726
lazyboy5d5fede02016-03-10 04:10:14727enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53728 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14729 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53730
731 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14732 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53733
734 // An extension or app tried to load a resource of a different platform app in
735 // a tab.
736 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
737
738 // A non-app and non-extension page tried to load a platform app in a tab.
739 APP_LOADED_IN_TAB_SOURCE_OTHER,
740
lazyboy5d5fede02016-03-10 04:10:14741 APP_LOADED_IN_TAB_SOURCE_MAX
742};
743
Lei Zhang2cfceac2018-11-14 19:36:33744// Cached version of the locale so we can return the locale on the I/O
745// thread.
746std::string& GetIOThreadApplicationLocale() {
747 static base::NoDestructor<std::string> s;
748 return *s;
749}
750
[email protected]f8f93eb2012-09-25 03:06:24751// Returns a copy of the given url with its host set to given host and path set
752// to given path. Other parts of the url will be the same.
753GURL ReplaceURLHostAndPath(const GURL& url,
754 const std::string& host,
755 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05756 url::Replacements<char> replacements;
757 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
758 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24759 return url.ReplaceComponents(replacements);
760}
761
madfbd10852017-01-20 03:15:33762// Handles the rewriting of the new tab page URL based on group policy.
763bool HandleNewTabPageLocationOverride(
764 GURL* url,
765 content::BrowserContext* browser_context) {
766 if (!url->SchemeIs(content::kChromeUIScheme) ||
767 url->host() != chrome::kChromeUINewTabHost)
768 return false;
769
770 Profile* profile = Profile::FromBrowserContext(browser_context);
771 std::string ntp_location =
772 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
773 if (ntp_location.empty())
774 return false;
775
776 *url = GURL(ntp_location);
777 return true;
778}
779
Becca Hughesfe8c32c2018-03-21 13:36:56780#if !defined(OS_ANDROID)
781// Check if the current url is whitelisted based on a list of whitelisted urls.
782bool IsURLWhitelisted(const GURL& current_url,
783 const base::Value::ListStorage& whitelisted_urls) {
784 // Only check on HTTP and HTTPS pages.
785 if (!current_url.SchemeIsHTTPOrHTTPS())
786 return false;
787
788 for (auto const& value : whitelisted_urls) {
789 ContentSettingsPattern pattern =
790 ContentSettingsPattern::FromString(value.GetString());
791 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
792 continue;
793 if (pattern.Matches(current_url))
794 return true;
795 }
796
797 return false;
798}
799
800// Check if autoplay is allowed by policy configuration.
801bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
802 PrefService* prefs) {
803 DCHECK(prefs);
804
805 // Check if we have globally allowed autoplay by policy.
806 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
807 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
808 return true;
809 }
810
811 if (!contents)
812 return false;
813
814 // Check if the current URL matches a URL pattern on the whitelist.
815 const base::ListValue* autoplay_whitelist =
816 prefs->GetList(prefs::kAutoplayWhitelist);
817 return autoplay_whitelist &&
818 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
819 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
820}
821#endif
822
Joshua Perazaf890e4b2019-01-03 19:19:02823#if defined(OS_ANDROID)
824int GetCrashSignalFD(const base::CommandLine& command_line) {
825 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
826}
827#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03828breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
829 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02830 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52831 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02832 {
833 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31834 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03835 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50836 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02837 crash_handler->StartUploaderThread();
838 return crash_handler;
839 }
840}
841
avi3ef9ec9e2014-12-22 22:50:17842int GetCrashSignalFD(const base::CommandLine& command_line) {
[email protected]9de4da52014-05-24 12:26:50843 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39844 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31845 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02846 if (!crash_handler)
847 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18848 return crash_handler->GetDeathSignalSocket();
849 }
850
[email protected]a1733df2012-06-22 11:24:18851 std::string process_type =
852 command_line.GetSwitchValueASCII(switches::kProcessType);
853
[email protected]779dd282013-10-19 15:57:02854 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31855 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02856 if (!crash_handler)
857 crash_handler = CreateCrashHandlerHost(process_type);
858 return crash_handler->GetDeathSignalSocket();
859 }
[email protected]a1733df2012-06-22 11:24:18860
[email protected]779dd282013-10-19 15:57:02861 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31862 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02863 if (!crash_handler)
864 crash_handler = CreateCrashHandlerHost(process_type);
865 return crash_handler->GetDeathSignalSocket();
866 }
[email protected]a1733df2012-06-22 11:24:18867
[email protected]779dd282013-10-19 15:57:02868 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31869 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02870 if (!crash_handler)
871 crash_handler = CreateCrashHandlerHost(process_type);
872 return crash_handler->GetDeathSignalSocket();
873 }
[email protected]a1733df2012-06-22 11:24:18874
James Cook9207cc12017-10-19 17:08:39875 if (process_type == switches::kUtilityProcess) {
876 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
877 if (!crash_handler)
878 crash_handler = CreateCrashHandlerHost(process_type);
879 return crash_handler->GetDeathSignalSocket();
880 }
881
[email protected]a1733df2012-06-22 11:24:18882 return -1;
883}
Joshua Perazaf890e4b2019-01-03 19:19:02884#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18885
[email protected]eabbfb12013-04-05 23:28:35886void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52887 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33888 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35889}
890
estark3ba11132015-04-10 01:38:33891// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31892// SSLErrorHandler. Uses CertificateReportingService to send reports. The
893// service handles queueing and re-sending of failed reports. Each certificate
894// error creates a new instance of this class.
895class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33896 public:
meacerf43117a2016-12-27 21:02:31897 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12898 content::WebContents* web_contents)
899 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
900 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31901 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33902
903 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55904 void ReportInvalidCertificateChain(
905 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31906 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33907 }
908
909 private:
meacerf43117a2016-12-27 21:02:31910 CertificateReportingService* service_;
911
912 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33913};
914
bshe4f53ce42015-11-30 16:56:31915#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05916float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59917 static const float kMinFSM = 1.05f;
918 static const int kWidthForMinFSM = 320;
919 static const float kMaxFSM = 1.3f;
920 static const int kWidthForMaxFSM = 800;
921
boliu21c5afa2017-01-11 19:34:23922 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59923
924 if (minWidth <= kWidthForMinFSM)
925 return kMinFSM;
926 if (minWidth >= kWidthForMaxFSM)
927 return kMaxFSM;
928
929 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
930 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
931 (kWidthForMaxFSM - kWidthForMinFSM);
932 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
933}
zpengdb4a58e2017-01-10 17:40:32934
[email protected]916615b2013-09-11 18:19:44935#endif // defined(OS_ANDROID)
936
brettw00899e62016-11-12 02:10:17937#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53938
939AppLoadedInTabSource ClassifyAppLoadedInTabSource(
940 const GURL& opener_url,
941 const extensions::Extension* target_platform_app) {
942 if (opener_url.SchemeIs(extensions::kExtensionScheme)) {
943 if (opener_url.host_piece() == target_platform_app->id()) {
944 // This platform app was trying to window.open() one of its own URLs.
945 if (opener_url ==
946 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
947 // Source was the background page.
948 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
949 } else {
950 // Source was a different page inside the app.
951 return APP_LOADED_IN_TAB_SOURCE_APP;
952 }
953 }
954 // The forbidden app URL was being opened by a different app or extension.
955 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
956 }
957 // The forbidden app URL was being opened by a non-extension page (e.g. http).
958 return APP_LOADED_IN_TAB_SOURCE_OTHER;
959}
[email protected]9c7656382014-08-08 21:02:30960
Charles Harrison34f67862017-08-22 01:04:17961// Returns true if there is is an extension matching |url| in
962// |opener_render_process_id| with APIPermission::kBackground.
963//
964// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
965// hosted app, even though normal extensions just use the host.
966bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35967 extensions::ProcessMap* process_map,
968 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17969 const GURL& url,
csharrison95f01e922017-04-24 18:52:35970 int opener_render_process_id) {
971 // Note: includes web URLs that are part of an extension's web extent.
972 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17973 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35974 return extension &&
975 extension->permissions_data()->HasAPIPermission(
976 APIPermission::kBackground) &&
977 process_map->Contains(extension->id(), opener_render_process_id);
978}
Kevin Marshall32f99d7e2017-07-11 23:17:46979
980void InvokeCallbackOnThread(
981 scoped_refptr<base::SequencedTaskRunner> task_runner,
982 base::Callback<void(bool)> callback,
983 bool result) {
tzikdf81f142018-10-26 00:23:34984 task_runner->PostTask(FROM_HERE, base::BindOnce(std::move(callback), result));
Kevin Marshall32f99d7e2017-07-11 23:17:46985}
csharrison95f01e922017-04-24 18:52:35986#endif
987
John Abd-El-Malekd2377982018-01-08 22:23:12988chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
989 const base::Callback<content::WebContents*()>& wc_getter) {
990 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
991 auto* web_contents = wc_getter.Run();
992 if (!web_contents)
993 return nullptr;
994
995 return prerender::PrerenderContents::FromWebContents(web_contents);
996}
997
John Abd-El-Malek92bf3602019-07-31 02:25:48998void LaunchURL(const GURL& url,
999 const content::WebContents::Getter& web_contents_getter,
1000 ui::PageTransition page_transition,
1001 bool has_user_gesture) {
John Abd-El-Maleka67add82018-03-09 18:22:011002 // If there is no longer a WebContents, the request may have raced with tab
1003 // closing. Don't fire the external request. (It may have been a prerender.)
1004 content::WebContents* web_contents = web_contents_getter.Run();
1005 if (!web_contents)
1006 return;
1007
1008 // Do not launch external requests attached to unswapped prerenders.
1009 prerender::PrerenderContents* prerender_contents =
1010 prerender::PrerenderContents::FromWebContents(web_contents);
1011 if (prerender_contents) {
1012 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
1013 prerender::ReportPrerenderExternalURL();
1014 return;
1015 }
1016
Robbie McElrath1294d242019-05-31 20:46:221017 // Do not launch external requests for schemes that have a handler registered.
1018 ProtocolHandlerRegistry* protocol_handler_registry =
1019 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1020 web_contents->GetBrowserContext());
1021 if (protocol_handler_registry &&
1022 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1023 return;
1024
John Abd-El-Maleka67add82018-03-09 18:22:011025 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:011026 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:191027 PolicyBlacklistFactory::GetForBrowserContext(
1028 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:011029 if (service) {
1030 const policy::URLBlacklist::URLBlacklistState url_state =
1031 service->GetURLBlacklistState(url);
1032 is_whitelisted =
1033 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1034 }
1035
1036 // If the URL is in whitelist, we launch it without asking the user and
1037 // without any additional security checks. Since the URL is whitelisted,
1038 // we assume it can be executed.
1039 if (is_whitelisted) {
1040 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1041 } else {
1042 ExternalProtocolHandler::LaunchUrl(
1043 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1044 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
1045 has_user_gesture);
1046 }
1047}
1048
Yutaka Hirano968d6252018-12-04 05:09:311049std::string GetProduct() {
1050 return version_info::GetProductNameAndVersionForUserAgent();
1051}
1052
Lukasz Anforowicz60d1253d2019-05-08 16:31:371053void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1054 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1055 // For renderer and utility (e.g. NetworkService) processes the switch is the
1056 // only available source, so below the combined (pref/policy + cmdline)
1057 // allowlist of secure origins is injected into |cmdline| for these other
1058 // processes.
1059 std::vector<std::string> allowlist =
1060 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1061 if (!allowlist.empty()) {
1062 cmdline->AppendSwitchASCII(
1063 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1064 base::JoinString(allowlist, ","));
1065 }
1066}
1067
Will Harrisc196ed942019-08-03 03:45:301068#if defined(OS_WIN) && !defined(COMPONENT_BUILD)
1069// Returns the full path to |module_name|. Both dev builds (where |module_name|
1070// is in the current executable's directory) and proper installs (where
1071// |module_name| is in a versioned sub-directory of the current executable's
1072// directory) are supported. The identified file is not guaranteed to exist.
1073base::FilePath GetModulePath(base::StringPiece16 module_name) {
1074 base::FilePath exe_dir;
1075 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1076 DCHECK(has_path);
1077
1078 // Look for the module in a versioned sub-directory of the current
1079 // executable's directory and return the path if it can be read. This is the
1080 // expected location of modules for proper installs.
1081 const base::FilePath module_path =
1082 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1083 if (base::PathExists(module_path))
1084 return module_path;
1085
1086 // Otherwise, return the path to the module in the current executable's
1087 // directory. This is the expected location of modules for dev builds.
1088 return exe_dir.Append(module_name);
1089}
1090#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD)
1091
[email protected]9dbfff12011-07-01 19:37:071092} // namespace
[email protected]c5dbef02011-05-13 05:06:091093
Yutaka Hirano968d6252018-12-04 05:09:311094std::string GetUserAgent() {
1095 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1096 if (command_line->HasSwitch(switches::kUserAgent)) {
1097 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1098 if (net::HttpUtil::IsValidHeaderValue(ua))
1099 return ua;
1100 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1101 }
1102
John Delaneyac24e572019-04-30 19:47:021103 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1104 return content::GetFrozenUserAgent(
1105 command_line->HasSwitch(switches::kUseMobileUserAgent))
1106 .as_string();
1107 }
1108
Yutaka Hirano968d6252018-12-04 05:09:311109 std::string product = GetProduct();
1110#if defined(OS_ANDROID)
1111 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1112 product += " Mobile";
1113#endif
1114 return content::BuildUserAgentFromProduct(product);
1115}
1116
Mike West6e4cbb32019-02-13 09:40:171117blink::UserAgentMetadata GetUserAgentMetadata() {
1118 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171119 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301120 metadata.full_version = version_info::GetVersionNumber();
1121 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171122 metadata.platform = version_info::GetOSType();
1123
1124 // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces.
1125 metadata.architecture = "";
1126 metadata.model = "";
1127
1128 return metadata;
1129}
1130
Ran Jia96d43d42018-05-02 17:14:531131ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051132 StartupData* startup_data)
Wojciech Dzierżanowski45380802019-04-29 14:50:321133 : data_reduction_proxy_throttle_manager_(
1134 nullptr,
1135 base::OnTaskRunnerDeleter(nullptr)),
Jeremy Roman495db682019-07-12 16:03:241136 startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161137#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371138 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421139 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371140 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251141 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371142 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401143 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551144
1145 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401146#endif
[email protected]1deace22013-05-22 06:14:461147
Ahmed Fakhryd70bf37b2018-04-04 17:07:241148#if defined(OS_CHROMEOS)
1149 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1150#endif // defined(OS_CHROMEOS)
1151
brettw00899e62016-11-12 02:10:171152#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131153 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271154#endif
bena06f7d62017-04-04 20:48:521155
Sigurdur Asgeirsson70696672019-02-08 16:14:511156 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
Sigurdur Asgeirsson50945f92019-01-25 20:26:011157
bena06f7d62017-04-04 20:48:521158 gpu_binder_registry_.AddInterface(
Mike Wittman16fa5362018-09-04 17:27:301159 base::Bind(&metrics::CallStackProfileCollector::Create));
[email protected]e461da2f2012-02-16 19:06:401160}
1161
1162ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031163 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1164 delete extra_parts_[i];
1165 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401166}
1167
[email protected]bca18382012-06-25 19:15:231168// static
Chris Palmerac7d75642017-11-22 20:12:541169void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1170 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131171 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1172 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541173 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1174 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Chris Hamilton8206aad2018-07-18 01:00:031175 registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true);
Julian Pastarmovfac28002018-02-01 11:17:451176 registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies,
1177 false);
Chris Palmerac7d75642017-11-22 20:12:541178}
1179
1180// static
[email protected]37ca3fe02013-07-05 15:32:441181void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341182 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251183 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1184 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1185 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281186 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1187 // user policy in addition to the same named ones in Local State (which are
1188 // used for mapping the command-line flags).
1189 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1190 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571191 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401192 registry->RegisterDictionaryPref(
1193 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041194 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101195#if !defined(OS_ANDROID)
1196 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561197 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101198#endif
[email protected]bca18382012-06-25 19:15:231199}
1200
[email protected]eabbfb12013-04-05 23:28:351201// static
1202void ChromeContentBrowserClient::SetApplicationLocale(
1203 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481204 // The common case is that this function is called early in Chrome startup
1205 // before any threads are created or registered. When there are no threads,
1206 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001207 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331208 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481209 return;
1210 }
1211
1212 // Otherwise we're being called to change the locale. In this case set it on
1213 // the IO thread.
thestig00844cea2015-09-08 21:44:521214 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351215
Eric Seckler8652dcd52018-09-20 10:42:281216 base::PostTaskWithTraits(
1217 FROM_HERE, {BrowserThread::IO},
Scott Violet875789e2018-02-02 07:46:481218 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351219}
1220
Patrick Monette61dfef92019-05-30 23:06:271221std::unique_ptr<content::BrowserMainParts>
1222ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311223 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271224 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301225 // Construct the Main browser parts based on the OS type.
1226#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051227 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271228 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1229#elif defined(OS_MACOSX)
1230 main_parts =
1231 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1232#elif defined(OS_CHROMEOS)
1233 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1234 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261235#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271236 main_parts =
1237 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141238#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271239 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1240 startup_data_);
[email protected]b48c9182011-10-26 18:03:301241#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271242 main_parts =
1243 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041244#else
[email protected]b48c9182011-10-26 18:03:301245 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271246 main_parts =
1247 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301248#endif
1249
Xi Han9fd44002019-04-30 17:39:361250 bool add_profiles_extra_parts = true;
1251#if defined(OS_ANDROID)
1252 if (startup_data_->HasBuiltProfilePrefService())
1253 add_profiles_extra_parts = false;
1254#endif
1255 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271256 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031257
Xi Han9fd44002019-04-30 17:39:361258 // Construct additional browser parts. Stages are called in the order in
1259 // which they are added.
[email protected]c7480942011-11-08 19:18:271260#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221261#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1262#if defined(USE_X11)
1263 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1264#else
estaded3aa0e82016-02-17 22:55:211265 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221266#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211267#else
riajiang7d6ec5c2017-01-25 16:40:331268 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351269#endif
1270#endif
1271
1272#if defined(OS_CHROMEOS)
1273 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331274 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221275#endif
[email protected]dc04be7c2012-03-15 23:57:491276
[email protected]e8b6ca02013-07-10 18:00:511277#if defined(USE_X11)
1278 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241279#endif
1280
Sigurdur Asgeirsson54b72702019-04-12 14:18:541281 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001282
Albert J. Wong59d85acb2017-08-10 00:50:571283 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571284
Patrick Monette61dfef92019-05-30 23:06:271285 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041286
[email protected]50462bf02011-11-21 19:13:311287 return main_parts;
[email protected]f967b722011-09-07 00:58:041288}
1289
michaeln96f887e22015-04-13 23:58:311290void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091291 const base::Location& from_here,
michaeln96f887e22015-04-13 23:58:311292 const scoped_refptr<base::TaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211293 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121294 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291295
1296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1297 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311298}
1299
falkenb09d443f2016-04-07 12:36:121300bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1301 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1302}
1303
Gabriel Charettec8cca992017-08-10 18:21:491304void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1305 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1306}
1307
John Abd-El-Malek9d57f9c2019-02-20 18:50:041308bool ChromeContentBrowserClient::IsShuttingDown() {
1309 return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID;
1310}
1311
[email protected]e94bbcb2012-09-07 05:33:571312std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191313 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571314 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531315 std::string partition_id;
1316
1317 // The partition ID for webview guest processes is the string value of its
1318 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451319 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531320 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171321#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501322 // The partition ID for extensions with isolated storage is treated similarly
1323 // to the above.
1324 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1325 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1326 partition_id = site.spec();
1327#endif
[email protected]1bc28312012-11-08 08:31:531328
[email protected]056efdc2013-04-06 00:14:531329 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531330 return partition_id;
1331}
1332
1333bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1334 content::BrowserContext* browser_context,
1335 const std::string& partition_id) {
1336 // The default ID is empty and is always valid.
1337 if (partition_id.empty())
1338 return true;
1339
1340 return GURL(partition_id).is_valid();
1341}
1342
1343void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1344 content::BrowserContext* browser_context,
1345 const GURL& site,
[email protected]14acc642012-11-17 12:20:101346 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531347 std::string* partition_domain,
1348 std::string* partition_name,
1349 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101350 // Default to the browser-wide storage partition and override based on |site|
1351 // below.
1352 partition_domain->clear();
1353 partition_name->clear();
1354 *in_memory = false;
1355
brettw00899e62016-11-12 02:10:171356#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451357 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331358 site, partition_domain, partition_name, in_memory);
1359
1360 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101361 // If |can_be_default| is false, the caller is stating that the |site|
1362 // should be parsed as if it had isolated storage. In particular it is
1363 // important to NOT check ExtensionService for the is_storage_isolated()
1364 // attribute because this code path is run during Extension uninstall
1365 // to do cleanup after the Extension has already been unloaded from the
1366 // ExtensionService.
1367 bool is_isolated = !can_be_default;
1368 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341369 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1370 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101371 }
[email protected]1bc28312012-11-08 08:31:531372
[email protected]14acc642012-11-17 12:20:101373 if (is_isolated) {
1374 CHECK(site.has_host());
1375 // For extensions with isolated storage, the the host of the |site| is
1376 // the |partition_domain|. The |in_memory| and |partition_name| are only
1377 // used in guest schemes so they are cleared here.
1378 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531379 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101380 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531381 }
[email protected]1df3d972014-06-11 04:55:181382 success = true;
1383 }
1384#endif
1385
[email protected]14acc642012-11-17 12:20:101386 // Assert that if |can_be_default| is false, the code above must have found a
1387 // non-default partition. If this fails, the caller has a serious logic
1388 // error about which StoragePartition they expect to be in and it is not
1389 // safe to continue.
1390 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441391}
1392
[email protected]38b098f2012-03-14 21:11:571393content::WebContentsViewDelegate*
1394 ChromeContentBrowserClient::GetWebContentsViewDelegate(
1395 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101396 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321397}
1398
Bo Liu4ade6b1b22017-11-28 02:26:351399bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1400#if defined(OS_ANDROID)
1401 const base::android::ApplicationState app_state =
1402 base::android::ApplicationStatusListener::GetState();
1403 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1404 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1405 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1406#else
1407 return true;
1408#endif
1409}
1410
[email protected]6f2862742013-12-20 07:53:191411void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231412 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301413 int id = host->GetID();
1414 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
horo062ef5352017-03-29 08:16:071415 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
thakis678822e2017-04-20 17:20:341416#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491417 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061418#endif
Brett Wilson65f951c2016-11-03 22:06:121419#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401420 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031421#endif
[email protected]ba780c12013-10-01 17:07:061422 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
thestig397accd2015-04-04 00:03:041423 host->AddFilter(new TtsMessageFilter(host->GetBrowserContext()));
Darin Fisher8c84328c2019-07-23 02:50:001424
1425 WebRtcLoggingHandlerHost::AttachToRenderProcessHost(
1426 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021427
grunell086a4112017-03-02 09:23:041428 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1429 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021430 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121431 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021432 host->SetUserData(
1433 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091434 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021435 audio_debug_recordings_handler));
1436
Nico Weberaf3b00b2017-09-11 17:58:171437#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031438 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1439 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351440#endif
jeremyim364ac1182015-03-03 18:49:431441
Xiaohan Wang9b34281b2017-09-08 23:48:331442#if defined(OS_ANDROID)
1443 // Data cannot be persisted if the profile is off the record.
1444 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061445 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071446
1447 // Register CrashMemoryMetricsCollector to report oom related metrics.
1448 host->SetUserData(
1449 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1450 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331451#endif
1452
Jun Caidb3f93cc2018-07-09 21:54:551453 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061454 RendererUpdaterFactory::GetForProfile(original_profile)
1455 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071456
[email protected]a48ab7112014-08-01 16:48:031457 for (size_t i = 0; i < extra_parts_.size(); ++i)
1458 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141459}
1460
[email protected]3d7474ff2011-07-27 17:47:371461GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571462 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301463 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371464 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521465 if (!profile)
1466 return url;
1467
Marc Treib7d467b792017-12-04 13:31:031468#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291469 // If the input |url| should be assigned to the Instant renderer, make its
1470 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311471 // This needs to happen even if |url| corresponds to an isolated origin; see
1472 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131473 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1474 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031475#endif
[email protected]b3cb3a32013-07-31 01:32:291476
brettw00899e62016-11-12 02:10:171477#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301478 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1479 url);
[email protected]d5a74be2014-08-08 01:01:271480#else
1481 return url;
1482#endif
[email protected]36fb2c7c2011-04-04 15:49:081483}
1484
Alexander Yashkin6aedc6e2018-08-15 08:58:451485bool ChromeContentBrowserClient::
1486 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1487 content::BrowserContext* browser_context,
1488 content::SiteInstance* candidate_site_instance,
1489 bool is_main_frame,
1490 const GURL& candidate_url,
1491 const GURL& destination_url) {
1492 DCHECK(browser_context);
1493 DCHECK(candidate_site_instance);
1494#if BUILDFLAG(ENABLE_EXTENSIONS)
1495 return ChromeContentBrowserClientExtensionsPart::
1496 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1497 browser_context, candidate_site_instance, is_main_frame,
1498 candidate_url, destination_url);
1499#else
1500 return true;
1501#endif
1502}
1503
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521504bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411505#if defined(OS_ANDROID)
1506 return true;
1507#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421508 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411509#else
1510 return false;
1511#endif // defined(OS_ANDROID)
1512}
1513
[email protected]056ad2a2011-07-12 02:13:551514bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371515 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521516 Profile* profile = Profile::FromBrowserContext(browser_context);
1517 if (!profile)
1518 return false;
1519
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301520 // NTP should use process-per-site. This is a performance optimization to
1521 // reduce process count associated with NTP tabs.
1522 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1523 return true;
Marc Treib7d467b792017-12-04 13:31:031524#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131525 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521526 return true;
Marc Treib7d467b792017-12-04 13:31:031527#endif
[email protected]c5dec6292013-01-25 04:54:521528
brettw00899e62016-11-12 02:10:171529#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301530 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1531 profile, effective_url))
1532 return true;
[email protected]d5a74be2014-08-08 01:01:271533#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301534
1535 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1536 // (rather than process-per-site).
1537 return false;
[email protected]056ad2a2011-07-12 02:13:551538}
1539
Lukasz Anforowicz32d27122018-04-09 21:48:331540bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1541 content::BrowserContext* browser_context,
1542 const GURL& site_url) {
1543 Profile* profile = Profile::FromBrowserContext(browser_context);
1544 if (!profile)
1545 return false;
1546
1547#if !defined(OS_ANDROID)
1548 // Instant renderers should not use a spare process, because they require
1549 // passing switches::kInstantProcess to the renderer process when it
1550 // launches. A spare process is launched earlier, before it is known which
1551 // navigation will use it, so it lacks this flag.
1552 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1553 return false;
1554#endif
1555
1556#if BUILDFLAG(ENABLE_EXTENSIONS)
1557 return ChromeContentBrowserClientExtensionsPart::
1558 ShouldUseSpareRenderProcessHost(profile, site_url);
1559#else
1560 return true;
1561#endif
1562}
1563
nickcc0d9142015-10-14 16:27:101564bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421565 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101566 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421567 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171568#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101569 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421570 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101571 return true;
1572 }
1573#endif
1574 return false;
1575}
1576
nick7d0984c2015-08-29 00:13:461577// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1578// origin-lock enforcement, where we don't have a way to efficiently know
1579// effective URLs on the IO thread, and wind up killing processes that e.g.
1580// request cookies for their actual URL. This whole function (and its
1581// ExtensionsPart) should be removed once we add that ability to the IO thread.
1582bool ChromeContentBrowserClient::ShouldLockToOrigin(
1583 content::BrowserContext* browser_context,
1584 const GURL& effective_site_url) {
1585 // Origin lock to the search scheme would kill processes upon legitimate
1586 // requests for cookies from the search engine's domain.
1587 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1588 return false;
1589
brettw00899e62016-11-12 02:10:171590#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461591 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1592 browser_context, effective_site_url)) {
1593 return false;
1594 }
1595#endif
1596 return true;
creise5d6d1732015-08-25 19:47:061597}
1598
Lukasz Anforowicz05f356e2018-03-13 20:26:111599const char*
Lukasz Anforowiczce869f0b2018-08-06 18:33:371600ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() {
Charles Reis358baf472017-12-06 05:30:431601#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz05f356e2018-03-13 20:26:111602 // Don't block responses for extension processes or for content scripts.
1603 // TODO(creis): When every extension fetch (including content scripts) has
1604 // been made to go through an extension-specific URLLoaderFactory, this
1605 // mechanism ought to work by enumerating the host permissions from the
1606 // extension manifest, and forwarding them on to the network service while
1607 // brokering the URLLoaderFactory.
1608 return extensions::kExtensionScheme;
1609#else
1610 return nullptr;
Charles Reis358baf472017-12-06 05:30:431611#endif
Charles Reis358baf472017-12-06 05:30:431612}
1613
Maks Orlovich0e23e312019-07-16 13:13:561614bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
1615 base::StringPiece scheme) {
1616#if BUILDFLAG(ENABLE_EXTENSIONS)
1617 return scheme == extensions::kExtensionScheme;
1618#else
1619 return false;
1620#endif
1621}
1622
Lukasz Anforowicz2f810162018-10-03 21:38:071623network::mojom::URLLoaderFactoryPtrInfo
1624ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests(
1625 content::RenderProcessHost* process,
1626 network::mojom::NetworkContext* network_context,
Clark DuValla5e25b752018-11-27 22:08:161627 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Lukasz Anforowicz2f810162018-10-03 21:38:071628 const url::Origin& request_initiator) {
1629#if BUILDFLAG(ENABLE_EXTENSIONS)
1630 return ChromeContentBrowserClientExtensionsPart::
Clark DuValla5e25b752018-11-27 22:08:161631 CreateURLLoaderFactoryForNetworkRequests(
1632 process, network_context, header_client, request_initiator);
Lukasz Anforowicz2f810162018-10-03 21:38:071633#else
1634 return network::mojom::URLLoaderFactoryPtrInfo();
1635#endif
1636}
1637
[email protected]73b718f2014-01-27 02:59:461638// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1639// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411640void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1641 std::vector<std::string>* additional_schemes) {
1642 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241643 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351644 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061645}
1646
alexmos94875b3b2017-03-16 22:19:011647void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1648 std::vector<std::string>* additional_schemes) {
1649 GetAdditionalWebUISchemes(additional_schemes);
1650
1651#if BUILDFLAG(ENABLE_EXTENSIONS)
1652 additional_schemes->push_back(extensions::kExtensionScheme);
1653#endif
1654}
1655
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521656bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011657 return webui::LogWebUIUrl(web_ui_url);
1658}
1659
John Abd-El-Malek04bfa8532018-07-12 05:28:221660bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1661 const url::Origin& origin) {
1662 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1663 origin);
1664}
1665
[email protected]46fb9442011-12-09 17:57:471666bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1667 return ProfileIOData::IsHandledURL(url);
1668}
1669
[email protected]c4365fa42013-05-14 01:08:241670bool ChromeContentBrowserClient::CanCommitURL(
1671 content::RenderProcessHost* process_host,
1672 const GURL& url) {
brettw00899e62016-11-12 02:10:171673#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131674 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1675 process_host, url);
[email protected]d5a74be2014-08-08 01:01:271676#else
1677 return true;
1678#endif
[email protected]c4365fa42013-05-14 01:08:241679}
1680
[email protected]9a60d1602013-09-11 04:09:121681bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1682 content::SiteInstance* site_instance, const GURL& url) {
brettw00899e62016-11-12 02:10:171683#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131684 bool result;
1685 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
alexmos1c3da4f2016-11-03 06:06:111686 site_instance, url, &result))
[email protected]f7daaa32014-08-02 07:58:131687 return result;
[email protected]d5a74be2014-08-08 01:01:271688#endif
[email protected]879816a92014-04-29 00:53:541689
1690 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1691 // the signin page may host untrusted web content.
alexmos1c3da4f2016-11-03 06:06:111692 GURL from_url = site_instance->GetSiteURL();
[email protected]879816a92014-04-29 00:53:541693 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
1694 url.SchemeIs(content::kChromeUIScheme) &&
brettwb65cd5c2016-01-23 00:46:381695 url.host_piece() != chrome::kChromeUIChromeSigninHost) {
[email protected]879816a92014-04-29 00:53:541696 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
1697 << chrome::kChromeUIChromeSigninURL;
1698 return false;
1699 }
1700
[email protected]9a60d1602013-09-11 04:09:121701 return true;
1702}
1703
rdevlin.cronina32a0902016-11-09 15:50:201704void ChromeContentBrowserClient::OverrideNavigationParams(
1705 SiteInstance* site_instance,
1706 ui::PageTransition* transition,
1707 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581708 content::Referrer* referrer,
1709 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201710 DCHECK(transition);
1711 DCHECK(is_renderer_initiated);
1712 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471713 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1714 // use for making security decisions 99.44% of the time, for detecting the NTP
1715 // it is reliable and the correct way. See http://crbug.com/624410.
1716 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201717 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581718 // Clicks on tiles of the new tab page should be treated as if a user
1719 // clicked on a bookmark. This is consistent with native implementations
1720 // like Android's. This also helps ensure that security features (like
1721 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1722 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201723 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1724 *is_renderer_initiated = false;
1725 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581726 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421727 }
rdevlin.cronina32a0902016-11-09 15:50:201728
brettw00899e62016-11-12 02:10:171729#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.cronina32a0902016-11-09 15:50:201730 ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams(
Lukasz Anforowicz63f3b9432019-05-30 05:42:581731 site_instance, transition, is_renderer_initiated, referrer,
1732 initiator_origin);
rdevlin.cronina32a0902016-11-09 15:50:201733#endif
mastiza77db6992016-06-30 09:48:421734}
1735
Charles Reis29e9dd12017-09-28 00:59:151736bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1737 const GURL& url,
1738 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471739 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1740 // use for making security decisions 99.44% of the time, for detecting the NTP
1741 // it is reliable and the correct way. See http://crbug.com/624410.
1742 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1743 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151744}
1745
[email protected]2a5221b2011-09-27 23:07:311746bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301747 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311748 const GURL& site_url) {
1749 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301750 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521751 // This may be NULL during tests. In that case, just assume any site can
1752 // share any host.
1753 if (!profile)
1754 return true;
1755
Marc Treib7895941d2017-11-28 12:37:021756#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141757 // Instant URLs should only be in the instant process and instant process
1758 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521759 InstantService* instant_service =
1760 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141761 if (instant_service) {
1762 bool is_instant_process = instant_service->IsInstantProcess(
1763 process_host->GetID());
1764 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131765 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141766 if (is_instant_process || should_be_in_instant_process)
1767 return is_instant_process && should_be_in_instant_process;
1768 }
Marc Treib7895941d2017-11-28 12:37:021769#endif
[email protected]c5dec6292013-01-25 04:54:521770
brettw00899e62016-11-12 02:10:171771#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131772 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1773 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271774#else
1775 return true;
1776#endif
[email protected]2a5221b2011-09-27 23:07:311777}
1778
[email protected]28c5d0b72014-05-13 08:19:591779bool ChromeContentBrowserClient::MayReuseHost(
1780 content::RenderProcessHost* process_host) {
1781 // If there is currently a prerender in progress for the host provided,
1782 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041783 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591784 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371785 prerender::PrerenderManagerFactory::GetForBrowserContext(
1786 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591787 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491788 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591789 return false;
1790 }
1791
1792 return true;
1793}
1794
[email protected]76411f412012-02-22 18:56:061795bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1796 content::BrowserContext* browser_context, const GURL& url) {
1797 // It has to be a valid URL for us to check for an extension.
1798 if (!url.is_valid())
1799 return false;
1800
brettw00899e62016-11-12 02:10:171801#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061802 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131803 return ChromeContentBrowserClientExtensionsPart::
1804 ShouldTryToUseExistingProcessHost(
1805 profile, url);
[email protected]d5a74be2014-08-08 01:01:271806#else
1807 return false;
1808#endif
[email protected]76411f412012-02-22 18:56:061809}
1810
Alex Moshchuk9c9e3882018-11-02 19:57:031811bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1812 content::RenderFrameHost* main_frame) {
1813#if BUILDFLAG(ENABLE_EXTENSIONS)
1814 return ChromeContentBrowserClientExtensionsPart::
1815 ShouldSubframesTryToReuseExistingProcess(main_frame);
1816#else
1817 return true;
1818#endif
1819}
1820
[email protected]6f371442011-11-09 06:45:461821void ChromeContentBrowserClient::SiteInstanceGotProcess(
1822 SiteInstance* site_instance) {
1823 CHECK(site_instance->HasProcess());
1824
1825 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021826 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521827 if (!profile)
1828 return;
1829
Marc Treib7895941d2017-11-28 12:37:021830#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521831 // Remember the ID of the Instant process to signal the renderer process
1832 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131833 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1834 profile)) {
[email protected]c5dec6292013-01-25 04:54:521835 InstantService* instant_service =
1836 InstantServiceFactory::GetForProfile(profile);
1837 if (instant_service)
1838 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1839 }
Marc Treib7895941d2017-11-28 12:37:021840#endif
[email protected]c5dec6292013-01-25 04:54:521841
[email protected]a48ab7112014-08-01 16:48:031842 for (size_t i = 0; i < extra_parts_.size(); ++i)
1843 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461844}
1845
1846void ChromeContentBrowserClient::SiteInstanceDeleting(
1847 SiteInstance* site_instance) {
1848 if (!site_instance->HasProcess())
1849 return;
1850
[email protected]a48ab7112014-08-01 16:48:031851 for (size_t i = 0; i < extra_parts_.size(); ++i)
1852 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461853}
1854
[email protected]453f5432013-11-26 19:43:001855bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141856 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081857 const GURL& current_url,
1858 const GURL& new_url) {
brettw00899e62016-11-12 02:10:171859#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131860 return ChromeContentBrowserClientExtensionsPart::
1861 ShouldSwapBrowsingInstancesForNavigation(
1862 site_instance, current_url, new_url);
[email protected]d5a74be2014-08-08 01:01:271863#else
1864 return false;
1865#endif
[email protected]e3daf3c2011-10-05 21:17:081866}
1867
Nasko Oskovd83b5712018-05-04 04:50:571868bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1869 // TODO(nasko): Consider supporting error page isolation in subframes if
1870 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381871 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571872}
1873
[email protected]3d831992013-07-04 01:13:291874bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1875 return !url.SchemeIs(chrome::kChromeNativeScheme);
1876}
1877
Alex Moshchukd252c192017-07-17 22:03:481878std::vector<url::Origin>
1879ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1880 std::vector<url::Origin> isolated_origin_list;
1881
Alex Moshchuk89352a72017-10-25 20:25:591882// Sign-in process isolation is not needed on Android, see
1883// https://crbug.com/739418.
1884#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381885 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121886 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591887#endif
Alex Moshchukd252c192017-07-17 22:03:481888
Alex Moshchuk81d2a29e2019-07-16 01:14:381889#if BUILDFLAG(ENABLE_EXTENSIONS)
1890 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1891 GetOriginsRequiringDedicatedProcess();
1892 std::move(std::begin(origins_from_extensions),
1893 std::end(origins_from_extensions),
1894 std::back_inserter(isolated_origin_list));
1895#endif
1896
Alex Moshchukd252c192017-07-17 22:03:481897 return isolated_origin_list;
1898}
1899
Lukasz Anforowicz5e201abd2018-03-24 00:41:061900bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341901 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1902}
1903
1904bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Lukasz Anforowicz0711a0f2019-03-28 18:15:311905 // Using 1077 rather than 1024 because 1) it helps ensure that devices with
1906 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one
1907 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2.
1908 // See also https://crbug.com/844118.
1909 constexpr int kDefaultMemoryThresholdMb = 1077;
Aaron Colwell25617f72018-11-27 20:56:341910
1911 // TODO(acolwell): Rename feature since it now affects more than just the
1912 // site-per-process case.
Lukasz Anforowicz46275d92018-04-12 14:57:381913 if (base::FeatureList::IsEnabled(
1914 features::kSitePerProcessOnlyForHighMemoryClients)) {
Lukasz Anforowicz46275d92018-04-12 14:57:381915 int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
1916 features::kSitePerProcessOnlyForHighMemoryClients,
1917 features::kSitePerProcessOnlyForHighMemoryClientsParamName,
1918 kDefaultMemoryThresholdMb);
Aaron Colwell25617f72018-11-27 20:56:341919 return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb;
Lukasz Anforowicz46275d92018-04-12 14:57:381920 }
1921
Aaron Colwell25617f72018-11-27 20:56:341922#if defined(OS_ANDROID)
1923 if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) {
1924 return true;
1925 }
1926#endif
1927
1928 return false;
Lukasz Anforowicz5e201abd2018-03-24 00:41:061929}
1930
Alex Moshchuk082b5f82019-03-14 01:34:161931std::vector<std::string>
1932ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1933 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1934 return {"Isolate Password Sites"};
1935 else
1936 return {};
1937}
1938
Alex Moshchuke256d562019-04-26 21:43:571939void ChromeContentBrowserClient::PersistIsolatedOrigin(
1940 content::BrowserContext* context,
1941 const url::Origin& origin) {
1942 DCHECK(!context->IsOffTheRecord());
1943 Profile* profile = Profile::FromBrowserContext(context);
1944 ListPrefUpdate update(profile->GetPrefs(),
1945 prefs::kUserTriggeredIsolatedOrigins);
1946 base::ListValue* list = update.Get();
1947 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361948 if (!base::Contains(list->GetList(), value))
Alex Moshchuke256d562019-04-26 21:43:571949 list->GetList().push_back(std::move(value));
1950}
1951
Ken Rockot314714c2017-11-05 23:36:241952bool ChromeContentBrowserClient::IsFileAccessAllowed(
1953 const base::FilePath& path,
1954 const base::FilePath& absolute_path,
1955 const base::FilePath& profile_path) {
1956 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1957 profile_path);
1958}
1959
[email protected]d2e1a0a2014-06-16 15:49:371960namespace {
1961
1962bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171963 const base::CommandLine& browser_command_line =
1964 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351965 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371966 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351967 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371968 return false;
[email protected]9ef49b42014-08-07 16:44:241969 return true;
[email protected]d2e1a0a2014-06-16 15:49:371970}
1971
bmcquade5d2d9cf32015-06-19 17:42:281972void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1973 const base::CommandLine& browser_command_line,
1974 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521975 // List of field trials that modify the blink-settings command line flag. No
1976 // two field trials in the list should specify the same keys, otherwise one
1977 // field trial may overwrite another. See Source/core/frame/Settings.in in
1978 // Blink for the list of valid keys.
1979 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161980 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1981 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1982 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1983 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521984 };
1985
1986 std::vector<std::string> blink_settings;
1987 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1988 // Each blink-settings field trial should include a forcing_flag group,
1989 // to make sure that clients that specify the blink-settings flag on the
1990 // command line are excluded from the experiment groups. To make
1991 // sure we assign clients that specify this flag to the forcing_flag
1992 // group, we must call GetVariationParams for each field trial first
1993 // (for example, before checking HasSwitch() and returning), since
1994 // GetVariationParams has the side-effect of assigning the client to
1995 // a field trial group.
1996 std::map<std::string, std::string> params;
1997 if (variations::GetVariationParams(field_trial_name, &params)) {
1998 for (const auto& param : params) {
1999 blink_settings.push_back(base::StringPrintf(
2000 "%s=%s", param.first.c_str(), param.second.c_str()));
2001 }
2002 }
2003 }
pmeenan9ac669682015-08-17 14:57:032004
bmcquade9dd54cc2015-06-22 16:56:522005 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282006 return;
2007 }
2008
2009 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2010 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032011 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522012 // blink-settings flag into a group with no params, and we return
2013 // above if no params were specified, so it's an error if we reach
2014 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282015 LOG(WARNING) << "Received field trial params, "
2016 "but blink-settings switch already specified.";
2017 return;
2018 }
2019
bmcquade5d2d9cf32015-06-19 17:42:282020 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262021 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282022}
2023
zpengdb4a58e2017-01-10 17:40:322024#if defined(OS_ANDROID)
Ben Goodger6a695c012017-06-20 20:21:202025template <typename Interface>
2026void ForwardToJavaFrameRegistry(
Ben Goodger6a695c012017-06-20 20:21:202027 mojo::InterfaceRequest<Interface> request,
2028 content::RenderFrameHost* render_frame_host) {
2029 render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request));
mgiuca3d9a1962017-04-07 05:25:442030}
2031
Ben Goodger6a695c012017-06-20 20:21:202032template <typename Interface>
2033void ForwardToJavaWebContentsRegistry(
Ben Goodger6a695c012017-06-20 20:21:202034 mojo::InterfaceRequest<Interface> request,
2035 content::RenderFrameHost* render_frame_host) {
2036 content::WebContents* contents =
2037 content::WebContents::FromRenderFrameHost(render_frame_host);
2038 if (contents)
2039 contents->GetJavaInterfaces()->GetInterface(std::move(request));
sammc0285a442016-10-04 23:03:562040}
2041#endif
2042
[email protected]d2e1a0a2014-06-16 15:49:372043} // namespace
2044
[email protected]b80f68432011-05-02 17:22:302045void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172046 base::CommandLine* command_line,
2047 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062048#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352049 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062050 GoogleUpdateSettings::LoadMetricsClientInfo();
2051 if (client_info) {
2052 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2053 client_info->client_id);
2054 }
2055#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022056#if defined(OS_ANDROID)
2057 bool enable_crash_reporter = true;
2058#else
2059 bool enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2060#endif
2061 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512062 std::string switch_value;
dcheng4af48582016-04-19 00:29:352063 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532064 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512065 if (client_info)
2066 switch_value = client_info->client_id;
2067 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252068 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302069 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512070 switch_value);
[email protected]b80f68432011-05-02 17:22:302071 }
Mark Mentovaic67fa64f2015-03-24 14:00:062072#endif
[email protected]b80f68432011-05-02 17:22:302073
[email protected]f1933792011-06-14 00:49:342074 if (logging::DialogsAreSuppressed())
2075 command_line->AppendSwitch(switches::kNoErrorDialogs);
2076
[email protected]b80f68432011-05-02 17:22:302077 std::string process_type =
2078 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172079 const base::CommandLine& browser_command_line =
2080 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322081
[email protected]7c9b6f92013-09-10 18:11:352082 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:562083 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:352084 switches::kUserDataDir, // Make logs go to the right file.
2085 };
2086 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372087 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322088
fqj15ff3f72015-10-09 19:20:022089 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432090 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312091 };
fqj15ff3f72015-10-09 19:20:022092 command_line->CopySwitchesFrom(browser_command_line,
2093 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372094 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312095
fqj15ff3f72015-10-09 19:20:022096#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332097 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2098 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522099 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332100 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2101 homedir.value().c_str());
2102#endif
2103
[email protected]718eab62011-10-05 21:16:522104 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032105 content::RenderProcessHost* process =
2106 content::RenderProcessHost::FromID(child_process_id);
2107 Profile* profile =
2108 process ? Profile::FromBrowserContext(process->GetBrowserContext())
2109 : NULL;
2110 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2111 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(
2112 command_line, process, profile);
2113 }
2114
[email protected]b80f68432011-05-02 17:22:302115#if defined(OS_CHROMEOS)
2116 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:442117 browser_command_line.GetSwitchValueASCII(
2118 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302119 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:442120 command_line->AppendSwitchASCII(
2121 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:302122#endif
2123
[email protected]30335fdf02014-02-26 19:51:272124 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
2125 browser_command_line,
sdefresne9fb67692015-08-03 18:48:222126 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372127 if (process) {
[email protected]a8d851f82011-12-21 00:32:372128 PrefService* prefs = profile->GetPrefs();
2129 // Currently this pref is only registered if applied via a policy.
2130 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2131 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2132 // Turn this policy into a command line switch.
2133 command_line->AppendSwitch(switches::kDisable3DAPIs);
2134 }
[email protected]718eab62011-10-05 21:16:522135
[email protected]1733b782014-06-19 18:51:552136 const base::ListValue* switches =
2137 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2138 if (switches) {
2139 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112140 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552141 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142142 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552143 command_line->AppendSwitch(switch_to_enable);
2144 }
2145 }
2146
[email protected]a8d851f82011-12-21 00:32:372147 // Disable client-side phishing detection in the renderer if it is
2148 // disabled in the Profile preferences or the browser process.
2149 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2150 !g_browser_process->safe_browsing_detection_service()) {
2151 command_line->AppendSwitch(
2152 switches::kDisableClientSidePhishingDetection);
2153 }
[email protected]0045b0f42012-07-26 11:52:082154
vitalybukaa7ae5052014-09-26 04:11:132155 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2156 command_line->AppendSwitch(switches::kDisablePrintPreview);
2157
Marc Treib7895941d2017-11-28 12:37:022158#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522159 InstantService* instant_service =
2160 InstantServiceFactory::GetForProfile(profile);
2161 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542162 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522163 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542164 }
Marc Treib7895941d2017-11-28 12:37:022165#endif
fqjba8749c2015-10-29 15:33:072166
fqj38306f7b2015-11-02 16:59:062167 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542168 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432169 command_line->AppendSwitch(
2170 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542171 }
Daniel Vogelheim976f1c22017-11-22 16:26:032172
Lukasz Anforowicz60d1253d2019-05-08 16:31:372173 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2174
Amr Aboelkherb04cbf32019-04-29 15:17:102175 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2176 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292177 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102178 }
[email protected]47c7ec82012-01-18 03:29:212179 }
[email protected]4287a3d2011-06-13 23:56:512180
[email protected]d2e1a0a2014-06-16 15:49:372181 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352182 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042183
bmcquade5d2d9cf32015-06-19 17:42:282184 MaybeAppendBlinkSettingsSwitchForFieldTrial(
2185 browser_command_line, command_line);
2186
mdjonesa6b9e172016-09-23 16:24:302187#if defined(OS_ANDROID)
2188 // If the platform is Android, force the distillability service on.
2189 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2190#endif
2191
[email protected]47c7ec82012-01-18 03:29:212192 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512193 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192194 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412195 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302196#if defined(OS_CHROMEOS)
2197 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2198#endif
brettw00899e62016-11-12 02:10:172199#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512200 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272201 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172202 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512203 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272204 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172205 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172206 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282207#endif
estark4b003b332015-02-14 01:07:052208 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512209 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482210 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512211 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502212 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572213 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462214 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302215 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512216 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172217#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242218 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482219 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552220#endif
[email protected]ce304ce2013-02-22 21:54:452221 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172222#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592223 switches::kForcePNaClSubzero,
2224#endif
Marc Treibad33cf942017-08-24 11:19:002225 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512226 switches::kJavaScriptHarmony,
iclelland79237e92016-06-23 12:03:512227 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552228 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022229 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512230 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512231 switches::kPpapiFlashPath,
2232 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032233 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092234 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512235 };
2236
2237 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372238 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172239 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172240#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382241 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:512242 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:512243 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272244 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a612eb32014-03-31 22:09:172245 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382246 };
2247
2248 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372249 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282250#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372251 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132252 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512253 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512254 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502255 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172256#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242257 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582258 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592259 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412260 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552261#endif
[email protected]4287a3d2011-06-13 23:56:512262 switches::kPpapiFlashPath,
2263 switches::kPpapiFlashVersion,
2264 };
2265
2266 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372267 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112268 } else if (process_type == switches::kGpuProcess) {
2269 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2270 // because GPU is expected to be unreliable.
2271 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2272 !command_line->HasSwitch(switches::kDisableBreakpad))
2273 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302274 }
[email protected]6f08af82011-09-15 01:19:032275
Ian Barkley-Yeung550aae052019-07-11 00:11:112276#if defined(OS_CHROMEOS)
2277 if (breakpad::ShouldPassCrashLoopBefore(process_type)) {
2278 static const char* const kSwitchNames[] = {
2279 switches::kCrashLoopBefore,
2280 };
2281 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2282 base::size(kSwitchNames));
2283 }
2284#endif
2285
wittman832321f52016-10-10 18:18:382286 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
2287 process_type,
2288 command_line);
Andrew Comminos66057672019-05-01 00:03:342289
2290#if defined(OS_LINUX)
2291 // Processes may only query perf_event_open with the BPF sandbox disabled.
2292 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2293 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2294 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2295 }
2296#endif
[email protected]b80f68432011-05-02 17:22:302297}
2298
Scott Violet776edf82017-09-29 02:03:012299void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
2300 const service_manager::Identity& identity,
2301 base::CommandLine* command_line) {
Guido Urdaneta191635e2018-05-09 16:00:532302#if defined(OS_MACOSX)
Ken Rockot2f8c1dd22019-07-23 21:56:022303 // On Mac, the audio service requires a CFRunLoop, provided by a UI message
2304 // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581.
2305 if (identity.name() == audio::mojom::kServiceName)
Guido Urdaneta191635e2018-05-09 16:00:532306 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2307#endif
Scott Violet776edf82017-09-29 02:03:012308}
2309
[email protected]b80f68432011-05-02 17:22:302310std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432311 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332312 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302313 return g_browser_process->GetApplicationLocale();
2314}
2315
[email protected]597a867b2011-11-18 18:31:202316std::string ChromeContentBrowserClient::GetAcceptLangs(
2317 content::BrowserContext* context) {
2318 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202319 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082320}
2321
Dana Fried34d580002019-04-24 20:05:482322gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492323 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482324 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082325}
2326
bengre8a146f2016-03-10 01:20:222327bool ChromeContentBrowserClient::IsDataSaverEnabled(
2328 content::BrowserContext* browser_context) {
Robert Ogdenc995d4fe2019-03-25 19:18:372329 Profile* profile = Profile::FromBrowserContext(browser_context);
2330 return profile && data_reduction_proxy::DataReductionProxySettings::
2331 IsDataSaverEnabledByUser(profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222332}
2333
Kenichi Ishibashi46329872018-07-17 09:43:402334void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2335 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192336 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402337 DCHECK(browser_context);
2338 DCHECK(out_prefs);
2339 renderer_preferences_util::UpdateFromSystemSettings(
2340 out_prefs, Profile::FromBrowserContext(browser_context));
2341}
2342
Clark DuVall5690e742019-07-17 18:26:172343bool ChromeContentBrowserClient::AllowAppCache(
2344 const GURL& manifest_url,
2345 const GURL& first_party,
2346 content::BrowserContext* context) {
2347 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2348 return CookieSettingsFactory::GetForProfile(
2349 Profile::FromBrowserContext(context))
2350 ->IsCookieAccessAllowed(manifest_url, first_party);
2351}
2352
falken3dbc36e2014-10-10 16:48:072353bool ChromeContentBrowserClient::AllowServiceWorker(
2354 const GURL& scope,
2355 const GURL& first_party_url,
David Bertoni3b3597d82019-06-22 02:29:362356 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202357 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342358 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522359 DCHECK_CURRENTLY_ON(BrowserThread::IO);
rdevlin.croninf5863da2015-09-10 19:21:452360
brettw00899e62016-11-12 02:10:172361#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452362 // Check if this is an extension-related service worker, and, if so, if it's
2363 // allowed (this can return false if, e.g., the extension is disabled).
2364 // If it's not allowed, return immediately. We deliberately do *not* report
2365 // to the TabSpecificContentSettings, since the service worker is blocked
2366 // because of the extension, rather than because of the user's content
2367 // settings.
2368 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
David Bertoni3b3597d82019-06-22 02:29:362369 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452370 return false;
2371 }
2372#endif
2373
falken3dbc36e2014-10-10 16:48:072374 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202375
shimazuce8af88122016-10-06 23:49:212376 // Check if JavaScript is allowed.
2377 content_settings::SettingInfo info;
2378 std::unique_ptr<base::Value> value =
2379 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
2380 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2381 std::string(), &info);
2382 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2383 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2384
2385 // Check if cookies are allowed.
2386 bool allow_serviceworker =
falken71691402017-01-27 03:38:002387 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope,
2388 first_party_url);
falken4a22dce2015-04-30 08:25:202389 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242390 // Only post the task if this is for a specific tab.
2391 if (!wc_getter.is_null()) {
Eric Seckler8652dcd52018-09-20 10:42:282392 base::PostTaskWithTraits(
2393 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512394 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342395 std::move(wc_getter), scope, !allow_javascript,
tzik29ea5c72017-04-20 02:16:512396 !allow_serviceworker));
rdevlin.croninf5863da2015-09-10 19:21:452397 }
shimazuce8af88122016-10-06 23:49:212398 return allow_javascript && allow_serviceworker;
falken3dbc36e2014-10-10 16:48:072399}
2400
Jochen Eisinger0ff7645c2017-11-28 08:11:262401bool ChromeContentBrowserClient::AllowSharedWorker(
2402 const GURL& worker_url,
2403 const GURL& main_frame_url,
2404 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372405 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262406 content::BrowserContext* context,
2407 int render_process_id,
2408 int render_frame_id) {
2409 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2410
2411 // Check if cookies are allowed.
2412 bool allow =
2413 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
2414 ->IsCookieAccessAllowed(worker_url, main_frame_url);
2415
2416 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372417 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2418 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262419 return allow;
2420}
2421
Clark DuVallab63d142019-07-23 04:24:362422bool ChromeContentBrowserClient::AllowSignedExchange(
2423 content::BrowserContext* browser_context) {
2424 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2425 Profile* profile = Profile::FromBrowserContext(browser_context);
2426 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2427}
2428
[email protected]f917df22014-07-10 07:45:492429void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352430 const GURL& url,
[email protected]df02aca2012-02-09 21:03:202431 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172432 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492433 base::Callback<void(bool)> callback) {
thestig00844cea2015-09-08 21:44:522434 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202435 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092436 content_settings::CookieSettings* cookie_settings =
2437 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002438 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352439
brettw00899e62016-11-12 02:10:172440#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492441 GuestPermissionRequestHelper(url, render_frames, callback, allow);
2442#else
2443 FileSystemAccessed(url, render_frames, callback, allow);
2444#endif
2445}
2446
brettw00899e62016-11-12 02:10:172447#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492448void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2449 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172450 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492451 base::Callback<void(bool)> callback,
2452 bool allow) {
thestig00844cea2015-09-08 21:44:522453 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]f917df22014-07-10 07:45:492454 std::map<int, int> process_map;
2455 std::map<int, int>::const_iterator it;
2456 bool has_web_view_guest = false;
2457 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172458 for (const auto& it : render_frames) {
2459 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492460 continue;
2461
Lukasz Anforowicz09060bdf72018-08-23 15:53:172462 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492463
Lukasz Anforowicz09060bdf72018-08-23 15:53:172464 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492465 has_web_view_guest = true;
2466 }
2467 if (!has_web_view_guest) {
2468 FileSystemAccessed(url, render_frames, callback, allow);
2469 return;
2470 }
[email protected]dffb9fc2014-07-16 04:14:022471 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492472 it = process_map.begin();
Eric Seckler8652dcd52018-09-20 10:42:282473 base::PostTaskWithTraits(
2474 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512475 base::BindOnce(
2476 &ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread,
2477 it->first, it->second, url, allow,
Kevin Marshall32f99d7e2017-07-11 23:17:462478 base::Bind(
2479 &ChromeContentBrowserClient::FileSystemAccessed,
2480 weak_factory_.GetWeakPtr(), url, render_frames,
2481 base::Bind(&InvokeCallbackOnThread,
2482 base::SequencedTaskRunnerHandle::Get(), callback))));
[email protected]f917df22014-07-10 07:45:492483}
2484
2485void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
2486 int render_process_id,
2487 int render_frame_id,
2488 const GURL& url,
2489 bool allowed_by_default,
2490 const base::Callback<void(bool)>& callback) {
thestig00844cea2015-09-08 21:44:522491 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]140d6cd92014-08-12 18:26:462492 extensions::WebViewPermissionHelper* web_view_permission_helper =
2493 extensions::WebViewPermissionHelper::FromFrameID(
2494 render_process_id, render_frame_id);
[email protected]f917df22014-07-10 07:45:492495 web_view_permission_helper->RequestFileSystemPermission(url,
2496 allowed_by_default,
2497 callback);
2498}
2499#endif
2500
2501void ChromeContentBrowserClient::FileSystemAccessed(
2502 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172503 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492504 base::Callback<void(bool)> callback,
2505 bool allow) {
[email protected]62151052012-02-01 18:40:482506 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172507 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282508 base::PostTaskWithTraits(
2509 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512510 base::BindOnce(&TabSpecificContentSettings::FileSystemAccessed,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172511 it.child_id, it.frame_routing_id, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:352512 }
[email protected]f917df22014-07-10 07:45:492513 callback.Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352514}
2515
[email protected]7c5ff9a2012-03-02 07:42:492516bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2517 const GURL& url,
[email protected]7c5ff9a2012-03-02 07:42:492518 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172519 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
thestig00844cea2015-09-08 21:44:522520 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c5ff9a2012-03-02 07:42:492521 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092522 content_settings::CookieSettings* cookie_settings =
2523 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002524 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492525
2526 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172527 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282528 base::PostTaskWithTraits(
2529 FROM_HERE, {BrowserThread::UI},
Lukasz Anforowicz09060bdf72018-08-23 15:53:172530 base::BindOnce(&TabSpecificContentSettings::IndexedDBAccessed,
Joshua Bell7cdaafca2018-10-31 06:27:112531 it.child_id, it.frame_routing_id, url, !allow));
[email protected]7c5ff9a2012-03-02 07:42:492532 }
2533
2534 return allow;
2535}
2536
Ben Kelly6b2e61c2019-03-14 16:06:292537bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2538 const GURL& url,
2539 content::ResourceContext* context,
2540 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2541 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2542 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
2543 content_settings::CookieSettings* cookie_settings =
2544 io_data->GetCookieSettings();
2545 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2546
2547 // Record access to CacheStorage for potential display in UI.
2548 for (const auto& it : render_frames) {
2549 base::PostTaskWithTraits(
2550 FROM_HERE, {BrowserThread::UI},
2551 base::BindOnce(&TabSpecificContentSettings::CacheStorageAccessed,
2552 it.child_id, it.frame_routing_id, url, !allow));
2553 }
2554
2555 return allow;
2556}
2557
jyasskinc993ce8d2016-03-31 00:38:342558ChromeContentBrowserClient::AllowWebBluetoothResult
2559ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452560 content::BrowserContext* browser_context,
2561 const url::Origin& requesting_origin,
2562 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342563 // TODO(crbug.com/598890): Don't disable if
2564 // base::CommandLine::ForCurrentProcess()->
2565 // HasSwitch(switches::kEnableWebBluetooth) is true.
2566 if (variations::GetVariationParamValue(
2567 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2568 "Bluetooth") ==
2569 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2570 // The kill switch is enabled for this permission. Block requests.
2571 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2572 }
2573
jyasskin98bdd3992016-02-26 20:25:452574 const HostContentSettingsMap* const content_settings =
2575 HostContentSettingsMapFactory::GetForProfile(
2576 Profile::FromBrowserContext(browser_context));
2577
csharrisonaec2c542016-10-12 19:40:362578 if (content_settings->GetContentSetting(
2579 requesting_origin.GetURL(), embedding_origin.GetURL(),
2580 CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD,
2581 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342582 return AllowWebBluetoothResult::BLOCK_POLICY;
2583 }
2584 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452585}
2586
beaufort.francois01135bf2016-11-23 14:37:362587std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2588 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2589 "blocklist_additions");
scheib74250322016-04-07 03:32:212590}
2591
John Abd-El-Malek21bca7c2018-10-26 22:13:332592#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522593void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek21bca7c2018-10-26 22:13:332594 const std::string& username_hash) {
2595 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(username_hash);
2596}
2597#endif
2598
Reilly Grant19aaccd2018-07-16 22:06:372599scoped_refptr<network::SharedURLLoaderFactory>
2600ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2602 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2603
2604 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372605 return nullptr;
2606
Min Qinda0d55b2018-10-12 18:30:052607 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372608 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042609}
2610
Sean Gilhulyda1ee4b2018-11-13 21:56:092611network::mojom::NetworkContext*
2612ChromeContentBrowserClient::GetSystemNetworkContext() {
2613 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2614 DCHECK(g_browser_process->system_network_context_manager());
2615 return g_browser_process->system_network_context_manager()->GetContext();
2616}
2617
Andrew Moylan17329fc2017-09-25 07:43:302618std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2619 return google_apis::GetAPIKey();
2620}
2621
Ke He21ee87f2018-05-30 02:35:322622#if defined(OS_ANDROID)
2623bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2624 // Indicate that Chrome uses the GMS core location provider.
2625 return true;
2626}
2627#endif
2628
Yeolf3dc22ca2019-04-18 17:25:322629scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412630ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2631 return new ChromeQuotaPermissionContext();
2632}
2633
michaeln10e5fc352017-02-07 02:07:582634void ChromeContentBrowserClient::GetQuotaSettings(
2635 content::BrowserContext* context,
2636 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452637 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582638 if (g_default_quota_settings) {
2639 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452640 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582641 return;
2642 }
taptede6d878e2017-06-24 01:53:452643 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062644 partition->GetPath(), context->IsOffTheRecord(),
2645 storage::GetDefaultDiskInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512646}
2647
Mythri Alle0b8de0d2018-10-22 11:06:222648content::GeneratedCodeCacheSettings
2649ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2650 content::BrowserContext* context) {
2651 base::FilePath cache_path;
2652 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2653 // If we pass 0 for size, disk_cache will pick a default size using the
2654 // heuristics based on available disk size. These are implemented in
2655 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162656 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132657 DCHECK(g_browser_process);
2658 PrefService* local_state = g_browser_process->local_state();
2659 if (local_state) {
2660 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2661 base::FilePath disk_cache_dir =
2662 local_state->GetFilePath(prefs::kDiskCacheDir);
2663 if (!disk_cache_dir.empty())
2664 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2665 }
Mythri Ab2486572019-06-13 14:48:162666 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222667}
2668
[email protected]848dd042011-06-04 18:24:032669void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262670 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172671 int cert_error,
2672 const net::SSLInfo& ssl_info,
2673 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232674 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222675 bool strict_enforcement,
estark719dde52016-08-09 03:14:272676 const base::Callback<void(content::CertificateRequestResultType)>&
2677 callback) {
clamy0d32d6d2015-11-24 11:16:262678 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232679 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142680 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022681 // have a context for making the right decision, so block the
2682 // request hard, without an info bar to allow showing the insecure
2683 // content.
estark719dde52016-08-09 03:14:272684 if (!callback.is_null())
2685 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022686 return;
2687 }
2688
[email protected]f9034cf2011-07-21 12:43:412689 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572690 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262691 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572692 if (prerender_contents) {
2693 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272694 if (!callback.is_null()) {
2695 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
2696 }
[email protected]09667f02014-01-06 15:37:572697 return;
[email protected]f9034cf2011-07-21 12:43:412698 }
2699
Carlos IL5a9e7512019-06-13 22:35:282700 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2701 return;
[email protected]848dd042011-06-04 18:24:032702}
2703
Alexander Hendrichbcf2616e2018-05-18 08:21:102704namespace {
2705
Pavol Markob211ab22019-01-23 20:03:042706certificate_matching::CertificatePrincipalPattern
2707ParseCertificatePrincipalPattern(const base::Value* pattern) {
2708 return certificate_matching::CertificatePrincipalPattern::
2709 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2710}
2711
Alexander Hendrichbcf2616e2018-05-18 08:21:102712// Attempts to auto-select a client certificate according to the value of
2713// |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for
2714// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2715std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2716 Profile* profile,
2717 const GURL& requesting_url,
2718 net::ClientCertIdentityList& client_certs) {
2719 HostContentSettingsMap* host_content_settings_map =
2720 HostContentSettingsMapFactory::GetForProfile(profile);
2721 std::unique_ptr<base::Value> setting =
2722 host_content_settings_map->GetWebsiteSetting(
2723 requesting_url, requesting_url,
2724 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL);
2725
Pavol Markob211ab22019-01-23 20:03:042726 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102727 return nullptr;
2728
Alexander Hendrichbcf2616e2018-05-18 08:21:102729 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042730 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2731 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102732 // |setting_dict| has the wrong format (e.g. single filter instead of a
2733 // list of filters). This content setting is only provided by
2734 // the |PolicyProvider|, which should always set it to a valid format.
2735 // Therefore, delete the invalid value.
2736 host_content_settings_map->SetWebsiteSettingDefaultScope(
2737 requesting_url, requesting_url,
2738 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042739 return nullptr;
2740 }
2741
2742 for (const base::Value& filter : filters->GetList()) {
2743 DCHECK(filter.is_dict());
2744
2745 auto issuer_pattern = ParseCertificatePrincipalPattern(
2746 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2747 auto subject_pattern = ParseCertificatePrincipalPattern(
2748 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2749 // Use the first certificate that is matched by the filter.
2750 for (auto& client_cert : client_certs) {
2751 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2752 subject_pattern.Matches(client_cert->certificate()->subject())) {
2753 return std::move(client_cert);
2754 }
2755 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102756 }
2757
2758 return nullptr;
2759}
2760
Eric Romana00cf682018-11-01 20:09:112761void AddDataReductionProxyBinding(
2762 content::ResourceContext* resource_context,
2763 data_reduction_proxy::mojom::DataReductionProxyRequest request) {
2764 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2765 auto* io_data = ProfileIOData::FromResourceContext(resource_context);
2766 if (io_data && io_data->data_reduction_proxy_io_data()) {
2767 io_data->data_reduction_proxy_io_data()->Clone(std::move(request));
2768 }
2769}
2770
Alexander Hendrichbcf2616e2018-05-18 08:21:102771} // namespace
2772
Daniel McArdle85735f52019-06-25 03:27:062773base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192774 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402775 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082776 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352777 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022778 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192779 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022780 if (prerender_contents) {
2781 prerender_contents->Destroy(
2782 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062783 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452784 }
2785
[email protected]791879c2013-12-17 07:22:412786 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2787 DCHECK(requesting_url.is_valid())
2788 << "Invalid URL string: https://"
2789 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452790
Pavol Marko230ea2c92017-12-03 22:35:442791 bool may_show_cert_selection = true;
2792
davidben3b8455ae72015-03-11 19:42:192793 Profile* profile =
2794 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442795#if defined(OS_CHROMEOS)
2796 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2797 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2798 // and remove the command-line flag after prototype phase when the
2799 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2800 may_show_cert_selection =
2801 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2802
2803 content::StoragePartition* storage_partition =
2804 content::BrowserContext::GetStoragePartition(
2805 profile, web_contents->GetSiteInstance());
2806 chromeos::login::SigninPartitionManager* signin_partition_manager =
2807 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2808 profile);
2809
2810 // On the sign-in profile, only allow client certs in the context of the
2811 // sign-in frame.
2812 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2813 storage_partition)) {
2814 LOG(WARNING)
2815 << "Client cert requested in sign-in profile in wrong context.";
2816 // Continue without client certificate. We do this to mimic the case of no
2817 // client certificate being present in the profile's certificate store.
2818 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062819 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442820 }
2821 VLOG(1) << "Client cert requested in sign-in profile.";
2822 }
2823#endif // defined(OS_CHROMEOS)
2824
Alexander Hendrichbcf2616e2018-05-18 08:21:102825 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2826 AutoSelectCertificate(profile, requesting_url, client_certs);
2827 if (auto_selected_identity) {
2828 // The callback will own |auto_selected_identity| and |delegate|, keeping
2829 // them alive until after ContinueWithCertificate is called.
2830 scoped_refptr<net::X509Certificate> cert =
2831 auto_selected_identity->certificate();
2832 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2833 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582834 base::BindOnce(
2835 &content::ClientCertificateDelegate::ContinueWithCertificate,
2836 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322837 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062838 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452839 }
2840
Pavol Marko230ea2c92017-12-03 22:35:442841 if (!may_show_cert_selection) {
2842 LOG(WARNING) << "No client cert matched by policy and user selection is "
2843 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322844 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442845 // Continue without client certificate. We do this to mimic the case of no
2846 // client certificate being present in the profile's certificate store.
2847 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062848 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442849 }
2850
Daniel McArdle85735f52019-06-25 03:27:062851 return chrome::ShowSSLClientCertificateSelector(
2852 web_contents, cert_request_info, std::move(client_certs),
2853 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452854}
2855
[email protected]dc73a7b2012-03-25 15:27:182856content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562857 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182858}
2859
peterc26c6c62014-12-10 14:13:592860content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022861ChromeContentBrowserClient::GetPlatformNotificationService(
2862 content::BrowserContext* browser_context) {
2863 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2864 Profile* profile = Profile::FromBrowserContext(browser_context);
2865 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042866}
2867
[email protected]9f3fba52011-06-08 20:37:192868bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352869 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352870 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572871 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352872 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032873 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232874 const GURL& target_url,
2875 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212876 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232877 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482878 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232879 bool user_gesture,
2880 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012881 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352882 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2883 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012884
csharrison95f01e922017-04-24 18:52:352885 content::WebContents* web_contents =
2886 content::WebContents::FromRenderFrameHost(opener);
2887 Profile* profile =
2888 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2889 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012890 *no_javascript_access = false;
2891
[email protected]9f3fba52011-06-08 20:37:192892 // If the opener is trying to create a background window but doesn't have
2893 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032894 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172895#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352896 auto* process_map = extensions::ProcessMap::Get(profile);
2897 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172898 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2899 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012900 return false;
2901 }
2902
[email protected]7b54ca02012-03-02 18:06:532903 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2904 // return a recently installed Extension even if this CanCreateWindow call
2905 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012906 // because the permission check above would have caused an early return
2907 // already. We must use the full URL to find hosted apps, though, and not
2908 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552909 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352910 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292911 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012912 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022913#endif
[email protected]190e5e22013-07-27 05:59:232914
2915 return true;
[email protected]9f3fba52011-06-08 20:37:192916 }
[email protected]056efdc2013-04-06 00:14:532917
brettw00899e62016-11-12 02:10:172918#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462919 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352920 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232921 return true;
lazyboy04b75d32016-02-25 03:12:182922 }
2923
nick0fbc3922016-12-16 20:52:072924 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352925 // Intentionally duplicating |registry| code from above because we want to
2926 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2927 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182928 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352929 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142930 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532931 UMA_HISTOGRAM_ENUMERATION(
2932 "Extensions.AppLoadedInTab",
2933 ClassifyAppLoadedInTabSource(opener_url, extension),
2934 APP_LOADED_IN_TAB_SOURCE_MAX);
2935
2936 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162937 return false;
lazyboy5d5fede02016-03-10 04:10:142938 }
lazyboy04b75d32016-02-25 03:12:182939 }
[email protected]5940b0d2014-07-01 00:18:262940#endif
[email protected]190e5e22013-07-27 05:59:232941
Charles Harrisonaf2acd02017-08-18 22:46:022942#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232943 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352944 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582945 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2946 content_settings, opener_top_level_frame_url, target_url,
2947 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352948 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2949 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582950 return false;
2951 }
2952#endif
2953
Charles Harrisonaf2acd02017-08-18 22:46:022954 // Don't let prerenders open popups.
2955 if (auto* prerender_contents =
2956 prerender::PrerenderContents::FromWebContents(web_contents)) {
2957 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2958 return false;
2959 }
2960
Nasko Oskove9f19782019-01-04 18:32:352961 BlockedWindowParams blocked_params(target_url, source_origin, referrer,
2962 frame_name, disposition, features,
2963 user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132964 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Charlie Harrison804659a2018-10-16 16:43:382965 if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params,
2966 nullptr /*=open_url_params*/,
2967 blocked_params.features())) {
Charles Harrisonaf2acd02017-08-18 22:46:022968 return false;
[email protected]916615b2013-09-11 18:19:442969 }
[email protected]190e5e22013-07-27 05:59:232970
zpengdb4a58e2017-01-10 17:40:322971#if defined(OS_ANDROID)
csharrison95f01e922017-04-24 18:52:352972 auto* single_tab_mode_helper =
2973 SingleTabModeTabHelper::FromWebContents(web_contents);
Bo Liu3d5b8d692017-12-14 22:42:032974 if (single_tab_mode_helper &&
2975 single_tab_mode_helper->block_all_new_windows()) {
Jinsuk Kim6f9253c2019-03-11 02:45:072976 TabModelList::HandlePopupNavigation(&nav_params);
[email protected]190e5e22013-07-27 05:59:232977 return false;
2978 }
[email protected]916615b2013-09-11 18:19:442979#endif
[email protected]190e5e22013-07-27 05:59:232980
[email protected]9f3fba52011-06-08 20:37:192981 return true;
2982}
2983
[email protected]c52b2892012-03-07 11:01:022984content::SpeechRecognitionManagerDelegate*
zorkb548de082014-11-14 21:40:472985 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002986 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:512987}
2988
Katie D840d9532018-11-27 06:20:482989content::TtsControllerDelegate*
2990ChromeContentBrowserClient::GetTtsControllerDelegate() {
2991 TtsControllerDelegateImpl* delegate =
2992 TtsControllerDelegateImpl::GetInstance();
2993#if !defined(OS_ANDROID)
2994 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
2995 delegate->SetTtsEngineDelegate(tts_extension_engine);
2996#endif
2997 return delegate;
2998}
2999
Katie D4713ee42018-11-30 01:48:273000content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3001#ifdef OS_CHROMEOS
3002 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273003#else
3004 return nullptr;
3005#endif
3006}
3007
Evan Liu7cdbf8872019-06-19 16:47:213008base::Optional<ui::CaptionStyle> GetCaptionStyleFromPrefs(PrefService* prefs) {
3009 if (!prefs) {
3010 return base::nullopt;
3011 }
3012
3013 ui::CaptionStyle style;
3014
3015 style.text_size = prefs->GetString(prefs::kAccessibilityCaptionsTextSize);
3016 style.font_family = prefs->GetString(prefs::kAccessibilityCaptionsTextFont);
Evan Liuf248d402019-06-26 22:57:103017 if (!prefs->GetString(prefs::kAccessibilityCaptionsTextColor).empty()) {
3018 style.text_color = base::StringPrintf(
3019 "rgba(%s,%s)",
3020 prefs->GetString(prefs::kAccessibilityCaptionsTextColor).c_str(),
3021 base::NumberToString(
3022 prefs->GetInteger(prefs::kAccessibilityCaptionsTextOpacity) / 100.0)
3023 .c_str());
3024 }
3025
3026 if (!prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).empty()) {
3027 style.background_color = base::StringPrintf(
3028 "rgba(%s,%s)",
3029 prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).c_str(),
3030 base::NumberToString(
3031 prefs->GetInteger(prefs::kAccessibilityCaptionsBackgroundOpacity) /
3032 100.0)
3033 .c_str());
3034 }
3035
Evan Liu7cdbf8872019-06-19 16:47:213036 style.text_shadow = prefs->GetString(prefs::kAccessibilityCaptionsTextShadow);
3037
3038 return style;
3039}
3040
[email protected]64d69de42012-02-06 00:19:543041void ChromeContentBrowserClient::OverrideWebkitPrefs(
creis7b2d3d12015-02-12 23:29:503042 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:063043 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:583044 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063045 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063046
aelias0df335a2017-03-02 23:43:513047// Fill font preferences. These are not registered on Android
3048// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453049#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193050 FontFamilyCache::FillFontFamilyMap(profile,
3051 prefs::kWebKitStandardFontFamilyMap,
3052 &web_prefs->standard_font_family_map);
3053 FontFamilyCache::FillFontFamilyMap(profile,
3054 prefs::kWebKitFixedFontFamilyMap,
3055 &web_prefs->fixed_font_family_map);
3056 FontFamilyCache::FillFontFamilyMap(profile,
3057 prefs::kWebKitSerifFontFamilyMap,
3058 &web_prefs->serif_font_family_map);
3059 FontFamilyCache::FillFontFamilyMap(profile,
3060 prefs::kWebKitSansSerifFontFamilyMap,
3061 &web_prefs->sans_serif_font_family_map);
3062 FontFamilyCache::FillFontFamilyMap(profile,
3063 prefs::kWebKitCursiveFontFamilyMap,
3064 &web_prefs->cursive_font_family_map);
3065 FontFamilyCache::FillFontFamilyMap(profile,
3066 prefs::kWebKitFantasyFontFamilyMap,
3067 &web_prefs->fantasy_font_family_map);
3068 FontFamilyCache::FillFontFamilyMap(profile,
3069 prefs::kWebKitPictographFontFamilyMap,
3070 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063071
[email protected]64d69de42012-02-06 00:19:543072 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403073 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543074 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403075 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543076 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403077 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543078 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403079 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513080#endif
[email protected]f3986f82012-01-03 20:00:063081
[email protected]ddf72142012-05-22 04:52:403082 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063083
[email protected]64d69de42012-02-06 00:19:543084 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063085 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213086 web_prefs->javascript_can_access_clipboard =
3087 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543088 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063089
[email protected]ddf72142012-05-22 04:52:403090 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543091 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573092
Avi Drissman1aa6cb92019-01-23 15:58:383093 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543094 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573095
[email protected]ddf72142012-05-22 04:52:403096 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543097 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543098 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403099 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063100
Zhenyao Moa3fda9972017-09-16 01:34:403101 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3102 web_prefs->webgl1_enabled = false;
3103 web_prefs->webgl2_enabled = false;
3104 }
[email protected]f3986f82012-01-03 20:00:063105
[email protected]64d69de42012-02-06 00:19:543106 web_prefs->allow_running_insecure_content =
3107 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323108#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053109 web_prefs->font_scale_factor =
3110 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3111 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323112 web_prefs->force_enable_zoom =
3113 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493114#endif
Becky Zhoubbfbde32019-02-20 17:07:593115 web_prefs->force_dark_mode_enabled =
3116 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393117
[email protected]af4256d52013-06-04 20:39:073118#if defined(OS_ANDROID)
3119 web_prefs->password_echo_enabled =
3120 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3121#else
[email protected]9d06d88d2012-02-23 22:37:083122 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073123#endif
3124
[email protected]64d69de42012-02-06 00:19:543125 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063126 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543127 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063128 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3129
brettw00899e62016-11-12 02:10:173130#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053131 std::string image_animation_policy =
3132 prefs->GetString(prefs::kAnimationPolicy);
3133 if (image_animation_policy == kAnimationPolicyOnce)
3134 web_prefs->animation_policy =
3135 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3136 else if (image_animation_policy == kAnimationPolicyNone)
3137 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3138 else
3139 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3140#endif
3141
[email protected]f3986f82012-01-03 20:00:063142 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153143 web_prefs->default_encoding =
3144 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543145 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403146 prefs->ClearPref(prefs::kDefaultCharset);
3147 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063148 }
[email protected]64d69de42012-02-06 00:19:543149 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063150
mkwst05544102015-01-10 20:26:163151 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3152 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073153 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163154 web_prefs->strict_mixed_content_checking = true;
3155 web_prefs->strict_powerful_feature_restrictions = true;
3156 }
3157
Robert Ogdencf2872d2019-03-19 18:59:373158 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213159
Tarun Bansal333819e2018-05-15 16:38:423160 web_prefs->data_saver_holdback_web_api_enabled =
3161 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3162 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423163
Jinsuk Kima3d393ce2019-05-27 00:57:423164 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133165 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533166#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423167 auto* delegate = TabAndroid::FromWebContents(contents)
3168 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3169 contents->GetDelegate())
3170 : nullptr;
3171 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133172 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423173 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133174
Mounir Lamouri9c99a1602018-07-05 15:01:443175 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423176 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383177
3178 web_prefs->preferred_color_scheme =
Jinsuk Kima3d393ce2019-05-27 00:57:423179 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3180 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113181 }
Ian Vollick6243dfe02018-03-08 01:08:533182#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533183
Mounir Lamouri6926107f2019-01-31 18:17:433184 // web_app_scope value is platform specific.
3185#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423186 if (delegate)
3187 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433188#elif BUILDFLAG(ENABLE_EXTENSIONS)
3189 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253190 web_prefs->web_app_scope = GURL();
3191 // Set |web_app_scope| based on the app associated with the app window if
3192 // any. Note that the app associated with the window never changes, even
3193 // if the app navigates off scope. This is not a problem because we still
3194 // want to use the scope of the app associated with the window, not the
3195 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433196 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233197 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443198 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273199 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443200 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253201 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053202 // for profiles that support them, so we should always be able to
3203 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253204 //
3205 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123206 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253207 web_prefs->web_app_scope =
3208 web_app::WebAppProvider::Get(profile)
3209 ->registrar()
Alan Cutterf25cfe42019-07-16 02:40:123210 .GetAppScope(*browser->app_controller()->GetAppId())
3211 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433212 }
Mounir Lamouri6926107f2019-01-31 18:17:433213 }
3214#endif
3215
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533216#if BUILDFLAG(ENABLE_EXTENSIONS)
3217 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443218 if (browser && browser->app_controller() &&
3219 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533220 web_prefs->strict_mixed_content_checking = true;
3221 }
3222#endif
3223
Ian Vollick6243dfe02018-03-08 01:08:533224 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113225 }
zqzhang93e959d12017-03-16 13:10:203226
Ian Vollick6243dfe02018-03-08 01:08:533227#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143228 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113229#endif // defined(OS_ANDROID)
3230
Tarun Bansal73d67f02018-01-17 05:56:253231 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3232 // Obtain the maximum effective connection type at which the feature is
3233 // enabled.
3234 std::string effective_connection_type_param =
3235 base::GetFieldTrialParamValueByFeature(
3236 features::kLowPriorityIframes,
3237 "max_effective_connection_type_threshold");
3238
3239 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3240 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3241 if (effective_connection_type) {
3242 web_prefs->low_priority_iframes_threshold =
3243 effective_connection_type.value();
3244 }
3245 }
3246
rajendrant0521cee2019-07-29 06:09:263247 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3248 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003249
Scott Little878f7d6702018-05-31 22:09:063250 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3251 const char* param_name =
3252 web_prefs->data_saver_enabled
3253 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3254 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3255 "saver_enabled";
3256
3257 base::StringPairs pairs;
3258 base::SplitStringIntoKeyValuePairs(
3259 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3260 param_name),
3261 ':', ',', &pairs);
3262
3263 for (const auto& pair : pairs) {
3264 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3265 net::GetEffectiveConnectionTypeForName(pair.first);
3266 int value = 0;
3267 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3268 web_prefs->lazy_frame_loading_distance_thresholds_px
3269 [effective_connection_type.value()] = value;
3270 }
3271 }
3272 }
3273
rajendrantd8026342018-08-29 08:08:393274 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3275 const char* param_name =
3276 web_prefs->data_saver_enabled
3277 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3278 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3279 "saver_enabled";
3280
3281 base::StringPairs pairs;
3282 base::SplitStringIntoKeyValuePairs(
3283 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3284 param_name),
3285 ':', ',', &pairs);
3286
3287 for (const auto& pair : pairs) {
3288 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3289 net::GetEffectiveConnectionTypeForName(pair.first);
3290 int value = 0;
3291 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3292 web_prefs->lazy_image_loading_distance_thresholds_px
3293 [effective_connection_type.value()] = value;
3294 }
3295 }
3296 }
3297
Tarun Bansald10f17a02018-09-13 00:23:173298 if (base::FeatureList::IsEnabled(
3299 features::kNetworkQualityEstimatorWebHoldback)) {
3300 std::string effective_connection_type_param =
3301 base::GetFieldTrialParamValueByFeature(
3302 features::kNetworkQualityEstimatorWebHoldback,
3303 "web_effective_connection_type_override");
3304
3305 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3306 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3307 DCHECK(effective_connection_type_param.empty() ||
3308 effective_connection_type);
3309 if (effective_connection_type) {
3310 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3311 effective_connection_type.value());
3312 web_prefs->network_quality_estimator_web_holdback =
3313 effective_connection_type.value();
3314 }
3315 }
3316
Dan Beamf0a7e112019-06-07 18:40:583317 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103318#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563319 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593320 // If autoplay is allowed by policy then force the no user gesture required
3321 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103322 web_prefs->autoplay_policy =
3323 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553324 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593325 web_prefs->autoplay_policy ==
3326 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553327 // If the autoplay disable settings feature is enabled and the autoplay
3328 // policy is set to using the unified policy then set the default autoplay
3329 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593330 web_prefs->autoplay_policy =
3331 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3332 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3333 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103334 }
Alison Maher67fd4d9f2019-07-12 18:34:213335#if !defined(OS_MACOSX)
3336 // Mac has a concept of high contrast that does not relate to forced colors.
Alison Maherbe15c072019-07-08 18:12:393337 web_prefs->forced_colors = native_theme->UsesHighContrastColors()
3338 ? blink::ForcedColors::kActive
3339 : blink::ForcedColors::kNone;
Alison Maher67fd4d9f2019-07-12 18:34:213340#endif // !defined(OS_MACOSX)
3341
3342 switch (native_theme->GetPreferredColorScheme()) {
3343 case ui::NativeTheme::PreferredColorScheme::kDark:
3344 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3345 break;
3346 case ui::NativeTheme::PreferredColorScheme::kLight:
3347 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3348 break;
3349 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3350 web_prefs->preferred_color_scheme =
3351 blink::PreferredColorScheme::kNoPreference;
3352 }
François Beaufort4f8107d2018-03-05 12:12:103353#endif // !defined(OS_ANDROID)
3354
Dave Tapuskac6627e12018-08-30 15:07:193355 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493356
Dan Beam836c02a2019-06-15 01:58:273357 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3358 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3359 // explicitly uses light (instead of not dark), which is why we don't reset
3360 // back to no-preference. https://crbug.com/965811
3361 if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3362 bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme);
3363#if BUILDFLAG(ENABLE_EXTENSIONS)
3364 if (!force_light) {
3365 force_light =
3366 contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
3367 contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
3368 }
3369#endif
3370 if (force_light)
3371 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
Dan Beamf0a7e112019-06-07 18:40:583372 }
3373
Elly Fong-Jonesf92897392019-01-24 16:05:493374 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213375 base::Optional<ui::CaptionStyle> style;
3376
3377 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3378 ::switches::kForceCaptionStyle)) {
3379 style = ui::CaptionStyle::FromSpec(
3380 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3381 switches::kForceCaptionStyle));
3382 }
3383
3384 // Apply system caption style.
3385 if (!style) {
3386 style = native_theme->GetSystemCaptionStyle();
3387 }
3388
3389 // Apply caption style from preferences if system caption style is undefined.
3390 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
3391 style = GetCaptionStyleFromPrefs(prefs);
3392 }
3393
3394 if (style) {
3395 web_prefs->text_track_background_color = style->background_color;
3396 web_prefs->text_track_text_color = style->text_color;
3397 web_prefs->text_track_text_size = style->text_size;
3398 web_prefs->text_track_text_shadow = style->text_shadow;
3399 web_prefs->text_track_font_family = style->font_family;
3400 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563401 web_prefs->text_track_window_color = style->window_color;
3402 web_prefs->text_track_window_padding = style->window_padding;
3403 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213404 }
Elly Fong-Jonesf92897392019-01-24 16:05:493405
[email protected]a48ab7112014-08-01 16:48:033406 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503407 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363408}
3409
[email protected]b8148ac2011-07-13 22:03:253410void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3411 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033412 for (size_t i = 0; i < extra_parts_.size(); ++i)
3413 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253414
[email protected]b3adbd02011-11-30 22:23:273415 // about: handler. Must come before chrome: handler, since it will
3416 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053417 // actually handle them. Also relies on a preliminary fixup phase.
3418 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253419 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3420 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033421
madfbd10852017-01-20 03:15:333422 // The group policy NTP URL handler must be registered before the other NTP
3423 // URL handlers below.
3424 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3425 BrowserURLHandler::null_handler());
3426
zpengdb4a58e2017-01-10 17:40:323427#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033428 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353429 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033430 BrowserURLHandler::null_handler());
3431#else
[email protected]231dba22013-07-25 23:53:033432 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133433 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3434 &search::HandleNewTabURLReverseRewrite);
[email protected]4bd78e92014-03-28 18:54:033435#endif
[email protected]231dba22013-07-25 23:53:033436
[email protected]b8148ac2011-07-13 22:03:253437 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313438 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3439 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063440
3441 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3442 // the user.
3443 handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite,
3444 &HandlePreviewsLitePageURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253445}
3446
[email protected]650b2d52013-02-10 03:41:453447base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493448 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323449}
3450
[email protected]c9b6eb62011-10-18 20:49:393451std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3452 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3453}
3454
Dominik Röttsches47347832019-03-12 17:45:013455base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3456 base::FilePath user_data_dir;
3457 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3458 DCHECK(!user_data_dir.empty());
3459 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3460}
3461
jmadill57b52d42015-08-21 18:16:133462base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3463 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523464 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133465 DCHECK(!user_data_dir.empty());
3466 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3467}
3468
Khushal7ca0b782018-07-20 05:53:273469base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3470 base::FilePath user_data_dir;
3471 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3472 DCHECK(!user_data_dir.empty());
3473 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3474}
3475
[email protected]b7631cc2012-09-15 05:08:383476void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3477 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163478#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553479 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543480#endif
[email protected]b7631cc2012-09-15 05:08:383481}
3482
[email protected]0c7193742012-11-07 19:05:033483content::BrowserPpapiHost*
3484 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
3485 int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173486#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553487 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033488 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:023489 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
3490 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:033491 if (host->process() &&
3492 host->process()->GetData().id == plugin_process_id) {
3493 // Found the plugin.
3494 return host->browser_ppapi_host();
3495 }
3496 ++iter;
3497 }
[email protected]a56f8322014-07-16 21:13:553498#endif
[email protected]0c7193742012-11-07 19:05:033499 return NULL;
3500}
3501
[email protected]38cd8f7f2012-06-15 22:06:073502bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583503 content::BrowserContext* browser_context,
3504 const GURL& url,
[email protected]dda54822013-06-15 01:26:393505 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123506 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163507#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553508 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3509 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403510#else
[email protected]a658d452012-03-02 12:45:293511 return false;
[email protected]93f72062013-05-29 20:29:403512#endif
[email protected]e461da2f2012-02-16 19:06:403513}
3514
adrian.belgund54465ba2016-05-18 10:03:583515bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3516 content::BrowserContext* browser_context,
3517 const GURL& url) {
brettw4b461082016-11-19 18:55:163518#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583519 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3520 browser_context, url);
3521#else
3522 return false;
3523#endif
3524}
3525
adrian.belgun5b341c72016-06-22 22:24:083526std::unique_ptr<content::VpnServiceProxy>
3527ChromeContentBrowserClient::GetVpnServiceProxy(
3528 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173529#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083530 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3531 browser_context);
3532#else
3533 return nullptr;
3534#endif
3535}
3536
Brett Wilson804e83c2017-08-18 22:57:333537std::unique_ptr<ui::SelectFilePolicy>
3538ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3539 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433540}
3541
[email protected]7d9424702013-04-14 13:14:163542void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3543 std::vector<std::string>* additional_allowed_schemes) {
3544 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3545 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483546 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293547 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033548 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3549 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3550 additional_allowed_schemes);
3551 }
[email protected]7d9424702013-04-14 13:14:163552}
3553
falkenad185092016-06-16 06:10:023554void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3555 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043556 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023557}
3558
[email protected]c79859b82014-03-20 22:43:553559void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313560 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033561 for (size_t i = 0; i < extra_parts_.size(); ++i)
3562 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553563}
3564
nzolghadrd87a308d2016-12-07 15:45:563565::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3566 return g_browser_process->rappor_service();
3567}
3568
[email protected]f19bbf62013-07-09 01:22:323569void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313570 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533571 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003572 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3573 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313574#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313575 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313576 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313577 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093578 auto backend = std::make_unique<chromeos::FileSystemBackend>(
3579 std::make_unique<drive::FileSystemBackendDelegate>(),
3580 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3581 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473582 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093583 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3584 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053585 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3586 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473587 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323588 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313589 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003590 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313591#endif
[email protected]445b7db2013-08-02 04:58:273592
[email protected]a48ab7112014-08-01 16:48:033593 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3594 extra_parts_[i]->GetAdditionalFileSystemBackends(
3595 browser_context, storage_partition_path, additional_backends);
3596 }
[email protected]02250952013-04-24 23:52:533597}
3598
jcivellie6f550742017-01-06 19:29:123599#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183600void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173601 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383602 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203603 PosixFileDescriptorInfo* mappings) {
Albert J. Wongb6942532017-07-13 22:49:303604
jcivellie6f550742017-01-06 19:29:123605#if defined(OS_ANDROID)
3606 base::MemoryMappedFile::Region region;
3607 int fd = ui::GetMainAndroidPackFd(&region);
3608 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003609
jcivellie6f550742017-01-06 19:29:123610 fd = ui::GetCommonResourcesPackFd(&region);
3611 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393612
jcivellie6f550742017-01-06 19:29:123613 fd = ui::GetLocalePackFd(&region);
3614 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383615
zpeng368afac82017-07-17 18:47:453616 // Optional secondary locale .pak file.
3617 fd = ui::GetSecondaryLocalePackFd(&region);
3618 if (fd != -1) {
3619 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3620 }
3621
[email protected]09560f7f2014-06-10 18:40:283622 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523623 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283624 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023625#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383626 int crash_signal_fd = GetCrashSignalFD(command_line);
3627 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133628 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383629 }
jcivellie6f550742017-01-06 19:29:123630}
3631#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303632
[email protected]4a65826d2011-08-25 16:04:013633#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033634base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:523635 int sandbox_type) {
wfh182da09c2015-06-24 19:23:033636 // TODO(wfh): Add support for more process types here. crbug.com/499523
3637 switch (sandbox_type) {
Tom Sepez15d4e5202017-09-27 23:59:053638 case service_manager::SANDBOX_TYPE_RENDERER:
Jerry Lina0de7ce2018-06-22 15:18:363639 return base::string16(install_static::GetSandboxSidPrefix()) +
3640 L"129201922";
Tom Sepez15d4e5202017-09-27 23:59:053641 case service_manager::SANDBOX_TYPE_UTILITY:
wfh182da09c2015-06-24 19:23:033642 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053643 case service_manager::SANDBOX_TYPE_GPU:
wfh182da09c2015-06-24 19:23:033644 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053645 case service_manager::SANDBOX_TYPE_PPAPI:
Jerry Lina0de7ce2018-06-22 15:18:363646 return base::string16(install_static::GetSandboxSidPrefix()) +
3647 L"129201925";
Nico Weberaf3b00b2017-09-11 17:58:173648#if BUILDFLAG(ENABLE_NACL)
wfh182da09c2015-06-24 19:23:033649 case PROCESS_TYPE_NACL_LOADER:
3650 return base::string16();
3651 case PROCESS_TYPE_NACL_BROKER:
3652 return base::string16();
3653#endif
3654 }
3655
3656 // Should never reach here.
3657 CHECK(0);
3658 return base::string16();
3659}
3660
rickyz50109312015-11-11 00:37:083661bool ChromeContentBrowserClient::PreSpawnRenderer(
3662 sandbox::TargetPolicy* policy) {
[email protected]34f48682013-03-20 00:30:183663 // Allow the server side of a pipe restricted to the "chrome.nacl."
3664 // namespace so that it cannot impersonate other system or other chrome
Will Harrisc196ed942019-08-03 03:45:303665 // service pipes. This is also done in nacl_broker_listener.cc.
3666 sandbox::ResultCode result =
3667 policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
3668 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
3669 L"\\\\.\\pipe\\chrome.nacl.*");
rickyz50109312015-11-11 00:37:083670 if (result != sandbox::SBOX_ALL_OK)
3671 return false;
Will Harrisc196ed942019-08-03 03:45:303672
3673#if !defined(COMPONENT_BUILD)
3674 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3675 return true;
3676
3677 // Only enable signing mitigation if launching from chrome.exe.
3678 base::FilePath exe_path;
3679 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3680 return true;
3681 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3682 return true;
3683
3684 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3685 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
3686 result = policy->SetProcessMitigations(mitigations);
3687 if (result != sandbox::SBOX_ALL_OK)
3688 return false;
3689
3690 // Allow loading Chrome's DLLs. The name of this depends on whether
3691 // is_multi_dll_chrome is defined or not. For multi-DLL Chrome,
3692 // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the
3693 // same DLL as the browser process.
3694#if defined(CHROME_MULTIPLE_DLL_BROWSER)
3695 constexpr auto* child_dll_path = chrome::kChildDll;
3696#else
3697 constexpr auto* child_dll_path = chrome::kBrowserResourcesDll;
3698#endif
3699 for (const auto* dll : {child_dll_path, chrome::kElfDll}) {
3700 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3701 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3702 GetModulePath(dll).value().c_str());
3703 if (result != sandbox::SBOX_ALL_OK)
3704 return false;
3705 }
3706#endif // !defined(COMPONENT_BUILD)
3707
3708 return true;
[email protected]34f48682013-03-20 00:30:183709}
wfhc91e9672016-01-27 00:14:203710#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013711
bend1dd50f52016-06-26 22:10:483712void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
bena06f7d62017-04-04 20:48:523713 service_manager::BinderRegistry* registry,
Sam McNally52e50282017-11-29 00:54:023714 blink::AssociatedInterfaceRegistry* associated_registry,
leon.han0b618792016-06-16 01:53:513715 content::RenderProcessHost* render_process_host) {
nigeltaobeff0a102017-04-29 09:30:373716 // The CacheStatsRecorder is an associated binding, instead of a
3717 // non-associated one, because the sender (in the renderer process) posts the
3718 // message after a time delay, in order to rate limit. The association
3719 // protects against the render process host ID being recycled in that time
3720 // gap between the preparation and the execution of that IPC.
3721 associated_registry->AddInterface(
3722 base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID()));
3723
ben5be0b9132016-08-03 00:17:183724 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
Eric Seckler8652dcd52018-09-20 10:42:283725 base::CreateSingleThreadTaskRunnerWithTraits(
3726 {content::BrowserThread::UI});
bend1dd50f52016-06-26 22:10:483727 registry->AddInterface(
nigeltao2f673762016-10-14 03:27:283728 base::Bind(&rappor::RapporRecorderImpl::Create,
3729 g_browser_process->rappor_service()),
3730 ui_task_runner);
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183731 registry->AddInterface(
Mike Wittman16fa5362018-09-04 17:27:303732 base::BindRepeating(&metrics::CallStackProfileCollector::Create));
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183733
dvallet233f57ab2016-12-21 03:17:103734 if (NetBenchmarking::CheckBenchmarkingEnabled()) {
3735 Profile* profile =
3736 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Alexandr Ilin4909ec82018-06-06 10:22:483737 auto* loading_predictor =
3738 predictors::LoadingPredictorFactory::GetForProfile(profile);
Robbie McElrathb0f248c2018-07-24 19:44:163739 registry->AddInterface(
3740 base::BindRepeating(
3741 &NetBenchmarking::Create,
3742 loading_predictor ? loading_predictor->GetWeakPtr() : nullptr,
Robbie McElrathb0f248c2018-07-24 19:44:163743 render_process_host->GetID()),
3744 ui_task_runner);
dvallet233f57ab2016-12-21 03:17:103745 }
yzshen2d8fb422017-06-01 20:29:403746
Nico Weberbc5b06f2019-07-26 14:00:133747#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Adam Rice41b89592017-07-28 10:33:443748 if (safe_browsing_service_) {
Yuzhu Shencb3011f62018-02-08 02:51:503749 content::ResourceContext* resource_context =
3750 render_process_host->GetBrowserContext()->GetResourceContext();
yzshen2d8fb422017-06-01 20:29:403751 registry->AddInterface(
Yuzhu Shen44094e22017-07-18 22:52:353752 base::Bind(
3753 &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
Yuzhu Shencb3011f62018-02-08 02:51:503754 render_process_host->GetID(), resource_context,
Yuzhu Shen44094e22017-07-18 22:52:353755 base::Bind(
3756 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Yuzhu Shencb3011f62018-02-08 02:51:503757 base::Unretained(this), resource_context)),
Eric Seckler8652dcd52018-09-20 10:42:283758 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}));
yzshen2d8fb422017-06-01 20:29:403759 }
Nico Weberbc5b06f2019-07-26 14:00:133760#endif
yzshen2d8fb422017-06-01 20:29:403761
Eric Romana00cf682018-11-01 20:09:113762 if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
3763 registry->AddInterface(base::BindRepeating(
3764 &AddDataReductionProxyBinding,
3765 render_process_host->GetBrowserContext()->GetResourceContext()));
3766 }
3767
chrisha927d8fe2017-01-18 23:09:513768#if defined(OS_WIN)
Patrick Monette9a10ae22018-06-14 22:18:183769 // Add the ModuleEventSink interface. This is the interface used by renderer
3770 // processes to notify the browser of modules in their address space. The
3771 // process handle is not yet available at this point so pass in a callback
3772 // to allow to retrieve a duplicate at the time the interface is actually
3773 // created. It is safe to pass a raw pointer to |render_process_host|: the
Patrick Monetteaa2ec562019-03-20 23:37:453774 // callback will be invoked during the Mojo initialization, which occurs while
3775 // the |render_process_host| is alive.
Patrick Monette9a10ae22018-06-14 22:18:183776 auto get_process = base::BindRepeating(
3777 [](content::RenderProcessHost* host) -> base::Process {
3778 return host->GetProcess().Duplicate();
3779 },
3780 base::Unretained(render_process_host));
Patrick Monette9a10ae22018-06-14 22:18:183781 registry->AddInterface(
Patrick Monetteaa2ec562019-03-20 23:37:453782 base::BindRepeating(
3783 &ModuleEventSinkImpl::Create, std::move(get_process),
3784 content::PROCESS_TYPE_RENDERER,
3785 base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)),
Patrick Monette9a10ae22018-06-14 22:18:183786 ui_task_runner);
chrisha927d8fe2017-01-18 23:09:513787#endif
Dan Harrington964d48c2018-08-03 15:52:243788#if defined(OS_ANDROID)
Carlos Knippschild63b3f042018-11-20 22:55:043789 Profile* profile =
3790 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Dan Harrington964d48c2018-08-03 15:52:243791 registry->AddInterface(
3792 base::BindRepeating(&android::AvailableOfflineContentProvider::Create,
Carlos Knippschild63b3f042018-11-20 22:55:043793 profile),
Eric Seckler8652dcd52018-09-20 10:42:283794 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
Dan Harrington964d48c2018-08-03 15:52:243795#endif
chrisha927d8fe2017-01-18 23:09:513796
Nicholas Verneb5df4f72017-11-08 09:12:073797 for (auto* ep : extra_parts_) {
3798 ep->ExposeInterfacesToRenderer(registry, associated_registry,
3799 render_process_host);
3800 }
sammc335844522016-06-09 10:15:593801}
3802
bendd157e1a2016-07-22 03:15:573803void ChromeContentBrowserClient::ExposeInterfacesToMediaService(
ben8408b132017-05-01 23:48:503804 service_manager::BinderRegistry* registry,
xhwang9ab96482015-05-11 22:02:333805 content::RenderFrameHost* render_frame_host) {
Xiaohan Wang15303d0c2017-10-06 05:22:443806#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3807 registry->AddInterface(
3808 base::Bind(&OutputProtectionImpl::Create, render_frame_host));
ben155ecf82016-06-21 22:43:263809 registry->AddInterface(
John Rummell1b5da6102017-11-02 02:15:453810 base::Bind(&PlatformVerificationImpl::Create, render_frame_host));
Xiaohan Wang15303d0c2017-10-06 05:22:443811#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:493812
xhwangdb24d602017-05-20 06:32:243813#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
cm.sanchiad3f42a62017-11-07 11:33:353814 registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host));
xhwang116acb92017-04-03 18:27:203815#endif
xhwang9ab96482015-05-11 22:02:333816}
3817
Ben Goodger6a695c012017-06-20 20:21:203818void ChromeContentBrowserClient::BindInterfaceRequestFromFrame(
3819 content::RenderFrameHost* render_frame_host,
Ben Goodger6a695c012017-06-20 20:21:203820 const std::string& interface_name,
3821 mojo::ScopedMessagePipeHandle interface_pipe) {
Sam McNallyfaf9a402017-10-31 03:06:313822 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3823 !worker_interfaces_parameterized_) {
3824 InitWebContextInterfaces();
3825 }
Ben Goodger6a695c012017-06-20 20:21:203826
Ben Goodger272e0632017-07-19 23:27:003827 if (!frame_interfaces_parameterized_->TryBindInterface(
3828 interface_name, &interface_pipe, render_frame_host)) {
3829 frame_interfaces_->TryBindInterface(interface_name, &interface_pipe);
juncai1bf9f7c2016-03-22 20:46:563830 }
rockot0fa66a82015-06-11 17:25:453831}
3832
Mario Sanchez Prada39dee4a2019-07-09 07:15:403833void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113834 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403835 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3836 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113837 render_frame_host);
3838}
3839
Ken Rockot0aad7ec2018-07-31 15:58:443840bool ChromeContentBrowserClient::BindAssociatedInterfaceRequestFromFrame(
3841 content::RenderFrameHost* render_frame_host,
3842 const std::string& interface_name,
3843 mojo::ScopedInterfaceEndpointHandle* handle) {
3844 if (interface_name == autofill::mojom::AutofillDriver::Name_) {
3845 autofill::ContentAutofillDriverFactory::BindAutofillDriver(
Shimi Zhang6b72d292019-07-12 20:52:423846 mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>(
3847 std::move(*handle)),
Ken Rockot0aad7ec2018-07-31 15:58:443848 render_frame_host);
3849 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583850 }
3851 if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) {
Shimi Zhang6b72d292019-07-12 20:52:423852 password_manager::ContentPasswordManagerDriverFactory::
3853 BindPasswordManagerDriver(
3854 autofill::mojom::PasswordManagerDriverAssociatedRequest(
3855 std::move(*handle)),
3856 render_frame_host);
Dominic Battre97d5edf2019-03-26 13:41:383857 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583858 }
3859 if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) {
Tao Bai02ab4dd42019-03-06 00:30:373860 content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver(
Shimi Zhang8ee32332019-07-12 17:59:363861 mojo::PendingAssociatedReceiver<
3862 content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)),
Tao Bai02ab4dd42019-03-06 00:30:373863 render_frame_host);
3864 return true;
Ken Rockot0aad7ec2018-07-31 15:58:443865 }
3866
3867 return false;
3868}
3869
Sam McNallyfaf9a402017-10-31 03:06:313870void ChromeContentBrowserClient::BindInterfaceRequestFromWorker(
3871 content::RenderProcessHost* render_process_host,
3872 const url::Origin& origin,
3873 const std::string& interface_name,
3874 mojo::ScopedMessagePipeHandle interface_pipe) {
3875 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3876 !worker_interfaces_parameterized_) {
3877 InitWebContextInterfaces();
3878 }
3879
3880 worker_interfaces_parameterized_->BindInterface(
3881 interface_name, std::move(interface_pipe), render_process_host, origin);
3882}
3883
bena06f7d62017-04-04 20:48:523884void ChromeContentBrowserClient::BindInterfaceRequest(
ben2c36828d2017-05-02 04:09:013885 const service_manager::BindSourceInfo& source_info,
bena06f7d62017-04-04 20:48:523886 const std::string& interface_name,
3887 mojo::ScopedMessagePipeHandle* interface_pipe) {
Ben Goodger272e0632017-07-19 23:27:003888 if (source_info.identity.name() == content::mojom::kGpuServiceName)
3889 gpu_binder_registry_.TryBindInterface(interface_name, interface_pipe);
wittman757af872016-08-16 00:13:463890}
3891
Ken Rockotc185b2a2019-08-01 22:19:483892void ChromeContentBrowserClient::BindHostReceiverForRenderer(
3893 content::RenderProcessHost* render_process_host,
3894 mojo::GenericPendingReceiver receiver) {
3895#if BUILDFLAG(ENABLE_SPELLCHECK)
3896 if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) {
3897 SpellCheckHostChromeImpl::Create(render_process_host->GetID(),
3898 std::move(host_receiver));
3899 return;
3900 }
3901
3902#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
3903 if (auto panel_host_receiver =
3904 receiver.As<spellcheck::mojom::SpellCheckPanelHost>()) {
3905 SpellCheckPanelHostImpl::Create(render_process_host->GetID(),
3906 std::move(panel_host_receiver));
3907 return;
3908 }
3909#endif // BUILDFLAG(HAS_SPELLCHECK_PANEL)
3910#endif // BUILDFLAG(ENABLE_SPELLCHECK)
3911}
3912
Ken Rockot7c6275b2019-08-02 20:00:233913void ChromeContentBrowserClient::BindHostReceiverForRendererOnIOThread(
3914 int render_process_id,
3915 mojo::GenericPendingReceiver* receiver) {
3916 if (auto host_receiver =
3917 receiver->As<startup_metric_utils::mojom::StartupMetricHost>()) {
3918 startup_metric_utils::StartupMetricHostImpl::Create(
3919 std::move(host_receiver));
3920 return;
3921 }
3922}
3923
Ken Rockotfa5d57112019-05-29 20:57:143924void ChromeContentBrowserClient::WillStartServiceManager() {
John Abd-El-Malek27b3ebd22019-02-12 18:59:183925#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:053926 if (startup_data_) {
3927 auto* chrome_feature_list_creator =
3928 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183929 // This has to run very early before ServiceManagerContext is created.
3930 const base::Value* force_network_in_process_value =
Xi Han85079c22019-04-18 21:43:053931 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183932 ->GetPolicyService()
3933 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
3934 std::string()))
3935 .GetValue(policy::key::kForceNetworkInProcess);
3936 bool force_network_in_process = false;
3937 if (force_network_in_process_value)
3938 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3939 if (force_network_in_process)
3940 content::ForceInProcessNetworkService(true);
3941 }
3942#endif
xhwang5e630462015-10-30 03:18:483943}
3944
Ken Rockot06fd2832019-05-24 17:24:443945void ChromeContentBrowserClient::RunServiceInstance(
3946 const service_manager::Identity& identity,
3947 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
3948 const std::string& service_name = identity.name();
Alexander Woolfed183c512019-05-17 01:18:033949#if defined(OS_WIN)
3950 bool run_quarantine_service_in_process =
3951 !base::FeatureList::IsEnabled(quarantine::kOutOfProcessQuarantine);
3952#else
3953 bool run_quarantine_service_in_process = true;
3954#endif
3955
3956 if (run_quarantine_service_in_process &&
3957 service_name == quarantine::mojom::kServiceName) {
3958 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443959 std::make_unique<quarantine::QuarantineService>(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413960 return;
Alexander Woolfed183c512019-05-17 01:18:033961 }
3962
Ken Rockot3d8be742018-11-22 08:59:383963#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
3964 if (service_name == media::mojom::kMediaServiceName) {
Ken Rockotd80eb102018-11-29 14:55:163965 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443966 media::CreateMediaService(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413967 return;
Ken Rockot3d8be742018-11-22 08:59:383968 }
3969#endif
Ken Rockote116c202018-11-30 01:52:503970
Ken Rockotc15f34992018-12-01 21:27:573971#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
3972 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3973 switches::kLaunchInProcessSimpleBrowserSwitch) &&
3974 service_name == simple_browser::mojom::kServiceName) {
3975 service_manager::Service::RunAsyncUntilTermination(
3976 std::make_unique<simple_browser::SimpleBrowserService>(
Ken Rockot06fd2832019-05-24 17:24:443977 std::move(*receiver), simple_browser::SimpleBrowserService::
3978 UIInitializationMode::kUseEnvironmentUI));
Lei Zhang194fcd32019-05-23 16:19:413979 return;
Ken Rockotc15f34992018-12-01 21:27:573980 }
3981#endif
3982
Ken Rockote116c202018-11-30 01:52:503983#if defined(OS_CHROMEOS)
Lei Zhang194fcd32019-05-23 16:19:413984 if (base::FeatureList::IsEnabled(
3985 chromeos::features::kUpdatedCellularActivationUi) &&
3986 service_name == chromeos::cellular_setup::mojom::kServiceName) {
Kyle Horimoto1d6a679f2019-04-16 23:24:213987 service_manager::Service::RunAsyncUntilTermination(
3988 std::make_unique<chromeos::cellular_setup::CellularSetupService>(
Ken Rockot06fd2832019-05-24 17:24:443989 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413990 return;
Kyle Horimoto1d6a679f2019-04-16 23:24:213991 }
3992
Regan Hsu07912b7d2018-12-13 21:27:013993 if (service_name == chromeos::secure_channel::mojom::kServiceName) {
Ken Rockotc15f34992018-12-01 21:27:573994 service_manager::Service::RunAsyncUntilTermination(
3995 std::make_unique<chromeos::secure_channel::SecureChannelService>(
Ken Rockot06fd2832019-05-24 17:24:443996 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413997 return;
Ken Rockotc15f34992018-12-01 21:27:573998 }
3999
Steven Bennetts0c565d5b2019-04-24 23:52:454000 if (service_name == chromeos::network_config::mojom::kServiceName) {
4001 service_manager::Service::RunAsyncUntilTermination(
4002 std::make_unique<chromeos::network_config::NetworkConfigService>(
Ken Rockot06fd2832019-05-24 17:24:444003 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414004 return;
Steven Bennetts0c565d5b2019-04-24 23:52:454005 }
4006
Ken Rockot06fd2832019-05-24 17:24:444007 auto service = ash_service_registry::HandleServiceRequest(
4008 service_name, std::move(*receiver));
Ken Rockotc15f34992018-12-01 21:27:574009 if (service)
4010 service_manager::Service::RunAsyncUntilTermination(std::move(service));
Lei Zhang194fcd32019-05-23 16:19:414011#endif // defined(OS_CHROMEOS)
Ken Rockot3d8be742018-11-22 08:59:384012}
4013
Ken Rockot8f39a272018-12-21 23:38:354014base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174015ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:584016 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:584017 return GetChromeContentBrowserOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584018 if (name == content::mojom::kGpuServiceName)
Ken Rockot341089f2019-01-11 23:11:584019 return GetChromeContentGpuOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584020 if (name == content::mojom::kRendererServiceName)
4021 return GetChromeContentRendererOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:584022 return base::nullopt;
benc70c0e32016-09-22 03:50:374023}
4024
Ken Rockot69aade02019-01-23 21:19:514025std::vector<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174026ChromeContentBrowserClient::GetExtraServiceManifests() {
Ken Rockot06fd2832019-05-24 17:24:444027 auto manifests = GetChromeBuiltinServiceManifests();
Ken Rockot06fd2832019-05-24 17:24:444028
Nico Weberaf3b00b2017-09-11 17:58:174029#if BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444030 manifests.push_back(GetNaClLoaderManifest());
Ken Rockot69aade02019-01-23 21:19:514031#if defined(OS_WIN) && defined(ARCH_CPU_X86)
Ken Rockot06fd2832019-05-24 17:24:444032 manifests.push_back(GetNaClBrokerManifest());
sammc2b0375b2016-12-22 01:26:174033#endif // defined(OS_WIN)
Nico Weberaf3b00b2017-09-11 17:58:174034#endif // BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444035
4036 return manifests;
sammc2b0375b2016-12-22 01:26:174037}
4038
peterbbcccc12015-02-11 22:23:334039void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:374040 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:334041 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:294042 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:084043 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:374044 DCHECK(ShouldAllowOpenURL(site_instance, params.url));
4045
4046 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:084047
zpengdb4a58e2017-01-10 17:40:324048#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:224049 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:294050 std::move(callback));
jam1c5a91492016-02-24 20:47:534051#else
cm.sanchi2522bc92017-12-04 08:04:134052 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
4053 params.url, params.transition);
4054 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:084055 nav_params.user_gesture = params.user_gesture;
4056
4057 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:294058 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:334059#endif
mlamourieb40d552015-02-05 00:57:084060}
4061
zhaobinf3704f82017-01-12 07:19:364062content::ControllerPresentationServiceDelegate*
4063ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
4064 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:464065 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:094066 return media_router::PresentationServiceDelegateImpl::
4067 GetOrCreateForWebContents(web_contents);
4068 }
haibinlu9e605a92015-06-06 03:45:094069 return nullptr;
4070}
4071
zhaobinf3704f82017-01-12 07:19:364072content::ReceiverPresentationServiceDelegate*
4073ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
4074 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:364075 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
4076 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
4077 // created for offscreen presentations. The WebContents must belong to
4078 // an incognito profile.
4079 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
4080 FromWebContents(web_contents)) {
4081 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
4082 return impl;
4083 }
4084 }
zhaobinf3704f82017-01-12 07:19:364085 return nullptr;
4086}
4087
horo48d4d3e2015-02-27 03:04:004088void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
4089 const GURL& url) {
mathp46284f32015-03-11 13:06:414090 if (url.is_valid()) {
4091 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
4092 metric, url);
4093 }
horo48d4d3e2015-02-27 03:04:004094}
4095
Matt Falkenhagen8479b202017-07-14 04:35:314096std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
4097 // Don't change these returned strings. They are written (in hashed form) into
4098 // UMA logs. If you add more strings, you must update histograms.xml and get
4099 // histograms review. Only Google domains should be here for privacy purposes.
4100 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
4101 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194102 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:314103 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194104 if (url.host() == "docs.google.com")
4105 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:314106 return std::string();
4107}
4108
avid6d88b912017-01-13 00:16:004109std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:474110ChromeContentBrowserClient::CreateThrottlesForNavigation(
4111 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:004112 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:274113
bmcquadeb4556552017-03-24 22:24:374114 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
4115 // that may delay or cancel navigations, so only NavigationThrottles that
4116 // don't delay or cancel navigations (e.g. throttles that are only observing
4117 // callbacks without affecting navigation behavior) should be added before
4118 // MetricsNavigationThrottle.
4119 if (handle->IsInMainFrame()) {
4120 throttles.push_back(
4121 page_load_metrics::MetricsNavigationThrottle::Create(handle));
4122 }
4123
brettw4b461082016-11-19 18:55:164124#if BUILDFLAG(ENABLE_PLUGINS)
tommycliae590f1602016-11-02 03:59:234125 std::unique_ptr<content::NavigationThrottle> flash_url_throttle =
4126 FlashDownloadInterception::MaybeCreateThrottleFor(handle);
4127 if (flash_url_throttle)
4128 throttles.push_back(std::move(flash_url_throttle));
trizzofo8ddaeb72016-09-01 23:18:274129#endif
4130
mmenkedb2637ff2017-03-30 23:59:424131#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4132 std::unique_ptr<content::NavigationThrottle> supervised_user_throttle =
4133 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle);
4134 if (supervised_user_throttle)
4135 throttles.push_back(std::move(supervised_user_throttle));
4136#endif
4137
clamy40c9e142015-09-29 11:18:474138#if defined(OS_ANDROID)
4139 // TODO(davidben): This is insufficient to integrate with prerender properly.
4140 // https://crbug.com/370595
4141 prerender::PrerenderContents* prerender_contents =
4142 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
4143 if (!prerender_contents && handle->IsInMainFrame()) {
4144 throttles.push_back(
4145 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304146 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474147 }
Min Qin0ab0e162017-11-14 21:57:194148 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574149#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474150 if (handle->IsInMainFrame()) {
4151 // Redirect some navigations to apps that have registered matching URL
4152 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574153 auto url_to_app_throttle =
4154 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:474155 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:094156 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:474157 }
4158#endif
clamy49678312015-10-22 21:59:004159
4160#if defined(OS_CHROMEOS)
4161 // Check if we need to add merge session throttle. This throttle will postpone
4162 // loading of main frames.
4163 if (handle->IsInMainFrame()) {
4164 // Add interstitial page while merge session process (cookie reconstruction
4165 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4166 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024167 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4168 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004169 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4170 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4171 }
Maggie Caia2f03f52019-04-02 02:13:284172 }
4173#endif
djacobo21e56e02016-07-02 01:14:314174
Maggie Caia2f03f52019-04-02 02:13:284175#if !defined(OS_ANDROID)
4176 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:154177 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:284178#if defined(OS_CHROMEOS)
4179 chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
4180#else
4181 apps::AppsNavigationThrottle::MaybeCreate(handle);
4182#endif
Dominick Ng7c289942018-03-27 05:57:154183 if (url_to_apps_throttle)
4184 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004185 }
4186#endif
4187
brettw00899e62016-11-12 02:10:174188#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004189 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094190 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514191
4192 std::unique_ptr<content::NavigationThrottle> user_script_throttle =
4193 extensions::ExtensionsBrowserClient::Get()
4194 ->GetUserScriptListener()
4195 ->CreateNavigationThrottle(handle);
4196 if (user_script_throttle)
4197 throttles.push_back(std::move(user_script_throttle));
naskob9164c42016-06-07 01:21:354198#endif
4199
bauerb8f9c37742017-03-30 15:04:124200#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4201 std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle =
4202 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle);
4203 if (supervised_user_nav_throttle)
4204 throttles.push_back(std::move(supervised_user_nav_throttle));
4205#endif
4206
csharrisone985ebc2017-04-04 17:05:034207 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:104208 if (auto* subresource_filter_client =
4209 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
4210 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
4211 &throttles);
csharrisone985ebc2017-04-04 17:05:034212 }
4213
zhenw6edd49c2017-07-12 05:49:454214#if !defined(OS_ANDROID)
4215 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4216 // enabled on non-Android platforms.
4217 std::unique_ptr<content::NavigationThrottle>
4218 background_tab_navigation_throttle = resource_coordinator::
4219 BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle);
4220 if (background_tab_navigation_throttle)
4221 throttles.push_back(std::move(background_tab_navigation_throttle));
4222#endif
4223
Nico Weberbc5b06f2019-07-26 14:00:134224#if BUILDFLAG(FULL_SAFE_BROWSING)
Jialiu Linbdbb81d2017-10-11 21:29:094225 std::unique_ptr<content::NavigationThrottle>
4226 password_protection_navigation_throttle =
4227 safe_browsing::MaybeCreateNavigationThrottle(handle);
4228 if (password_protection_navigation_throttle) {
4229 throttles.push_back(std::move(password_protection_navigation_throttle));
4230 }
4231#endif
4232
Joe DeBlasio6e8409a2019-02-20 23:08:274233 std::unique_ptr<content::NavigationThrottle>
Mustafa Emre Acere14f6262019-04-02 00:19:314234 lookalike_url_navigation_throttle = lookalikes::
Joe DeBlasio6e8409a2019-02-20 23:08:274235 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle);
4236 if (lookalike_url_navigation_throttle)
4237 throttles.push_back(std::move(lookalike_url_navigation_throttle));
Joe DeBlasio6e8409a2019-02-20 23:08:274238
Amber Wonf56d8f42017-08-31 22:29:404239 std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle =
4240 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle);
4241 if (pdf_iframe_throttle)
4242 throttles.push_back(std::move(pdf_iframe_throttle));
Amber Won6b5edc752017-08-17 19:23:544243
Charles Harrison6dd11d282017-10-03 06:14:514244 std::unique_ptr<content::NavigationThrottle> tab_under_throttle =
4245 TabUnderNavigationThrottle::MaybeCreate(handle);
4246 if (tab_under_throttle)
4247 throttles.push_back(std::move(tab_under_throttle));
4248
Jeremy Romanec48d7a2018-03-01 17:35:094249 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534250 handle, handle->GetWebContents()->GetBrowserContext()));
4251
Carlos IL5a9e7512019-06-13 22:35:284252 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4253 handle,
4254 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
4255 base::Bind(&SSLErrorHandler::HandleSSLError)));
Lucas Garron94b16052017-11-11 01:58:124256
Christopher Thompson4137cec2017-12-19 05:34:234257 std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle =
4258 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle);
4259 if (https_upgrade_timing_throttle)
4260 throttles.push_back(std::move(https_upgrade_timing_throttle));
4261
Dmitry Gozman57b92ce2017-12-28 22:24:544262#if !defined(OS_ANDROID)
4263 std::unique_ptr<content::NavigationThrottle> devtools_throttle =
4264 DevToolsWindow::MaybeCreateNavigationThrottle(handle);
4265 if (devtools_throttle)
4266 throttles.push_back(std::move(devtools_throttle));
Conley Owensaafcf122018-02-26 18:53:514267
4268 std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle =
4269 NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle);
4270 if (new_tab_page_throttle)
4271 throttles.push_back(std::move(new_tab_page_throttle));
jdoerrie4f9376f2018-12-12 18:26:204272
4273 std::unique_ptr<content::NavigationThrottle>
4274 google_password_manager_throttle =
4275 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(
4276 handle);
4277 if (google_password_manager_throttle)
4278 throttles.push_back(std::move(google_password_manager_throttle));
Dmitry Gozman57b92ce2017-12-28 22:24:544279#endif
4280
Robert Ogdenafd250b2018-07-25 22:21:034281 std::unique_ptr<content::NavigationThrottle> previews_lite_page_throttle =
4282 PreviewsLitePageDecider::MaybeCreateThrottleFor(handle);
4283 if (previews_lite_page_throttle)
4284 throttles.push_back(std::move(previews_lite_page_throttle));
Carlos IL4ee307e2018-12-22 03:19:004285 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
4286 throttles.push_back(
4287 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
4288 handle));
4289 }
Robert Ogdenafd250b2018-07-25 22:21:034290
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334291#if defined(OS_WIN) || defined(OS_MACOSX) || \
4292 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134293 std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle =
4294 browser_switcher::BrowserSwitcherNavigationThrottle ::
4295 MaybeCreateThrottleFor(handle);
4296 if (browser_switcher_throttle)
4297 throttles.push_back(std::move(browser_switcher_throttle));
4298#endif
4299
dchenge73d8520c2015-12-27 01:19:094300 return throttles;
clamy40c9e142015-09-29 11:18:474301}
4302
clamy1e5574e2016-09-29 16:48:444303std::unique_ptr<content::NavigationUIData>
4304ChromeContentBrowserClient::GetNavigationUIData(
4305 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094306 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444307}
4308
Xiaohan Wanga4e41842018-06-26 18:45:104309void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4310 const std::string& key_system,
4311 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4312 base::flat_set<media::VideoCodec>* video_codecs,
4313 base::flat_set<media::EncryptionMode>* encryption_schemes) {
4314#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264315 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104316 if (key_system == kWidevineKeySystem) {
4317 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4318 encryption_schemes);
4319 }
4320#endif
4321}
4322
[email protected]487974a2014-06-13 16:49:014323content::DevToolsManagerDelegate*
4324ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354325#if defined(OS_ANDROID)
4326 return new DevToolsManagerDelegateAndroid();
4327#else
[email protected]487974a2014-06-13 16:49:014328 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354329#endif
[email protected]487974a2014-06-13 16:49:014330}
4331
Rayan Kanso411e84e2019-02-13 15:27:404332void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4333 content::BrowserContext* browser_context,
4334 int service,
4335 base::Time expiration_time) {
4336 Profile* profile = Profile::FromBrowserContext(browser_context);
4337 DCHECK(profile);
4338
4339 auto* pref_service = profile->GetPrefs();
4340 DCHECK(pref_service);
4341
4342 DictionaryPrefUpdate pref_update(
4343 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4344 base::DictionaryValue* exp_dict = pref_update.Get();
4345
4346 // Convert |expiration_time| to minutes since that is the most granular
4347 // option that returns an int. base::Value does not accept int64.
4348 int expiration_time_minutes =
4349 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4350 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4351}
4352
4353base::flat_map<int, base::Time>
4354ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4355 content::BrowserContext* browser_context) {
4356 Profile* profile = Profile::FromBrowserContext(browser_context);
4357 DCHECK(profile);
4358
4359 auto* pref_service = profile->GetPrefs();
4360 DCHECK(pref_service);
4361
4362 auto* expiration_dict = pref_service->GetDictionary(
4363 prefs::kDevToolsBackgroundServicesExpirationDict);
4364 DCHECK(expiration_dict);
4365
4366 base::flat_map<int, base::Time> expiration_times;
4367 for (const auto& it : *expiration_dict) {
4368 // key.
4369 int service = 0;
4370 bool did_convert = base::StringToInt(it.first, &service);
4371 DCHECK(did_convert);
4372
4373 // value.
4374 DCHECK(it.second->is_int());
4375 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4376 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4377
4378 expiration_times[service] = expiration_time;
4379 }
4380
4381 return expiration_times;
4382}
4383
oysteinec563c582015-02-13 19:19:524384content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524385 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524386}
4387
[email protected]a6868c22013-10-09 02:50:294388bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4389 content::BrowserContext* browser_context,
4390 const GURL& url) {
brettw4b461082016-11-19 18:55:164391#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554392 return ChromeContentBrowserClientPluginsPart::
4393 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4394 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294395#else
4396 return false;
4397#endif
4398}
4399
[email protected]aec5ed52014-06-20 07:51:424400bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4401 content::BrowserContext* browser_context,
4402 const GURL& url) {
brettw4b461082016-11-19 18:55:164403#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554404 return ChromeContentBrowserClientPluginsPart::
4405 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4406 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064407#else
4408 return false;
4409#endif
4410}
4411
mlamourif8c23a2002015-01-27 13:10:104412void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014413 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434414 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524415 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104416
4417 WebContents* web_contents =
4418 WebContents::FromRenderFrameHost(render_frame_host);
4419 DCHECK(web_contents);
4420
mlamourif8c23a2002015-01-27 13:10:104421 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374422 prerender::PrerenderManagerFactory::GetForBrowserContext(
4423 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104424 if (prerender_manager &&
4425 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
danakj0018a29a2018-12-01 01:03:434426 *visibility_state = content::PageVisibilityState::kPrerender;
mlamourif8c23a2002015-01-27 13:10:104427 }
4428}
4429
Andrew Moylan8ed9d83c82019-01-29 20:23:524430// Forward image Annotator requests to the image_annotation service.
4431void BindImageAnnotator(image_annotation::mojom::AnnotatorRequest request,
4432 RenderFrameHost* const frame_host) {
4433 content::BrowserContext::GetConnectorFor(
4434 frame_host->GetProcess()->GetBrowserContext())
4435 ->BindInterface(image_annotation::mojom::kServiceName,
4436 std::move(request));
4437}
4438
Sam McNallyfaf9a402017-10-31 03:06:314439void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094440 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4441 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014442 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Sam McNallyfaf9a402017-10-31 03:06:314443 worker_interfaces_parameterized_ =
Jeremy Romanec48d7a2018-03-01 17:35:094444 std::make_unique<service_manager::BinderRegistryWithArgs<
Sam McNallyfaf9a402017-10-31 03:06:314445 content::RenderProcessHost*, const url::Origin&>>();
Ben Goodger6a695c012017-06-20 20:21:204446
Michael Martis4a542f52017-07-28 01:51:444447 // Register mojo ContentTranslateDriver interface only for main frame.
Anthony Vallee-Duboise2432137a2019-01-17 20:06:014448 frame_interfaces_parameterized_->AddInterface(
4449 base::BindRepeating(&language::BindContentTranslateDriver));
Ben Goodger6a695c012017-06-20 20:21:204450
4451 frame_interfaces_parameterized_->AddInterface(
Eric Lawrenced0acf2a7c2017-07-20 18:02:484452 base::Bind(&InsecureSensitiveInputDriverFactory::BindDriver));
Andrew Moylan8ed9d83c82019-01-29 20:23:524453 frame_interfaces_parameterized_->AddInterface(
4454 base::BindRepeating(&BindImageAnnotator));
Ben Goodger6a695c012017-06-20 20:21:204455
4456#if defined(OS_ANDROID)
4457 frame_interfaces_parameterized_->AddInterface(base::Bind(
Matt Giucaee4aefb2017-08-04 03:11:554458 &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>));
Ben Goodger6a695c012017-06-20 20:21:204459 frame_interfaces_parameterized_->AddInterface(
4460 base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>));
Kim Paulhamus3d33e442018-03-29 23:04:144461 frame_interfaces_parameterized_->AddInterface(
Amos Limdddb6992018-07-19 22:14:324462 base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>));
Michael Thiessen909ba032019-03-26 23:47:434463#if defined(BROWSER_MEDIA_CONTROLS_MENU)
4464 frame_interfaces_parameterized_->AddInterface(base::Bind(
4465 &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>));
4466#endif
Ben Goodger6a695c012017-06-20 20:21:204467#else
4468 if (base::FeatureList::IsEnabled(features::kWebPayments)) {
4469 frame_interfaces_parameterized_->AddInterface(
4470 base::Bind(&payments::CreatePaymentRequest));
4471 }
4472#endif
4473
Ben Goodger6a695c012017-06-20 20:21:204474#if defined(OS_ANDROID)
Matt Giuca00e993602017-06-23 05:17:544475 frame_interfaces_parameterized_->AddInterface(base::Bind(
4476 &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>));
Michael Thiessen07c444c2019-04-26 03:53:114477#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
4478 frame_interfaces_parameterized_->AddInterface(base::Bind(
4479 &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>));
4480#endif
Ben Goodger6a695c012017-06-20 20:21:204481#endif
Reilly Grant8e5c85c2017-07-07 16:35:064482
Jay Harris5a42aa21b2018-11-28 01:23:554483#if !defined(OS_ANDROID)
Eric Stevenson1d074a972018-12-07 14:16:454484 frame_interfaces_parameterized_->AddInterface(
Jay Harris1ddcffa2019-07-09 03:07:404485 base::BindRepeating(&badging::BadgeManager::BindRequest));
Eric Stevensonc3b18052018-10-01 22:22:004486#endif
4487
Reilly Grant8e5c85c2017-07-07 16:35:064488 frame_interfaces_parameterized_->AddInterface(
Lu Chen5bec7a302018-06-26 18:52:324489 base::BindRepeating(&NavigationPredictor::Create));
Dan Harringtonbc87c062018-10-31 15:21:244490
4491#if defined(OS_ANDROID)
4492 frame_interfaces_parameterized_->AddInterface(
4493 base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create),
4494 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
4495#endif
Ben Goodger6a695c012017-06-20 20:21:204496}
4497
[email protected]30335fdf02014-02-26 19:51:274498void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174499 base::CommandLine* to_command_line,
4500 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544501 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274502#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544503 const version_info::Channel kMaxDisableEncryptionChannel =
4504 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274505#else
sdefresne6e883e42015-07-30 08:05:544506 const version_info::Channel kMaxDisableEncryptionChannel =
4507 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274508#endif
4509 if (channel <= kMaxDisableEncryptionChannel) {
4510 static const char* const kWebRtcDevSwitchNames[] = {
4511 switches::kDisableWebRtcEncryption,
4512 };
Avi Drissmand251e912018-12-26 15:46:374513 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4514 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274515 }
4516}
bashi933629552016-10-13 23:32:404517
miu54dca6c2016-11-17 10:59:384518#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4519void ChromeContentBrowserClient::CreateMediaRemoter(
4520 content::RenderFrameHost* render_frame_host,
4521 media::mojom::RemotingSourcePtr source,
4522 media::mojom::RemoterRequest request) {
miu54dca6c2016-11-17 10:59:384523 CastRemotingConnector::CreateMediaRemoter(
4524 render_frame_host, std::move(source), std::move(request));
miu54dca6c2016-11-17 10:59:384525}
4526#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464527
Michael Giuffrida6802ffe2017-09-29 03:40:254528base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4529 const base::CommandLine& command_line) {
4530 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164531}
4532
John Abd-El-Malek8efa11f2019-01-06 00:51:534533namespace {
4534// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024535class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534536 public:
4537 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174538 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534539 : protocol_handler_registry_(protocol_handler_registry) {}
4540 ~ProtocolHandlerThrottle() override = default;
4541
4542 void WillStartRequest(network::ResourceRequest* request,
4543 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294544 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534545 }
4546
4547 void WillRedirectRequest(net::RedirectInfo* redirect_info,
4548 const network::ResourceResponseHead& response_head,
4549 bool* defer,
4550 std::vector<std::string>* to_be_removed_headers,
4551 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294552 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534553 }
4554
4555 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294556 void TranslateUrl(GURL* url) {
4557 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4558 return;
4559 GURL translated_url = protocol_handler_registry_->Translate(*url);
4560 if (!translated_url.is_empty())
4561 *url = translated_url;
4562 }
4563
Clark DuValla411bda2019-08-02 03:09:174564 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534565};
4566} // namespace
4567
Minggang Wangf6840ecf2019-07-29 05:15:024568std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194569ChromeContentBrowserClient::CreateURLLoaderThrottles(
4570 const network::ResourceRequest& request,
4571 content::BrowserContext* browser_context,
4572 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4573 content::NavigationUIData* navigation_ui_data,
4574 int frame_tree_node_id) {
4575 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4576
Minggang Wangf6840ecf2019-07-29 05:15:024577 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194578
4579 Profile* profile = Profile::FromBrowserContext(browser_context);
4580
4581 ChromeNavigationUIData* chrome_navigation_ui_data =
4582 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4583
Clark DuVall68eb997f2019-06-28 05:42:284584 auto* drp_settings =
4585 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4586 browser_context);
4587 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4588 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4589 drp_settings) {
4590 if (!data_reduction_proxy_throttle_manager_) {
4591 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4592 data_reduction_proxy::DataReductionProxyThrottleManager,
4593 base::OnTaskRunnerDeleter>(
4594 new data_reduction_proxy::DataReductionProxyThrottleManager(
4595 drp_settings->data_reduction_proxy_service(),
4596 data_reduction_proxy::DataReductionProxyThrottleManager::
4597 CreateConfig(drp_settings->proxies_for_http())),
4598 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4599 }
4600 net::HttpRequestHeaders headers;
4601 data_reduction_proxy::DataReductionProxyRequestOptions::
4602 AddPageIDRequestHeader(
4603 &headers,
4604 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4605 result.push_back(std::make_unique<
4606 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4607 headers, data_reduction_proxy_throttle_manager_.get()));
4608 }
4609
Nico Weberbc5b06f2019-07-26 14:00:134610#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564611 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4612 request.url, *profile->GetPrefs());
4613 if (!matches_enterprise_whitelist) {
4614 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4615 base::BindOnce(
4616 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4617 base::Unretained(this)),
4618 wc_getter, frame_tree_node_id, profile->GetResourceContext()));
4619 }
Nico Weberbc5b06f2019-07-26 14:00:134620#endif
Clark DuVall5497288d2019-07-17 00:17:564621
Clark DuVallfffa41e2019-06-25 20:27:194622 if (chrome_navigation_ui_data &&
4623 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4624 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4625 chrome_navigation_ui_data->prerender_mode(),
4626 chrome_navigation_ui_data->prerender_histogram_prefix(),
4627 base::BindOnce(GetPrerenderCanceller, wc_getter),
4628 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})));
4629 }
4630
4631 bool is_off_the_record = profile->IsOffTheRecord();
4632 bool is_signed_in = !is_off_the_record &&
4633 !profile->GetPrefs()
4634 ->GetString(prefs::kGoogleServicesUserAccountId)
4635 .empty();
4636
4637 chrome::mojom::DynamicParams dynamic_params = {
4638 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4639 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4640 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4641 variations::VariationsHttpHeaderProvider::GetInstance()
4642 ->GetClientDataHeader(is_signed_in)};
4643 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
4644 is_off_the_record, std::move(dynamic_params)));
4645
Clark DuValla411bda2019-08-02 03:09:174646 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4647 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214648
Clark DuVall39c2cfc2019-06-25 21:49:284649#if BUILDFLAG(ENABLE_PLUGINS)
4650 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464651 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284652#endif
4653
Robbie McElrath127ad2b2019-07-22 22:38:114654 auto delegate =
4655 std::make_unique<signin::HeaderModificationDelegateOnUIThreadImpl>(
4656 profile);
4657 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4658 std::move(delegate), navigation_ui_data, wc_getter);
4659 if (signin_throttle)
4660 result.push_back(std::move(signin_throttle));
4661
Clark DuVallfffa41e2019-06-25 20:27:194662 return result;
4663}
4664
Ken Rockot6414c4d92017-11-08 19:58:324665void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464666 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324667 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414668#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464669 content::WebContents* web_contents =
4670 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414671#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324672 factories->emplace(
4673 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574674 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464675 web_contents->GetBrowserContext(),
4676 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414677#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4678#if defined(OS_CHROMEOS)
4679 Profile* profile =
4680 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304681 factories->emplace(content::kExternalFileScheme,
4682 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4683 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414684#endif // defined(OS_CHROMEOS)
4685#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324686}
4687
Ting Shao2dc60582019-07-15 04:43:364688void ChromeContentBrowserClient::
4689 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4690 content::BrowserContext* browser_context,
4691 NonNetworkURLLoaderFactoryMap* factories) {
4692#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4693 DCHECK(browser_context);
4694 DCHECK(factories);
4695#if BUILDFLAG(ENABLE_EXTENSIONS)
4696 factories->emplace(
4697 extensions::kExtensionScheme,
4698 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4699 browser_context));
4700#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4701#if defined(OS_CHROMEOS)
4702 Profile* profile = Profile::FromBrowserContext(browser_context);
4703 factories->emplace(content::kExternalFileScheme,
4704 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4705 profile, content::ChildProcessHost::kInvalidUniqueID));
4706#endif // defined(OS_CHROMEOS)
4707#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4708}
4709
Jay Civelli2578ebe2018-06-05 18:44:314710namespace {
4711
4712// The FileURLLoaderFactory provided to the extension background pages.
4713// Checks with the ChildProcessSecurityPolicy to validate the file access.
4714class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4715 public:
4716 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4717
4718 private:
4719 // network::mojom::URLLoaderFactory:
4720 void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
4721 int32_t routing_id,
4722 int32_t request_id,
4723 uint32_t options,
4724 const network::ResourceRequest& request,
4725 network::mojom::URLLoaderClientPtr client,
4726 const net::MutableNetworkTrafficAnnotationTag&
4727 traffic_annotation) override {
4728 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4729 child_id_, request.url)) {
4730 client->OnComplete(
4731 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
4732 return;
4733 }
4734 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454735 /*observer=*/nullptr,
4736 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314737 }
4738
4739 void Clone(network::mojom::URLLoaderFactoryRequest loader) override {
4740 bindings_.AddBinding(this, std::move(loader));
4741 }
4742
4743 int child_id_;
4744 mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
4745 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4746};
4747
4748} // namespace
4749
Ken Rockot6414c4d92017-11-08 19:58:324750void ChromeContentBrowserClient::
4751 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464752 int render_process_id,
4753 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324754 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414755#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4756 content::RenderFrameHost* frame_host =
4757 RenderFrameHost::FromID(render_process_id, render_frame_id);
4758 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4759#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4760
4761#if defined(OS_CHROMEOS)
4762 if (web_contents) {
4763 Profile* profile =
4764 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304765 factories->emplace(content::kExternalFileScheme,
4766 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4767 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414768 }
4769#endif // defined(OS_CHROMEOS)
4770
Ken Rockot6414c4d92017-11-08 19:58:324771#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464772 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4773 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324774 if (factory)
4775 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234776
4777 // This logic should match
4778 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314779 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234780 return;
Jay Civellic9bbf72d2018-03-24 01:58:314781
4782 Profile* profile =
4783 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4784 InstantService* instant_service =
4785 InstantServiceFactory::GetForProfile(profile);
4786 // The test below matches what's done by ShouldServiceRequestIOThread in
4787 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464788 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314789 factories->emplace(
4790 chrome::kChromeSearchScheme,
4791 content::CreateWebUIURLLoader(
4792 frame_host, chrome::kChromeSearchScheme,
4793 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234794 }
Jay Civellic9bbf72d2018-03-24 01:58:314795
Chris Mumfordbae8a742018-03-01 23:02:234796 extensions::ChromeExtensionWebContentsObserver* web_observer =
4797 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4798 web_contents);
4799
Karan Bhatia91928572018-03-06 01:18:074800 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4801 // to the |web_contents|.
4802 if (!web_observer)
4803 return;
4804
Chris Mumfordbae8a742018-03-01 23:02:234805 const Extension* extension =
4806 web_observer->GetExtensionFromFrame(frame_host, false);
4807 if (!extension)
4808 return;
4809
Sam McNally7414eeb72018-09-03 04:05:304810 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234811 // Support for chrome:// scheme if appropriate.
4812 if ((extension->is_extension() || extension->is_platform_app()) &&
4813 Manifest::IsComponentLocation(extension->location())) {
4814 // Components of chrome that are implemented as extensions or platform apps
4815 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304816 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4817 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4818 }
4819 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4820 (extension->is_platform_app() &&
4821 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234822 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024823 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4824 // URLs. Hosted apps are not allowed because they are served via web servers
4825 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304826 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4827 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024828 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304829 }
4830 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234831 factories->emplace(
4832 content::kChromeUIScheme,
4833 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4834 std::move(allowed_webui_hosts)));
4835 }
Jay Civelli2578ebe2018-06-05 18:44:314836
4837 // Extension with a background page get file access that gets approval from
4838 // ChildProcessSecurityPolicy.
4839 extensions::ExtensionHost* host =
4840 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4841 ->GetBackgroundHostForExtension(extension->id());
4842 if (host) {
4843 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4844 render_process_id));
4845 }
Chris Mumfordbae8a742018-03-01 23:02:234846#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324847}
4848
Ken Rockota0dfaca12018-02-15 07:26:254849bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214850 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254851 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384852 int render_process_id,
Ken Rockota0dfaca12018-02-15 07:26:254853 bool is_navigation,
Ken Rockot1726e182019-02-28 09:48:564854 bool is_download,
Lukasz Anforowicz762733652018-09-28 14:48:264855 const url::Origin& request_initiator,
Dominic Farolino1be897a2019-07-20 08:11:424856 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Clark DuValla5e25b752018-11-27 22:08:164857 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Clark DuVall8dc4e502018-09-07 01:51:124858 bool* bypass_redirect_checks) {
Reilly Grant24bf8332018-08-27 21:55:014859 bool use_proxy = false;
4860
Ken Rockota0dfaca12018-02-15 07:26:254861#if BUILDFLAG(ENABLE_EXTENSIONS)
4862 auto* web_request_api =
4863 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214864 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254865
4866 // NOTE: Some unit test environments do not initialize
4867 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014868 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124869 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384870 web_request_api->MaybeProxyURLLoaderFactory(
4871 browser_context, frame, render_process_id, is_navigation,
Dominic Farolino1be897a2019-07-20 08:11:424872 is_download, factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124873 if (bypass_redirect_checks)
4874 *bypass_redirect_checks = use_proxy_for_web_request;
4875 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014876 }
Ken Rockota0dfaca12018-02-15 07:26:254877#endif
Reilly Grant24bf8332018-08-27 21:55:014878
Reilly Grantcc22e602018-09-07 15:25:204879 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Dominic Farolino1be897a2019-07-20 08:11:424880 frame, is_navigation, request_initiator, factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014881
4882 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254883}
4884
Jian Lide7b43792018-06-01 23:22:134885std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4886ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4887 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144888 int frame_tree_node_id,
4889 const scoped_refptr<network::SharedURLLoaderFactory>&
4890 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134891 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4892 interceptors;
4893#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234894 interceptors.push_back(
4895 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4896 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134897#endif
Ryan Sturmaf523742019-01-16 00:15:454898
Robert Ogden3d5d5b42019-04-22 05:13:114899 ChromeNavigationUIData* chrome_navigation_ui_data =
4900 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4901
Ryan Sturm27d93f412019-02-15 21:30:144902 // TODO(ryansturm): Once this is on the UI thread, stop passing
4903 // |network_loader_factory| and have interceptors create one themselves.
4904 // https://crbug.com/931786
John Abd-El-Malek7577f262019-06-10 21:23:234905 if (base::FeatureList::IsEnabled(
Ryan Sturmaf523742019-01-16 00:15:454906 previews::features::kHTTPSServerPreviewsUsingURLLoader)) {
4907 interceptors.push_back(
4908 std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114909 network_loader_factory,
4910 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4911 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454912 }
4913
Jian Lide7b43792018-06-01 23:22:134914 return interceptors;
4915}
4916
Yutaka Hirano8e0b4d432019-07-04 07:12:384917bool ChromeContentBrowserClient::WillInterceptWebSocket(
4918 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334919#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384920 if (!frame) {
4921 return false;
4922 }
4923 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334924 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4925 frame->GetProcess()->GetBrowserContext());
4926
4927 // NOTE: Some unit test environments do not initialize
4928 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4929 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384930 return false;
Yutaka Hirano36c94952018-05-30 21:33:334931
Yutaka Hirano8e0b4d432019-07-04 07:12:384932 return web_request_api->MayHaveProxies();
4933#else
4934 return false;
4935#endif
4936}
4937
4938void ChromeContentBrowserClient::CreateWebSocket(
4939 content::RenderFrameHost* frame,
4940 WebSocketFactory factory,
4941 const GURL& url,
4942 const GURL& site_for_cookies,
4943 const base::Optional<std::string>& user_agent,
4944 network::mojom::WebSocketHandshakeClientPtr handshake_client) {
4945#if BUILDFLAG(ENABLE_EXTENSIONS)
4946 if (!frame) {
4947 return;
4948 }
4949 auto* web_request_api =
4950 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4951 frame->GetProcess()->GetBrowserContext());
4952
4953 DCHECK(web_request_api);
4954 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
4955 site_for_cookies, user_agent,
4956 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334957#endif
4958}
4959
Maks Orlovich710d5e32019-07-09 20:16:454960bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464961 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454962 content::BrowserContext* browser_context,
4963 const url::Origin& origin,
4964 bool is_service_worker,
4965 int process_id,
4966 int routing_id,
4967 network::mojom::RestrictedCookieManagerRequest* request) {
4968 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4969#if BUILDFLAG(ENABLE_EXTENSIONS)
4970 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464971 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454972 extensions::ChromeExtensionCookies::Get(browser_context)
4973 ->CreateRestrictedCookieManager(origin, std::move(*request));
4974 return true;
4975 }
4976#endif
4977 return false;
4978}
4979
Matt Menkeae4fdb12018-06-02 06:32:544980void ChromeContentBrowserClient::OnNetworkServiceCreated(
4981 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534982 PrefService* local_state;
4983 if (g_browser_process) {
4984 DCHECK(g_browser_process->local_state());
4985 local_state = g_browser_process->local_state();
4986 } else {
Xi Han85079c22019-04-18 21:43:054987 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4988 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534989 }
4990
4991 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4992 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4993
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494994 // Create SystemNetworkContextManager if it has not been created yet. We need
4995 // to set up global NetworkService state before anything else uses it and this
4996 // is the first opportunity to initialize SystemNetworkContextManager with the
4997 // NetworkService.
4998 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534999 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:075000
Min Qin8caab1d2018-10-03 17:28:135001 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:545002 network_service);
5003}
5004
Ken Rockota0dfaca12018-02-15 07:26:255005network::mojom::NetworkContextPtr
5006ChromeContentBrowserClient::CreateNetworkContext(
5007 content::BrowserContext* context,
5008 bool in_memory,
5009 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:505010 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:455011 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:255012}
5013
Robert Sesek34f68f312019-01-14 20:25:115014std::vector<base::FilePath>
5015ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
5016 base::FilePath user_data_dir;
5017 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
5018 DCHECK(!user_data_dir.empty());
5019
5020 base::FilePath cache_dir;
5021 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
5022 DCHECK(!cache_dir.empty());
5023
5024 // On some platforms, the cache is a child of the user_data_dir so only
5025 // return the one path.
5026 if (user_data_dir.IsParent(cache_dir))
5027 return {user_data_dir};
5028
5029 return {user_data_dir, cache_dir};
5030}
5031
Min Qin75ed6df2017-12-01 20:39:155032bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135033 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155034#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5035 // It is OK to load the saved offline copy, in MHTML format.
5036 ChromeNavigationUIData* chrome_navigation_ui_data =
5037 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5038 if (!chrome_navigation_ui_data)
5039 return false;
5040 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5041 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5042 return offline_page_data && offline_page_data->is_offline_page();
5043#else
5044 return false;
5045#endif
5046}
5047
Min Qin30a78a12017-12-06 01:29:135048bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5049 const GURL& url,
5050 const std::string& mime_type) {
5051#if BUILDFLAG(ENABLE_EXTENSIONS)
5052 // Special-case user scripts to get downloaded instead of viewed.
5053 return extensions::UserScript::IsURLUserScript(url, mime_type);
5054#else
5055 return false;
5056#endif
5057}
5058
Donna Wu838ac362018-08-10 10:36:335059void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345060 content::RenderFrameHost* render_frame_host,
Donna Wu838ac362018-08-10 10:36:335061 mojo::InterfaceRequest<blink::mojom::WebUsbService> request) {
Reilly Grantc31b8192017-12-15 19:54:345062 if (!base::FeatureList::IsEnabled(features::kWebUsb))
5063 return;
5064
Reilly Grantc31b8192017-12-15 19:54:345065 WebContents* web_contents =
5066 WebContents::FromRenderFrameHost(render_frame_host);
5067 if (!web_contents) {
5068 NOTREACHED();
5069 return;
5070 }
5071
5072 UsbTabHelper* tab_helper =
5073 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Donna Wu838ac362018-08-10 10:36:335074 tab_helper->CreateWebUsbService(render_frame_host, std::move(request));
Reilly Grantc31b8192017-12-15 19:54:345075}
5076
Reilly Grant0d282322019-01-29 02:42:585077#if !defined(OS_ANDROID)
5078content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5079 if (!serial_delegate_)
5080 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5081 return serial_delegate_.get();
5082}
Matt Reynolds93616f9b2019-06-07 01:28:525083
5084content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5085 if (!hid_delegate_)
5086 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5087 return hid_delegate_.get();
5088}
Reilly Grant0d282322019-01-29 02:42:585089
Balazs Engedya7ff70982018-06-04 18:14:475090std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5091ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:225092 content::RenderFrameHost* render_frame_host,
5093 const std::string& relying_party_id) {
5094 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
5095 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:475096}
Nina Satragno8c832df2019-07-29 15:59:395097#endif
Balazs Engedya7ff70982018-06-04 18:14:475098
Jun Cai9409ded2018-01-30 00:19:465099std::unique_ptr<net::ClientCertStore>
5100ChromeContentBrowserClient::CreateClientCertStore(
5101 content::ResourceContext* resource_context) {
5102 if (!resource_context)
5103 return nullptr;
5104 return ProfileIOData::FromResourceContext(resource_context)
5105 ->CreateClientCertStore();
5106}
5107
David Benjamineced01fc2019-02-27 18:29:025108std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395109ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585110 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025111 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035112 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245113 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395114 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035115 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395116 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565117 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:035118 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:025119 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:205120 std::move(response_headers), LoginHandler::PRE_COMMIT,
5121 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:395122}
5123
John Abd-El-Maleka67add82018-03-09 18:22:015124bool ChromeContentBrowserClient::HandleExternalProtocol(
5125 const GURL& url,
John Abd-El-Malek92bf3602019-07-31 02:25:485126 content::WebContents::Getter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015127 int child_id,
5128 content::NavigationUIData* navigation_data,
5129 bool is_main_frame,
5130 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455131 bool has_user_gesture,
Clark DuVallb6042ed32019-07-15 17:20:455132 network::mojom::URLLoaderFactoryPtr* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015133#if BUILDFLAG(ENABLE_EXTENSIONS)
5134 // External protocols are disabled for guests. An exception is made for the
5135 // "mailto" protocol, so that pages that utilize it work properly in a
5136 // WebView.
5137 ChromeNavigationUIData* chrome_data =
5138 static_cast<ChromeNavigationUIData*>(navigation_data);
5139 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5140 (chrome_data &&
5141 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5142 !url.SchemeIs(url::kMailToScheme)) {
5143 return false;
5144 }
5145#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5146
5147#if defined(OS_ANDROID)
5148 // Main frame external protocols are handled by
5149 // InterceptNavigationResourceThrottle.
5150 if (is_main_frame)
5151 return false;
5152#endif // defined(ANDROID)
5153
Eric Seckler8652dcd52018-09-20 10:42:285154 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
5155 base::BindOnce(&LaunchURL, url, web_contents_getter,
5156 page_transition, has_user_gesture));
John Abd-El-Maleka67add82018-03-09 18:22:015157 return true;
5158}
5159
Jennifer Apacible4f854a82018-04-06 22:22:115160std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285161ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5162 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115163 // Note: content::OverlayWindow::Create() is defined by platform-specific
5164 // implementation in chrome/browser/ui/views. This layering hack, which goes
5165 // through //content and ContentBrowserClient, allows us to work around the
5166 // dependency constraints that disallow directly calling
5167 // chrome/browser/ui/views code either from here or from other code in
5168 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285169 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115170}
5171
Clark DuVallfffa41e2019-06-25 20:27:195172bool ChromeContentBrowserClient::IsSafeRedirectTarget(
5173 const GURL& url,
5174 content::BrowserContext* context) {
5175#if BUILDFLAG(ENABLE_EXTENSIONS)
5176 if (url.SchemeIs(extensions::kExtensionScheme)) {
5177 const Extension* extension = extensions::ExtensionRegistry::Get(context)
5178 ->enabled_extensions()
5179 .GetByID(url.host());
5180 if (!extension)
5181 return false;
5182 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5183 extension, url.path());
5184 }
5185#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5186 return true;
5187}
5188
Kunihiko Sakamoto19aa7082019-02-25 03:14:435189void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565190 content::BrowserContext* browser_context,
Leon Hanf4003a162019-01-28 05:31:585191 blink::mojom::RendererPreferenceWatcherPtr watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565192 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435193 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5194 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565195}
5196
dbeam25472e0c2017-06-23 19:02:315197// Static; handles rewriting Web UI URLs.
5198bool ChromeContentBrowserClient::HandleWebUI(
5199 GURL* url,
5200 content::BrowserContext* browser_context) {
5201 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
5202 if (url->SchemeIs(content::kChromeUIScheme) &&
5203 (url->host() == chrome::kChromeUIHelpHost ||
5204 (url->host() == chrome::kChromeUIUberHost &&
5205 (url->path().empty() || url->path() == "/")))) {
5206 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5207 chrome::kChromeUIHelpHost);
5208 return true; // Return true to update the displayed URL.
5209 }
5210
5211 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5212 browser_context, *url)) {
5213 return false;
5214 }
5215
5216#if defined(OS_CHROMEOS)
5217 // Special case : in ChromeOS in Guest mode bookmarks and history are
5218 // disabled for security reasons. New tab page explains the reasons, so
5219 // we redirect user to new tab page.
5220 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5221 if (url->SchemeIs(content::kChromeUIScheme) &&
5222 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5223 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5224 // Rewrite with new tab URL
5225 *url = GURL(chrome::kChromeUINewTabURL);
5226 }
5227 }
5228#endif
5229
5230 return true;
5231}
5232
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065233bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5234 content::BrowserContext* browser_context,
5235 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325236 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065237#if defined(OS_ANDROID)
5238 return false;
5239#else
5240 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5241 ->GetForBrowserContext(browser_context)
5242 ->ShowPaymentHandlerWindow(url, std::move(callback));
5243 return true;
5244#endif
5245}
5246
dbeam25472e0c2017-06-23 19:02:315247// Static; reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
5248// "chrome://foo/".
5249bool ChromeContentBrowserClient::HandleWebUIReverse(
5250 GURL* url,
5251 content::BrowserContext* browser_context) {
5252 // No need to actually reverse-rewrite the URL, but return true to update the
5253 // displayed URL when rewriting chrome://help to chrome://settings/help.
5254 return url->SchemeIs(content::kChromeUIScheme) &&
5255 url->host() == chrome::kChromeUISettingsHost;
5256}
5257
Dan Beamf0a7e112019-06-07 18:40:585258const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
5259 return ui::NativeTheme::GetInstanceForWeb();
5260}
5261
scottmgde42fb92017-02-10 17:56:035262// static
michaeln10e5fc352017-02-07 02:07:585263void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
5264 const storage::QuotaSettings* settings) {
5265 g_default_quota_settings = settings;
5266}
Yuzhu Shen44094e22017-07-18 22:52:355267
Clark DuVall5497288d2019-07-17 00:17:565268scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505269ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
5270 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:355271 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5272
Yuzhu Shencb3011f62018-02-08 02:51:505273 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
5274 if (!io_data->safe_browsing_enabled()->GetValue())
5275 return nullptr;
5276
Yuzhu Shen44094e22017-07-18 22:52:355277 // |safe_browsing_service_| may be unavailable in tests.
5278 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5279 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435280 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355281 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435282 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355283 }
5284
Clark DuVall5497288d2019-07-17 00:17:565285 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355286}
Daniel Vogelheim6008f572018-09-24 14:35:145287
5288base::Optional<std::string>
5289ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:265290 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185291 content::NavigationHandle* handle) {
5292 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5293 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145294}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525295
Takashi Toyoshima5af383aa2019-07-22 15:24:225296bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525297 // We require --user-data-dir flag too so that no dangerous changes are made
5298 // in the user's regular profile.
5299 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5300 switches::kUserDataDir);
5301}
rajendrantfeea8592018-10-19 18:26:065302
5303void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5304 int32_t network_traffic_annotation_id_hash,
5305 int64_t recv_bytes,
5306 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035307 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5308 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5309 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5310 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065311 }
5312}
Ryan Sturmaa05092f2018-10-21 03:56:545313
5314content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5315 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395316 content::NavigationHandle* navigation_handle,
5317 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135318 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5319 initial_state, navigation_handle, current_navigation_url);
5320
5321 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5322}
5323
5324content::PreviewsState
5325ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5326 content::PreviewsState initial_state,
5327 content::NavigationHandle* navigation_handle,
5328 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545329 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295330 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215331
Ryan Sturmaa05092f2018-10-21 03:56:545332 // If this is not a main frame, return the initial state. If there are no
5333 // previews in the state, return the state as is.
5334 if (!navigation_handle->IsInMainFrame() ||
5335 navigation_handle->IsSameDocument()) {
5336 return initial_state;
5337 }
5338
Robert Ogdena994eb42019-02-14 19:15:085339 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395340 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085341
5342 // Do not allow previews on POST navigations since the primary opt-out
5343 // mechanism is to reload the page. Because POST navigations are not
5344 // idempotent, we do not want to show a preview on a POST navigation where
5345 // opting out would cause another navigation, i.e.: a reload.
5346 if (navigation_handle->IsPost())
5347 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395348
5349 content::WebContents* web_contents = navigation_handle->GetWebContents();
5350 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5351
Ryan Sturmda2a0e02018-10-25 01:52:215352 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545353
5354 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5355 Profile::FromBrowserContext(browser_context));
5356 auto* data_reduction_proxy_settings =
5357 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5358 browser_context);
5359 // If the profile does not support previews or Data Saver, do not turn on
5360 // Previews.
5361 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355362 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545363 return content::PREVIEWS_OFF;
5364 }
5365
5366 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215367 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545368 // If this tab does not have a PreviewsUITabHelper, no preview should be
5369 // served.
5370 if (!ui_tab_helper)
5371 return content::PREVIEWS_OFF;
5372
5373 DCHECK(!browser_context->IsOffTheRecord());
5374
5375 // Other previews objects should all exist and be initialized if we have made
5376 // it past earlier checks.
5377 previews::PreviewsDeciderImpl* previews_decider_impl =
5378 previews_service->previews_ui_service()->previews_decider_impl();
5379 DCHECK(previews_decider_impl);
5380
Ryan Sturm647d1d92018-11-07 15:41:395381 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545382 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5383
Ryan Sturm647d1d92018-11-07 15:41:395384 previews::PreviewsUserData* previews_data =
5385 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5386
5387 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315388 // previews) and cannot re-evaluate PreviewsState once previews triggering
5389 // logic has already been run, so they should not change. Assume that
5390 // previews triggering logic has run when PreviewsUserData already exists and
5391 // a Lite Page Redirect preview is not being attempted, since it may also
5392 // create a previews_data before this point.
5393 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395394 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315395 previews_triggering_logic_already_ran =
5396 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395397 } else {
5398 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5399 navigation_handle, previews_decider_impl->GeneratePageId());
5400 }
5401
5402 DCHECK(previews_data);
5403
Robert Ogden01770b362019-05-22 17:36:435404 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5405 previews::switches::kForceEnablePreviews)) {
5406 previews_decider_impl->LoadPageHints(current_navigation_url);
5407 return content::ALL_SUPPORTED_PREVIEWS;
5408 }
5409
Ryan Sturmaa05092f2018-10-21 03:56:545410 bool is_reload =
5411 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5412
Ryan Sturm647d1d92018-11-07 15:41:395413 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515414 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395415
5416 // For now, treat server previews types as a single decision, and do not
5417 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5418 // header, nor does the plumbing exist to modify the PreviewsState within the
5419 // URLLoader.
Seanac57e9b92019-04-29 19:19:315420 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395421 // Copy the server state that was used before the redirect for the initial
5422 // URL.
Robert Ogden869986f2019-06-20 19:12:055423 previews_state |=
5424 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395425 } else {
Doug Arnetta3dc71582018-11-08 00:25:105426 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Ryan Sturm647d1d92018-11-07 15:41:395427 previews_data, current_navigation_url, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305428 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395429 previews_state |= server_previews_enabled_state;
5430 }
Ryan Sturmaa05092f2018-10-21 03:56:545431 }
5432
Robert Ogden198d6572019-06-26 15:15:335433 // Evaluate Offline, NoScript, and ResourceBlocking previews.
Ryan Sturmaa05092f2018-10-21 03:56:545434 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315435 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355436 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5437 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545438
5439 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395440 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545441 return content::PREVIEWS_OFF;
5442 }
5443
5444 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395445 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545446 return content::PREVIEWS_NO_TRANSFORM;
5447 }
5448
5449 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395450 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5451 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545452 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395453 }
5454
5455 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5456 if (delegate) {
5457 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5458 }
Ryan Sturmaa05092f2018-10-21 03:56:545459
5460 // If the allowed previews are limited by the embedder, ensure previews honors
5461 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395462 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5463 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545464 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5465 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5466 previews_state = content::PREVIEWS_OFF;
5467 }
Ryan Sturm647d1d92018-11-07 15:41:395468 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545469 return previews_state;
5470}
5471
5472// static
5473content::PreviewsState
5474ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5475 const GURL& url,
5476 data_reduction_proxy::DataReductionProxyData* drp_data,
5477 previews::PreviewsUserData* previews_user_data,
5478 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055479 content::PreviewsState initial_state,
5480 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545481 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5482 if (!previews::HasEnabledPreviews(initial_state))
5483 return content::PREVIEWS_OFF;
5484
5485 // Check if the server sent a preview directive.
5486 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555487 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545488
Ryan Sturmaa05092f2018-10-21 03:56:545489 // Check the various other client previews types.
5490 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055491 previews_user_data, url, previews_state, previews_decider,
5492 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545493}
5494
5495content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5496 content::PreviewsState initial_state,
5497 content::NavigationHandle* navigation_handle,
5498 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135499 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5500 initial_state, navigation_handle, response_headers);
5501
5502 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5503}
5504
5505content::PreviewsState
5506ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5507 content::PreviewsState initial_state,
5508 content::NavigationHandle* navigation_handle,
5509 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545510 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5511 // Only support HTTP and HTTPS.
5512 if (navigation_handle->IsErrorPage() ||
5513 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5514 return content::PREVIEWS_OFF;
5515 }
5516
5517 // If this is not a main frame, return the initial state. If there are no
5518 // previews in the state, return the state as is.
5519 if (!previews::HasEnabledPreviews(initial_state) ||
5520 !navigation_handle->IsInMainFrame() ||
5521 navigation_handle->IsSameDocument()) {
5522 return initial_state;
5523 }
5524
5525 // WebContents that don't have a PreviewsUITabHelper are not supported.
5526 PreviewsUITabHelper* ui_tab_helper =
5527 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5528 if (!ui_tab_helper)
5529 return content::PREVIEWS_OFF;
5530
5531 // If we did not previously create a PreviewsUserData, do not go any further.
5532 previews::PreviewsUserData* previews_user_data =
5533 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5534 if (!previews_user_data)
5535 return content::PREVIEWS_OFF;
5536
5537 PreviewsService* previews_service =
5538 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5539 navigation_handle->GetWebContents()->GetBrowserContext()));
5540
5541 if (!previews_service || !previews_service->previews_ui_service())
5542 return content::PREVIEWS_OFF;
5543
5544// Check if offline previews are being used and set it in the user data.
5545#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5546 offline_pages::OfflinePageTabHelper* tab_helper =
5547 offline_pages::OfflinePageTabHelper::FromWebContents(
5548 navigation_handle->GetWebContents());
5549
Ryan Sturmfc7d92f2019-02-12 02:24:235550 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5551 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5552
5553 // If this is an offline page, but not a preview, then we should not attempt
5554 // any previews or surface the previews UI.
5555 if (is_offline_page && !is_offline_preview)
5556 return content::PREVIEWS_OFF;
5557
5558 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545559#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5560
5561 // Annotate request if no-transform directive found in response headers.
5562 if (response_headers &&
5563 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265564 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545565 }
5566
5567 previews::PreviewsDeciderImpl* previews_decider_impl =
5568 previews_service->previews_ui_service()->previews_decider_impl();
5569 DCHECK(previews_decider_impl);
5570
Clark DuVall9c5a72cc2018-10-25 01:29:215571 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5572 auto* settings =
5573 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5574 navigation_handle->GetWebContents()->GetBrowserContext());
5575 if (settings) {
5576 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5577 // does not yet have all the response information.
5578 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5579 response_headers);
5580 }
Ryan Sturmaa05092f2018-10-21 03:56:545581
5582 // Determine effective PreviewsState for this committed main frame response.
5583 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215584 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055585 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545586
5587 // Double check that we never serve a preview when we have a
5588 // cache-control:no-transform directive.
5589 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5590 !previews::HasEnabledPreviews(committed_state));
5591
Robert Ogdended292c6f2019-05-03 22:44:515592 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545593 previews_user_data->set_committed_previews_state(committed_state);
5594
5595 previews::PreviewsType committed_type =
5596 previews::GetMainFramePreviewsType(committed_state);
5597
5598 // Capture committed previews type, if any, in PreviewsUserData.
5599 // Note: this is for the subset of previews types that are decided upon
5600 // navigation commit. Previews types that are determined prior to
5601 // navigation (such as for offline pages or for redirecting to another
5602 // url), are not set here.
5603 previews_user_data->SetCommittedPreviewsType(committed_type);
5604
5605 // Log the commit decision.
5606 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5607 previews_decider_impl->LogPreviewDecisionMade(
5608 (previews_user_data->cache_control_no_transform_directive()
5609 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5610 : previews::PreviewsEligibilityReason::COMMITTED),
5611 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055612 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055613 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545614
5615 return committed_state;
5616}
Charlie Harrison650e11422018-12-04 00:37:265617
5618void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5619 content::RenderFrameHost* render_frame_host,
5620 blink::mojom::WebFeature feature) {
5621 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5622 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5623 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5624 render_frame_host, new_features);
5625}
Yutaka Hirano968d6252018-12-04 05:09:315626
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525627std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315628 return ::GetProduct();
5629}
5630
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525631std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315632 return ::GetUserAgent();
5633}
Sam McNallyd54e23f92019-01-16 04:42:395634
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525635blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175636 return ::GetUserAgentMetadata();
5637}
5638
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525639base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275640 // This icon is available on Android, but adds 19KiB to the APK. Since it
5641 // isn't used on Android we exclude it to avoid bloat.
5642#if !defined(OS_ANDROID)
5643 return base::Optional<gfx::ImageSkia>(
5644 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5645 IDR_PRODUCT_LOGO_256));
5646#else
5647 return base::nullopt;
5648#endif
5649}
5650
Sam McNallyd54e23f92019-01-16 04:42:395651bool ChromeContentBrowserClient::IsBuiltinComponent(
5652 content::BrowserContext* browser_context,
5653 const url::Origin& origin) {
5654#if BUILDFLAG(ENABLE_EXTENSIONS)
5655 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5656 browser_context, origin);
5657#else
5658 return false;
5659#endif
5660}
Oleg Davydov2cc0167b2019-02-05 14:32:485661
5662bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5663 const GURL& url,
5664 content::BrowserContext* context) {
5665 PolicyBlacklistService* service =
5666 PolicyBlacklistFactory::GetForBrowserContext(context);
5667
5668 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5669 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5670 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5671}
Dominic Mazzoni21fb0282019-02-13 18:32:475672
5673ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5674 content::BrowserContext* browser_context) {
5675 Profile* profile = Profile::FromBrowserContext(browser_context);
5676 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5677}
Eric Karld6cd75b2019-03-14 22:01:365678
5679#if defined(OS_ANDROID)
5680content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525681ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365682 if (features::UseDisplayWideColorGamut()) {
5683 return WideColorGamutHeuristic::kUseDisplay;
5684 }
5685 return WideColorGamutHeuristic::kNone;
5686}
5687#endif
Ehsan Karamad91413d72019-03-22 16:37:485688
5689base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435690ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465691 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485692 base::flat_set<std::string> mime_types;
5693#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465694 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485695 for (const auto& pair : map)
5696 mime_types.insert(pair.first);
5697#endif
5698 return mime_types;
5699}
Yao Xiaod06607b2019-05-02 23:16:365700
5701void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5702 const content::WebContents* web_contents,
5703 const content::RenderFrameHost* frame_host,
5704 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525705 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365706 const ChromeSubresourceFilterClient* client =
5707 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5708 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045709 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365710 if (!user_gesture) {
5711 if (base::FeatureList::IsEnabled(
5712 blink::features::
5713 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5714 download_policy->SetDisallowed(
5715 content::NavigationDownloadType::kAdFrameNoGesture);
5716 } else {
5717 download_policy->SetAllowed(
5718 content::NavigationDownloadType::kAdFrameNoGesture);
5719 }
Yao Xiaod06607b2019-05-02 23:16:365720 }
5721 }
5722}
Jun Cai732a05e32019-05-29 19:34:195723
5724bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5725 content::BrowserContext* browser_context,
5726 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525727 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195728 const HostContentSettingsMap* const content_settings =
5729 HostContentSettingsMapFactory::GetForProfile(
5730 Profile::FromBrowserContext(browser_context));
5731
5732 if (content_settings->GetContentSetting(
5733 requesting_origin.GetURL(), embedding_origin.GetURL(),
5734 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING,
5735 std::string()) == CONTENT_SETTING_BLOCK) {
5736 return true;
5737 }
5738
5739 return false;
5740}
5741
5742void ChromeContentBrowserClient::BlockBluetoothScanning(
5743 content::BrowserContext* browser_context,
5744 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525745 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195746 HostContentSettingsMap* const content_settings =
5747 HostContentSettingsMapFactory::GetForProfile(
5748 Profile::FromBrowserContext(browser_context));
5749
5750 content_settings->SetContentSettingDefaultScope(
5751 requesting_origin.GetURL(), embedding_origin.GetURL(),
5752 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(),
5753 CONTENT_SETTING_BLOCK);
5754}