blob: 6cdca1affb9fa937dac279ea257fc7c2b5a3d54a [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"
Ken Rockot91c40da82019-08-12 20:07:1116#include "base/compiler_specific.h"
Will Harrisc196ed942019-08-03 03:45:3017#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2418#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0019#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1520#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5821#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2522#include "base/metrics/field_trial_params.h"
evliuedcbb87d2019-11-22 19:49:4123#include "base/metrics/histogram_functions.h"
lazyboy5d5fede02016-03-10 04:10:1424#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3325#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3926#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0227#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3728#include "base/stl_util.h"
[email protected]e7463412013-06-10 22:53:4629#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0330#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2831#include "base/strings/string_util.h"
32#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2033#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0334#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2835#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3236#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4137#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1838#include "build/build_config.h"
Ken Rockot341089f2019-01-11 23:11:5839#include "chrome/app/chrome_content_browser_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"
Colin Blundell111b61c02020-01-24 11:53:5147#include "chrome/browser/captive_portal/captive_portal_service_factory.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"
Lily Chenc2c9e9f2019-12-05 19:55:3160#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4561#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0162#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1963#include "chrome/browser/font_family_cache.h"
Peng Huangee82ef82019-11-22 13:15:2964#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5265#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1066#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2767#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2768#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3469#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4270#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
71#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1672#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3673#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3674#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5675#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0476#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0577#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0778#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2379#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1080#include "chrome/browser/net/profile_network_context_service.h"
81#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5482#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0283#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5984#include "chrome/browser/notifications/platform_notification_service_impl.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"
Robert Ogdenea4ea7392020-01-25 01:44:5395#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3096#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.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 Ogden0f4d88682019-09-24 22:27:52103#include "chrome/browser/previews/previews_lite_page_redirect_decider.h"
104#include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.h"
Ryan Sturmaa05092f2018-10-21 03:56:54105#include "chrome/browser/previews/previews_service.h"
106#include "chrome/browser/previews/previews_service_factory.h"
107#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03108#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14109#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32110#include "chrome/browser/profiles/profile_io_data.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06111#include "chrome/browser/profiles/renderer_updater.h"
112#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56113#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
114#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44115#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38116#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40117#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45118#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31119#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
120#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24121#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Carlos IL4ee307e2018-12-22 03:19:00122#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40123#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35124#include "chrome/browser/safe_browsing/ui_manager.h"
125#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43126#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44127#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20128#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35129#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40130#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23131#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28132#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02133#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48134#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38135#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32136#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07137#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23138#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10139#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35140#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45141#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52142#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19143#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44144#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38145#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51146#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08147#include "chrome/browser/ui/browser_navigator.h"
148#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43149#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39150#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54151#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56152#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25153#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44154#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58155#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50156#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01157#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25158#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53159#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25160#include "chrome/browser/web_applications/components/app_registrar.h"
161#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23162#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22163#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01164#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48165#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51166#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14167#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22168#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30169#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02170#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50171#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34172#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37173#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12174#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19175#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12176#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22177#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32178#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38179#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28180#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02181#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09182#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47183#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37184#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18185#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30186#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12187#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53188#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51189#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49190#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44191#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04192#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48193#include "components/cloud_devices/common/cloud_devices_switches.h"
mukai8eaec822014-10-25 17:53:16194#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09195#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16196#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52197#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45198#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08199#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03200#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09201#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Clark DuVall0e901722019-08-14 23:31:37202#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
Ryan Sturmaa05092f2018-10-21 03:56:54203#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28204#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43205#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09206#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32207#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03208#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24209#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43210#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01211#include "components/feature_engagement/public/feature_constants.h"
212#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39213#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20214#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53215#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16216#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12217#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
218#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
219#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06220#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53221#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54222#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18223#include "components/policy/core/common/policy_service.h"
224#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26225#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54226#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08227#include "components/prefs/pref_service.h"
228#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21229#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54230#include "components/previews/content/previews_decider_impl.h"
231#include "components/previews/content/previews_ui_service.h"
232#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54233#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45234#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43235#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56236#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56237#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13238#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47239#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
240#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
241#include "components/safe_browsing/core/browser/url_checker_delegate.h"
242#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
243#include "components/safe_browsing/core/db/database_manager.h"
244#include "components/safe_browsing/core/features.h"
245#include "components/safe_browsing/core/realtime/policy_engine.h"
246#include "components/safe_browsing/core/verdict_cache_manager.h"
Daniel Vogelheim6008f572018-09-24 14:35:14247#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49248#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48249#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49250#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23251#include "components/signin/public/identity_manager/identity_manager.h"
csharrisone985ebc2017-04-04 17:05:03252#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17253#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21254#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28255#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33256#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46257#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22258#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43259#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30260#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38261#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28262#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03263#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31264#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41265#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09266#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03267#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59268#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19269#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31270#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35271#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47272#include "content/public/browser/navigation_handle.h"
273#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11274#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50275#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30276#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33277#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05278#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34279#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48280#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27281#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13282#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08283#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19284#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21285#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23286#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43287#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18288#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56289#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40290#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02291#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18292#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58293#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57294#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23295#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44296#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31297#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05298#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56299#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43300#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59301#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48302#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30303#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28304#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04305#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31306#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44307#include "media/media_buildflags.h"
308#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12309#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42310#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52311#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08312#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53313#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51314#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58315#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23316#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46317#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57318#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48319#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14320#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38321#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19322#include "printing/buildflags/buildflags.h"
Takashi Toyoshima128441462019-10-16 04:19:17323#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37324#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50325#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50326#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13327#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05328#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34329#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03330#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06331#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02332#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02333#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02334#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19335#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31336#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17337#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21338#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26339#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18340#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54341#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39342#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08343#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35344#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21345#include "ui/base/ui_base_switches.h"
Khushal1fc0da52019-10-09 00:38:56346#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21347#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49348#include "ui/native_theme/caption_style.h"
349#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57350#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45351#include "url/gurl.h"
352#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26353
[email protected]b48c9182011-10-26 18:03:30354#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20355#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38356#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36357#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18358#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38359#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25360#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38361#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30362#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42363#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30364#include "chrome/app/chrome_crash_reporter_client.h"
hashimotoa53e7e82016-10-26 06:30:47365#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17366#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30367#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24368#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18369#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08370#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48371#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41372#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32373#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58374#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00375#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
376#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44377#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39378#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31379#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33380#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44381#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10382#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36383#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27384#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31385#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10386#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21387#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10388#include "chromeos/constants/chromeos_switches.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11389#include "components/crash/content/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07390#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58391#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50392#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26393#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30394#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09395#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35396#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45397#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47398#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20399#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36400#include "chrome/browser/android/chrome_context_util.h"
401#include "chrome/browser/android/devtools_manager_delegate_android.h"
402#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
403#include "chrome/browser/android/service_tab_launcher.h"
404#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42405#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09406#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56407#include "chrome/browser/download/android/available_offline_content_provider.h"
408#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07409#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38410#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11411#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07412#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47413#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36414#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54415#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00416#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36417#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45418#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04419#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45420#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30421#elif defined(OS_POSIX)
422#include "chrome/browser/chrome_browser_main_posix.h"
423#endif
424
tmartinofb341882017-02-10 19:36:53425#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40426#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36427#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54428#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59429#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02430#include "chrome/browser/search/instant_service.h"
431#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46432#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51433#include "chrome/browser/ui/browser.h"
434#include "chrome/browser/ui/browser_finder.h"
435#include "chrome/browser/ui/browser_list.h"
436#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20437#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51438#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39439#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
440#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43441#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27442#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28443#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36444
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33445#if defined(OS_WIN) || defined(OS_MACOSX) || \
446 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52447#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12448#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52449#endif
450
Joshua Perazace68e2f2019-09-23 18:44:24451#if defined(OS_LINUX)
452#include "components/crash/content/app/crash_switches.h"
453#include "components/crash/content/app/crashpad.h"
454#endif
455
[email protected]a220b5932013-09-21 03:47:44456#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02457#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02458#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13459#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02460#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13461#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43462#endif
[email protected]b80f68432011-05-02 17:22:30463
Maggie Caia2f03f52019-04-02 02:13:28464// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
465// single navigation throttle to display the intent picker on all platforms.
466#if !defined(OS_ANDROID)
467#if defined(OS_CHROMEOS)
468#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51469#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28470#else
471#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
472#endif
473#endif
474
[email protected]e8b6ca02013-07-10 18:00:51475#if defined(TOOLKIT_VIEWS)
476#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
477#endif
478
estaded3aa0e82016-02-17 22:55:21479#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22480#if defined(USE_X11)
481#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
482#else
estaded3aa0e82016-02-17 22:55:21483#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22484#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51485#endif
486
Mohsen Izadif1958f22019-01-18 20:29:31487#if defined(USE_OZONE)
488#include "ui/ozone/public/ozone_platform.h"
489#endif
490
[email protected]e8b6ca02013-07-10 18:00:51491#if defined(USE_X11)
492#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
493#endif
494
brettwab78fef2016-10-12 02:56:05495#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10496#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38497#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19498#endif
499
Nico Weberaf3b00b2017-09-11 17:58:17500#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55501#include "components/nacl/browser/nacl_browser.h"
502#include "components/nacl/browser/nacl_host_message_filter.h"
503#include "components/nacl/browser/nacl_process_host.h"
504#include "components/nacl/common/nacl_process_type.h"
505#include "components/nacl/common/nacl_switches.h"
506#endif
507
brettw00899e62016-11-12 02:10:17508#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05509#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20510#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27511#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23512#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32513#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51514#include "chrome/browser/extensions/user_script_listener.h"
515#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28516#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49517#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46518#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39519#include "components/guest_view/browser/guest_view_base.h"
520#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25521#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31522#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35523#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32524#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12525#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57526#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48527#include "extensions/browser/guest_view/web_view/web_view_guest.h"
528#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
529#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31530#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27531#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28532#include "extensions/common/extension.h"
533#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13534#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28535#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33536#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28537#include "extensions/common/permissions/permissions_data.h"
538#include "extensions/common/permissions/socket_permission.h"
539#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34540#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25541
brettw4b461082016-11-19 18:55:16542#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55543#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27544#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39545#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55546#endif
547
bauerb8f9c37742017-03-30 15:04:12548#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
549#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
550#endif
551
yilkal240b4f22019-11-27 19:09:06552#if defined(OS_CHROMEOS)
553#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
554#endif // defined(OS_CHROMEOS)
555
thakis678822e2017-04-20 17:20:34556#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38557#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09558#endif
559
weilifabbf7572017-05-22 19:05:16560#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21561#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16562#endif
Lei Zhanga2fa14c2018-05-15 00:05:21563
Xiaohan Wanga4e41842018-06-26 18:45:10564#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49565#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26566#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10567#include "chrome/browser/media/widevine_hardware_caps_win.h"
568#include "third_party/widevine/cdm/widevine_cdm_common.h"
569#endif
570#endif
571
mmenkedb2637ff2017-03-30 23:59:42572#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
573#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
574#endif
575
Nico Weberbc5b06f2019-07-26 14:00:13576#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35577#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
578#endif
579
Jian Lide7b43792018-06-01 23:22:13580#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54581#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13582#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
583#endif
584
Will Cassella40837ba2019-07-01 21:32:00585#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43586#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
587#endif
588
John Lee0ee748bf2019-12-11 21:35:44589#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
590#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
591#endif
592
Roger Tawa03ffdbd2020-01-16 18:12:54593#if BUILDFLAG(FULL_SAFE_BROWSING)
594#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
595#endif
596
[email protected]c7abd422012-09-25 00:20:08597using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39598using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31599using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13600using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59601using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00602using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02603using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11604using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07605using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33606using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13607using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05608using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38609using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39610
[email protected]0daaebfe2014-03-15 00:09:05611#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20612using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05613#endif
614
brettw00899e62016-11-12 02:10:17615#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28616using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27617using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28618using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28619using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27620#endif
621
brettw4b461082016-11-19 18:55:16622#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55623using plugins::ChromeContentBrowserClientPluginsPart;
624#endif
625
[email protected]c5dbef02011-05-13 05:06:09626namespace {
627
brettw4b461082016-11-19 18:55:16628#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42629// TODO(teravest): Add renderer-side API-specific checking for these APIs so
630// that blanket permission isn't granted to all dev channel APIs for these.
631// http://crbug.com/386743
632const char* const kPredefinedAllowedDevChannelOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44633 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
634 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
[email protected]aec5ed52014-06-20 07:51:42635};
636
[email protected]9de4da52014-05-24 12:26:50637const char* const kPredefinedAllowedFileHandleOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44638 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
639 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
[email protected]10c39222013-11-13 20:09:25640};
641
[email protected]9de4da52014-05-24 12:26:50642const char* const kPredefinedAllowedSocketOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44643 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
644 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
645 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
646 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
647 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
Aran Gilmanf010bdd2019-08-28 19:55:44648 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
649 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
650 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
651 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
652 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
653 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
654 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
655 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
656 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
657 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
658 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
659 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
660 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40661};
[email protected]93f72062013-05-29 20:29:40662#endif
[email protected]e461da2f2012-02-16 19:06:40663
Will Harris1b9b4152019-08-21 22:33:50664#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30665// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
666// running on Windows 10 1511 and above. See
667// https://blogs.windows.com/blog/tag/code-integrity-guard/.
668const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35669 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50670#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
671 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30672
Colin Blundell9ee731dd2020-01-23 10:42:38673// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
674// parameters.
675void HandleSSLErrorWrapper(
676 content::WebContents* web_contents,
677 int cert_error,
678 const net::SSLInfo& ssl_info,
679 const GURL& request_url,
680 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38681 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
682 Profile* profile =
683 Profile::FromBrowserContext(web_contents->GetBrowserContext());
684
685 // This can happen if GetBrowserContext no longer exists by the time this
686 // gets called (e.g. the SSL error was in a webview that has since been
687 // destroyed); if that's the case we don't need to handle the error (and will
688 // crash if we attempt to).
689 if (!profile)
690 return;
691
Colin Blundell111b61c02020-01-24 11:53:51692 CaptivePortalService* captive_portal_service = nullptr;
693
694#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
695 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
696#endif
697
Colin Blundell9ee731dd2020-01-23 10:42:38698 SSLErrorHandler::HandleSSLError(
699 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53700 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51701 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38702 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38703 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
704}
705
lazyboy5d5fede02016-03-10 04:10:14706enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53707 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14708 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53709
710 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14711 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53712
713 // An extension or app tried to load a resource of a different platform app in
714 // a tab.
715 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
716
717 // A non-app and non-extension page tried to load a platform app in a tab.
718 APP_LOADED_IN_TAB_SOURCE_OTHER,
719
lazyboy5d5fede02016-03-10 04:10:14720 APP_LOADED_IN_TAB_SOURCE_MAX
721};
722
Lei Zhang2cfceac2018-11-14 19:36:33723// Cached version of the locale so we can return the locale on the I/O
724// thread.
725std::string& GetIOThreadApplicationLocale() {
726 static base::NoDestructor<std::string> s;
727 return *s;
728}
729
[email protected]f8f93eb2012-09-25 03:06:24730// Returns a copy of the given url with its host set to given host and path set
731// to given path. Other parts of the url will be the same.
732GURL ReplaceURLHostAndPath(const GURL& url,
733 const std::string& host,
734 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05735 url::Replacements<char> replacements;
736 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
737 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24738 return url.ReplaceComponents(replacements);
739}
740
madfbd10852017-01-20 03:15:33741// Handles the rewriting of the new tab page URL based on group policy.
742bool HandleNewTabPageLocationOverride(
743 GURL* url,
744 content::BrowserContext* browser_context) {
745 if (!url->SchemeIs(content::kChromeUIScheme) ||
746 url->host() != chrome::kChromeUINewTabHost)
747 return false;
748
749 Profile* profile = Profile::FromBrowserContext(browser_context);
750 std::string ntp_location =
751 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
752 if (ntp_location.empty())
753 return false;
754
755 *url = GURL(ntp_location);
756 return true;
757}
758
Becca Hughesfe8c32c2018-03-21 13:36:56759#if !defined(OS_ANDROID)
760// Check if the current url is whitelisted based on a list of whitelisted urls.
761bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57762 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56763 // Only check on HTTP and HTTPS pages.
764 if (!current_url.SchemeIsHTTPOrHTTPS())
765 return false;
766
767 for (auto const& value : whitelisted_urls) {
768 ContentSettingsPattern pattern =
769 ContentSettingsPattern::FromString(value.GetString());
770 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
771 continue;
772 if (pattern.Matches(current_url))
773 return true;
774 }
775
776 return false;
777}
778
779// Check if autoplay is allowed by policy configuration.
780bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
781 PrefService* prefs) {
782 DCHECK(prefs);
783
784 // Check if we have globally allowed autoplay by policy.
785 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
786 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
787 return true;
788 }
789
790 if (!contents)
791 return false;
792
793 // Check if the current URL matches a URL pattern on the whitelist.
794 const base::ListValue* autoplay_whitelist =
795 prefs->GetList(prefs::kAutoplayWhitelist);
796 return autoplay_whitelist &&
797 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
798 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
799}
800#endif
801
Joshua Perazaf890e4b2019-01-03 19:19:02802#if defined(OS_ANDROID)
803int GetCrashSignalFD(const base::CommandLine& command_line) {
804 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
805}
806#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03807breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
808 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02809 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52810 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02811 {
812 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31813 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03814 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50815 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02816 crash_handler->StartUploaderThread();
817 return crash_handler;
818 }
819}
820
avi3ef9ec9e2014-12-22 22:50:17821int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24822 if (crash_reporter::IsCrashpadEnabled()) {
823 int fd;
824 pid_t pid;
825 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
826 }
827
[email protected]9de4da52014-05-24 12:26:50828 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39829 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31830 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02831 if (!crash_handler)
832 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18833 return crash_handler->GetDeathSignalSocket();
834 }
835
836 std::string process_type =
837 command_line.GetSwitchValueASCII(switches::kProcessType);
838
[email protected]779dd282013-10-19 15:57:02839 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31840 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02841 if (!crash_handler)
842 crash_handler = CreateCrashHandlerHost(process_type);
843 return crash_handler->GetDeathSignalSocket();
844 }
[email protected]a1733df2012-06-22 11:24:18845
[email protected]779dd282013-10-19 15:57:02846 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31847 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02848 if (!crash_handler)
849 crash_handler = CreateCrashHandlerHost(process_type);
850 return crash_handler->GetDeathSignalSocket();
851 }
[email protected]a1733df2012-06-22 11:24:18852
[email protected]779dd282013-10-19 15:57:02853 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31854 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02855 if (!crash_handler)
856 crash_handler = CreateCrashHandlerHost(process_type);
857 return crash_handler->GetDeathSignalSocket();
858 }
[email protected]a1733df2012-06-22 11:24:18859
James Cook9207cc12017-10-19 17:08:39860 if (process_type == switches::kUtilityProcess) {
861 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
862 if (!crash_handler)
863 crash_handler = CreateCrashHandlerHost(process_type);
864 return crash_handler->GetDeathSignalSocket();
865 }
866
[email protected]a1733df2012-06-22 11:24:18867 return -1;
868}
Joshua Perazaf890e4b2019-01-03 19:19:02869#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18870
[email protected]eabbfb12013-04-05 23:28:35871void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52872 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33873 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35874}
875
estark3ba11132015-04-10 01:38:33876// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31877// SSLErrorHandler. Uses CertificateReportingService to send reports. The
878// service handles queueing and re-sending of failed reports. Each certificate
879// error creates a new instance of this class.
880class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33881 public:
meacerf43117a2016-12-27 21:02:31882 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12883 content::WebContents* web_contents)
884 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
885 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31886 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33887
888 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55889 void ReportInvalidCertificateChain(
890 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31891 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33892 }
893
894 private:
meacerf43117a2016-12-27 21:02:31895 CertificateReportingService* service_;
896
897 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33898};
899
bshe4f53ce42015-11-30 16:56:31900#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05901float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59902 static const float kMinFSM = 1.05f;
903 static const int kWidthForMinFSM = 320;
904 static const float kMaxFSM = 1.3f;
905 static const int kWidthForMaxFSM = 800;
906
boliu21c5afa2017-01-11 19:34:23907 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59908
909 if (minWidth <= kWidthForMinFSM)
910 return kMinFSM;
911 if (minWidth >= kWidthForMaxFSM)
912 return kMaxFSM;
913
914 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
915 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
Aran Gilmanf010bdd2019-08-28 19:55:44916 (kWidthForMaxFSM - kWidthForMinFSM);
[email protected]b255a8e0e82013-10-22 04:03:59917 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
918}
zpengdb4a58e2017-01-10 17:40:32919
[email protected]916615b2013-09-11 18:19:44920#endif // defined(OS_ANDROID)
921
brettw00899e62016-11-12 02:10:17922#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53923
924AppLoadedInTabSource ClassifyAppLoadedInTabSource(
925 const GURL& opener_url,
926 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58927 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
928 // The forbidden app URL was being opened by a non-extension page (e.g.
929 // http).
930 return APP_LOADED_IN_TAB_SOURCE_OTHER;
931 }
932
933 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53934 // The forbidden app URL was being opened by a different app or extension.
935 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
936 }
Lei Zhang7d0b0f42019-10-12 03:47:58937
938 // This platform app was trying to window.open() one of its own URLs.
939 if (opener_url ==
940 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
941 // Source was the background page.
942 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
943 }
944
945 // Source was a different page inside the app.
946 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53947}
[email protected]9c7656382014-08-08 21:02:30948
Charles Harrison34f67862017-08-22 01:04:17949// Returns true if there is is an extension matching |url| in
950// |opener_render_process_id| with APIPermission::kBackground.
951//
952// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
953// hosted app, even though normal extensions just use the host.
954bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35955 extensions::ProcessMap* process_map,
956 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17957 const GURL& url,
csharrison95f01e922017-04-24 18:52:35958 int opener_render_process_id) {
959 // Note: includes web URLs that are part of an extension's web extent.
960 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17961 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35962 return extension &&
963 extension->permissions_data()->HasAPIPermission(
964 APIPermission::kBackground) &&
965 process_map->Contains(extension->id(), opener_render_process_id);
966}
Kevin Marshall32f99d7e2017-07-11 23:17:46967
csharrison95f01e922017-04-24 18:52:35968#endif
969
Darin Fishere41aab52020-01-29 18:31:23970mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12971 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23972 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
973 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
974 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
975 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12976}
977
John Abd-El-Malek92bf3602019-07-31 02:25:48978void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04979 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48980 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45981 bool has_user_gesture,
982 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01983 // If there is no longer a WebContents, the request may have raced with tab
984 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04985 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01986 if (!web_contents)
987 return;
988
989 // Do not launch external requests attached to unswapped prerenders.
990 prerender::PrerenderContents* prerender_contents =
991 prerender::PrerenderContents::FromWebContents(web_contents);
992 if (prerender_contents) {
993 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
994 prerender::ReportPrerenderExternalURL();
995 return;
996 }
997
Robbie McElrath1294d242019-05-31 20:46:22998 // Do not launch external requests for schemes that have a handler registered.
999 ProtocolHandlerRegistry* protocol_handler_registry =
1000 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1001 web_contents->GetBrowserContext());
1002 if (protocol_handler_registry &&
1003 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1004 return;
1005
John Abd-El-Maleka67add82018-03-09 18:22:011006 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:011007 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:191008 PolicyBlacklistFactory::GetForBrowserContext(
1009 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:011010 if (service) {
1011 const policy::URLBlacklist::URLBlacklistState url_state =
1012 service->GetURLBlacklistState(url);
1013 is_whitelisted =
1014 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1015 }
1016
1017 // If the URL is in whitelist, we launch it without asking the user and
1018 // without any additional security checks. Since the URL is whitelisted,
1019 // we assume it can be executed.
1020 if (is_whitelisted) {
1021 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1022 } else {
1023 ExternalProtocolHandler::LaunchUrl(
1024 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1025 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451026 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011027 }
1028}
1029
Yutaka Hirano968d6252018-12-04 05:09:311030std::string GetProduct() {
1031 return version_info::GetProductNameAndVersionForUserAgent();
1032}
1033
Lukasz Anforowicz60d1253d2019-05-08 16:31:371034void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1035 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1036 // For renderer and utility (e.g. NetworkService) processes the switch is the
1037 // only available source, so below the combined (pref/policy + cmdline)
1038 // allowlist of secure origins is injected into |cmdline| for these other
1039 // processes.
1040 std::vector<std::string> allowlist =
1041 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1042 if (!allowlist.empty()) {
1043 cmdline->AppendSwitchASCII(
1044 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1045 base::JoinString(allowlist, ","));
1046 }
1047}
1048
Will Harris1b9b4152019-08-21 22:33:501049#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301050// Returns the full path to |module_name|. Both dev builds (where |module_name|
1051// is in the current executable's directory) and proper installs (where
1052// |module_name| is in a versioned sub-directory of the current executable's
1053// directory) are supported. The identified file is not guaranteed to exist.
1054base::FilePath GetModulePath(base::StringPiece16 module_name) {
1055 base::FilePath exe_dir;
1056 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1057 DCHECK(has_path);
1058
1059 // Look for the module in a versioned sub-directory of the current
1060 // executable's directory and return the path if it can be read. This is the
1061 // expected location of modules for proper installs.
1062 const base::FilePath module_path =
1063 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1064 if (base::PathExists(module_path))
1065 return module_path;
1066
1067 // Otherwise, return the path to the module in the current executable's
1068 // directory. This is the expected location of modules for dev builds.
1069 return exe_dir.Append(module_name);
1070}
Will Harris1b9b4152019-08-21 22:33:501071#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1072 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301073
Lukasz Anforowicz7724d092019-10-03 23:50:211074void MaybeAddThrottle(
1075 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles,
1076 std::unique_ptr<content::NavigationThrottle> maybe_throttle) {
1077 if (maybe_throttle)
1078 throttles->push_back(std::move(maybe_throttle));
1079}
1080
Evan Stade1e71d6dd2019-10-29 03:04:491081// Returns whether |web_contents| is within a hosted app.
1082bool IsInHostedApp(WebContents* web_contents) {
1083#if BUILDFLAG(ENABLE_EXTENSIONS)
1084 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1085 return (browser &&
1086 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1087#else
1088 return false;
1089#endif
1090}
1091
Lily Chenc2c9e9f2019-12-05 19:55:311092void MaybeRecordSameSiteCookieEngagementHistogram(
1093 content::RenderFrameHost* render_frame_host,
1094 blink::mojom::WebFeature feature) {
1095 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1096 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1097 return;
1098 }
1099
1100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1101 DCHECK(render_frame_host);
1102
1103 content::BrowserContext* browser_context =
1104 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1105 Profile* profile = Profile::FromBrowserContext(browser_context);
1106 SiteEngagementService* site_engagement_service =
1107 SiteEngagementService::Get(profile);
1108 if (!site_engagement_service)
1109 return;
1110
1111 blink::mojom::EngagementLevel engagement_level =
1112 site_engagement_service->GetEngagementLevel(
1113 render_frame_host->GetLastCommittedURL());
1114 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1115 UMA_HISTOGRAM_ENUMERATION(
1116 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1117 engagement_level);
1118 } else {
1119 UMA_HISTOGRAM_ENUMERATION(
1120 "Net.SameSiteBlockedCookieSiteEngagement."
1121 "CookieInsecureAndSameSiteNone",
1122 engagement_level);
1123 }
1124}
1125
[email protected]9dbfff12011-07-01 19:37:071126} // namespace
[email protected]c5dbef02011-05-13 05:06:091127
Yutaka Hirano968d6252018-12-04 05:09:311128std::string GetUserAgent() {
1129 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1130 if (command_line->HasSwitch(switches::kUserAgent)) {
1131 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1132 if (net::HttpUtil::IsValidHeaderValue(ua))
1133 return ua;
1134 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1135 }
1136
John Delaneyac24e572019-04-30 19:47:021137 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1138 return content::GetFrozenUserAgent(
1139 command_line->HasSwitch(switches::kUseMobileUserAgent))
1140 .as_string();
1141 }
1142
Yutaka Hirano968d6252018-12-04 05:09:311143 std::string product = GetProduct();
1144#if defined(OS_ANDROID)
1145 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1146 product += " Mobile";
1147#endif
1148 return content::BuildUserAgentFromProduct(product);
1149}
1150
Mike West6e4cbb32019-02-13 09:40:171151blink::UserAgentMetadata GetUserAgentMetadata() {
1152 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171153 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301154 metadata.full_version = version_info::GetVersionNumber();
1155 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171156 metadata.platform = version_info::GetOSType();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361157 metadata.architecture = content::BuildCpuInfo();
1158 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171159
Aaron Tagliaboschibe775e12019-12-09 19:33:041160 // TODO(crbug.com/1031511): Integrate DevTools and "Request Desktop Site"
1161 metadata.mobile = false;
1162#if defined(OS_ANDROID)
1163 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1164 switches::kUseMobileUserAgent);
1165#endif
1166
Mike West6e4cbb32019-02-13 09:40:171167 return metadata;
1168}
1169
Ran Jia96d43d42018-05-02 17:14:531170ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051171 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311172 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161173#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371174 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421175 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371176 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251177 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371178 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401179 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551180
1181 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401182#endif
[email protected]1deace22013-05-22 06:14:461183
Ahmed Fakhryd70bf37b2018-04-04 17:07:241184#if defined(OS_CHROMEOS)
1185 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1186#endif // defined(OS_CHROMEOS)
1187
John Lee0ee748bf2019-12-11 21:35:441188#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1189 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1190#endif
1191
brettw00899e62016-11-12 02:10:171192#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131193 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271194#endif
bena06f7d62017-04-04 20:48:521195
Sigurdur Asgeirsson70696672019-02-08 16:14:511196 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401197}
1198
1199ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031200 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1201 delete extra_parts_[i];
1202 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401203}
1204
[email protected]bca18382012-06-25 19:15:231205// static
Chris Palmerac7d75642017-11-22 20:12:541206void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1207 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131208 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1209 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541210 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1211 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461212 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541213}
1214
1215// static
[email protected]37ca3fe02013-07-05 15:32:441216void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341217 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251218 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1219 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1220 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281221 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1222 // user policy in addition to the same named ones in Local State (which are
1223 // used for mapping the command-line flags).
1224 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1225 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571226 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401227 registry->RegisterDictionaryPref(
1228 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041229 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101230#if !defined(OS_ANDROID)
1231 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561232 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101233#endif
Takashi Toyoshima128441462019-10-16 04:19:171234 registry->RegisterListPref(prefs::kCorsMitigationList);
1235 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231236}
1237
[email protected]eabbfb12013-04-05 23:28:351238// static
1239void ChromeContentBrowserClient::SetApplicationLocale(
1240 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481241 // The common case is that this function is called early in Chrome startup
1242 // before any threads are created or registered. When there are no threads,
1243 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001244 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331245 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481246 return;
1247 }
1248
1249 // Otherwise we're being called to change the locale. In this case set it on
1250 // the IO thread.
thestig00844cea2015-09-08 21:44:521251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351252
Sami Kyostila5e1306d2019-08-14 11:01:291253 base::PostTask(FROM_HERE, {BrowserThread::IO},
1254 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351255}
1256
Patrick Monette61dfef92019-05-30 23:06:271257std::unique_ptr<content::BrowserMainParts>
1258ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311259 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271260 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301261 // Construct the Main browser parts based on the OS type.
1262#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051263 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271264 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1265#elif defined(OS_MACOSX)
1266 main_parts =
1267 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1268#elif defined(OS_CHROMEOS)
1269 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1270 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261271#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271272 main_parts =
1273 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141274#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271275 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1276 startup_data_);
[email protected]b48c9182011-10-26 18:03:301277#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271278 main_parts =
1279 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041280#else
[email protected]b48c9182011-10-26 18:03:301281 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271282 main_parts =
1283 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301284#endif
1285
Xi Han9fd44002019-04-30 17:39:361286 bool add_profiles_extra_parts = true;
1287#if defined(OS_ANDROID)
1288 if (startup_data_->HasBuiltProfilePrefService())
1289 add_profiles_extra_parts = false;
1290#endif
1291 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271292 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031293
Xi Han9fd44002019-04-30 17:39:361294 // Construct additional browser parts. Stages are called in the order in
1295 // which they are added.
[email protected]c7480942011-11-08 19:18:271296#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221297#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1298#if defined(USE_X11)
1299 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1300#else
estaded3aa0e82016-02-17 22:55:211301 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221302#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211303#else
riajiang7d6ec5c2017-01-25 16:40:331304 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351305#endif
1306#endif
1307
1308#if defined(OS_CHROMEOS)
1309 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331310 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221311#endif
[email protected]dc04be7c2012-03-15 23:57:491312
[email protected]e8b6ca02013-07-10 18:00:511313#if defined(USE_X11)
1314 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241315#endif
1316
Sigurdur Asgeirsson54b72702019-04-12 14:18:541317 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001318
Albert J. Wong59d85acb2017-08-10 00:50:571319 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571320
Sebastien Marchand8c0088102019-10-11 16:47:561321 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1322
Peng Huangee82ef82019-11-22 13:15:291323 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1324
Patrick Monette61dfef92019-05-30 23:06:271325 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041326
[email protected]50462bf02011-11-21 19:13:311327 return main_parts;
[email protected]f967b722011-09-07 00:58:041328}
1329
michaeln96f887e22015-04-13 23:58:311330void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091331 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021332 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211333 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121334 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291335
Robert Sesek466e43e2019-08-19 22:02:021336 InitNetworkContextsParentDirectory();
1337
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291338 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1339 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311340}
1341
falkenb09d443f2016-04-07 12:36:121342bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1343 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1344}
1345
Gabriel Charettec8cca992017-08-10 18:21:491346void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1347 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1348}
1349
John Abd-El-Malek9d57f9c2019-02-20 18:50:041350bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361351 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041352}
1353
[email protected]e94bbcb2012-09-07 05:33:571354std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191355 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571356 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531357 std::string partition_id;
1358
1359 // The partition ID for webview guest processes is the string value of its
1360 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451361 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531362 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171363#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501364 // The partition ID for extensions with isolated storage is treated similarly
1365 // to the above.
1366 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1367 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1368 partition_id = site.spec();
1369#endif
[email protected]1bc28312012-11-08 08:31:531370
[email protected]056efdc2013-04-06 00:14:531371 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531372 return partition_id;
1373}
1374
1375bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1376 content::BrowserContext* browser_context,
1377 const std::string& partition_id) {
1378 // The default ID is empty and is always valid.
1379 if (partition_id.empty())
1380 return true;
1381
1382 return GURL(partition_id).is_valid();
1383}
1384
1385void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1386 content::BrowserContext* browser_context,
1387 const GURL& site,
[email protected]14acc642012-11-17 12:20:101388 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531389 std::string* partition_domain,
1390 std::string* partition_name,
1391 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101392 // Default to the browser-wide storage partition and override based on |site|
1393 // below.
1394 partition_domain->clear();
1395 partition_name->clear();
1396 *in_memory = false;
1397
brettw00899e62016-11-12 02:10:171398#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451399 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331400 site, partition_domain, partition_name, in_memory);
1401
1402 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101403 // If |can_be_default| is false, the caller is stating that the |site|
1404 // should be parsed as if it had isolated storage. In particular it is
1405 // important to NOT check ExtensionService for the is_storage_isolated()
1406 // attribute because this code path is run during Extension uninstall
1407 // to do cleanup after the Extension has already been unloaded from the
1408 // ExtensionService.
1409 bool is_isolated = !can_be_default;
1410 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341411 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1412 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101413 }
[email protected]1bc28312012-11-08 08:31:531414
[email protected]14acc642012-11-17 12:20:101415 if (is_isolated) {
1416 CHECK(site.has_host());
1417 // For extensions with isolated storage, the the host of the |site| is
1418 // the |partition_domain|. The |in_memory| and |partition_name| are only
1419 // used in guest schemes so they are cleared here.
1420 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531421 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101422 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531423 }
[email protected]1df3d972014-06-11 04:55:181424 success = true;
1425 }
1426#endif
1427
[email protected]14acc642012-11-17 12:20:101428 // Assert that if |can_be_default| is false, the code above must have found a
1429 // non-default partition. If this fails, the caller has a serious logic
1430 // error about which StoragePartition they expect to be in and it is not
1431 // safe to continue.
1432 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441433}
1434
[email protected]38b098f2012-03-14 21:11:571435content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441436ChromeContentBrowserClient::GetWebContentsViewDelegate(
1437 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101438 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321439}
1440
Bo Liu4ade6b1b22017-11-28 02:26:351441bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1442#if defined(OS_ANDROID)
1443 const base::android::ApplicationState app_state =
1444 base::android::ApplicationStatusListener::GetState();
1445 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1446 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1447 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1448#else
1449 return true;
1450#endif
1451}
1452
[email protected]6f2862742013-12-20 07:53:191453void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231454 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301455 int id = host->GetID();
1456 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341457#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491458 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061459#endif
Brett Wilson65f951c2016-11-03 22:06:121460#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401461 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031462#endif
[email protected]ba780c12013-10-01 17:07:061463 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
Darin Fisher8c84328c2019-07-23 02:50:001464
Darin Fisher09aa7222019-08-29 09:27:361465 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001466 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021467
grunell086a4112017-03-02 09:23:041468 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1469 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021470 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121471 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021472 host->SetUserData(
1473 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091474 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021475 audio_debug_recordings_handler));
1476
Nico Weberaf3b00b2017-09-11 17:58:171477#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031478 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1479 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351480#endif
jeremyim364ac1182015-03-03 18:49:431481
Xiaohan Wang9b34281b2017-09-08 23:48:331482#if defined(OS_ANDROID)
1483 // Data cannot be persisted if the profile is off the record.
1484 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061485 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071486
1487 // Register CrashMemoryMetricsCollector to report oom related metrics.
1488 host->SetUserData(
1489 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1490 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331491#endif
1492
Jun Caidb3f93cc2018-07-09 21:54:551493 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061494 RendererUpdaterFactory::GetForProfile(original_profile)
1495 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071496
[email protected]a48ab7112014-08-01 16:48:031497 for (size_t i = 0; i < extra_parts_.size(); ++i)
1498 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141499}
1500
[email protected]3d7474ff2011-07-27 17:47:371501GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571502 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301503 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371504 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521505 if (!profile)
1506 return url;
1507
Marc Treib7d467b792017-12-04 13:31:031508#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291509 // If the input |url| should be assigned to the Instant renderer, make its
1510 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311511 // This needs to happen even if |url| corresponds to an isolated origin; see
1512 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131513 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1514 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031515#endif
[email protected]b3cb3a32013-07-31 01:32:291516
brettw00899e62016-11-12 02:10:171517#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301518 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1519 url);
[email protected]d5a74be2014-08-08 01:01:271520#else
1521 return url;
1522#endif
[email protected]36fb2c7c2011-04-04 15:49:081523}
1524
Alexander Yashkin6aedc6e2018-08-15 08:58:451525bool ChromeContentBrowserClient::
1526 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1527 content::BrowserContext* browser_context,
1528 content::SiteInstance* candidate_site_instance,
1529 bool is_main_frame,
1530 const GURL& candidate_url,
1531 const GURL& destination_url) {
1532 DCHECK(browser_context);
1533 DCHECK(candidate_site_instance);
1534#if BUILDFLAG(ENABLE_EXTENSIONS)
1535 return ChromeContentBrowserClientExtensionsPart::
1536 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1537 browser_context, candidate_site_instance, is_main_frame,
1538 candidate_url, destination_url);
1539#else
1540 return true;
1541#endif
1542}
1543
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521544bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411545#if defined(OS_ANDROID)
1546 return true;
1547#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421548 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411549#else
1550 return false;
1551#endif // defined(OS_ANDROID)
1552}
1553
[email protected]056ad2a2011-07-12 02:13:551554bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441555 content::BrowserContext* browser_context,
1556 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521557 Profile* profile = Profile::FromBrowserContext(browser_context);
1558 if (!profile)
1559 return false;
1560
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301561 // NTP should use process-per-site. This is a performance optimization to
1562 // reduce process count associated with NTP tabs.
1563 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1564 return true;
Peter Boström8e9b1632019-08-22 23:12:471565
1566 // The web footer experiment should share its renderer to not effectively
1567 // instantiate one per window. See https://crbug.com/993502.
1568 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1569 return true;
1570
Marc Treib7d467b792017-12-04 13:31:031571#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131572 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521573 return true;
Marc Treib7d467b792017-12-04 13:31:031574#endif
[email protected]c5dec6292013-01-25 04:54:521575
brettw00899e62016-11-12 02:10:171576#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301577 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1578 profile, effective_url))
1579 return true;
[email protected]d5a74be2014-08-08 01:01:271580#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301581
1582 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1583 // (rather than process-per-site).
1584 return false;
[email protected]056ad2a2011-07-12 02:13:551585}
1586
Lukasz Anforowicz32d27122018-04-09 21:48:331587bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1588 content::BrowserContext* browser_context,
1589 const GURL& site_url) {
1590 Profile* profile = Profile::FromBrowserContext(browser_context);
1591 if (!profile)
1592 return false;
1593
1594#if !defined(OS_ANDROID)
1595 // Instant renderers should not use a spare process, because they require
1596 // passing switches::kInstantProcess to the renderer process when it
1597 // launches. A spare process is launched earlier, before it is known which
1598 // navigation will use it, so it lacks this flag.
1599 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1600 return false;
1601#endif
1602
1603#if BUILDFLAG(ENABLE_EXTENSIONS)
1604 return ChromeContentBrowserClientExtensionsPart::
1605 ShouldUseSpareRenderProcessHost(profile, site_url);
1606#else
1607 return true;
1608#endif
1609}
1610
nickcc0d9142015-10-14 16:27:101611bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421612 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101613 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421614 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171615#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101616 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421617 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101618 return true;
1619 }
1620#endif
1621 return false;
1622}
1623
nick7d0984c2015-08-29 00:13:461624// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1625// origin-lock enforcement, where we don't have a way to efficiently know
1626// effective URLs on the IO thread, and wind up killing processes that e.g.
1627// request cookies for their actual URL. This whole function (and its
1628// ExtensionsPart) should be removed once we add that ability to the IO thread.
1629bool ChromeContentBrowserClient::ShouldLockToOrigin(
1630 content::BrowserContext* browser_context,
1631 const GURL& effective_site_url) {
1632 // Origin lock to the search scheme would kill processes upon legitimate
1633 // requests for cookies from the search engine's domain.
1634 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1635 return false;
1636
brettw00899e62016-11-12 02:10:171637#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461638 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1639 browser_context, effective_site_url)) {
1640 return false;
1641 }
1642#endif
1643 return true;
creise5d6d1732015-08-25 19:47:061644}
1645
Maks Orlovich0e23e312019-07-16 13:13:561646bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021647 base::StringPiece scheme,
1648 bool is_embedded_origin_secure) {
1649 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1650 return true;
Maks Orlovich0e23e312019-07-16 13:13:561651#if BUILDFLAG(ENABLE_EXTENSIONS)
1652 return scheme == extensions::kExtensionScheme;
1653#else
1654 return false;
1655#endif
1656}
1657
Lily Chen0db055b2019-11-15 20:29:021658bool ChromeContentBrowserClient::
1659 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1660 base::StringPiece scheme,
1661 bool is_embedded_origin_secure) {
1662 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1663}
1664
Lukasz Anforowicz7097890d2019-11-20 21:49:221665void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021666 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591667 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021668 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221669 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071670#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221671 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021672 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071673#endif
1674}
1675
[email protected]73b718f2014-01-27 02:59:461676// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1677// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411678void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1679 std::vector<std::string>* additional_schemes) {
1680 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241681 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351682 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061683}
1684
alexmos94875b3b2017-03-16 22:19:011685void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1686 std::vector<std::string>* additional_schemes) {
1687 GetAdditionalWebUISchemes(additional_schemes);
1688
1689#if BUILDFLAG(ENABLE_EXTENSIONS)
1690 additional_schemes->push_back(extensions::kExtensionScheme);
1691#endif
1692}
1693
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521694bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011695 return webui::LogWebUIUrl(web_ui_url);
1696}
1697
John Abd-El-Malek04bfa8532018-07-12 05:28:221698bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1699 const url::Origin& origin) {
1700 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1701 origin);
1702}
1703
[email protected]46fb9442011-12-09 17:57:471704bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1705 return ProfileIOData::IsHandledURL(url);
1706}
1707
[email protected]c4365fa42013-05-14 01:08:241708bool ChromeContentBrowserClient::CanCommitURL(
1709 content::RenderProcessHost* process_host,
1710 const GURL& url) {
brettw00899e62016-11-12 02:10:171711#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441712 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1713 url);
[email protected]d5a74be2014-08-08 01:01:271714#else
1715 return true;
1716#endif
[email protected]c4365fa42013-05-14 01:08:241717}
1718
rdevlin.cronina32a0902016-11-09 15:50:201719void ChromeContentBrowserClient::OverrideNavigationParams(
1720 SiteInstance* site_instance,
1721 ui::PageTransition* transition,
1722 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581723 content::Referrer* referrer,
1724 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201725 DCHECK(transition);
1726 DCHECK(is_renderer_initiated);
1727 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471728 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1729 // use for making security decisions 99.44% of the time, for detecting the NTP
1730 // it is reliable and the correct way. See http://crbug.com/624410.
1731 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201732 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581733 // Clicks on tiles of the new tab page should be treated as if a user
1734 // clicked on a bookmark. This is consistent with native implementations
1735 // like Android's. This also helps ensure that security features (like
1736 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1737 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201738 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1739 *is_renderer_initiated = false;
1740 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581741 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421742 }
1743}
1744
Charles Reis29e9dd12017-09-28 00:59:151745bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1746 const GURL& url,
1747 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471748 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1749 // use for making security decisions 99.44% of the time, for detecting the NTP
1750 // it is reliable and the correct way. See http://crbug.com/624410.
1751 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1752 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151753}
1754
[email protected]2a5221b2011-09-27 23:07:311755bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301756 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311757 const GURL& site_url) {
1758 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301759 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441760 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521761 // share any host.
1762 if (!profile)
1763 return true;
1764
Marc Treib7895941d2017-11-28 12:37:021765#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141766 // Instant URLs should only be in the instant process and instant process
1767 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521768 InstantService* instant_service =
1769 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141770 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441771 bool is_instant_process =
1772 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141773 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131774 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141775 if (is_instant_process || should_be_in_instant_process)
1776 return is_instant_process && should_be_in_instant_process;
1777 }
Marc Treib7895941d2017-11-28 12:37:021778#endif
[email protected]c5dec6292013-01-25 04:54:521779
brettw00899e62016-11-12 02:10:171780#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131781 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1782 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271783#else
1784 return true;
1785#endif
[email protected]2a5221b2011-09-27 23:07:311786}
1787
[email protected]28c5d0b72014-05-13 08:19:591788bool ChromeContentBrowserClient::MayReuseHost(
1789 content::RenderProcessHost* process_host) {
1790 // If there is currently a prerender in progress for the host provided,
1791 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041792 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591793 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371794 prerender::PrerenderManagerFactory::GetForBrowserContext(
1795 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591796 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491797 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591798 return false;
1799 }
1800
1801 return true;
1802}
1803
[email protected]76411f412012-02-22 18:56:061804bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441805 content::BrowserContext* browser_context,
1806 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061807 // It has to be a valid URL for us to check for an extension.
1808 if (!url.is_valid())
1809 return false;
1810
brettw00899e62016-11-12 02:10:171811#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061812 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131813 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441814 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271815#else
1816 return false;
1817#endif
[email protected]76411f412012-02-22 18:56:061818}
1819
Alex Moshchuk9c9e3882018-11-02 19:57:031820bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1821 content::RenderFrameHost* main_frame) {
1822#if BUILDFLAG(ENABLE_EXTENSIONS)
1823 return ChromeContentBrowserClientExtensionsPart::
1824 ShouldSubframesTryToReuseExistingProcess(main_frame);
1825#else
1826 return true;
1827#endif
1828}
1829
[email protected]6f371442011-11-09 06:45:461830void ChromeContentBrowserClient::SiteInstanceGotProcess(
1831 SiteInstance* site_instance) {
1832 CHECK(site_instance->HasProcess());
1833
Aran Gilmanf010bdd2019-08-28 19:55:441834 Profile* profile =
1835 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521836 if (!profile)
1837 return;
1838
Marc Treib7895941d2017-11-28 12:37:021839#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521840 // Remember the ID of the Instant process to signal the renderer process
1841 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131842 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1843 profile)) {
[email protected]c5dec6292013-01-25 04:54:521844 InstantService* instant_service =
1845 InstantServiceFactory::GetForProfile(profile);
1846 if (instant_service)
1847 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1848 }
Marc Treib7895941d2017-11-28 12:37:021849#endif
[email protected]c5dec6292013-01-25 04:54:521850
[email protected]a48ab7112014-08-01 16:48:031851 for (size_t i = 0; i < extra_parts_.size(); ++i)
1852 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461853}
1854
1855void ChromeContentBrowserClient::SiteInstanceDeleting(
1856 SiteInstance* site_instance) {
1857 if (!site_instance->HasProcess())
1858 return;
1859
[email protected]a48ab7112014-08-01 16:48:031860 for (size_t i = 0; i < extra_parts_.size(); ++i)
1861 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461862}
1863
[email protected]453f5432013-11-26 19:43:001864bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141865 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561866 const GURL& current_effective_url,
1867 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171868#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131869 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561870 ShouldSwapBrowsingInstancesForNavigation(
1871 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271872#else
1873 return false;
1874#endif
[email protected]e3daf3c2011-10-05 21:17:081875}
1876
Nasko Oskovd83b5712018-05-04 04:50:571877bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1878 // TODO(nasko): Consider supporting error page isolation in subframes if
1879 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381880 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571881}
1882
[email protected]3d831992013-07-04 01:13:291883bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1884 return !url.SchemeIs(chrome::kChromeNativeScheme);
1885}
1886
Alex Moshchukd252c192017-07-17 22:03:481887std::vector<url::Origin>
1888ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1889 std::vector<url::Origin> isolated_origin_list;
1890
Alex Moshchuk89352a72017-10-25 20:25:591891// Sign-in process isolation is not needed on Android, see
1892// https://crbug.com/739418.
1893#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381894 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121895 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591896#endif
Alex Moshchukd252c192017-07-17 22:03:481897
Alex Moshchuk81d2a29e2019-07-16 01:14:381898#if BUILDFLAG(ENABLE_EXTENSIONS)
1899 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1900 GetOriginsRequiringDedicatedProcess();
1901 std::move(std::begin(origins_from_extensions),
1902 std::end(origins_from_extensions),
1903 std::back_inserter(isolated_origin_list));
1904#endif
1905
Alex Moshchukd252c192017-07-17 22:03:481906 return isolated_origin_list;
1907}
1908
Lukasz Anforowicz5e201abd2018-03-24 00:41:061909bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341910 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1911}
1912
1913bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371914 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061915}
1916
Alex Moshchuk082b5f82019-03-14 01:34:161917std::vector<std::string>
1918ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1919 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1920 return {"Isolate Password Sites"};
1921 else
1922 return {};
1923}
1924
Alex Moshchuke256d562019-04-26 21:43:571925void ChromeContentBrowserClient::PersistIsolatedOrigin(
1926 content::BrowserContext* context,
1927 const url::Origin& origin) {
1928 DCHECK(!context->IsOffTheRecord());
1929 Profile* profile = Profile::FromBrowserContext(context);
1930 ListPrefUpdate update(profile->GetPrefs(),
1931 prefs::kUserTriggeredIsolatedOrigins);
1932 base::ListValue* list = update.Get();
1933 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361934 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121935 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571936}
1937
Ken Rockot314714c2017-11-05 23:36:241938bool ChromeContentBrowserClient::IsFileAccessAllowed(
1939 const base::FilePath& path,
1940 const base::FilePath& absolute_path,
1941 const base::FilePath& profile_path) {
1942 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1943 profile_path);
1944}
1945
[email protected]d2e1a0a2014-06-16 15:49:371946namespace {
1947
1948bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171949 const base::CommandLine& browser_command_line =
1950 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351951 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371952 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351953 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371954 return false;
[email protected]9ef49b42014-08-07 16:44:241955 return true;
[email protected]d2e1a0a2014-06-16 15:49:371956}
1957
bmcquade5d2d9cf32015-06-19 17:42:281958void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1959 const base::CommandLine& browser_command_line,
1960 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521961 // List of field trials that modify the blink-settings command line flag. No
1962 // two field trials in the list should specify the same keys, otherwise one
1963 // field trial may overwrite another. See Source/core/frame/Settings.in in
1964 // Blink for the list of valid keys.
1965 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161966 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1967 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1968 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1969 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521970 };
1971
1972 std::vector<std::string> blink_settings;
1973 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1974 // Each blink-settings field trial should include a forcing_flag group,
1975 // to make sure that clients that specify the blink-settings flag on the
1976 // command line are excluded from the experiment groups. To make
1977 // sure we assign clients that specify this flag to the forcing_flag
1978 // group, we must call GetVariationParams for each field trial first
1979 // (for example, before checking HasSwitch() and returning), since
1980 // GetVariationParams has the side-effect of assigning the client to
1981 // a field trial group.
1982 std::map<std::string, std::string> params;
1983 if (variations::GetVariationParams(field_trial_name, &params)) {
1984 for (const auto& param : params) {
1985 blink_settings.push_back(base::StringPrintf(
1986 "%s=%s", param.first.c_str(), param.second.c_str()));
1987 }
1988 }
1989 }
pmeenan9ac669682015-08-17 14:57:031990
bmcquade9dd54cc2015-06-22 16:56:521991 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281992 return;
1993 }
1994
1995 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1996 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031997 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521998 // blink-settings flag into a group with no params, and we return
1999 // above if no params were specified, so it's an error if we reach
2000 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282001 LOG(WARNING) << "Received field trial params, "
2002 "but blink-settings switch already specified.";
2003 return;
2004 }
2005
bmcquade5d2d9cf32015-06-19 17:42:282006 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262007 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282008}
2009
[email protected]d2e1a0a2014-06-16 15:49:372010} // namespace
2011
[email protected]b80f68432011-05-02 17:22:302012void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172013 base::CommandLine* command_line,
2014 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062015#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352016 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062017 GoogleUpdateSettings::LoadMetricsClientInfo();
2018 if (client_info) {
2019 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2020 client_info->client_id);
2021 }
2022#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022023#if defined(OS_ANDROID)
2024 bool enable_crash_reporter = true;
2025#else
Joshua Perazace68e2f2019-09-23 18:44:242026 bool enable_crash_reporter = false;
2027 if (crash_reporter::IsCrashpadEnabled()) {
2028 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2029 enable_crash_reporter = true;
2030
2031 int fd;
2032 pid_t pid;
2033 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2034 command_line->AppendSwitchASCII(
2035 crash_reporter::switches::kCrashpadHandlerPid,
2036 base::NumberToString(pid));
2037 }
2038 } else {
2039 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2040 }
Joshua Perazaf890e4b2019-01-03 19:19:022041#endif
2042 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512043 std::string switch_value;
dcheng4af48582016-04-19 00:29:352044 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532045 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512046 if (client_info)
2047 switch_value = client_info->client_id;
2048 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252049 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302050 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512051 switch_value);
[email protected]b80f68432011-05-02 17:22:302052 }
Mark Mentovaic67fa64f2015-03-24 14:00:062053#endif
[email protected]b80f68432011-05-02 17:22:302054
[email protected]f1933792011-06-14 00:49:342055 if (logging::DialogsAreSuppressed())
2056 command_line->AppendSwitch(switches::kNoErrorDialogs);
2057
[email protected]b80f68432011-05-02 17:22:302058 std::string process_type =
2059 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172060 const base::CommandLine& browser_command_line =
2061 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322062
[email protected]7c9b6f92013-09-10 18:11:352063 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442064 switches::kUserAgent,
2065 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352066 };
2067 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372068 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322069
fqj15ff3f72015-10-09 19:20:022070 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432071 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312072 };
fqj15ff3f72015-10-09 19:20:022073 command_line->CopySwitchesFrom(browser_command_line,
2074 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372075 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312076
David Van Cleve3df6abb2019-11-26 17:52:512077 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2078 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2079
fqj15ff3f72015-10-09 19:20:022080#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332081 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2082 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522083 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332084 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2085 homedir.value().c_str());
2086#endif
2087
[email protected]718eab62011-10-05 21:16:522088 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032089 content::RenderProcessHost* process =
2090 content::RenderProcessHost::FromID(child_process_id);
2091 Profile* profile =
2092 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442093 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032094 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442095 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2096 process, profile);
[email protected]a48ab7112014-08-01 16:48:032097 }
2098
[email protected]b80f68432011-05-02 17:22:302099#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442100 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2101 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302102 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442103 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2104 login_profile);
[email protected]b80f68432011-05-02 17:22:302105#endif
2106
Aran Gilmanf010bdd2019-08-28 19:55:442107 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222108 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372109 if (process) {
[email protected]a8d851f82011-12-21 00:32:372110 PrefService* prefs = profile->GetPrefs();
2111 // Currently this pref is only registered if applied via a policy.
2112 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2113 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2114 // Turn this policy into a command line switch.
2115 command_line->AppendSwitch(switches::kDisable3DAPIs);
2116 }
[email protected]718eab62011-10-05 21:16:522117
[email protected]1733b782014-06-19 18:51:552118 const base::ListValue* switches =
2119 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2120 if (switches) {
2121 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112122 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552123 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142124 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552125 command_line->AppendSwitch(switch_to_enable);
2126 }
2127 }
2128
[email protected]a8d851f82011-12-21 00:32:372129 // Disable client-side phishing detection in the renderer if it is
2130 // disabled in the Profile preferences or the browser process.
2131 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2132 !g_browser_process->safe_browsing_detection_service()) {
2133 command_line->AppendSwitch(
2134 switches::kDisableClientSidePhishingDetection);
2135 }
[email protected]0045b0f42012-07-26 11:52:082136
vitalybukaa7ae5052014-09-26 04:11:132137 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2138 command_line->AppendSwitch(switches::kDisablePrintPreview);
2139
Marc Treib7895941d2017-11-28 12:37:022140#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522141 InstantService* instant_service =
2142 InstantServiceFactory::GetForProfile(profile);
2143 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542144 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522145 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542146 }
Marc Treib7895941d2017-11-28 12:37:022147#endif
fqjba8749c2015-10-29 15:33:072148
fqj38306f7b2015-11-02 16:59:062149 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542150 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432151 command_line->AppendSwitch(
2152 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542153 }
Daniel Vogelheim976f1c22017-11-22 16:26:032154
Lukasz Anforowicz60d1253d2019-05-08 16:31:372155 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2156
Amr Aboelkherb04cbf32019-04-29 15:17:102157 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2158 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292159 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102160 }
Katie Dillonc25ee5c92019-09-12 17:05:422161
2162 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2163 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2164 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2165 }
Takashi Toyoshima128441462019-10-16 04:19:172166
Mason Freed490f2a22019-11-05 21:41:292167 if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) &&
2168 prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) {
2169 command_line->AppendSwitch(switches::kWebComponentsV0Enabled);
2170 }
2171
Takashi Toyoshima0dab73302019-10-18 01:51:362172 if (!profile->ShouldEnableOutOfBlinkCors()) {
2173 command_line->AppendSwitch(
2174 network::switches::kForceToDisableOutOfBlinkCors);
2175 }
[email protected]47c7ec82012-01-18 03:29:212176 }
[email protected]4287a3d2011-06-13 23:56:512177
[email protected]d2e1a0a2014-06-16 15:49:372178 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352179 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042180
Aran Gilmanf010bdd2019-08-28 19:55:442181 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2182 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282183
mdjonesa6b9e172016-09-23 16:24:302184#if defined(OS_ANDROID)
2185 // If the platform is Android, force the distillability service on.
2186 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2187#endif
2188
[email protected]47c7ec82012-01-18 03:29:212189 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512190 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192191 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412192 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302193#if defined(OS_CHROMEOS)
2194 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2195#endif
brettw00899e62016-11-12 02:10:172196#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512197 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272198 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172199 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512200 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272201 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172202 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172203 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282204#endif
estark4b003b332015-02-14 01:07:052205 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512206 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482207 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512208 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502209 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572210 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462211 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302212 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512213 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172214#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242215 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482216 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552217#endif
[email protected]ce304ce2013-02-22 21:54:452218 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342219#if defined(OS_CHROMEOS)
2220 switches::kForceAppMode,
2221#endif
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,
Andreas Haasb400d912019-08-28 18:54:102227 switches::kEnableExperimentalWebAssemblyFeatures,
iclelland79237e92016-06-23 12:03:512228 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552229 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022230 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512231 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512232 switches::kPpapiFlashPath,
2233 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032234 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092235 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512236 };
2237
2238 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372239 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172240 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172241#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382242 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442243 extensions::switches::kAllowHTTPBackgroundPage,
2244 extensions::switches::kEnableExperimentalExtensionApis,
2245 extensions::switches::kExtensionsOnChromeURLs,
2246 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382247 };
2248
2249 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372250 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282251#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372252 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132253 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512254 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512255 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502256 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172257#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242258 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582259 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592260 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412261 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552262#endif
[email protected]4287a3d2011-06-13 23:56:512263 switches::kPpapiFlashPath,
2264 switches::kPpapiFlashVersion,
2265 };
2266
2267 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372268 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112269 } else if (process_type == switches::kGpuProcess) {
2270 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2271 // because GPU is expected to be unreliable.
2272 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2273 !command_line->HasSwitch(switches::kDisableBreakpad))
2274 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302275 }
[email protected]6f08af82011-09-15 01:19:032276
Ian Barkley-Yeung550aae052019-07-11 00:11:112277#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302278 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112279 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292280 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112281 };
2282 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2283 base::size(kSwitchNames));
2284 }
2285#endif
2286
wittman832321f52016-10-10 18:18:382287 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442288 process_type, 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
Olivier Yiptong0daa93f2019-08-22 19:40:082299std::string
2300ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2301 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2302}
2303
[email protected]b80f68432011-05-02 17:22:302304std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432305 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332306 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302307 return g_browser_process->GetApplicationLocale();
2308}
2309
[email protected]597a867b2011-11-18 18:31:202310std::string ChromeContentBrowserClient::GetAcceptLangs(
2311 content::BrowserContext* context) {
2312 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202313 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082314}
2315
Dana Fried34d580002019-04-24 20:05:482316gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492317 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482318 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082319}
2320
bengre8a146f2016-03-10 01:20:222321bool ChromeContentBrowserClient::IsDataSaverEnabled(
2322 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382323 if (!browser_context || browser_context->IsOffTheRecord())
2324 return false;
2325
Robert Ogdenc995d4fe2019-03-25 19:18:372326 Profile* profile = Profile::FromBrowserContext(browser_context);
2327 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412328 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2329 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222330}
2331
Kenichi Ishibashi46329872018-07-17 09:43:402332void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2333 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192334 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402335 DCHECK(browser_context);
2336 DCHECK(out_prefs);
2337 renderer_preferences_util::UpdateFromSystemSettings(
2338 out_prefs, Profile::FromBrowserContext(browser_context));
2339}
2340
Clark DuVall5690e742019-07-17 18:26:172341bool ChromeContentBrowserClient::AllowAppCache(
2342 const GURL& manifest_url,
2343 const GURL& first_party,
2344 content::BrowserContext* context) {
2345 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2346 return CookieSettingsFactory::GetForProfile(
2347 Profile::FromBrowserContext(context))
2348 ->IsCookieAccessAllowed(manifest_url, first_party);
2349}
2350
Matt Falkenhagen7b509e52019-08-15 23:11:412351bool ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072352 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542353 const GURL& site_for_cookies,
2354 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362355 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202356 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342357 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522358 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542359 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
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.
Matt Falkenhagena59e1cce2019-08-22 23:45:022368 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
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(
Darin Fisher42f5e7d2019-10-30 07:15:452380 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212381 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.
Christian Dullweber2a2f2182019-09-25 15:44:542386 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2387 scope, site_for_cookies, top_frame_origin);
falken4a22dce2015-04-30 08:25:202388 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242389 // Only post the task if this is for a specific tab.
2390 if (!wc_getter.is_null()) {
Sami Kyostila5e1306d2019-08-14 11:01:292391 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:282392 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512393 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342394 std::move(wc_getter), scope, !allow_javascript,
Christian Dullweber2a2f2182019-09-25 15:44:542395 !allow_cookies));
rdevlin.croninf5863da2015-09-10 19:21:452396 }
Christian Dullweber2a2f2182019-09-25 15:44:542397 return allow_javascript && allow_cookies;
falken3dbc36e2014-10-10 16:48:072398}
2399
Matt Falkenhagen7b509e52019-08-15 23:11:412400bool ChromeContentBrowserClient::AllowServiceWorkerOnUI(
2401 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542402 const GURL& site_for_cookies,
2403 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412404 const GURL& script_url,
2405 content::BrowserContext* context,
2406 base::RepeatingCallback<content::WebContents*()> wc_getter) {
2407 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542408 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412409
2410#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022411 // Check if this is an extension-related service worker, and, if so, if it's
2412 // allowed (this can return false if, e.g., the extension is disabled).
2413 // If it's not allowed, return immediately. We deliberately do *not* report
2414 // to the TabSpecificContentSettings, since the service worker is blocked
2415 // because of the extension, rather than because of the user's content
2416 // settings.
2417 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2418 scope, first_party_url, script_url, context)) {
2419 return false;
2420 }
Matt Falkenhagen7b509e52019-08-15 23:11:412421#endif
2422
2423 Profile* profile = Profile::FromBrowserContext(context);
2424
2425 // Check if JavaScript is allowed.
2426 content_settings::SettingInfo info;
2427 std::unique_ptr<base::Value> value =
2428 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452429 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412430 std::string(), &info);
2431 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2432 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2433
2434 // Check if cookies are allowed.
2435 bool allow_cookies =
2436 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542437 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412438
2439 // Record access to database for potential display in UI.
2440 // Only post the task if this is for a specific tab.
2441 if (!wc_getter.is_null()) {
2442 TabSpecificContentSettings::ServiceWorkerAccessed(
2443 std::move(wc_getter), scope, !allow_javascript, !allow_cookies);
2444 }
2445 return allow_javascript && allow_cookies;
2446}
2447
Jochen Eisinger0ff7645c2017-11-28 08:11:262448bool ChromeContentBrowserClient::AllowSharedWorker(
2449 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542450 const GURL& site_for_cookies,
2451 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262452 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372453 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262454 content::BrowserContext* context,
2455 int render_process_id,
2456 int render_frame_id) {
2457 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2458
2459 // Check if cookies are allowed.
2460 bool allow =
2461 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542462 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2463 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262464
2465 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372466 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2467 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262468 return allow;
2469}
2470
Patrick Monette6cb099a2019-09-18 19:31:272471bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2472 const std::string& scheme) {
2473#if BUILDFLAG(ENABLE_EXTENSIONS)
2474 // Extensions are allowed to start cross-origin shared workers.
2475 if (scheme == extensions::kExtensionScheme)
2476 return true;
2477#endif
2478
2479 return false;
2480}
2481
Clark DuVallab63d142019-07-23 04:24:362482bool ChromeContentBrowserClient::AllowSignedExchange(
2483 content::BrowserContext* browser_context) {
2484 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2485 Profile* profile = Profile::FromBrowserContext(browser_context);
2486 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2487}
2488
[email protected]f917df22014-07-10 07:45:492489void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352490 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572491 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172492 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572493 base::OnceCallback<void(bool)> callback) {
2494 Profile* profile = Profile::FromBrowserContext(browser_context);
2495 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002496 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352497
brettw00899e62016-11-12 02:10:172498#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572499 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492500#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572501 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492502#endif
2503}
2504
brettw00899e62016-11-12 02:10:172505#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492506void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2507 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172508 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572509 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492510 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572511 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492512 std::map<int, int> process_map;
2513 std::map<int, int>::const_iterator it;
2514 bool has_web_view_guest = false;
2515 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172516 for (const auto& it : render_frames) {
2517 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492518 continue;
2519
Lukasz Anforowicz09060bdf72018-08-23 15:53:172520 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492521
Lukasz Anforowicz09060bdf72018-08-23 15:53:172522 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492523 has_web_view_guest = true;
2524 }
2525 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572526 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492527 return;
2528 }
[email protected]dffb9fc2014-07-16 04:14:022529 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492530 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492531
[email protected]140d6cd92014-08-12 18:26:462532 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572533 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2534 web_view_permission_helper->RequestFileSystemPermission(
2535 url, allow,
2536 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2537 weak_factory_.GetWeakPtr(), url, render_frames,
2538 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492539}
2540#endif
2541
2542void ChromeContentBrowserClient::FileSystemAccessed(
2543 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172544 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572545 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492546 bool allow) {
[email protected]62151052012-02-01 18:40:482547 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172548 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572549 TabSpecificContentSettings::FileSystemAccessed(
2550 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352551 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572552 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352553}
2554
[email protected]7c5ff9a2012-03-02 07:42:492555bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2556 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572557 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172558 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572559 Profile* profile = Profile::FromBrowserContext(browser_context);
2560 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2561
falken71691402017-01-27 03:38:002562 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492563
2564 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172565 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572566 TabSpecificContentSettings::IndexedDBAccessed(
2567 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492568 }
2569
2570 return allow;
2571}
2572
Ben Kelly6b2e61c2019-03-14 16:06:292573bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2574 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572575 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292576 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572577 Profile* profile = Profile::FromBrowserContext(browser_context);
2578 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292579 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2580
2581 // Record access to CacheStorage for potential display in UI.
2582 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572583 TabSpecificContentSettings::CacheStorageAccessed(
2584 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292585 }
2586
2587 return allow;
2588}
2589
Joshua Bell1ebc8df2019-11-06 00:27:582590bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2591 const GURL& url,
2592 content::BrowserContext* browser_context,
2593 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2594 Profile* profile = Profile::FromBrowserContext(browser_context);
2595 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2596 return cookie_settings->IsCookieAccessAllowed(url, url);
2597}
2598
jyasskinc993ce8d2016-03-31 00:38:342599ChromeContentBrowserClient::AllowWebBluetoothResult
2600ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452601 content::BrowserContext* browser_context,
2602 const url::Origin& requesting_origin,
2603 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342604 // TODO(crbug.com/598890): Don't disable if
2605 // base::CommandLine::ForCurrentProcess()->
2606 // HasSwitch(switches::kEnableWebBluetooth) is true.
2607 if (variations::GetVariationParamValue(
2608 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2609 "Bluetooth") ==
2610 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2611 // The kill switch is enabled for this permission. Block requests.
2612 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2613 }
2614
jyasskin98bdd3992016-02-26 20:25:452615 const HostContentSettingsMap* const content_settings =
2616 HostContentSettingsMapFactory::GetForProfile(
2617 Profile::FromBrowserContext(browser_context));
2618
csharrisonaec2c542016-10-12 19:40:362619 if (content_settings->GetContentSetting(
2620 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452621 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362622 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342623 return AllowWebBluetoothResult::BLOCK_POLICY;
2624 }
2625 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452626}
2627
beaufort.francois01135bf2016-11-23 14:37:362628std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2629 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2630 "blocklist_additions");
scheib74250322016-04-07 03:32:212631}
2632
John Abd-El-Malek21bca7c2018-10-26 22:13:332633#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522634void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072635 content::BrowserContext* browser_context) {
2636 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2637 if (user_manager) {
2638 const user_manager::User* user =
2639 chromeos::ProfileHelper::Get()->GetUserByProfile(
2640 Profile::FromBrowserContext(browser_context));
2641 if (user && !user->username_hash().empty()) {
2642 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2643 user->username_hash());
2644 }
2645 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332646}
2647#endif
2648
Reilly Grant19aaccd2018-07-16 22:06:372649scoped_refptr<network::SharedURLLoaderFactory>
2650ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2652 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2653
2654 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372655 return nullptr;
2656
Min Qinda0d55b2018-10-12 18:30:052657 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372658 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042659}
2660
Sean Gilhulyda1ee4b2018-11-13 21:56:092661network::mojom::NetworkContext*
2662ChromeContentBrowserClient::GetSystemNetworkContext() {
2663 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2664 DCHECK(g_browser_process->system_network_context_manager());
2665 return g_browser_process->system_network_context_manager()->GetContext();
2666}
2667
Andrew Moylan17329fc2017-09-25 07:43:302668std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2669 return google_apis::GetAPIKey();
2670}
2671
Ke He21ee87f2018-05-30 02:35:322672#if defined(OS_ANDROID)
2673bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2674 // Indicate that Chrome uses the GMS core location provider.
2675 return true;
2676}
2677#endif
2678
Yeolf3dc22ca2019-04-18 17:25:322679scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412680ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2681 return new ChromeQuotaPermissionContext();
2682}
2683
Mythri Alle0b8de0d2018-10-22 11:06:222684content::GeneratedCodeCacheSettings
2685ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2686 content::BrowserContext* context) {
2687 base::FilePath cache_path;
2688 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2689 // If we pass 0 for size, disk_cache will pick a default size using the
2690 // heuristics based on available disk size. These are implemented in
2691 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162692 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132693 DCHECK(g_browser_process);
2694 PrefService* local_state = g_browser_process->local_state();
2695 if (local_state) {
2696 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2697 base::FilePath disk_cache_dir =
2698 local_state->GetFilePath(prefs::kDiskCacheDir);
2699 if (!disk_cache_dir.empty())
2700 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2701 }
Mythri Ab2486572019-06-13 14:48:162702 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222703}
2704
[email protected]848dd042011-06-04 18:24:032705void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262706 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172707 int cert_error,
2708 const net::SSLInfo& ssl_info,
2709 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232710 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222711 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262712 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262713 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232714 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142715 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022716 // have a context for making the right decision, so block the
2717 // request hard, without an info bar to allow showing the insecure
2718 // content.
estark719dde52016-08-09 03:14:272719 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262720 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022721 return;
2722 }
2723
[email protected]f9034cf2011-07-21 12:43:412724 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572725 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262726 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572727 if (prerender_contents) {
2728 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272729 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262730 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272731 }
[email protected]09667f02014-01-06 15:37:572732 return;
[email protected]f9034cf2011-07-21 12:43:412733 }
2734
Erik Staaba65a6032019-11-27 22:23:262735 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282736 return;
[email protected]848dd042011-06-04 18:24:032737}
2738
Alexander Hendrichbcf2616e2018-05-18 08:21:102739namespace {
2740
Pavol Markob211ab22019-01-23 20:03:042741certificate_matching::CertificatePrincipalPattern
2742ParseCertificatePrincipalPattern(const base::Value* pattern) {
2743 return certificate_matching::CertificatePrincipalPattern::
2744 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2745}
2746
Alexander Hendrichbcf2616e2018-05-18 08:21:102747// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452748// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102749// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2750std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2751 Profile* profile,
2752 const GURL& requesting_url,
2753 net::ClientCertIdentityList& client_certs) {
2754 HostContentSettingsMap* host_content_settings_map =
2755 HostContentSettingsMapFactory::GetForProfile(profile);
2756 std::unique_ptr<base::Value> setting =
2757 host_content_settings_map->GetWebsiteSetting(
2758 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452759 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102760
Pavol Markob211ab22019-01-23 20:03:042761 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102762 return nullptr;
2763
Alexander Hendrichbcf2616e2018-05-18 08:21:102764 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042765 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2766 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102767 // |setting_dict| has the wrong format (e.g. single filter instead of a
2768 // list of filters). This content setting is only provided by
2769 // the |PolicyProvider|, which should always set it to a valid format.
2770 // Therefore, delete the invalid value.
2771 host_content_settings_map->SetWebsiteSettingDefaultScope(
2772 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452773 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042774 return nullptr;
2775 }
2776
2777 for (const base::Value& filter : filters->GetList()) {
2778 DCHECK(filter.is_dict());
2779
2780 auto issuer_pattern = ParseCertificatePrincipalPattern(
2781 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2782 auto subject_pattern = ParseCertificatePrincipalPattern(
2783 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2784 // Use the first certificate that is matched by the filter.
2785 for (auto& client_cert : client_certs) {
2786 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2787 subject_pattern.Matches(client_cert->certificate()->subject())) {
2788 return std::move(client_cert);
2789 }
2790 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102791 }
2792
2793 return nullptr;
2794}
2795
2796} // namespace
2797
Daniel McArdle85735f52019-06-25 03:27:062798base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192799 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402800 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082801 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352802 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022803 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192804 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022805 if (prerender_contents) {
2806 prerender_contents->Destroy(
2807 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062808 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452809 }
2810
[email protected]791879c2013-12-17 07:22:412811 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2812 DCHECK(requesting_url.is_valid())
2813 << "Invalid URL string: https://"
2814 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452815
Pavol Marko230ea2c92017-12-03 22:35:442816 bool may_show_cert_selection = true;
2817
davidben3b8455ae72015-03-11 19:42:192818 Profile* profile =
2819 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442820#if defined(OS_CHROMEOS)
2821 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252822 // On the sign-in profile, never show certificate selection to the user. A
2823 // client certificate is an identifier that can be stable for a long time,
2824 // so only the administrator is allowed to decide which endpoints should see
2825 // it.
2826 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442827
2828 content::StoragePartition* storage_partition =
2829 content::BrowserContext::GetStoragePartition(
2830 profile, web_contents->GetSiteInstance());
2831 chromeos::login::SigninPartitionManager* signin_partition_manager =
2832 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2833 profile);
2834
2835 // On the sign-in profile, only allow client certs in the context of the
2836 // sign-in frame.
2837 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2838 storage_partition)) {
2839 LOG(WARNING)
2840 << "Client cert requested in sign-in profile in wrong context.";
2841 // Continue without client certificate. We do this to mimic the case of no
2842 // client certificate being present in the profile's certificate store.
2843 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062844 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442845 }
2846 VLOG(1) << "Client cert requested in sign-in profile.";
2847 }
2848#endif // defined(OS_CHROMEOS)
2849
Alexander Hendrichbcf2616e2018-05-18 08:21:102850 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2851 AutoSelectCertificate(profile, requesting_url, client_certs);
2852 if (auto_selected_identity) {
2853 // The callback will own |auto_selected_identity| and |delegate|, keeping
2854 // them alive until after ContinueWithCertificate is called.
2855 scoped_refptr<net::X509Certificate> cert =
2856 auto_selected_identity->certificate();
2857 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2858 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582859 base::BindOnce(
2860 &content::ClientCertificateDelegate::ContinueWithCertificate,
2861 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322862 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062863 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452864 }
2865
Pavol Marko230ea2c92017-12-03 22:35:442866 if (!may_show_cert_selection) {
2867 LOG(WARNING) << "No client cert matched by policy and user selection is "
2868 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322869 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442870 // Continue without client certificate. We do this to mimic the case of no
2871 // client certificate being present in the profile's certificate store.
2872 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062873 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442874 }
2875
Daniel McArdle85735f52019-06-25 03:27:062876 return chrome::ShowSSLClientCertificateSelector(
2877 web_contents, cert_request_info, std::move(client_certs),
2878 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452879}
2880
[email protected]dc73a7b2012-03-25 15:27:182881content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562882 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182883}
2884
Francois Dorayfd823bb12019-10-04 18:03:052885content::LockObserver* ChromeContentBrowserClient::GetLockObserver() {
François Dorayaa3f80102019-10-12 02:29:242886 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
2887 ->GetLockObserver();
Francois Dorayfd823bb12019-10-04 18:03:052888}
2889
peterc26c6c62014-12-10 14:13:592890content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022891ChromeContentBrowserClient::GetPlatformNotificationService(
2892 content::BrowserContext* browser_context) {
2893 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2894 Profile* profile = Profile::FromBrowserContext(browser_context);
2895 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042896}
2897
[email protected]9f3fba52011-06-08 20:37:192898bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352899 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352900 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572901 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352902 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032903 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232904 const GURL& target_url,
2905 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212906 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232907 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482908 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232909 bool user_gesture,
2910 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012911 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352912 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2913 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012914
csharrison95f01e922017-04-24 18:52:352915 content::WebContents* web_contents =
2916 content::WebContents::FromRenderFrameHost(opener);
2917 Profile* profile =
2918 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2919 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012920 *no_javascript_access = false;
2921
[email protected]9f3fba52011-06-08 20:37:192922 // If the opener is trying to create a background window but doesn't have
2923 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032924 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172925#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352926 auto* process_map = extensions::ProcessMap::Get(profile);
2927 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172928 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2929 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012930 return false;
2931 }
2932
[email protected]7b54ca02012-03-02 18:06:532933 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2934 // return a recently installed Extension even if this CanCreateWindow call
2935 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012936 // because the permission check above would have caused an early return
2937 // already. We must use the full URL to find hosted apps, though, and not
2938 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552939 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352940 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292941 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012942 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022943#endif
[email protected]190e5e22013-07-27 05:59:232944
2945 return true;
[email protected]9f3fba52011-06-08 20:37:192946 }
[email protected]056efdc2013-04-06 00:14:532947
brettw00899e62016-11-12 02:10:172948#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462949 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352950 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232951 return true;
lazyboy04b75d32016-02-25 03:12:182952 }
2953
nick0fbc3922016-12-16 20:52:072954 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352955 // Intentionally duplicating |registry| code from above because we want to
2956 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2957 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182958 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352959 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142960 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532961 UMA_HISTOGRAM_ENUMERATION(
2962 "Extensions.AppLoadedInTab",
2963 ClassifyAppLoadedInTabSource(opener_url, extension),
2964 APP_LOADED_IN_TAB_SOURCE_MAX);
2965
2966 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162967 return false;
lazyboy5d5fede02016-03-10 04:10:142968 }
lazyboy04b75d32016-02-25 03:12:182969 }
[email protected]5940b0d2014-07-01 00:18:262970#endif
[email protected]190e5e22013-07-27 05:59:232971
Charles Harrisonaf2acd02017-08-18 22:46:022972#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232973 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352974 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582975 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2976 content_settings, opener_top_level_frame_url, target_url,
2977 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352978 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2979 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582980 return false;
2981 }
2982#endif
2983
Charles Harrisonaf2acd02017-08-18 22:46:022984 // Don't let prerenders open popups.
2985 if (auto* prerender_contents =
2986 prerender::PrerenderContents::FromWebContents(web_contents)) {
2987 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2988 return false;
2989 }
2990
Aaron Colwell9dab1652019-12-09 18:29:492991 BlockedWindowParams blocked_params(
2992 target_url, source_origin, opener->GetSiteInstance(), referrer,
2993 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132994 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:192995 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
2996 &nav_params, nullptr /*=open_url_params*/,
2997 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:192998}
2999
[email protected]c52b2892012-03-07 11:01:023000content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443001ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003002 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513003}
3004
Katie D840d9532018-11-27 06:20:483005content::TtsControllerDelegate*
3006ChromeContentBrowserClient::GetTtsControllerDelegate() {
3007 TtsControllerDelegateImpl* delegate =
3008 TtsControllerDelegateImpl::GetInstance();
3009#if !defined(OS_ANDROID)
3010 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3011 delegate->SetTtsEngineDelegate(tts_extension_engine);
3012#endif
3013 return delegate;
3014}
3015
Katie D4713ee42018-11-30 01:48:273016content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3017#ifdef OS_CHROMEOS
3018 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273019#else
3020 return nullptr;
3021#endif
3022}
3023
[email protected]64d69de42012-02-06 00:19:543024void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443025 RenderViewHost* rvh,
3026 WebPreferences* web_prefs) {
3027 Profile* profile =
3028 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063029 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063030
aelias0df335a2017-03-02 23:43:513031// Fill font preferences. These are not registered on Android
3032// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453033#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193034 FontFamilyCache::FillFontFamilyMap(profile,
3035 prefs::kWebKitStandardFontFamilyMap,
3036 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443037 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193038 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443039 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193040 &web_prefs->serif_font_family_map);
3041 FontFamilyCache::FillFontFamilyMap(profile,
3042 prefs::kWebKitSansSerifFontFamilyMap,
3043 &web_prefs->sans_serif_font_family_map);
3044 FontFamilyCache::FillFontFamilyMap(profile,
3045 prefs::kWebKitCursiveFontFamilyMap,
3046 &web_prefs->cursive_font_family_map);
3047 FontFamilyCache::FillFontFamilyMap(profile,
3048 prefs::kWebKitFantasyFontFamilyMap,
3049 &web_prefs->fantasy_font_family_map);
3050 FontFamilyCache::FillFontFamilyMap(profile,
3051 prefs::kWebKitPictographFontFamilyMap,
3052 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063053
[email protected]64d69de42012-02-06 00:19:543054 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403055 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543056 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403057 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543058 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403059 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543060 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403061 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513062#endif
[email protected]f3986f82012-01-03 20:00:063063
[email protected]ddf72142012-05-22 04:52:403064 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063065
[email protected]64d69de42012-02-06 00:19:543066 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063067 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213068 web_prefs->javascript_can_access_clipboard =
3069 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543070 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063071
[email protected]ddf72142012-05-22 04:52:403072 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543073 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573074
Avi Drissman1aa6cb92019-01-23 15:58:383075 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543076 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573077
[email protected]ddf72142012-05-22 04:52:403078 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543079 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543080 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403081 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063082
Zhenyao Moa3fda9972017-09-16 01:34:403083 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3084 web_prefs->webgl1_enabled = false;
3085 web_prefs->webgl2_enabled = false;
3086 }
[email protected]f3986f82012-01-03 20:00:063087
[email protected]64d69de42012-02-06 00:19:543088 web_prefs->allow_running_insecure_content =
3089 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323090#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053091 web_prefs->font_scale_factor =
3092 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3093 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323094 web_prefs->force_enable_zoom =
3095 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493096#endif
Becky Zhoubbfbde32019-02-20 17:07:593097 web_prefs->force_dark_mode_enabled =
3098 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393099
[email protected]af4256d52013-06-04 20:39:073100#if defined(OS_ANDROID)
3101 web_prefs->password_echo_enabled =
3102 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3103#else
[email protected]9d06d88d2012-02-23 22:37:083104 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073105#endif
3106
[email protected]64d69de42012-02-06 00:19:543107 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063108 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543109 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063110 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3111
brettw00899e62016-11-12 02:10:173112#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053113 std::string image_animation_policy =
3114 prefs->GetString(prefs::kAnimationPolicy);
3115 if (image_animation_policy == kAnimationPolicyOnce)
3116 web_prefs->animation_policy =
3117 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3118 else if (image_animation_policy == kAnimationPolicyNone)
3119 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3120 else
3121 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3122#endif
3123
[email protected]f3986f82012-01-03 20:00:063124 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153125 web_prefs->default_encoding =
3126 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543127 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403128 prefs->ClearPref(prefs::kDefaultCharset);
3129 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063130 }
[email protected]64d69de42012-02-06 00:19:543131 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063132
mkwst05544102015-01-10 20:26:163133 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3134 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073135 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163136 web_prefs->strict_mixed_content_checking = true;
3137 web_prefs->strict_powerful_feature_restrictions = true;
3138 }
3139
Robert Ogdencf2872d2019-03-19 18:59:373140 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213141
Tarun Bansal333819e2018-05-15 16:38:423142 web_prefs->data_saver_holdback_web_api_enabled =
3143 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3144 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423145
Alison Maher28a73e22019-10-18 19:26:353146 auto* native_theme = GetWebTheme();
Jinsuk Kima3d393ce2019-05-27 00:57:423147 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133148 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533149#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423150 auto* delegate = TabAndroid::FromWebContents(contents)
3151 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3152 contents->GetDelegate())
3153 : nullptr;
3154 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133155 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423156 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133157
Mounir Lamouri9c99a1602018-07-05 15:01:443158 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423159 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383160
Alison Maher28a73e22019-10-18 19:26:353161 // Notify NativeTheme of changes to night mode.
3162 native_theme->set_preferred_color_scheme(
3163 delegate->IsNightModeEnabled()
3164 ? ui::NativeTheme::PreferredColorScheme::kDark
3165 : ui::NativeTheme::PreferredColorScheme::kLight);
zqzhang183dc822017-02-15 17:04:113166 }
Ian Vollick6243dfe02018-03-08 01:08:533167#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533168
Mounir Lamouri6926107f2019-01-31 18:17:433169 // web_app_scope value is platform specific.
3170#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423171 if (delegate)
3172 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433173#elif BUILDFLAG(ENABLE_EXTENSIONS)
3174 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253175 web_prefs->web_app_scope = GURL();
3176 // Set |web_app_scope| based on the app associated with the app window if
3177 // any. Note that the app associated with the window never changes, even
3178 // if the app navigates off scope. This is not a problem because we still
3179 // want to use the scope of the app associated with the window, not the
3180 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433181 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233182 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443183 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273184 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443185 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253186 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053187 // for profiles that support them, so we should always be able to
3188 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253189 //
3190 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123191 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253192 web_prefs->web_app_scope =
3193 web_app::WebAppProvider::Get(profile)
3194 ->registrar()
Jiewei Qianf33ba1a2019-11-04 23:23:033195 .GetAppScope(browser->app_controller()->GetAppId())
Alan Cutterf25cfe42019-07-16 02:40:123196 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433197 }
Mounir Lamouri6926107f2019-01-31 18:17:433198 }
3199#endif
3200
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533201#if BUILDFLAG(ENABLE_EXTENSIONS)
3202 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443203 if (browser && browser->app_controller() &&
3204 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533205 web_prefs->strict_mixed_content_checking = true;
3206 }
3207#endif
3208
Ian Vollick6243dfe02018-03-08 01:08:533209 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113210 }
zqzhang93e959d12017-03-16 13:10:203211
Ian Vollick6243dfe02018-03-08 01:08:533212#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143213 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113214#endif // defined(OS_ANDROID)
3215
Tarun Bansal73d67f02018-01-17 05:56:253216 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3217 // Obtain the maximum effective connection type at which the feature is
3218 // enabled.
3219 std::string effective_connection_type_param =
3220 base::GetFieldTrialParamValueByFeature(
3221 features::kLowPriorityIframes,
3222 "max_effective_connection_type_threshold");
3223
3224 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3225 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3226 if (effective_connection_type) {
3227 web_prefs->low_priority_iframes_threshold =
3228 effective_connection_type.value();
3229 }
3230 }
3231
rajendrant0521cee2019-07-29 06:09:263232 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3233 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003234
Scott Little878f7d6702018-05-31 22:09:063235 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3236 const char* param_name =
3237 web_prefs->data_saver_enabled
3238 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3239 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3240 "saver_enabled";
3241
3242 base::StringPairs pairs;
3243 base::SplitStringIntoKeyValuePairs(
3244 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3245 param_name),
3246 ':', ',', &pairs);
3247
3248 for (const auto& pair : pairs) {
3249 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3250 net::GetEffectiveConnectionTypeForName(pair.first);
3251 int value = 0;
3252 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3253 web_prefs->lazy_frame_loading_distance_thresholds_px
3254 [effective_connection_type.value()] = value;
3255 }
3256 }
3257 }
3258
rajendrantd8026342018-08-29 08:08:393259 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3260 const char* param_name =
3261 web_prefs->data_saver_enabled
3262 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3263 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3264 "saver_enabled";
3265
3266 base::StringPairs pairs;
3267 base::SplitStringIntoKeyValuePairs(
3268 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3269 param_name),
3270 ':', ',', &pairs);
3271
3272 for (const auto& pair : pairs) {
3273 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3274 net::GetEffectiveConnectionTypeForName(pair.first);
3275 int value = 0;
3276 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3277 web_prefs->lazy_image_loading_distance_thresholds_px
3278 [effective_connection_type.value()] = value;
3279 }
3280 }
rajendrant3daeae292019-09-20 07:57:543281
3282 pairs.clear();
3283 base::SplitStringIntoKeyValuePairs(
3284 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3285 "lazy_image_first_k_fully_load"),
3286 ':', ',', &pairs);
3287
3288 for (const auto& pair : pairs) {
3289 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3290 net::GetEffectiveConnectionTypeForName(pair.first);
3291 int value = 0;
3292 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3293 web_prefs
3294 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3295 value;
3296 }
3297 }
rajendrantd8026342018-08-29 08:08:393298 }
3299
Tarun Bansald10f17a02018-09-13 00:23:173300 if (base::FeatureList::IsEnabled(
3301 features::kNetworkQualityEstimatorWebHoldback)) {
3302 std::string effective_connection_type_param =
3303 base::GetFieldTrialParamValueByFeature(
3304 features::kNetworkQualityEstimatorWebHoldback,
3305 "web_effective_connection_type_override");
3306
3307 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3308 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3309 DCHECK(effective_connection_type_param.empty() ||
3310 effective_connection_type);
3311 if (effective_connection_type) {
3312 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3313 effective_connection_type.value());
3314 web_prefs->network_quality_estimator_web_holdback =
3315 effective_connection_type.value();
3316 }
3317 }
3318
François Beaufort4f8107d2018-03-05 12:12:103319#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563320 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593321 // If autoplay is allowed by policy then force the no user gesture required
3322 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103323 web_prefs->autoplay_policy =
3324 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553325 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593326 web_prefs->autoplay_policy ==
3327 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553328 // If the autoplay disable settings feature is enabled and the autoplay
3329 // policy is set to using the unified policy then set the default autoplay
3330 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593331 web_prefs->autoplay_policy =
3332 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3333 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3334 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103335 }
3336#endif // !defined(OS_ANDROID)
3337
Dave Tapuskac6627e12018-08-30 15:07:193338 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493339
3340 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213341 base::Optional<ui::CaptionStyle> style;
3342
3343 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3344 ::switches::kForceCaptionStyle)) {
3345 style = ui::CaptionStyle::FromSpec(
3346 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3347 switches::kForceCaptionStyle));
3348 }
3349
3350 // Apply system caption style.
3351 if (!style) {
3352 style = native_theme->GetSystemCaptionStyle();
3353 }
3354
3355 // Apply caption style from preferences if system caption style is undefined.
evliu21b2a902020-01-27 21:12:563356 if (!style) {
evliubc2aa0472019-08-09 20:19:193357 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
evliuedcbb87d2019-11-22 19:49:413358
3359 base::UmaHistogramBoolean("Accessibility.CaptionSettingsLoadedFromPrefs",
3360 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213361 }
3362
3363 if (style) {
3364 web_prefs->text_track_background_color = style->background_color;
3365 web_prefs->text_track_text_color = style->text_color;
3366 web_prefs->text_track_text_size = style->text_size;
3367 web_prefs->text_track_text_shadow = style->text_shadow;
3368 web_prefs->text_track_font_family = style->font_family;
3369 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563370 web_prefs->text_track_window_color = style->window_color;
3371 web_prefs->text_track_window_padding = style->window_padding;
3372 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213373 }
Elly Fong-Jonesf92897392019-01-24 16:05:493374
[email protected]a48ab7112014-08-01 16:48:033375 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503376 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363377}
3378
[email protected]b8148ac2011-07-13 22:03:253379void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3380 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033381 for (size_t i = 0; i < extra_parts_.size(); ++i)
3382 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253383
[email protected]b3adbd02011-11-30 22:23:273384 // about: handler. Must come before chrome: handler, since it will
3385 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053386 // actually handle them. Also relies on a preliminary fixup phase.
3387 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253388 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3389 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033390
madfbd10852017-01-20 03:15:333391 // The group policy NTP URL handler must be registered before the other NTP
3392 // URL handlers below.
3393 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3394 BrowserURLHandler::null_handler());
3395
zpengdb4a58e2017-01-10 17:40:323396#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033397 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353398 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033399 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453400#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033401 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133402 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3403 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453404#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033405
[email protected]b8148ac2011-07-13 22:03:253406 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313407 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3408 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063409
3410 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3411 // the user.
Robert Ogden0f4d88682019-09-24 22:27:523412 handler->AddHandlerPair(
3413 &previews::HandlePreviewsLitePageRedirectURLRewrite,
3414 &previews::HandlePreviewsLitePageRedirectURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253415}
3416
[email protected]650b2d52013-02-10 03:41:453417base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493418 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323419}
3420
[email protected]c9b6eb62011-10-18 20:49:393421std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3422 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3423}
3424
Dominik Röttsches47347832019-03-12 17:45:013425base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3426 base::FilePath user_data_dir;
3427 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3428 DCHECK(!user_data_dir.empty());
3429 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3430}
3431
jmadill57b52d42015-08-21 18:16:133432base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3433 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523434 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133435 DCHECK(!user_data_dir.empty());
3436 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3437}
3438
Khushal7ca0b782018-07-20 05:53:273439base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3440 base::FilePath user_data_dir;
3441 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3442 DCHECK(!user_data_dir.empty());
3443 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3444}
3445
[email protected]b7631cc2012-09-15 05:08:383446void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3447 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163448#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553449 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543450#endif
[email protected]b7631cc2012-09-15 05:08:383451}
3452
[email protected]0c7193742012-11-07 19:05:033453content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443454ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173455#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553456 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033457 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443458 nacl::NaClProcessHost* host =
3459 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3460 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033461 // Found the plugin.
3462 return host->browser_ppapi_host();
3463 }
3464 ++iter;
3465 }
[email protected]a56f8322014-07-16 21:13:553466#endif
Aran Gilmanf010bdd2019-08-28 19:55:443467 return nullptr;
[email protected]0c7193742012-11-07 19:05:033468}
3469
[email protected]38cd8f7f2012-06-15 22:06:073470bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583471 content::BrowserContext* browser_context,
3472 const GURL& url,
[email protected]dda54822013-06-15 01:26:393473 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123474 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163475#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553476 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3477 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403478#else
[email protected]a658d452012-03-02 12:45:293479 return false;
[email protected]93f72062013-05-29 20:29:403480#endif
[email protected]e461da2f2012-02-16 19:06:403481}
3482
adrian.belgund54465ba2016-05-18 10:03:583483bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3484 content::BrowserContext* browser_context,
3485 const GURL& url) {
brettw4b461082016-11-19 18:55:163486#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583487 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3488 browser_context, url);
3489#else
3490 return false;
3491#endif
3492}
3493
adrian.belgun5b341c72016-06-22 22:24:083494std::unique_ptr<content::VpnServiceProxy>
3495ChromeContentBrowserClient::GetVpnServiceProxy(
3496 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173497#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083498 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3499 browser_context);
3500#else
3501 return nullptr;
3502#endif
3503}
3504
Brett Wilson804e83c2017-08-18 22:57:333505std::unique_ptr<ui::SelectFilePolicy>
3506ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3507 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433508}
3509
[email protected]7d9424702013-04-14 13:14:163510void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3511 std::vector<std::string>* additional_allowed_schemes) {
3512 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3513 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483514 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293515 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033516 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3517 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3518 additional_allowed_schemes);
3519 }
[email protected]7d9424702013-04-14 13:14:163520}
3521
falkenad185092016-06-16 06:10:023522void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3523 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043524 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023525}
3526
[email protected]c79859b82014-03-20 22:43:553527void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313528 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033529 for (size_t i = 0; i < extra_parts_.size(); ++i)
3530 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553531}
3532
nzolghadrd87a308d2016-12-07 15:45:563533::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3534 return g_browser_process->rappor_service();
3535}
3536
[email protected]f19bbf62013-07-09 01:22:323537void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313538 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533539 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003540 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3541 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313542#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313543 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313544 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313545 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093546 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093547 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3548 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473549 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093550 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3551 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053552 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3553 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473554 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323555 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313556 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003557 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313558#endif
[email protected]445b7db2013-08-02 04:58:273559
[email protected]a48ab7112014-08-01 16:48:033560 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3561 extra_parts_[i]->GetAdditionalFileSystemBackends(
3562 browser_context, storage_partition_path, additional_backends);
3563 }
[email protected]02250952013-04-24 23:52:533564}
3565
jcivellie6f550742017-01-06 19:29:123566#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183567void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173568 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383569 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203570 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123571#if defined(OS_ANDROID)
3572 base::MemoryMappedFile::Region region;
3573 int fd = ui::GetMainAndroidPackFd(&region);
3574 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003575
Samuel Huang31eadf082019-08-28 19:50:433576 // For Android: Native resources for DFMs should only be used by the browser
3577 // process. Their file descriptors and memory mapped file regions are not
3578 // passed to child processes.
3579
jcivellie6f550742017-01-06 19:29:123580 fd = ui::GetCommonResourcesPackFd(&region);
3581 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393582
jcivellie6f550742017-01-06 19:29:123583 fd = ui::GetLocalePackFd(&region);
3584 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383585
zpeng368afac82017-07-17 18:47:453586 // Optional secondary locale .pak file.
3587 fd = ui::GetSecondaryLocalePackFd(&region);
3588 if (fd != -1) {
3589 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3590 }
3591
[email protected]09560f7f2014-06-10 18:40:283592 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523593 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283594 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023595#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383596 int crash_signal_fd = GetCrashSignalFD(command_line);
3597 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133598 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383599 }
jcivellie6f550742017-01-06 19:29:123600}
3601#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303602
[email protected]4a65826d2011-08-25 16:04:013603#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033604base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223605 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033606 // TODO(wfh): Add support for more process types here. crbug.com/499523
3607 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223608 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363609 return base::string16(install_static::GetSandboxSidPrefix()) +
3610 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223611 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033612 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223613 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033614 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223615 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363616 return base::string16(install_static::GetSandboxSidPrefix()) +
3617 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223618 case service_manager::SandboxType::kInvalid:
3619 case service_manager::SandboxType::kNoSandbox:
3620 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3621 case service_manager::SandboxType::kXrCompositing:
3622 case service_manager::SandboxType::kNetwork:
3623 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523624 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223625 case service_manager::SandboxType::kAudio:
evliu46223582020-01-10 22:45:513626 case service_manager::SandboxType::kSoda:
Alex Gough9ab468a6c32019-12-10 19:10:223627 // Should never reach here.
3628 CHECK(0);
wfh182da09c2015-06-24 19:23:033629 return base::string16();
wfh182da09c2015-06-24 19:23:033630 }
wfh182da09c2015-06-24 19:23:033631}
3632
Will Harris956e0ca2019-08-23 20:47:393633bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3634 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503635// Does not work under component build because all the component DLLs would need
3636// to be manually added and maintained. Does not work under ASAN build because
3637// ASAN has not yet fully initialized its instrumentation by the time the CIG
3638// intercepts run.
3639#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393640 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3641 return true;
Will Harrisc196ed942019-08-03 03:45:303642 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3643 return true;
3644
3645 // Only enable signing mitigation if launching from chrome.exe.
3646 base::FilePath exe_path;
3647 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3648 return true;
3649 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3650 return true;
3651
3652 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3653 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093654 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303655 if (result != sandbox::SBOX_ALL_OK)
3656 return false;
3657
Aran Gilmanf010bdd2019-08-28 19:55:443658 // Allow loading Chrome's DLLs. The name of this depends on whether
3659 // is_multi_dll_chrome is defined or not. For multi-DLL Chrome,
3660 // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the
3661 // same DLL as the browser process.
Will Harrisc196ed942019-08-03 03:45:303662#if defined(CHROME_MULTIPLE_DLL_BROWSER)
3663 constexpr auto* child_dll_path = chrome::kChildDll;
3664#else
3665 constexpr auto* child_dll_path = chrome::kBrowserResourcesDll;
3666#endif
3667 for (const auto* dll : {child_dll_path, chrome::kElfDll}) {
3668 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3669 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3670 GetModulePath(dll).value().c_str());
3671 if (result != sandbox::SBOX_ALL_OK)
3672 return false;
3673 }
Will Harris1b9b4152019-08-21 22:33:503674#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303675
3676 return true;
[email protected]34f48682013-03-20 00:30:183677}
Will Harris956e0ca2019-08-23 20:47:393678
3679bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3680 PrefService* local_state = g_browser_process->local_state();
3681 if (local_state &&
3682 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3683 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3684 return false;
3685 return true;
3686}
3687
wfhc91e9672016-01-27 00:14:203688#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013689
Mario Sanchez Prada39dee4a2019-07-09 07:15:403690void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113691 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403692 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3693 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113694 render_frame_host);
3695}
3696
Armando Miraglia3a7be232019-11-08 00:33:323697#if defined(OS_WIN) || defined(OS_MACOSX) || \
3698 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3699bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3700 const base::Value* audio_sandbox_enabled_policy_value =
3701 policies.GetValue(policy::key::kAudioSandboxEnabled);
3702 if (audio_sandbox_enabled_policy_value) {
3703 bool force_enable_audio_sandbox;
3704 audio_sandbox_enabled_policy_value->GetAsBoolean(
3705 &force_enable_audio_sandbox);
3706 return force_enable_audio_sandbox;
3707 }
3708
3709 return base::FeatureList::IsEnabled(
3710 service_manager::features::kAudioServiceSandbox);
3711}
3712#endif
3713
Ken Rockotfa5d57112019-05-29 20:57:143714void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123715#if defined(OS_WIN) || defined(OS_MACOSX) || \
3716 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053717 if (startup_data_) {
3718 auto* chrome_feature_list_creator =
3719 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183720 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123721 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053722 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183723 ->GetPolicyService()
3724 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123725 std::string()));
3726
3727#if defined(OS_WIN)
3728 const base::Value* force_network_in_process_value =
3729 policies.GetValue(policy::key::kForceNetworkInProcess);
John Abd-El-Malek27b3ebd22019-02-12 18:59:183730 bool force_network_in_process = false;
3731 if (force_network_in_process_value)
3732 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3733 if (force_network_in_process)
3734 content::ForceInProcessNetworkService(true);
Guido Urdanetad06ae842019-10-10 20:04:123735#endif
3736 bool enable_audio_process =
3737 base::FeatureList::IsEnabled(features::kAudioServiceOutOfProcess);
Armando Miraglia3a7be232019-11-08 00:33:323738
3739 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
3740 if (!service_manager::IsAudioSandboxEnabled() || !enable_audio_process) {
Guido Urdanetad06ae842019-10-10 20:04:123741 // Disabling the audio process or audio sandbox implies disabling APM in
3742 // the audio service for security reasons. Append a switch so that this
3743 // is communicated to the audio and renderer processes.
3744 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3745 switches::kForceDisableWebRtcApmInAudioService);
3746 }
John Abd-El-Malek27b3ebd22019-02-12 18:59:183747 }
3748#endif
xhwang5e630462015-10-30 03:18:483749}
3750
Ken Rockot8f39a272018-12-21 23:38:353751base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173752ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583753 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583754 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583755 return base::nullopt;
benc70c0e32016-09-22 03:50:373756}
3757
peterbbcccc12015-02-11 22:23:333758void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373759 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333760 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293761 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083762 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373763
3764 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083765
zpengdb4a58e2017-01-10 17:40:323766#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223767 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293768 std::move(callback));
jam1c5a91492016-02-24 20:47:533769#else
cm.sanchi2522bc92017-12-04 08:04:133770 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3771 params.url, params.transition);
3772 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083773
3774 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293775 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333776#endif
mlamourieb40d552015-02-05 00:57:083777}
3778
zhaobinf3704f82017-01-12 07:19:363779content::ControllerPresentationServiceDelegate*
3780ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3781 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463782 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093783 return media_router::PresentationServiceDelegateImpl::
3784 GetOrCreateForWebContents(web_contents);
3785 }
haibinlu9e605a92015-06-06 03:45:093786 return nullptr;
3787}
3788
zhaobinf3704f82017-01-12 07:19:363789content::ReceiverPresentationServiceDelegate*
3790ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3791 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363792 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3793 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3794 // created for offscreen presentations. The WebContents must belong to
3795 // an incognito profile.
3796 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3797 FromWebContents(web_contents)) {
3798 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3799 return impl;
3800 }
3801 }
zhaobinf3704f82017-01-12 07:19:363802 return nullptr;
3803}
3804
horo48d4d3e2015-02-27 03:04:003805void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3806 const GURL& url) {
mathp46284f32015-03-11 13:06:413807 if (url.is_valid()) {
3808 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3809 metric, url);
3810 }
horo48d4d3e2015-02-27 03:04:003811}
3812
Matt Falkenhagen8479b202017-07-14 04:35:313813std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3814 // Don't change these returned strings. They are written (in hashed form) into
3815 // UMA logs. If you add more strings, you must update histograms.xml and get
3816 // histograms review. Only Google domains should be here for privacy purposes.
3817 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3818 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193819 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313820 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193821 if (url.host() == "docs.google.com")
3822 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313823 return std::string();
3824}
3825
avid6d88b912017-01-13 00:16:003826std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473827ChromeContentBrowserClient::CreateThrottlesForNavigation(
3828 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003829 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273830
bmcquadeb4556552017-03-24 22:24:373831 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3832 // that may delay or cancel navigations, so only NavigationThrottles that
3833 // don't delay or cancel navigations (e.g. throttles that are only observing
3834 // callbacks without affecting navigation behavior) should be added before
3835 // MetricsNavigationThrottle.
3836 if (handle->IsInMainFrame()) {
3837 throttles.push_back(
3838 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3839 }
3840
brettw4b461082016-11-19 18:55:163841#if BUILDFLAG(ENABLE_PLUGINS)
Lukasz Anforowicz7724d092019-10-03 23:50:213842 MaybeAddThrottle(&throttles,
3843 FlashDownloadInterception::MaybeCreateThrottleFor(handle));
trizzofo8ddaeb72016-09-01 23:18:273844#endif
3845
yilkal240b4f22019-11-27 19:09:063846#if defined(OS_CHROMEOS)
3847 MaybeAddThrottle(
3848 &throttles,
3849 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle));
3850#endif // defined(OS_CHROMEOS)
3851
mmenkedb2637ff2017-03-30 23:59:423852#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213853 MaybeAddThrottle(
3854 &throttles,
3855 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle));
mmenkedb2637ff2017-03-30 23:59:423856#endif
3857
clamy40c9e142015-09-29 11:18:473858#if defined(OS_ANDROID)
3859 // TODO(davidben): This is insufficient to integrate with prerender properly.
3860 // https://crbug.com/370595
3861 prerender::PrerenderContents* prerender_contents =
3862 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3863 if (!prerender_contents && handle->IsInMainFrame()) {
3864 throttles.push_back(
3865 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303866 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473867 }
Min Qin0ab0e162017-11-14 21:57:193868 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043869
3870#if BUILDFLAG(DFMIFY_DEV_UI)
3871 // If the DevUI DFM is already installed, then this is a no-op, except for the
3872 // side effect of ensuring that the DevUI DFM is loaded.
3873 MaybeAddThrottle(&throttles,
3874 dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle));
3875#endif // BUILDFLAG(DFMIFY_DEV_UI)
3876
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573877#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473878 if (handle->IsInMainFrame()) {
3879 // Redirect some navigations to apps that have registered matching URL
3880 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573881 auto url_to_app_throttle =
3882 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:473883 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:093884 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:473885 }
3886#endif
clamy49678312015-10-22 21:59:003887
3888#if defined(OS_CHROMEOS)
3889 // Check if we need to add merge session throttle. This throttle will postpone
3890 // loading of main frames.
3891 if (handle->IsInMainFrame()) {
3892 // Add interstitial page while merge session process (cookie reconstruction
3893 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3894 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023895 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3896 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003897 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3898 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3899 }
Maggie Caia2f03f52019-04-02 02:13:283900 }
3901#endif
djacobo21e56e02016-07-02 01:14:313902
Maggie Caia2f03f52019-04-02 02:13:283903#if !defined(OS_ANDROID)
3904 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:153905 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283906#if defined(OS_CHROMEOS)
Maggie Cai00e2a21e2019-10-16 00:47:513907 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3908 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3909 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253910#elif defined(OS_MACOSX)
3911 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283912#else
3913 apps::AppsNavigationThrottle::MaybeCreate(handle);
3914#endif
Dominick Ng7c289942018-03-27 05:57:153915 if (url_to_apps_throttle)
3916 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003917 }
3918#endif
3919
brettw00899e62016-11-12 02:10:173920#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003921 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093922 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513923
Lukasz Anforowicz7724d092019-10-03 23:50:213924 MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get()
3925 ->GetUserScriptListener()
3926 ->CreateNavigationThrottle(handle));
naskob9164c42016-06-07 01:21:353927#endif
3928
bauerb8f9c37742017-03-30 15:04:123929#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213930 MaybeAddThrottle(
3931 &throttles,
3932 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle));
bauerb8f9c37742017-03-30 15:04:123933#endif
3934
csharrisone985ebc2017-04-04 17:05:033935 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103936 if (auto* subresource_filter_client =
3937 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3938 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3939 &throttles);
csharrisone985ebc2017-04-04 17:05:033940 }
3941
zhenw6edd49c2017-07-12 05:49:453942#if !defined(OS_ANDROID)
3943 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3944 // enabled on non-Android platforms.
Lukasz Anforowicz7724d092019-10-03 23:50:213945 MaybeAddThrottle(&throttles,
3946 resource_coordinator::BackgroundTabNavigationThrottle::
3947 MaybeCreateThrottleFor(handle));
zhenw6edd49c2017-07-12 05:49:453948#endif
3949
Nico Weberbc5b06f2019-07-26 14:00:133950#if BUILDFLAG(FULL_SAFE_BROWSING)
Lukasz Anforowicz7724d092019-10-03 23:50:213951 MaybeAddThrottle(&throttles,
3952 safe_browsing::MaybeCreateNavigationThrottle(handle));
Jialiu Linbdbb81d2017-10-11 21:29:093953#endif
3954
Lukasz Anforowicz7724d092019-10-03 23:50:213955 MaybeAddThrottle(
3956 &throttles,
Emily Starkfa0ddb42019-10-24 15:49:583957 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
Joe DeBlasio6e8409a2019-02-20 23:08:273958
Lukasz Anforowicz7724d092019-10-03 23:50:213959 MaybeAddThrottle(&throttles,
3960 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
Amber Won6b5edc752017-08-17 19:23:543961
Lukasz Anforowicz7724d092019-10-03 23:50:213962 MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle));
Charles Harrison6dd11d282017-10-03 06:14:513963
Jeremy Romanec48d7a2018-03-01 17:35:093964 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533965 handle, handle->GetWebContents()->GetBrowserContext()));
3966
Colin Blundelleaa7377bf2020-01-22 08:49:103967 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
3968 // the relevant extension API whenever an SSL interstitial is shown.
3969 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
3970 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:283971 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3972 handle,
3973 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:383974 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123975
Emily Starkd6896cd32019-08-21 04:55:543976 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3977
Lukasz Anforowicz7724d092019-10-03 23:50:213978 MaybeAddThrottle(
3979 &throttles,
3980 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle));
Christopher Thompson4137cec2017-12-19 05:34:233981
Dmitry Gozman57b92ce2017-12-28 22:24:543982#if !defined(OS_ANDROID)
Lukasz Anforowicz7724d092019-10-03 23:50:213983 MaybeAddThrottle(&throttles,
3984 DevToolsWindow::MaybeCreateNavigationThrottle(handle));
Conley Owensaafcf122018-02-26 18:53:513985
Lukasz Anforowicz7724d092019-10-03 23:50:213986 MaybeAddThrottle(
3987 &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle));
jdoerrie4f9376f2018-12-12 18:26:203988
Lukasz Anforowicz7724d092019-10-03 23:50:213989 MaybeAddThrottle(
3990 &throttles,
3991 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle));
Dmitry Gozman57b92ce2017-12-28 22:24:543992#endif
3993
Carlos IL4ee307e2018-12-22 03:19:003994 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
3995 throttles.push_back(
3996 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
3997 handle));
3998 }
Robert Ogdenafd250b2018-07-25 22:21:033999
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334000#if defined(OS_WIN) || defined(OS_MACOSX) || \
4001 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Lukasz Anforowicz7724d092019-10-03 23:50:214002 MaybeAddThrottle(&throttles,
4003 browser_switcher::BrowserSwitcherNavigationThrottle::
4004 MaybeCreateThrottleFor(handle));
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134005#endif
4006
dchenge73d8520c2015-12-27 01:19:094007 return throttles;
clamy40c9e142015-09-29 11:18:474008}
4009
clamy1e5574e2016-09-29 16:48:444010std::unique_ptr<content::NavigationUIData>
4011ChromeContentBrowserClient::GetNavigationUIData(
4012 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094013 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444014}
4015
Xiaohan Wanga4e41842018-06-26 18:45:104016void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4017 const std::string& key_system,
4018 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4019 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124020 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104021#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264022 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104023 if (key_system == kWidevineKeySystem) {
4024 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4025 encryption_schemes);
4026 }
4027#endif
4028}
4029
[email protected]487974a2014-06-13 16:49:014030content::DevToolsManagerDelegate*
4031ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354032#if defined(OS_ANDROID)
4033 return new DevToolsManagerDelegateAndroid();
4034#else
[email protected]487974a2014-06-13 16:49:014035 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354036#endif
[email protected]487974a2014-06-13 16:49:014037}
4038
Rayan Kanso411e84e2019-02-13 15:27:404039void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4040 content::BrowserContext* browser_context,
4041 int service,
4042 base::Time expiration_time) {
4043 Profile* profile = Profile::FromBrowserContext(browser_context);
4044 DCHECK(profile);
4045
4046 auto* pref_service = profile->GetPrefs();
4047 DCHECK(pref_service);
4048
4049 DictionaryPrefUpdate pref_update(
4050 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4051 base::DictionaryValue* exp_dict = pref_update.Get();
4052
4053 // Convert |expiration_time| to minutes since that is the most granular
4054 // option that returns an int. base::Value does not accept int64.
4055 int expiration_time_minutes =
4056 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4057 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4058}
4059
4060base::flat_map<int, base::Time>
4061ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4062 content::BrowserContext* browser_context) {
4063 Profile* profile = Profile::FromBrowserContext(browser_context);
4064 DCHECK(profile);
4065
4066 auto* pref_service = profile->GetPrefs();
4067 DCHECK(pref_service);
4068
4069 auto* expiration_dict = pref_service->GetDictionary(
4070 prefs::kDevToolsBackgroundServicesExpirationDict);
4071 DCHECK(expiration_dict);
4072
4073 base::flat_map<int, base::Time> expiration_times;
4074 for (const auto& it : *expiration_dict) {
4075 // key.
4076 int service = 0;
4077 bool did_convert = base::StringToInt(it.first, &service);
4078 DCHECK(did_convert);
4079
4080 // value.
4081 DCHECK(it.second->is_int());
4082 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4083 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4084
4085 expiration_times[service] = expiration_time;
4086 }
4087
4088 return expiration_times;
4089}
4090
oysteinec563c582015-02-13 19:19:524091content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524092 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524093}
4094
[email protected]a6868c22013-10-09 02:50:294095bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4096 content::BrowserContext* browser_context,
4097 const GURL& url) {
brettw4b461082016-11-19 18:55:164098#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554099 return ChromeContentBrowserClientPluginsPart::
4100 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4101 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294102#else
4103 return false;
4104#endif
4105}
4106
[email protected]aec5ed52014-06-20 07:51:424107bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4108 content::BrowserContext* browser_context,
4109 const GURL& url) {
brettw4b461082016-11-19 18:55:164110#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554111 return ChromeContentBrowserClientPluginsPart::
4112 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4113 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064114#else
4115 return false;
4116#endif
4117}
4118
mlamourif8c23a2002015-01-27 13:10:104119void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014120 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434121 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524122 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104123
4124 WebContents* web_contents =
4125 WebContents::FromRenderFrameHost(render_frame_host);
4126 DCHECK(web_contents);
4127
mlamourif8c23a2002015-01-27 13:10:104128 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374129 prerender::PrerenderManagerFactory::GetForBrowserContext(
4130 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104131 if (prerender_manager &&
4132 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294133 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104134 }
4135}
4136
Sam McNallyfaf9a402017-10-31 03:06:314137void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094138 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4139 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014140 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Ben Goodger6a695c012017-06-20 20:21:204141}
4142
Robert Sesek466e43e2019-08-19 22:02:024143void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4144 base::FilePath user_data_dir;
4145 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4146 DCHECK(!user_data_dir.empty());
4147 network_contexts_parent_directory_.push_back(user_data_dir);
4148
4149 base::FilePath cache_dir;
4150 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4151 DCHECK(!cache_dir.empty());
4152 // On some platforms, the cache is a child of the user_data_dir so only
4153 // return the one path.
4154 if (!user_data_dir.IsParent(cache_dir))
4155 network_contexts_parent_directory_.push_back(cache_dir);
4156
4157 // If the cache location has been overridden by a switch or preference,
4158 // include that as well.
4159 if (auto* local_state = g_browser_process->local_state()) {
4160 base::FilePath pref_cache_dir =
4161 local_state->GetFilePath(prefs::kDiskCacheDir);
4162 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4163 network_contexts_parent_directory_.push_back(pref_cache_dir);
4164 }
4165}
4166
[email protected]30335fdf02014-02-26 19:51:274167void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174168 base::CommandLine* to_command_line,
4169 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544170 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274171#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544172 const version_info::Channel kMaxDisableEncryptionChannel =
4173 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274174#else
sdefresne6e883e42015-07-30 08:05:544175 const version_info::Channel kMaxDisableEncryptionChannel =
4176 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274177#endif
4178 if (channel <= kMaxDisableEncryptionChannel) {
4179 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444180 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274181 };
Avi Drissmand251e912018-12-26 15:46:374182 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4183 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274184 }
4185}
bashi933629552016-10-13 23:32:404186
miu54dca6c2016-11-17 10:59:384187#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4188void ChromeContentBrowserClient::CreateMediaRemoter(
4189 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504190 mojo::PendingRemote<media::mojom::RemotingSource> source,
4191 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384192 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504193 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384194}
4195#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464196
Michael Giuffrida6802ffe2017-09-29 03:40:254197base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4198 const base::CommandLine& command_line) {
4199 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164200}
4201
John Abd-El-Malek8efa11f2019-01-06 00:51:534202namespace {
4203// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024204class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534205 public:
4206 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174207 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534208 : protocol_handler_registry_(protocol_handler_registry) {}
4209 ~ProtocolHandlerThrottle() override = default;
4210
4211 void WillStartRequest(network::ResourceRequest* request,
4212 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294213 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534214 }
4215
4216 void WillRedirectRequest(net::RedirectInfo* redirect_info,
Lucas Furukawa Gadani011886592019-10-23 17:12:244217 const network::mojom::URLResponseHead& response_head,
John Abd-El-Malek8efa11f2019-01-06 00:51:534218 bool* defer,
4219 std::vector<std::string>* to_be_removed_headers,
4220 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294221 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534222 }
4223
4224 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294225 void TranslateUrl(GURL* url) {
4226 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4227 return;
4228 GURL translated_url = protocol_handler_registry_->Translate(*url);
4229 if (!translated_url.is_empty())
4230 *url = translated_url;
4231 }
4232
Clark DuValla411bda2019-08-02 03:09:174233 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534234};
4235} // namespace
4236
Minggang Wangf6840ecf2019-07-29 05:15:024237std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194238ChromeContentBrowserClient::CreateURLLoaderThrottles(
4239 const network::ResourceRequest& request,
4240 content::BrowserContext* browser_context,
4241 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4242 content::NavigationUIData* navigation_ui_data,
4243 int frame_tree_node_id) {
4244 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4245
Minggang Wangf6840ecf2019-07-29 05:15:024246 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194247
4248 Profile* profile = Profile::FromBrowserContext(browser_context);
4249
4250 ChromeNavigationUIData* chrome_navigation_ui_data =
4251 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4252
Clark DuVall68eb997f2019-06-28 05:42:284253 auto* drp_settings =
4254 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4255 browser_context);
4256 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4257 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4258 drp_settings) {
4259 if (!data_reduction_proxy_throttle_manager_) {
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:314260 data_reduction_proxy_throttle_manager_ = std::make_unique<
4261 data_reduction_proxy::DataReductionProxyThrottleManager>(
4262 drp_settings->data_reduction_proxy_service(),
4263 data_reduction_proxy::DataReductionProxyThrottleManager::CreateConfig(
4264 drp_settings->data_reduction_proxy_service()
4265 ->config()
4266 ->GetProxiesForHttp()));
Clark DuVall68eb997f2019-06-28 05:42:284267 }
4268 net::HttpRequestHeaders headers;
4269 data_reduction_proxy::DataReductionProxyRequestOptions::
4270 AddPageIDRequestHeader(
4271 &headers,
4272 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4273 result.push_back(std::make_unique<
4274 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4275 headers, data_reduction_proxy_throttle_manager_.get()));
4276 }
4277
Nico Weberbc5b06f2019-07-26 14:00:134278#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564279 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4280 request.url, *profile->GetPrefs());
4281 if (!matches_enterprise_whitelist) {
Xinghui Lu1b2922c2019-12-18 20:57:454282 // |cache_manager| is used when real time url check is enabled.
4283 base::WeakPtr<safe_browsing::VerdictCacheManager> cache_manager =
4284 // |safe_browsing_service_| may be unavailable in tests.
4285 safe_browsing_service_ &&
4286 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
4287 profile)
4288 ? safe_browsing_service_->GetVerdictCacheManagerWeakPtr(profile)
4289 : nullptr;
4290
Xinghui Ludd8b0ef2020-01-29 20:42:594291 // |identity_manager| is used when real time url check with token is
4292 // enabled.
4293 signin::IdentityManager* identity_manager =
4294 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookupWithToken(
4295 profile)
4296 ? IdentityManagerFactory::GetForProfile(profile)
4297 : nullptr;
4298
Clark DuVall5497288d2019-07-17 00:17:564299 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4300 base::BindOnce(
4301 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534302 base::Unretained(this),
4303 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)),
Xinghui Ludd8b0ef2020-01-29 20:42:594304 wc_getter, frame_tree_node_id, cache_manager, identity_manager));
Clark DuVall5497288d2019-07-17 00:17:564305 }
Nico Weberbc5b06f2019-07-26 14:00:134306#endif
Clark DuVall5497288d2019-07-17 00:17:564307
dalykba7bbfc2019-12-18 19:59:214308#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4309 result.push_back(
4310 std::make_unique<CaptivePortalURLLoaderThrottle>(wc_getter.Run()));
4311#endif
4312
Clark DuVallfffa41e2019-06-25 20:27:194313 if (chrome_navigation_ui_data &&
4314 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4315 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4316 chrome_navigation_ui_data->prerender_mode(),
4317 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234318 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194319 }
4320
David Rogere8e83f3c2019-09-12 10:56:234321 signin::IdentityManager* identity_manager =
4322 IdentityManagerFactory::GetForProfile(profile);
4323 bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount();
Clark DuVallfffa41e2019-06-25 20:27:194324
4325 chrome::mojom::DynamicParams dynamic_params = {
4326 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4327 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4328 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4329 variations::VariationsHttpHeaderProvider::GetInstance()
4330 ->GetClientDataHeader(is_signed_in)};
4331 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
David Rogere8e83f3c2019-09-12 10:56:234332 profile->IsOffTheRecord(), std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194333
Clark DuValla411bda2019-08-02 03:09:174334 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4335 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214336
Clark DuVall39c2cfc2019-06-25 21:49:284337#if BUILDFLAG(ENABLE_PLUGINS)
4338 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464339 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284340#endif
4341
Robbie McElrath127ad2b2019-07-22 22:38:114342 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404343 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584344 auto signin_throttle =
4345 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114346 if (signin_throttle)
4347 result.push_back(std::move(signin_throttle));
4348
Clark DuVallfffa41e2019-06-25 20:27:194349 return result;
4350}
4351
Ken Rockot6414c4d92017-11-08 19:58:324352void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464353 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324354 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414355#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464356 content::WebContents* web_contents =
4357 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414358#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324359 factories->emplace(
4360 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574361 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464362 web_contents->GetBrowserContext(),
4363 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414364#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4365#if defined(OS_CHROMEOS)
4366 Profile* profile =
4367 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304368 factories->emplace(content::kExternalFileScheme,
4369 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4370 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414371#endif // defined(OS_CHROMEOS)
4372#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324373}
4374
Ting Shao2dc60582019-07-15 04:43:364375void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344376 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4377 content::BrowserContext* browser_context,
4378 NonNetworkURLLoaderFactoryMap* factories) {
4379#if BUILDFLAG(ENABLE_EXTENSIONS)
4380 DCHECK(browser_context);
4381 DCHECK(factories);
4382 factories->emplace(
4383 extensions::kExtensionScheme,
4384 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4385 browser_context));
4386#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4387}
4388
4389void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364390 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4391 content::BrowserContext* browser_context,
4392 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114393#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364394 DCHECK(browser_context);
4395 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364396 factories->emplace(
4397 extensions::kExtensionScheme,
4398 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4399 browser_context));
4400#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364401}
4402
Jay Civelli2578ebe2018-06-05 18:44:314403namespace {
4404
4405// The FileURLLoaderFactory provided to the extension background pages.
4406// Checks with the ChildProcessSecurityPolicy to validate the file access.
4407class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4408 public:
4409 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4410
4411 private:
4412 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274413 void CreateLoaderAndStart(
4414 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4415 int32_t routing_id,
4416 int32_t request_id,
4417 uint32_t options,
4418 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304419 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274420 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4421 override {
Jay Civelli2578ebe2018-06-05 18:44:314422 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4423 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304424 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4425 ->OnComplete(
4426 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314427 return;
4428 }
Yutaka Hiranodf83dca42020-01-07 06:24:554429 content::CreateFileURLLoaderBypassingSecurityChecks(
4430 request, std::move(loader), std::move(client),
4431 /*observer=*/nullptr,
4432 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314433 }
4434
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524435 void Clone(
4436 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4437 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314438 }
4439
4440 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524441 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314442 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4443};
4444
4445} // namespace
4446
Ken Rockot6414c4d92017-11-08 19:58:324447void ChromeContentBrowserClient::
4448 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464449 int render_process_id,
4450 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324451 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414452#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4453 content::RenderFrameHost* frame_host =
4454 RenderFrameHost::FromID(render_process_id, render_frame_id);
4455 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4456#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4457
4458#if defined(OS_CHROMEOS)
4459 if (web_contents) {
4460 Profile* profile =
4461 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304462 factories->emplace(content::kExternalFileScheme,
4463 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4464 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414465 }
4466#endif // defined(OS_CHROMEOS)
4467
Ken Rockot6414c4d92017-11-08 19:58:324468#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464469 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4470 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324471 if (factory)
4472 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234473
4474 // This logic should match
4475 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314476 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234477 return;
Jay Civellic9bbf72d2018-03-24 01:58:314478
4479 Profile* profile =
4480 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4481 InstantService* instant_service =
4482 InstantServiceFactory::GetForProfile(profile);
4483 // The test below matches what's done by ShouldServiceRequestIOThread in
4484 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464485 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314486 factories->emplace(
4487 chrome::kChromeSearchScheme,
4488 content::CreateWebUIURLLoader(
4489 frame_host, chrome::kChromeSearchScheme,
4490 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234491 }
Jay Civellic9bbf72d2018-03-24 01:58:314492
Chris Mumfordbae8a742018-03-01 23:02:234493 extensions::ChromeExtensionWebContentsObserver* web_observer =
4494 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4495 web_contents);
4496
Karan Bhatia91928572018-03-06 01:18:074497 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4498 // to the |web_contents|.
4499 if (!web_observer)
4500 return;
4501
Chris Mumfordbae8a742018-03-01 23:02:234502 const Extension* extension =
4503 web_observer->GetExtensionFromFrame(frame_host, false);
4504 if (!extension)
4505 return;
4506
Sam McNally7414eeb72018-09-03 04:05:304507 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234508 // Support for chrome:// scheme if appropriate.
4509 if ((extension->is_extension() || extension->is_platform_app()) &&
4510 Manifest::IsComponentLocation(extension->location())) {
4511 // Components of chrome that are implemented as extensions or platform apps
4512 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304513 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4514 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4515 }
4516 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4517 (extension->is_platform_app() &&
4518 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234519 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024520 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4521 // URLs. Hosted apps are not allowed because they are served via web servers
4522 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304523 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4524 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024525 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304526 }
4527 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234528 factories->emplace(
4529 content::kChromeUIScheme,
4530 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4531 std::move(allowed_webui_hosts)));
4532 }
Jay Civelli2578ebe2018-06-05 18:44:314533
4534 // Extension with a background page get file access that gets approval from
4535 // ChildProcessSecurityPolicy.
4536 extensions::ExtensionHost* host =
4537 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4538 ->GetBackgroundHostForExtension(extension->id());
4539 if (host) {
4540 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4541 render_process_id));
4542 }
Chris Mumfordbae8a742018-03-01 23:02:234543#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324544}
4545
Ken Rockota0dfaca12018-02-15 07:26:254546bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214547 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254548 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384549 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444550 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264551 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004552 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424553 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184554 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4555 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334556 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084557 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334558 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014559 bool use_proxy = false;
4560
Ken Rockota0dfaca12018-02-15 07:26:254561#if BUILDFLAG(ENABLE_EXTENSIONS)
4562 auto* web_request_api =
4563 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214564 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254565
4566 // NOTE: Some unit test environments do not initialize
4567 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014568 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124569 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384570 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004571 browser_context, frame, render_process_id, type,
4572 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124573 if (bypass_redirect_checks)
4574 *bypass_redirect_checks = use_proxy_for_web_request;
4575 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014576 }
Ken Rockota0dfaca12018-02-15 07:26:254577#endif
Reilly Grant24bf8332018-08-27 21:55:014578
Reilly Grantcc22e602018-09-07 15:25:204579 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444580 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4581 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014582
dalyk0018c16f2020-01-08 20:20:084583#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4584 if (disable_secure_dns) {
4585 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4586 *disable_secure_dns =
4587 web_contents && CaptivePortalTabHelper::FromWebContents(web_contents) &&
4588 CaptivePortalTabHelper::FromWebContents(web_contents)
4589 ->is_captive_portal_window();
4590 }
4591#endif
4592
Reilly Grant24bf8332018-08-27 21:55:014593 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254594}
4595
Jian Lide7b43792018-06-01 23:22:134596std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4597ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4598 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144599 int frame_tree_node_id,
4600 const scoped_refptr<network::SharedURLLoaderFactory>&
4601 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134602 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4603 interceptors;
4604#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234605 interceptors.push_back(
4606 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4607 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134608#endif
Ryan Sturmaf523742019-01-16 00:15:454609
Robert Ogden3d5d5b42019-04-22 05:13:114610 ChromeNavigationUIData* chrome_navigation_ui_data =
4611 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4612
Ryan Sturm27d93f412019-02-15 21:30:144613 // TODO(ryansturm): Once this is on the UI thread, stop passing
4614 // |network_loader_factory| and have interceptors create one themselves.
4615 // https://crbug.com/931786
Doug Arnett27154792019-10-15 21:00:594616 if (previews::params::IsLitePageServerPreviewsEnabled()) {
Ryan Sturmaf523742019-01-16 00:15:454617 interceptors.push_back(
Robert Ogden0f4d88682019-09-24 22:27:524618 std::make_unique<
4619 previews::PreviewsLitePageRedirectURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114620 network_loader_factory,
4621 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4622 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454623 }
4624
Robert Ogden6946ad42020-01-13 18:01:304625 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4626 interceptors.push_back(
4627 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4628 frame_tree_node_id));
4629 }
4630
Jian Lide7b43792018-06-01 23:22:134631 return interceptors;
4632}
4633
Yutaka Hirano8e0b4d432019-07-04 07:12:384634bool ChromeContentBrowserClient::WillInterceptWebSocket(
4635 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334636#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384637 if (!frame) {
4638 return false;
4639 }
4640 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334641 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4642 frame->GetProcess()->GetBrowserContext());
4643
4644 // NOTE: Some unit test environments do not initialize
4645 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4646 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384647 return false;
Yutaka Hirano36c94952018-05-30 21:33:334648
Yutaka Hirano8e0b4d432019-07-04 07:12:384649 return web_request_api->MayHaveProxies();
4650#else
4651 return false;
4652#endif
4653}
4654
4655void ChromeContentBrowserClient::CreateWebSocket(
4656 content::RenderFrameHost* frame,
4657 WebSocketFactory factory,
4658 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394659 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384660 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404661 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4662 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384663#if BUILDFLAG(ENABLE_EXTENSIONS)
4664 if (!frame) {
4665 return;
4666 }
4667 auto* web_request_api =
4668 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4669 frame->GetProcess()->GetBrowserContext());
4670
4671 DCHECK(web_request_api);
4672 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394673 site_for_cookies.RepresentativeUrl(),
4674 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334675#endif
4676}
4677
Maks Orlovich710d5e32019-07-09 20:16:454678bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464679 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454680 content::BrowserContext* browser_context,
4681 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394682 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404683 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454684 bool is_service_worker,
4685 int process_id,
4686 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034687 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454688 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4689#if BUILDFLAG(ENABLE_EXTENSIONS)
4690 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464691 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454692 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404693 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4694 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454695 return true;
4696 }
4697#endif
4698 return false;
4699}
4700
Matt Menkeae4fdb12018-06-02 06:32:544701void ChromeContentBrowserClient::OnNetworkServiceCreated(
4702 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534703 PrefService* local_state;
4704 if (g_browser_process) {
4705 DCHECK(g_browser_process->local_state());
4706 local_state = g_browser_process->local_state();
4707 } else {
Xi Han85079c22019-04-18 21:43:054708 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4709 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534710 }
4711
4712 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4713 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4714
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494715 // Create SystemNetworkContextManager if it has not been created yet. We need
4716 // to set up global NetworkService state before anything else uses it and this
4717 // is the first opportunity to initialize SystemNetworkContextManager with the
4718 // NetworkService.
4719 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534720 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074721
Min Qin8caab1d2018-10-03 17:28:134722 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544723 network_service);
4724}
4725
Julie Jeongeun Kim5984e992019-09-11 11:00:464726mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254727ChromeContentBrowserClient::CreateNetworkContext(
4728 content::BrowserContext* context,
4729 bool in_memory,
4730 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504731 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454732 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254733}
4734
Robert Sesek34f68f312019-01-14 20:25:114735std::vector<base::FilePath>
4736ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024737 DCHECK(!network_contexts_parent_directory_.empty());
4738 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114739}
4740
Min Qin75ed6df2017-12-01 20:39:154741bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134742 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154743#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4744 // It is OK to load the saved offline copy, in MHTML format.
4745 ChromeNavigationUIData* chrome_navigation_ui_data =
4746 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4747 if (!chrome_navigation_ui_data)
4748 return false;
4749 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4750 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4751 return offline_page_data && offline_page_data->is_offline_page();
4752#else
4753 return false;
4754#endif
4755}
4756
Min Qin30a78a12017-12-06 01:29:134757bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4758 const GURL& url,
4759 const std::string& mime_type) {
4760#if BUILDFLAG(ENABLE_EXTENSIONS)
4761 // Special-case user scripts to get downloaded instead of viewed.
4762 return extensions::UserScript::IsURLUserScript(url, mime_type);
4763#else
4764 return false;
4765#endif
4766}
4767
Donna Wu838ac362018-08-10 10:36:334768void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344769 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044770 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grantc31b8192017-12-15 19:54:344771 if (!base::FeatureList::IsEnabled(features::kWebUsb))
4772 return;
4773
Reilly Grantc31b8192017-12-15 19:54:344774 WebContents* web_contents =
4775 WebContents::FromRenderFrameHost(render_frame_host);
4776 if (!web_contents) {
4777 NOTREACHED();
4778 return;
4779 }
4780
4781 UsbTabHelper* tab_helper =
4782 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Miyoung Shin62622152019-08-27 05:13:044783 tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344784}
4785
Reilly Grant0d282322019-01-29 02:42:584786#if !defined(OS_ANDROID)
4787content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4788 if (!serial_delegate_)
4789 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4790 return serial_delegate_.get();
4791}
Matt Reynolds93616f9b2019-06-07 01:28:524792
4793content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4794 if (!hid_delegate_)
4795 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4796 return hid_delegate_.get();
4797}
Reilly Grant0d282322019-01-29 02:42:584798
Balazs Engedya7ff70982018-06-04 18:14:474799std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4800ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334801 content::RenderFrameHost* render_frame_host) {
4802 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4803 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474804}
Nina Satragno8c832df2019-07-29 15:59:394805#endif
Balazs Engedya7ff70982018-06-04 18:14:474806
Jun Cai9409ded2018-01-30 00:19:464807std::unique_ptr<net::ClientCertStore>
4808ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104809 content::BrowserContext* browser_context) {
4810 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464811 ->CreateClientCertStore();
4812}
4813
David Benjamineced01fc2019-02-27 18:29:024814std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394815ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584816 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024817 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034818 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244819 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394820 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034821 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394822 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564823 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:034824 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:024825 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:204826 std::move(response_headers), LoginHandler::PRE_COMMIT,
4827 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:394828}
4829
John Abd-El-Maleka67add82018-03-09 18:22:014830bool ChromeContentBrowserClient::HandleExternalProtocol(
4831 const GURL& url,
danakjf4b9e942019-11-29 15:43:044832 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014833 int child_id,
4834 content::NavigationUIData* navigation_data,
4835 bool is_main_frame,
4836 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454837 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454838 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104839 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014840#if BUILDFLAG(ENABLE_EXTENSIONS)
4841 // External protocols are disabled for guests. An exception is made for the
4842 // "mailto" protocol, so that pages that utilize it work properly in a
4843 // WebView.
4844 ChromeNavigationUIData* chrome_data =
4845 static_cast<ChromeNavigationUIData*>(navigation_data);
4846 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4847 (chrome_data &&
4848 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4849 !url.SchemeIs(url::kMailToScheme)) {
4850 return false;
4851 }
4852#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4853
4854#if defined(OS_ANDROID)
4855 // Main frame external protocols are handled by
4856 // InterceptNavigationResourceThrottle.
4857 if (is_main_frame)
4858 return false;
4859#endif // defined(ANDROID)
4860
Emily Stark13b66bdf2019-10-04 17:11:454861 base::PostTask(
4862 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044863 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4864 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014865 return true;
4866}
4867
Jennifer Apacible4f854a82018-04-06 22:22:114868std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284869ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4870 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114871 // Note: content::OverlayWindow::Create() is defined by platform-specific
4872 // implementation in chrome/browser/ui/views. This layering hack, which goes
4873 // through //content and ContentBrowserClient, allows us to work around the
4874 // dependency constraints that disallow directly calling
4875 // chrome/browser/ui/views code either from here or from other code in
4876 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284877 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114878}
4879
Kunihiko Sakamoto19aa7082019-02-25 03:14:434880void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564881 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114882 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564883 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434884 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4885 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564886}
4887
dbeam25472e0c2017-06-23 19:02:314888// Static; handles rewriting Web UI URLs.
4889bool ChromeContentBrowserClient::HandleWebUI(
4890 GURL* url,
4891 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394892 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314893 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394894 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314895 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4896 chrome::kChromeUIHelpHost);
4897 return true; // Return true to update the displayed URL.
4898 }
4899
Hector Carmona566a20b2019-09-13 22:44:424900#if defined(OS_WIN)
4901 // TODO(crbug.com/1003960): Remove when issue is resolved.
4902 if (url->SchemeIs(content::kChromeUIScheme) &&
4903 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4904 url::Replacements<char> replacements;
4905 replacements.SetHost(
4906 chrome::kChromeUIWelcomeHost,
4907 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4908 *url = url->ReplaceComponents(replacements);
4909 return true;
4910 }
4911#endif // defined(OS_WIN)
4912
dbeam25472e0c2017-06-23 19:02:314913 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4914 browser_context, *url)) {
4915 return false;
4916 }
4917
4918#if defined(OS_CHROMEOS)
4919 // Special case : in ChromeOS in Guest mode bookmarks and history are
4920 // disabled for security reasons. New tab page explains the reasons, so
4921 // we redirect user to new tab page.
4922 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4923 if (url->SchemeIs(content::kChromeUIScheme) &&
4924 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4925 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4926 // Rewrite with new tab URL
4927 *url = GURL(chrome::kChromeUINewTabURL);
4928 }
4929 }
4930#endif
4931
4932 return true;
4933}
4934
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064935bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
4936 content::BrowserContext* browser_context,
4937 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:324938 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064939#if defined(OS_ANDROID)
4940 return false;
4941#else
4942 payments::PaymentRequestDisplayManagerFactory::GetInstance()
4943 ->GetForBrowserContext(browser_context)
4944 ->ShowPaymentHandlerWindow(url, std::move(callback));
4945 return true;
4946#endif
4947}
4948
Dan Beam141c48932019-08-22 02:29:394949// static
dbeam25472e0c2017-06-23 19:02:314950bool ChromeContentBrowserClient::HandleWebUIReverse(
4951 GURL* url,
4952 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:424953#if defined(OS_WIN)
4954 // TODO(crbug.com/1003960): Remove when issue is resolved.
4955 // No need to actually reverse-rewrite the URL, but return true to update the
4956 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
4957 if (url->SchemeIs(content::kChromeUIScheme) &&
4958 url->host() == chrome::kChromeUIWelcomeHost) {
4959 return true;
4960 }
4961#endif // defined(OS_WIN)
4962
dbeam25472e0c2017-06-23 19:02:314963 // No need to actually reverse-rewrite the URL, but return true to update the
4964 // displayed URL when rewriting chrome://help to chrome://settings/help.
4965 return url->SchemeIs(content::kChromeUIScheme) &&
4966 url->host() == chrome::kChromeUISettingsHost;
4967}
4968
Alison Maher28a73e22019-10-18 19:26:354969ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:584970 return ui::NativeTheme::GetInstanceForWeb();
4971}
4972
Clark DuVall5497288d2019-07-17 00:17:564973scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:504974ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:534975 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:354976 DCHECK_CURRENTLY_ON(BrowserThread::IO);
4977
Matt Menke562675cfe2020-01-07 15:50:534978 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:504979 return nullptr;
4980
Yuzhu Shen44094e22017-07-18 22:52:354981 // |safe_browsing_service_| may be unavailable in tests.
4982 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
4983 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:434984 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:354985 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:434986 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:354987 }
4988
Clark DuVall5497288d2019-07-17 00:17:564989 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:354990}
Daniel Vogelheim6008f572018-09-24 14:35:144991
4992base::Optional<std::string>
4993ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:264994 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:184995 content::NavigationHandle* handle) {
4996 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
4997 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:144998}
Kunihiko Sakamoto73b803d2018-10-05 09:09:524999
Takashi Toyoshima5af383aa2019-07-22 15:24:225000bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525001 // We require --user-data-dir flag too so that no dangerous changes are made
5002 // in the user's regular profile.
5003 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5004 switches::kUserDataDir);
5005}
rajendrantfeea8592018-10-19 18:26:065006
5007void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5008 int32_t network_traffic_annotation_id_hash,
5009 int64_t recv_bytes,
5010 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035011 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5012 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5013 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5014 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065015 }
5016}
Ryan Sturmaa05092f2018-10-21 03:56:545017
5018content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5019 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395020 content::NavigationHandle* navigation_handle,
5021 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135022 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5023 initial_state, navigation_handle, current_navigation_url);
5024
5025 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5026}
5027
5028content::PreviewsState
5029ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5030 content::PreviewsState initial_state,
5031 content::NavigationHandle* navigation_handle,
5032 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545033 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295034 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215035
Ryan Sturmaa05092f2018-10-21 03:56:545036 // If this is not a main frame, return the initial state. If there are no
5037 // previews in the state, return the state as is.
5038 if (!navigation_handle->IsInMainFrame() ||
5039 navigation_handle->IsSameDocument()) {
5040 return initial_state;
5041 }
5042
Robert Ogdena994eb42019-02-14 19:15:085043 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395044 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085045
Doug Arnettb3b99bc2019-08-09 16:55:565046 // Check if initial state specifies no previews should be considered.
5047 if (initial_state == content::PREVIEWS_OFF)
5048 return initial_state;
5049
Robert Ogdena994eb42019-02-14 19:15:085050 // Do not allow previews on POST navigations since the primary opt-out
5051 // mechanism is to reload the page. Because POST navigations are not
5052 // idempotent, we do not want to show a preview on a POST navigation where
5053 // opting out would cause another navigation, i.e.: a reload.
5054 if (navigation_handle->IsPost())
5055 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395056
5057 content::WebContents* web_contents = navigation_handle->GetWebContents();
5058 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5059
Ryan Sturmda2a0e02018-10-25 01:52:215060 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545061
5062 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5063 Profile::FromBrowserContext(browser_context));
5064 auto* data_reduction_proxy_settings =
5065 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5066 browser_context);
5067 // If the profile does not support previews or Data Saver, do not turn on
5068 // Previews.
5069 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355070 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545071 return content::PREVIEWS_OFF;
5072 }
5073
5074 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215075 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545076 // If this tab does not have a PreviewsUITabHelper, no preview should be
5077 // served.
5078 if (!ui_tab_helper)
5079 return content::PREVIEWS_OFF;
5080
5081 DCHECK(!browser_context->IsOffTheRecord());
5082
5083 // Other previews objects should all exist and be initialized if we have made
5084 // it past earlier checks.
5085 previews::PreviewsDeciderImpl* previews_decider_impl =
5086 previews_service->previews_ui_service()->previews_decider_impl();
5087 DCHECK(previews_decider_impl);
5088
Ryan Sturm647d1d92018-11-07 15:41:395089 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545090 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5091
Ryan Sturm647d1d92018-11-07 15:41:395092 previews::PreviewsUserData* previews_data =
5093 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5094
5095 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315096 // previews) and cannot re-evaluate PreviewsState once previews triggering
5097 // logic has already been run, so they should not change. Assume that
5098 // previews triggering logic has run when PreviewsUserData already exists and
5099 // a Lite Page Redirect preview is not being attempted, since it may also
5100 // create a previews_data before this point.
5101 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395102 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315103 previews_triggering_logic_already_ran =
5104 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395105 } else {
5106 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5107 navigation_handle, previews_decider_impl->GeneratePageId());
5108 }
5109
5110 DCHECK(previews_data);
5111
Robert Ogden01770b362019-05-22 17:36:435112 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5113 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435114 return content::ALL_SUPPORTED_PREVIEWS;
5115 }
5116
Ryan Sturmaa05092f2018-10-21 03:56:545117 bool is_reload =
5118 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5119
Ryan Sturm647d1d92018-11-07 15:41:395120 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515121 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395122
5123 // For now, treat server previews types as a single decision, and do not
5124 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5125 // header, nor does the plumbing exist to modify the PreviewsState within the
5126 // URLLoader.
Seanac57e9b92019-04-29 19:19:315127 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395128 // Copy the server state that was used before the redirect for the initial
5129 // URL.
Robert Ogden869986f2019-06-20 19:12:055130 previews_state |=
5131 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395132 } else {
Doug Arnetta3dc71582018-11-08 00:25:105133 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215134 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305135 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395136 previews_state |= server_previews_enabled_state;
5137 }
Ryan Sturmaa05092f2018-10-21 03:56:545138 }
5139
Sophie Changa71fa5d2019-11-19 23:53:515140 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545141 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315142 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355143 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5144 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545145
5146 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395147 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545148 return content::PREVIEWS_OFF;
5149 }
5150
5151 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395152 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545153 return content::PREVIEWS_NO_TRANSFORM;
5154 }
5155
5156 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395157 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5158 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545159 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395160 }
5161
5162 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5163 if (delegate) {
5164 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5165 }
Ryan Sturmaa05092f2018-10-21 03:56:545166
5167 // If the allowed previews are limited by the embedder, ensure previews honors
5168 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395169 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5170 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545171 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5172 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5173 previews_state = content::PREVIEWS_OFF;
5174 }
Ryan Sturm647d1d92018-11-07 15:41:395175 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545176 return previews_state;
5177}
5178
5179// static
5180content::PreviewsState
5181ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5182 const GURL& url,
5183 data_reduction_proxy::DataReductionProxyData* drp_data,
5184 previews::PreviewsUserData* previews_user_data,
5185 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055186 content::PreviewsState initial_state,
5187 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545188 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5189 if (!previews::HasEnabledPreviews(initial_state))
5190 return content::PREVIEWS_OFF;
5191
5192 // Check if the server sent a preview directive.
5193 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555194 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545195
Ryan Sturmaa05092f2018-10-21 03:56:545196 // Check the various other client previews types.
5197 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055198 previews_user_data, url, previews_state, previews_decider,
5199 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545200}
5201
5202content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5203 content::PreviewsState initial_state,
5204 content::NavigationHandle* navigation_handle,
5205 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135206 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5207 initial_state, navigation_handle, response_headers);
5208
5209 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5210}
5211
5212content::PreviewsState
5213ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5214 content::PreviewsState initial_state,
5215 content::NavigationHandle* navigation_handle,
5216 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545217 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5218 // Only support HTTP and HTTPS.
5219 if (navigation_handle->IsErrorPage() ||
5220 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5221 return content::PREVIEWS_OFF;
5222 }
5223
5224 // If this is not a main frame, return the initial state. If there are no
5225 // previews in the state, return the state as is.
5226 if (!previews::HasEnabledPreviews(initial_state) ||
5227 !navigation_handle->IsInMainFrame() ||
5228 navigation_handle->IsSameDocument()) {
5229 return initial_state;
5230 }
5231
5232 // WebContents that don't have a PreviewsUITabHelper are not supported.
5233 PreviewsUITabHelper* ui_tab_helper =
5234 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5235 if (!ui_tab_helper)
5236 return content::PREVIEWS_OFF;
5237
5238 // If we did not previously create a PreviewsUserData, do not go any further.
5239 previews::PreviewsUserData* previews_user_data =
5240 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5241 if (!previews_user_data)
5242 return content::PREVIEWS_OFF;
5243
5244 PreviewsService* previews_service =
5245 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5246 navigation_handle->GetWebContents()->GetBrowserContext()));
5247
5248 if (!previews_service || !previews_service->previews_ui_service())
5249 return content::PREVIEWS_OFF;
5250
5251// Check if offline previews are being used and set it in the user data.
5252#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5253 offline_pages::OfflinePageTabHelper* tab_helper =
5254 offline_pages::OfflinePageTabHelper::FromWebContents(
5255 navigation_handle->GetWebContents());
5256
Ryan Sturmfc7d92f2019-02-12 02:24:235257 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5258 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5259
5260 // If this is an offline page, but not a preview, then we should not attempt
5261 // any previews or surface the previews UI.
5262 if (is_offline_page && !is_offline_preview)
5263 return content::PREVIEWS_OFF;
5264
5265 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545266#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5267
5268 // Annotate request if no-transform directive found in response headers.
5269 if (response_headers &&
5270 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265271 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545272 }
5273
5274 previews::PreviewsDeciderImpl* previews_decider_impl =
5275 previews_service->previews_ui_service()->previews_decider_impl();
5276 DCHECK(previews_decider_impl);
5277
Clark DuVall9c5a72cc2018-10-25 01:29:215278 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5279 auto* settings =
5280 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5281 navigation_handle->GetWebContents()->GetBrowserContext());
5282 if (settings) {
5283 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5284 // does not yet have all the response information.
5285 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5286 response_headers);
5287 }
Ryan Sturmaa05092f2018-10-21 03:56:545288
5289 // Determine effective PreviewsState for this committed main frame response.
5290 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215291 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055292 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545293
5294 // Double check that we never serve a preview when we have a
5295 // cache-control:no-transform directive.
5296 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5297 !previews::HasEnabledPreviews(committed_state));
5298
Robert Ogdended292c6f2019-05-03 22:44:515299 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545300 previews_user_data->set_committed_previews_state(committed_state);
5301
5302 previews::PreviewsType committed_type =
5303 previews::GetMainFramePreviewsType(committed_state);
5304
5305 // Capture committed previews type, if any, in PreviewsUserData.
5306 // Note: this is for the subset of previews types that are decided upon
5307 // navigation commit. Previews types that are determined prior to
5308 // navigation (such as for offline pages or for redirecting to another
5309 // url), are not set here.
5310 previews_user_data->SetCommittedPreviewsType(committed_type);
5311
5312 // Log the commit decision.
5313 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5314 previews_decider_impl->LogPreviewDecisionMade(
5315 (previews_user_data->cache_control_no_transform_directive()
5316 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5317 : previews::PreviewsEligibilityReason::COMMITTED),
5318 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055319 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055320 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545321
5322 return committed_state;
5323}
Charlie Harrison650e11422018-12-04 00:37:265324
5325void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5326 content::RenderFrameHost* render_frame_host,
5327 blink::mojom::WebFeature feature) {
5328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5329 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5330 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5331 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315332
5333 // For the SameSite-by-default-cookies related features, log
5334 // the site engagement score for the site whose cookie was blocked. This is to
5335 // gauge the user impact of the cookies being blocked.
5336 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265337}
Yutaka Hirano968d6252018-12-04 05:09:315338
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525339std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315340 return ::GetProduct();
5341}
5342
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525343std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315344 return ::GetUserAgent();
5345}
Sam McNallyd54e23f92019-01-16 04:42:395346
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525347blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175348 return ::GetUserAgentMetadata();
5349}
5350
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525351base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275352 // This icon is available on Android, but adds 19KiB to the APK. Since it
5353 // isn't used on Android we exclude it to avoid bloat.
5354#if !defined(OS_ANDROID)
5355 return base::Optional<gfx::ImageSkia>(
5356 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5357 IDR_PRODUCT_LOGO_256));
5358#else
5359 return base::nullopt;
5360#endif
5361}
5362
Sam McNallyd54e23f92019-01-16 04:42:395363bool ChromeContentBrowserClient::IsBuiltinComponent(
5364 content::BrowserContext* browser_context,
5365 const url::Origin& origin) {
5366#if BUILDFLAG(ENABLE_EXTENSIONS)
5367 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5368 browser_context, origin);
5369#else
5370 return false;
5371#endif
5372}
Oleg Davydov2cc0167b2019-02-05 14:32:485373
5374bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5375 const GURL& url,
5376 content::BrowserContext* context) {
5377 PolicyBlacklistService* service =
5378 PolicyBlacklistFactory::GetForBrowserContext(context);
5379
5380 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5381 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5382 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5383}
Dominic Mazzoni21fb0282019-02-13 18:32:475384
5385ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5386 content::BrowserContext* browser_context) {
5387 Profile* profile = Profile::FromBrowserContext(browser_context);
5388 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5389}
Eric Karld6cd75b2019-03-14 22:01:365390
5391#if defined(OS_ANDROID)
5392content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525393ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365394 if (features::UseDisplayWideColorGamut()) {
5395 return WideColorGamutHeuristic::kUseDisplay;
5396 }
Khushal1fc0da52019-10-09 00:38:565397
5398 if (display::Display::HasForceDisplayColorProfile() &&
5399 display::Display::GetForcedDisplayColorProfile() ==
5400 gfx::ColorSpace::CreateDisplayP3D65()) {
5401 return WideColorGamutHeuristic::kUseDisplay;
5402 }
5403
Eric Karld6cd75b2019-03-14 22:01:365404 return WideColorGamutHeuristic::kNone;
5405}
5406#endif
Ehsan Karamad91413d72019-03-22 16:37:485407
5408base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435409ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465410 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485411 base::flat_set<std::string> mime_types;
5412#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465413 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485414 for (const auto& pair : map)
5415 mime_types.insert(pair.first);
5416#endif
5417 return mime_types;
5418}
Yao Xiaod06607b2019-05-02 23:16:365419
5420void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5421 const content::WebContents* web_contents,
5422 const content::RenderFrameHost* frame_host,
5423 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525424 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365425 const ChromeSubresourceFilterClient* client =
5426 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5427 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045428 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365429 if (!user_gesture) {
5430 if (base::FeatureList::IsEnabled(
5431 blink::features::
5432 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5433 download_policy->SetDisallowed(
5434 content::NavigationDownloadType::kAdFrameNoGesture);
5435 } else {
5436 download_policy->SetAllowed(
5437 content::NavigationDownloadType::kAdFrameNoGesture);
5438 }
Yao Xiaod06607b2019-05-02 23:16:365439 }
5440 }
5441}
Jun Cai732a05e32019-05-29 19:34:195442
5443bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5444 content::BrowserContext* browser_context,
5445 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525446 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195447 const HostContentSettingsMap* const content_settings =
5448 HostContentSettingsMapFactory::GetForProfile(
5449 Profile::FromBrowserContext(browser_context));
5450
5451 if (content_settings->GetContentSetting(
5452 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455453 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195454 std::string()) == CONTENT_SETTING_BLOCK) {
5455 return true;
5456 }
5457
5458 return false;
5459}
5460
5461void ChromeContentBrowserClient::BlockBluetoothScanning(
5462 content::BrowserContext* browser_context,
5463 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525464 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195465 HostContentSettingsMap* const content_settings =
5466 HostContentSettingsMapFactory::GetForProfile(
5467 Profile::FromBrowserContext(browser_context));
5468
5469 content_settings->SetContentSettingDefaultScope(
5470 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455471 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195472 CONTENT_SETTING_BLOCK);
5473}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475474
5475bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5476#if defined(OS_ANDROID)
5477 return extra_icu::ModuleProvider::IsModuleInstalled();
5478#endif
5479 return false;
5480}
Guido Urdaneta4030d6a32019-10-17 09:38:165481
5482bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5483 content::BrowserContext* browser_context,
5484 const GURL& url,
5485 const GURL& site_for_cookies,
5486 const base::Optional<url::Origin>& top_frame_origin) {
5487 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5488 return CookieSettingsFactory::GetForProfile(
5489 Profile::FromBrowserContext(browser_context))
5490 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5491}
Sam Goto5cf068e82019-11-04 23:08:445492
5493#if !defined(OS_ANDROID)
5494void ChromeContentBrowserClient::FetchRemoteSms(
5495 content::BrowserContext* browser_context,
5496 const url::Origin& origin,
5497 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5498 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5499}
5500#endif
Roger Tawa03ffdbd2020-01-16 18:12:545501
5502void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5503 content::WebContents* web_contents,
5504 const GURL& url,
5505 const ui::ClipboardFormatType& data_type,
5506 const std::string& data,
5507 IsClipboardPasteAllowedCallback callback) {
5508#if BUILDFLAG(FULL_SAFE_BROWSING)
5509 // Safe browsing does not support images, so accept without checking.
5510 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5511 // types when it is implemented.
5512 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5513 std::move(callback).Run(ClipboardPasteAllowed(true));
5514 return;
5515 }
5516
5517 Profile* profile =
5518 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5519 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
5520 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(profile, url,
5521 &dialog_data)) {
5522 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5523 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5524 web_contents, std::move(dialog_data),
5525 base::BindOnce(
5526 [](IsClipboardPasteAllowedCallback callback,
5527 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5528 const safe_browsing::DeepScanningDialogDelegate::Result&
5529 result) {
5530 std::move(callback).Run(
5531 ClipboardPasteAllowed(result.text_results[0]));
5532 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245533 std::move(callback)),
5534 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545535 } else {
5536 std::move(callback).Run(ClipboardPasteAllowed(true));
5537 }
5538#else
5539 std::move(callback).Run(ClipboardPasteAllowed(true));
5540#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5541}
Lukasz Anforowicz4600ea32020-01-18 02:37:485542
5543#if BUILDFLAG(ENABLE_PLUGINS)
5544bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5545 const url::Origin& embedder_origin,
5546 const content::PepperPluginInfo& plugin_info) {
5547#if BUILDFLAG(ENABLE_PDF)
5548 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5549#if BUILDFLAG(ENABLE_EXTENSIONS)
5550 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5551 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5552 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5553 return true;
5554 }
5555#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5556
5557 // Allow embedding the internal PDF plugin in chrome://print.
5558 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5559 return true;
5560
5561 // Only allow the PDF plugin in the known, trustworthy origins that are
5562 // allowlisted above. See also https://crbug.com/520422 and
5563 // https://crbug.com/1027173.
5564 return false;
5565 }
5566#endif // BUILDFLAG(ENABLE_PDF)
5567
5568 return true;
5569}
5570#endif // BUILDFLAG(ENABLE_PLUGINS)