blob: 5cda357376c240358419d83ae24fb8654ca13dbe [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
Chris Hamiltonab4722122020-05-13 18:01:287#include <iterator>
bmcquade5d2d9cf32015-06-19 17:42:288#include <map>
[email protected]7c3228a2011-11-11 21:35:229#include <set>
[email protected]1033acd2012-02-08 08:46:2710#include <utility>
[email protected]7c3228a2011-11-11 21:35:2211#include <vector>
12
brettwf1958912015-10-07 19:43:1213#include "base/base_switches.h"
[email protected]317c58f02011-11-09 02:15:0314#include "base/bind.h"
danakjdb9ae7942020-11-11 16:01:3515#include "base/callback_helpers.h"
[email protected]b80f68432011-05-02 17:22:3016#include "base/command_line.h"
Ken Rockot91c40da82019-08-12 20:07:1117#include "base/compiler_specific.h"
Jan Wilken Dörrieb5a41c32020-12-09 18:55:4718#include "base/containers/contains.h"
Will Harrisc196ed942019-08-03 03:45:3019#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2420#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0021#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1522#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5823#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2524#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1425#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3326#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3927#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0228#include "base/sequenced_task_runner.h"
Aaron Tagliaboschi19ad8d32020-05-12 20:10:4429#include "base/strings/strcat.h"
[email protected]e7463412013-06-10 22:53:4630#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0331#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2832#include "base/strings/string_util.h"
33#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2034#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0335#include "base/system/sys_info.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"
Hidehiko Abe7c68f582020-09-03 15:47:2539#include "build/chromeos_buildflags.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"
Abigail Kleina81f2e22020-05-04 14:32:4142#include "chrome/browser/accessibility/caption_util.h"
michaeln96f887e22015-04-13 23:58:3143#include "chrome/browser/after_startup_task_utils.h"
Ovidio Henriquez3d729f62020-02-07 00:43:2944#include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h"
[email protected]b8148ac2011-07-13 22:03:2545#include "chrome/browser/browser_about_handler.h"
Yutaka Hirano93e924742020-11-11 10:40:1346#include "chrome/browser/browser_features.h"
[email protected]b80f68432011-05-02 17:22:3047#include "chrome/browser/browser_process.h"
James Hollyer63eb7e0f2021-02-24 03:02:4048#include "chrome/browser/browser_process_platform_part.h"
msramek1c2b3ca2017-03-14 17:57:5649#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5150#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
Lingqi Chi775e60752020-12-14 06:31:1651#include "chrome/browser/chrome_content_browser_client_binder_policies.h"
[email protected]d5a74be2014-08-08 01:01:2752#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0953#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0854#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2255#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
56#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3057#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
58#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0659#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0860#include "chrome/browser/defaults.h"
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:2161#include "chrome/browser/device_api/device_service_impl.h"
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:5962#include "chrome/browser/download/chrome_download_manager_delegate.h"
[email protected]b1d97272013-08-17 13:38:4963#include "chrome/browser/download/download_prefs.h"
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:4964#include "chrome/browser/enterprise/connectors/connectors_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4565#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0166#include "chrome/browser/external_protocol/external_protocol_handler.h"
Yao Xiaoc5436ad2021-01-12 00:22:3067#include "chrome/browser/federated_learning/floc_eligibility_observer.h"
Yao Xiaoebed8c12020-09-26 07:51:2068#include "chrome/browser/federated_learning/floc_id_provider.h"
69#include "chrome/browser/federated_learning/floc_id_provider_factory.h"
Olivier Yiptong935e6c42020-11-21 01:28:2370#include "chrome/browser/font_access/chrome_font_access_delegate.h"
[email protected]354de9e2014-08-07 03:27:1971#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5372#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5273#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1074#include "chrome/browser/interstitials/enterprise_util.h"
Greg Thompson724aa4d92021-02-25 20:31:3375#include "chrome/browser/lifetime/application_lifetime.h"
Avi Drissmand30927342018-05-22 15:04:2776#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2777#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
Guido Urdanetae02b5722020-07-22 05:58:2178#include "chrome/browser/media/audio_service_util.h"
thakis678822e2017-04-20 17:20:3479#include "chrome/browser/media/router/media_router_feature.h"
Patrik Höglundb564859b2018-05-17 11:17:1680#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3681#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3682#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5683#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0484#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0585#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0786#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2387#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1088#include "chrome/browser/net/profile_network_context_service.h"
89#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5490#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0291#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5992#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5693#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0694#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5495#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5196#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Patrick Monettea4084692021-01-18 17:51:3097#include "chrome/browser/performance_monitor/chrome_browser_main_extra_parts_performance_monitor.h"
Adam Langley85339f62018-02-12 22:03:5698#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4299#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:11100#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:48101#include "chrome/browser/plugins/plugin_utils.h"
Liquan (Max) Gu4fd38d862021-01-15 02:14:51102#include "chrome/browser/policy/profile_policy_connector.h"
Hiroki Nakagawa7230e3412021-01-22 10:08:29103#include "chrome/browser/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h"
Hiroki Nakagawab4cd18aa2021-01-25 18:11:01104#include "chrome/browser/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
Hiroki Nakagawa483686a92020-10-29 04:31:45105#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_features.h"
106#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service.h"
107#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service_factory.h"
108#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_url_loader_interceptor.h"
Ryan Sturm8670b572020-10-21 18:45:30109#include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h"
110#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h"
111#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
Ryan Sturm6b2f6392020-12-09 21:46:00112#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader.h"
Ryan Sturm8670b572020-10-21 18:45:30113#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader_interceptor.h"
John Delaneyc2782792021-01-15 01:29:07114#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings.h"
115#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
[email protected]7e75e4a2013-05-17 17:20:03116#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14117#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32118#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49119#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06120#include "chrome/browser/profiles/renderer_updater.h"
121#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56122#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
123#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44124#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38125#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40126#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45127#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31128#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
129#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24130#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43131#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00132#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40133#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35134#include "chrome/browser/safe_browsing/ui_manager.h"
135#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58136#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43137#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44138#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20139#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35140#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40141#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23142#include "chrome/browser/signin/identity_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:02143#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Colin Blundell13e92ec2020-01-27 09:47:38144#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Chris Thompsone2e073d42020-07-23 12:33:45145#include "chrome/browser/ssl/sct_reporting_service.h"
146#include "chrome/browser/ssl/sct_reporting_service_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32147#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07148#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Mustafa Emre Acer06028d792021-01-05 19:48:51149#include "chrome/browser/ssl/typed_navigation_upgrade_throttle.h"
meacer4ef065e2015-01-09 03:21:35150#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45151#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52152#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19153#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44154#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Clark DuVall8a020d622020-06-04 00:45:50155#include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h"
Charles Harrison6dd11d282017-10-03 06:14:51156#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08157#include "chrome/browser/ui/browser_navigator.h"
158#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43159#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39160#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54161#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28162#include "chrome/browser/ui/login/login_tab_helper.h"
Jonathan Mengedoht42a19bb2020-07-28 14:10:16163#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56164#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25165#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44166#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58167#include "chrome/browser/ui/ui_features.h"
Ken Buchanan7d688352020-12-05 05:45:57168#include "chrome/browser/ui/webid/identity_dialog_controller.h"
[email protected]863f70a2012-01-27 02:05:50169#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01170#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45171#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53172#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25173#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59174#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23175#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22176#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01177#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48178#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51179#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14180#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22181#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30182#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02183#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50184#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34185#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37186#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12187#include "chrome/common/pref_names.h"
Mike Wittman67d63112020-09-19 00:33:46188#include "chrome/common/profiler/thread_profiler_configuration.h"
nigeltao7cd8d5582016-12-12 06:05:28189#include "chrome/common/renderer_configuration.mojom.h"
Ayu Ishiifbb1fad2020-06-22 20:15:07190#include "chrome/common/secure_origin_allowlist.h"
[email protected]c5dbef02011-05-13 05:06:09191#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47192#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37193#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18194#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30195#include "chrome/installer/util/google_update_settings.h"
Jiewei Qian64237ac2021-02-01 02:49:50196#include "chromeos/components/camera_app_ui/url_constants.h"
brettwf1958912015-10-07 19:43:12197#include "components/autofill/core/common/autofill_switches.h"
Clark DuVall8a020d622020-06-04 00:45:50198#include "components/blocked_content/popup_blocker.h"
Clark DuVallf5189252020-04-15 22:33:34199#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53200#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51201#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49202#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44203#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04204#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48205#include "components/cloud_devices/common/cloud_devices_switches.h"
Carlos Caballerob4283202020-08-10 14:40:46206#include "components/content_settings/browser/page_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16207#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09208#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16209#include "components/content_settings/core/browser/host_content_settings_map.h"
Titouan Rigoudy9c2c0142020-08-19 17:57:12210#include "components/content_settings/core/browser/private_network_settings.h"
mukai077089f2014-09-11 18:41:52211#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45212#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08213#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03214#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54215#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28216#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43217#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09218#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03219#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24220#include "components/dom_distiller/core/url_constants.h"
Clark DuVall7a051762021-02-12 20:22:35221#include "components/embedder_support/content_settings_utils.h"
Clark DuVall3d4e89b92020-04-03 23:07:32222#include "components/embedder_support/switches.h"
John Abd-El-Malekec1fc69e2021-01-28 19:14:41223#include "components/embedder_support/user_agent_utils.h"
Rakina Zata Amniba3eecb2020-11-02 10:12:28224#include "components/error_page/common/error.h"
blundella5e3240a2016-01-05 11:30:43225#include "components/error_page/common/error_page_switches.h"
Rakina Zata Amniba3eecb2020-11-02 10:12:28226#include "components/error_page/common/localized_error.h"
Ken Rockot4408a0f2020-07-27 19:40:54227#include "components/error_page/content/browser/net_error_auto_reloader.h"
khushalsagarc5447db22017-08-22 17:53:01228#include "components/feature_engagement/public/feature_constants.h"
229#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malekcdb5b522020-05-26 22:41:03230#include "components/google/core/common/google_switches.h"
Yutaka Hirano93e924742020-11-11 10:40:13231#include "components/keep_alive_registry/keep_alive_types.h"
232#include "components/keep_alive_registry/scoped_keep_alive.h"
Alexandre Frechette572755b2019-02-13 22:30:20233#include "components/language/core/browser/pref_names.h"
Evan Stadebbb9f5242020-09-25 17:26:46234#include "components/media_router/browser/presentation/presentation_service_delegate_impl.h"
235#include "components/media_router/browser/presentation/receiver_presentation_service_delegate_impl.h"
[email protected]8e885de2014-07-22 23:36:53236#include "components/metrics/client_info.h"
John Abd-El-Malekdc026012020-06-15 23:28:56237#include "components/metrics_services_manager/metrics_services_manager.h"
drogerc690e8802015-09-21 14:29:16238#include "components/net_log/chrome_net_log.h"
Hiroki Nakagawab4cd18aa2021-01-25 18:11:01239#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
Hiroki Nakagawa76e0fe01b2020-11-06 04:32:45240#include "components/no_state_prefetch/common/prerender_final_status.h"
Hiroki Nakagawa76e0fe01b2020-11-06 04:32:45241#include "components/no_state_prefetch/common/prerender_url_loader_throttle.h"
242#include "components/no_state_prefetch/common/prerender_util.h"
Mustafa Emre Acer06028d792021-01-05 19:48:51243#include "components/omnibox/common/omnibox_features.h"
Tao Baib827b202019-09-19 21:22:12244#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
245#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
Liquan (Max) Gu4fd38d862021-01-15 02:14:51246#include "components/payments/content/payment_handler_navigation_throttle.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06247#include "components/payments/content/payment_request_display_manager.h"
Chris Hamiltonab4722122020-05-13 18:01:28248#include "components/performance_manager/embedder/performance_manager_registry.h"
Clark DuValla11361ad32020-02-20 22:14:27249#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54250#include "components/permissions/quota_permission_context_impl.h"
Aaron Colwellb4226222020-07-25 16:11:36251#include "components/policy/content/policy_blocklist_navigation_throttle.h"
252#include "components/policy/content/policy_blocklist_service.h"
Chris Hamilton65c41312020-06-10 13:14:40253#include "components/policy/core/common/policy_pref_names.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18254#include "components/policy/core/common/policy_service.h"
255#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26256#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54257#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08258#include "components/prefs/pref_service.h"
259#include "components/prefs/scoped_user_pref_update.h"
Nico Weberbc5b06f2019-07-26 14:00:13260#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47261#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
262#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
263#include "components/safe_browsing/core/browser/url_checker_delegate.h"
264#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
265#include "components/safe_browsing/core/db/database_manager.h"
266#include "components/safe_browsing/core/features.h"
267#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58268#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Carlos IL1a5edec2020-06-12 17:56:57269#include "components/security_interstitials/content/insecure_form_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14270#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49271#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48272#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49273#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23274#include "components/signin/public/identity_manager/identity_manager.h"
Liquan (Max) Gu4fd38d862021-01-15 02:14:51275#include "components/site_engagement/content/site_engagement_service.h"
Clark DuVallaadc244c2020-06-06 03:47:14276#include "components/site_isolation/pref_names.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54277#include "components/site_isolation/preloaded_isolated_origins.h"
Clark DuVallaadc244c2020-06-06 03:47:14278#include "components/site_isolation/site_isolation_policy.h"
csharrisone985ebc2017-04-04 17:05:03279#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17280#include "components/translate/core/common/translate_switches.h"
Maks Orlovich5408ddfc2020-07-28 23:07:35281#include "components/ukm/content/source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21282#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28283#include "components/variations/variations_associated_data.h"
Ben Goldberger72533cd2020-07-21 16:11:38284#include "components/variations/variations_ids_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46285#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22286#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39287#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33288#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43289#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30290#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38291#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28292#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03293#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31294#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41295#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09296#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03297#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59298#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19299#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31300#include "content/public/browser/file_url_loader.h"
Olivier Yiptong935e6c42020-11-21 01:28:23301#include "content/public/browser/font_access_delegate.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35302#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47303#include "content/public/browser/navigation_handle.h"
304#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11305#include "content/public/browser/overlay_window.h"
Darwin Huang6195d042021-02-12 22:36:00306#include "content/public/browser/permission_controller.h"
[email protected]094c8772013-12-21 17:54:50307#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30308#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33309#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05310#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54311#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34312#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48313#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27314#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13315#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08316#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19317#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21318#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23319#include "content/public/browser/web_ui_url_loader_factory.h"
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:21320#include "content/public/common/bindings_policy.h"
[email protected]e0ada9c2012-03-20 03:54:43321#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18322#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56323#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40324#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18325#include "content/public/common/network_service_util.h"
Chris Mumfordbae8a742018-03-01 23:02:23326#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44327#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31328#include "content/public/common/user_agent.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56329#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43330#include "device/vr/buildflags/buildflags.h"
Karandeep Bhatiaae5d9f32020-07-17 02:52:34331#include "extensions/browser/process_map.h"
Scott Violetc8240b02018-03-08 22:03:59332#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48333#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30334#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28335#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18336#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04337#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31338#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44339#include "media/media_buildflags.h"
340#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12341#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42342#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52343#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08344#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53345#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51346#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58347#include "net/base/mime_util.h"
Jun Cai9409ded2018-01-30 00:19:46348#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57349#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48350#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14351#include "ppapi/buildflags/buildflags.h"
Scott Violet318a55f2018-03-30 19:08:19352#include "printing/buildflags/buildflags.h"
Guido Urdanetae02b5722020-07-22 05:58:21353#include "sandbox/policy/features.h"
Robert Sesek7d0b49b2020-07-08 18:31:27354#include "sandbox/policy/sandbox_type.h"
355#include "sandbox/policy/switches.h"
Yue Ru Sun03a6990a2020-10-24 18:04:31356#include "services/metrics/public/cpp/ukm_source_id.h"
Takashi Toyoshima128441462019-10-16 04:19:17357#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37358#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50359#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50360#include "services/network/public/cpp/resource_request.h"
Lukasz Anforowicz25620d32021-01-27 22:03:44361#include "services/network/public/cpp/self_deleting_url_loader_factory.h"
Ken Rockotcebdf9c82019-05-28 20:33:03362#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06363#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02364#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02365#include "third_party/blink/public/common/features.h"
Minggang Wangb2f82902020-08-25 16:07:09366#include "third_party/blink/public/common/loader/referrer_utils.h"
Minggang Wangf6840ecf2019-07-29 05:15:02367#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Yeunjoo Choi3df791a2021-02-17 07:07:25368#include "third_party/blink/public/common/navigation/navigation_policy.h"
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:23369#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
Chris Hamilton65c41312020-06-10 13:14:40370#include "third_party/blink/public/common/switches.h"
Yao Xiao3d1b19d2021-02-24 18:25:09371#include "third_party/blink/public/mojom/federated_learning/floc.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31372#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17373#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Gyuyoung Kim1e9d3c32020-10-12 14:04:57374#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h"
Koji Ishii3cbd93a2020-10-16 13:48:02375#include "third_party/blink/public/public_buildflags.h"
Evan Liu7cdbf8872019-06-19 16:47:21376#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26377#include "third_party/widevine/cdm/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54378#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39379#include "ui/base/l10n/l10n_util.h"
Scott Violet5ae6c42e2020-10-28 02:47:37380#include "ui/base/page_transition_types.h"
[email protected]ac55e292011-06-24 05:16:08381#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35382#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56383#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21384#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49385#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57386#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45387#include "url/gurl.h"
388#include "url/origin.h"
Olya Kalitova78ae04932020-09-21 11:26:06389#include "url/third_party/mozilla/url_parse.h"
390#include "url/url_constants.h"
[email protected]d977f9c2011-03-14 16:10:26391
[email protected]b48c9182011-10-26 18:03:30392#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20393#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14394#include "base/win/win_util.h"
395#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38396#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36397#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18398#include "sandbox/win/src/sandbox_policy.h"
Avi Drissman2e458df2020-07-29 16:24:31399#elif defined(OS_MAC)
[email protected]199fc7a2011-09-28 22:45:38400#include "chrome/browser/chrome_browser_main_mac.h"
Evan Liu054dc082020-09-30 14:09:42401#include "components/soda/constants.h"
402#include "sandbox/mac/seatbelt_exec.h"
403#include "sandbox/policy/mac/sandbox_mac.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32404#elif BUILDFLAG(IS_CHROMEOS_ASH)
Henrique Ferreirof3fbcea22021-02-05 23:12:19405#include "ash/constants/ash_switches.h"
Alice Boxhallda2659142020-05-14 06:04:37406#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42407#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30408#include "chrome/app/chrome_crash_reporter_client.h"
Henrique Ferreiroad3c6a572021-03-02 12:43:51409#include "chrome/browser/ash/login/signin/merge_session_navigation_throttle.h"
410#include "chrome/browser/ash/login/signin/merge_session_throttling_utils.h"
Yeunjoo Choi15ab1ac2021-02-04 17:15:07411#include "chrome/browser/ash/profiles/profile_helper.h"
Yeunjoo Choia43d74a2021-02-10 23:23:19412#include "chrome/browser/ash/system/input_device_settings.h"
Aya ElAttareb5fee12020-05-05 08:56:05413#include "chrome/browser/browser_process.h"
Andreea Costinas81218bf2021-01-08 11:48:14414#include "chrome/browser/browser_process_platform_part.h"
hashimotoa53e7e82016-10-26 06:30:47415#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17416#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30417#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24418#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18419#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08420#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48421#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41422#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32423#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58424#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
Pavol Marko230ea2c92017-12-03 22:35:44425#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39426#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31427#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33428#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05429#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Andreea Costinas81218bf2021-01-08 11:48:14430#include "chrome/browser/chromeos/policy/system_proxy_manager.h"
Anand K. Mistry7694c362020-03-17 23:33:34431#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
Katie Db2d07092018-12-04 18:59:36432#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27433#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31434#include "chrome/browser/ui/browser_dialogs.h"
Jesse Schettlerb7047f32020-09-18 14:50:40435#include "chromeos/components/scanning/url_constants.h"
Rohit Rao92f84b6a2020-03-25 14:57:50436#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05437#include "components/policy/core/common/policy_pref_names.h"
438#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07439#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58440#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50441#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32442#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
[email protected]b48c9182011-10-26 18:03:30443#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09444#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35445#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23446#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45447#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47448#include "chrome/android/modules/extra_icu/provider/module_provider.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36449#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36450#include "chrome/browser/android/devtools_manager_delegate_android.h"
451#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
452#include "chrome/browser/android/service_tab_launcher.h"
453#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42454#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09455#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56456#include "chrome/browser/download/android/available_offline_content_provider.h"
457#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23458#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07459#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38460#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11461#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07462#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47463#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36464#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54465#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00466#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36467#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45468#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04469#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45470#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30471#elif defined(OS_POSIX)
472#include "chrome/browser/chrome_browser_main_posix.h"
473#endif
474
Yuta Hijikata235fc62b2020-12-08 03:48:32475#if !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51476#include "ui/accessibility/accessibility_features.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32477#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51478
tmartinofb341882017-02-10 19:36:53479#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40480#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36481#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54482#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59483#include "chrome/browser/media/unified_autoplay_config.h"
Zach Trudocc4aa4d2020-09-21 22:19:45484#include "chrome/browser/policy/dm_token_utils.h"
Marc Treib7895941d2017-11-28 12:37:02485#include "chrome/browser/search/instant_service.h"
486#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46487#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51488#include "chrome/browser/ui/browser.h"
489#include "chrome/browser/ui/browser_finder.h"
490#include "chrome/browser/ui/browser_list.h"
491#include "chrome/browser/ui/browser_window.h"
Conley Owensaafcf122018-02-26 18:53:51492#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
dpapad8cc6e0f82021-02-05 09:50:52493#include "chrome/browser/ui/webui/chrome_content_browser_client_webui_part.h"
Nina Satragno8c832df2019-07-29 15:59:39494#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
495#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43496#include "chrome/common/importer/profile_import.mojom.h"
Glen Robertson8a825ae4f2020-09-16 06:50:08497#include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897
Maggie Caia2f03f52019-04-02 02:13:28498#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36499
Yuta Hijikata235fc62b2020-12-08 03:48:32500// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
501// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:31502#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:32503 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52504#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
505#endif
506
Sean McAllister0d73ca3d2020-08-19 17:54:37507#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Rohit Rao92f84b6a2020-03-25 14:57:50508#include "components/crash/core/app/crash_switches.h"
509#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24510#endif
511
Avi Drissman2e458df2020-07-29 16:24:31512#if defined(OS_POSIX) && !defined(OS_MAC)
Joshua Perazaf890e4b2019-01-03 19:19:02513#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02514#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50515#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02516#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13517#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43518#endif
[email protected]b80f68432011-05-02 17:22:30519
Maggie Caia2f03f52019-04-02 02:13:28520// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
521// single navigation throttle to display the intent picker on all platforms.
522#if !defined(OS_ANDROID)
Yuta Hijikata235fc62b2020-12-08 03:48:32523#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Cai00e2a21e2019-10-16 00:47:51524#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28525#else
526#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
527#endif
528#endif
529
[email protected]e8b6ca02013-07-10 18:00:51530#if defined(TOOLKIT_VIEWS)
531#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
532#endif
533
Yuta Hijikata235fc62b2020-12-08 03:48:32534// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
535// of lacros-chrome is complete.
536#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
estaded3aa0e82016-02-17 22:55:21537#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51538#endif
539
Mohsen Izadif1958f22019-01-18 20:29:31540#if defined(USE_OZONE)
541#include "ui/ozone/public/ozone_platform.h"
542#endif
543
Maksim Sisov1686fc22020-06-17 07:59:20544#if defined(USE_X11) || defined(USE_OZONE)
545#include "chrome/browser/chrome_browser_main_extra_parts_ozone.h"
[email protected]e8b6ca02013-07-10 18:00:51546#endif
547
brettwab78fef2016-10-12 02:56:05548#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10549#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38550#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19551#endif
552
Nico Weberaf3b00b2017-09-11 17:58:17553#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55554#include "components/nacl/browser/nacl_browser.h"
555#include "components/nacl/browser/nacl_host_message_filter.h"
556#include "components/nacl/browser/nacl_process_host.h"
557#include "components/nacl/common/nacl_process_type.h"
558#include "components/nacl/common/nacl_switches.h"
559#endif
560
brettw00899e62016-11-12 02:10:17561#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05562#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20563#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27564#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23565#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32566#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51567#include "chrome/browser/extensions/user_script_listener.h"
thestig2dbee717e2014-09-05 14:54:28568#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49569#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46570#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39571#include "components/guest_view/browser/guest_view_base.h"
572#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25573#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31574#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35575#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32576#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12577#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57578#include "extensions/browser/extension_system.h"
Aaron Colwell8c430642020-08-04 01:55:20579#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48580#include "extensions/browser/guest_view/web_view/web_view_guest.h"
581#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
582#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31583#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27584#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28585#include "extensions/common/extension.h"
586#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13587#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28588#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33589#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28590#include "extensions/common/permissions/permissions_data.h"
591#include "extensions/common/permissions/socket_permission.h"
592#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34593#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25594
brettw4b461082016-11-19 18:55:16595#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55596#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39597#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55598#endif
599
bauerb8f9c37742017-03-30 15:04:12600#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
601#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
602#endif
603
Yuta Hijikata235fc62b2020-12-08 03:48:32604#if BUILDFLAG(IS_CHROMEOS_ASH)
Henrique Ferreiro53d4dc42021-01-27 01:02:38605#include "chrome/browser/ash/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06606#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
Scott Violet1644cf72020-06-24 04:51:55607#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32608#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:06609
thakis678822e2017-04-20 17:20:34610#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38611#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09612#endif
613
Xiaohan Wanga4e41842018-06-26 18:45:10614#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49615#include "chrome/browser/media/output_protection_impl.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06616#if BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10617#include "third_party/widevine/cdm/widevine_cdm_common.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06618#if defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)
619#include "chrome/browser/media/widevine_hardware_caps.h"
Xiaohan Wanga4e41842018-06-26 18:45:10620#endif
Jeffrey Kardatzke614424232020-12-12 00:54:06621#endif // BUILDFLAG(ENABLE_WIDEVINE)
622#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wanga4e41842018-06-26 18:45:10623
mmenkedb2637ff2017-03-30 23:59:42624#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
625#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
626#endif
627
Bettinafd0c1102020-08-06 00:23:43628#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Daniel Ruberya1611e32019-04-24 21:38:35629#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32630#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35631#endif
632
Glen Robertson8a825ae4f2020-09-16 06:50:08633#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
634#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897
635#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897
636#endif
637
Jian Lide7b43792018-06-01 23:22:13638#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54639#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13640#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
641#endif
642
Will Cassella40837ba2019-07-01 21:32:00643#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Glen Robertson8a825ae4f2020-09-16 06:50:08644#include "device/vr/public/mojom/isolated_xr_service.mojom.h" // nogncheck crbug.com/1125897
Bill Orreb429222018-08-08 21:14:43645#endif
646
Roger Tawa03ffdbd2020-01-16 18:12:54647#if BUILDFLAG(FULL_SAFE_BROWSING)
Dominique Fauteux-Chapleaud280fd52021-02-03 20:06:00648#include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"
Roger Tawa03ffdbd2020-01-16 18:12:54649#endif
650
Alexander Cooperc8448702020-03-14 01:39:56651#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23652#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56653#endif
654
Yuta Hijikata235fc62b2020-12-08 03:48:32655#if BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook70fee9862020-11-18 17:28:40656#include "chrome/browser/chrome_browser_main_parts_lacros.h"
Antonio Gomesaa2603362020-10-24 12:20:18657#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_lacros.h"
James Cook92730252020-07-22 01:57:26658#include "chromeos/lacros/lacros_chrome_service_impl.h"
James Cook247a8cb2020-12-22 23:09:51659#include "ui/base/ui_base_switches.h"
Hidehiko Abeeaffbbce2020-06-23 19:41:52660#endif
661
Koji Ishii3cbd93a2020-10-16 13:48:02662#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
663#include "chrome/browser/component_updater/hyphenation_component_installer.h"
664#endif
665
[email protected]c7abd422012-09-25 00:20:08666using base::FileDescriptor;
Gyuyoung Kimd6d4f992020-11-20 14:13:22667using blink::mojom::EffectiveConnectionType;
Gyuyoung Kim1ac4ca782020-09-11 03:32:51668using blink::web_pref::WebPreferences;
[email protected]631bb742011-11-02 11:29:39669using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31670using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13671using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59672using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00673using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02674using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11675using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33676using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13677using content::WebContents;
[email protected]593d2a72013-07-26 08:48:38678using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39679
[email protected]0daaebfe2014-03-15 00:09:05680#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20681using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05682#endif
683
brettw00899e62016-11-12 02:10:17684#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28685using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27686using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28687using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28688using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27689#endif
690
brettw4b461082016-11-19 18:55:16691#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55692using plugins::ChromeContentBrowserClientPluginsPart;
693#endif
694
[email protected]c5dbef02011-05-13 05:06:09695namespace {
696
Will Harris1b9b4152019-08-21 22:33:50697#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30698// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
699// running on Windows 10 1511 and above. See
700// https://blogs.windows.com/blog/tag/code-integrity-guard/.
701const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35702 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris3249aa32021-02-25 19:30:45703// Enables pre-launch Code Integrity Guard (CIG) for Chrome network service
704// process, when running on Windows 10 1511 and above. This has no effect if
705// NetworkServiceSandbox feature is disabled. See
706// https://blogs.windows.com/blog/tag/code-integrity-guard/.
707const base::Feature kNetworkServiceCodeIntegrity{
708 "NetworkServiceCodeIntegrity", base::FEATURE_DISABLED_BY_DEFAULT};
709
Will Harris1b9b4152019-08-21 22:33:50710#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
711 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30712
Nicolas Arciniega917107c2021-02-03 02:34:35713bool IsSSLErrorOverrideAllowedForOrigin(const GURL& request_url,
714 PrefService* prefs) {
Nicolas Arciniegafa9f4c92021-01-22 19:49:25715 DCHECK(request_url.SchemeIsCryptographic());
716
Nicolas Arciniega917107c2021-02-03 02:34:35717 if (prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed))
718 return true;
Nicolas Arciniegafa9f4c92021-01-22 19:49:25719
Nicolas Arciniega917107c2021-02-03 02:34:35720 if (!prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins))
Nicolas Arciniegafa9f4c92021-01-22 19:49:25721 return true;
722
723 base::Value::ConstListView allow_list_urls =
Nicolas Arciniega917107c2021-02-03 02:34:35724 prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins)->GetList();
Nicolas Arciniegafa9f4c92021-01-22 19:49:25725 if (allow_list_urls.empty())
726 return true;
727
728 for (auto const& value : allow_list_urls) {
729 ContentSettingsPattern pattern =
730 ContentSettingsPattern::FromString(value.GetString());
731 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
732 continue;
Nicolas Arciniega917107c2021-02-03 02:34:35733
734 // Despite |request_url| being a GURL, the path is ignored when matching.
Nicolas Arciniegafa9f4c92021-01-22 19:49:25735 if (pattern.Matches(request_url))
736 return true;
737 }
738
739 return false;
740}
741
Colin Blundell9ee731dd2020-01-23 10:42:38742// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
743// parameters.
744void HandleSSLErrorWrapper(
745 content::WebContents* web_contents,
746 int cert_error,
747 const net::SSLInfo& ssl_info,
748 const GURL& request_url,
749 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38750 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
751 Profile* profile =
752 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Scott Violet2fb481102020-07-27 00:23:54753 // Profile should always outlive a WebContents
754 DCHECK(profile);
Colin Blundell9ee731dd2020-01-23 10:42:38755
Colin Blundell27331f92020-02-05 21:13:01756 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51757
758#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
759 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
760#endif
761
Colin Blundell9ee731dd2020-01-23 10:42:38762 SSLErrorHandler::HandleSSLError(
763 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53764 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51765 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38766 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Nicolas Arciniega917107c2021-02-03 02:34:35767 IsSSLErrorOverrideAllowedForOrigin(request_url, profile->GetPrefs()));
Colin Blundell9ee731dd2020-01-23 10:42:38768}
769
lazyboy5d5fede02016-03-10 04:10:14770enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53771 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14772 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53773
774 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14775 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53776
777 // An extension or app tried to load a resource of a different platform app in
778 // a tab.
779 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
780
781 // A non-app and non-extension page tried to load a platform app in a tab.
782 APP_LOADED_IN_TAB_SOURCE_OTHER,
783
lazyboy5d5fede02016-03-10 04:10:14784 APP_LOADED_IN_TAB_SOURCE_MAX
785};
786
Lei Zhang2cfceac2018-11-14 19:36:33787// Cached version of the locale so we can return the locale on the I/O
788// thread.
789std::string& GetIOThreadApplicationLocale() {
790 static base::NoDestructor<std::string> s;
791 return *s;
792}
793
[email protected]f8f93eb2012-09-25 03:06:24794// Returns a copy of the given url with its host set to given host and path set
795// to given path. Other parts of the url will be the same.
796GURL ReplaceURLHostAndPath(const GURL& url,
797 const std::string& host,
798 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05799 url::Replacements<char> replacements;
800 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
801 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24802 return url.ReplaceComponents(replacements);
803}
804
madfbd10852017-01-20 03:15:33805// Handles the rewriting of the new tab page URL based on group policy.
806bool HandleNewTabPageLocationOverride(
807 GURL* url,
808 content::BrowserContext* browser_context) {
809 if (!url->SchemeIs(content::kChromeUIScheme) ||
810 url->host() != chrome::kChromeUINewTabHost)
811 return false;
812
813 Profile* profile = Profile::FromBrowserContext(browser_context);
814 std::string ntp_location =
815 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
816 if (ntp_location.empty())
817 return false;
Olya Kalitova78ae04932020-09-21 11:26:06818 url::Component scheme;
819 if (!url::ExtractScheme(ntp_location.data(),
820 static_cast<int>(ntp_location.length()), &scheme)) {
821 ntp_location = base::StrCat(
822 {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location});
823 }
madfbd10852017-01-20 03:15:33824
825 *url = GURL(ntp_location);
826 return true;
827}
828
Becca Hughesfe8c32c2018-03-21 13:36:56829#if !defined(OS_ANDROID)
830// Check if the current url is whitelisted based on a list of whitelisted urls.
831bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57832 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56833 // Only check on HTTP and HTTPS pages.
834 if (!current_url.SchemeIsHTTPOrHTTPS())
835 return false;
836
837 for (auto const& value : whitelisted_urls) {
838 ContentSettingsPattern pattern =
839 ContentSettingsPattern::FromString(value.GetString());
840 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
841 continue;
842 if (pattern.Matches(current_url))
843 return true;
844 }
845
846 return false;
847}
848
849// Check if autoplay is allowed by policy configuration.
850bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
851 PrefService* prefs) {
852 DCHECK(prefs);
853
854 // Check if we have globally allowed autoplay by policy.
855 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
856 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
857 return true;
858 }
859
860 if (!contents)
861 return false;
862
863 // Check if the current URL matches a URL pattern on the whitelist.
864 const base::ListValue* autoplay_whitelist =
865 prefs->GetList(prefs::kAutoplayWhitelist);
866 return autoplay_whitelist &&
867 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
868 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
869}
870#endif
871
Joshua Perazaf890e4b2019-01-03 19:19:02872#if defined(OS_ANDROID)
873int GetCrashSignalFD(const base::CommandLine& command_line) {
874 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
875}
Avi Drissman2e458df2020-07-29 16:24:31876#elif defined(OS_POSIX) && !defined(OS_MAC)
[email protected]0b818f72013-10-22 00:11:03877breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
878 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02879 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52880 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02881 {
882 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31883 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03884 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50885 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02886 crash_handler->StartUploaderThread();
887 return crash_handler;
888 }
889}
890
avi3ef9ec9e2014-12-22 22:50:17891int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24892 if (crash_reporter::IsCrashpadEnabled()) {
893 int fd;
894 pid_t pid;
895 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
896 }
897
[email protected]9de4da52014-05-24 12:26:50898 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39899 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31900 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02901 if (!crash_handler)
902 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18903 return crash_handler->GetDeathSignalSocket();
904 }
905
906 std::string process_type =
907 command_line.GetSwitchValueASCII(switches::kProcessType);
908
[email protected]779dd282013-10-19 15:57:02909 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31910 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02911 if (!crash_handler)
912 crash_handler = CreateCrashHandlerHost(process_type);
913 return crash_handler->GetDeathSignalSocket();
914 }
[email protected]a1733df2012-06-22 11:24:18915
[email protected]779dd282013-10-19 15:57:02916 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31917 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02918 if (!crash_handler)
919 crash_handler = CreateCrashHandlerHost(process_type);
920 return crash_handler->GetDeathSignalSocket();
921 }
[email protected]a1733df2012-06-22 11:24:18922
[email protected]779dd282013-10-19 15:57:02923 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31924 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02925 if (!crash_handler)
926 crash_handler = CreateCrashHandlerHost(process_type);
927 return crash_handler->GetDeathSignalSocket();
928 }
[email protected]a1733df2012-06-22 11:24:18929
James Cook9207cc12017-10-19 17:08:39930 if (process_type == switches::kUtilityProcess) {
931 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
932 if (!crash_handler)
933 crash_handler = CreateCrashHandlerHost(process_type);
934 return crash_handler->GetDeathSignalSocket();
935 }
936
[email protected]a1733df2012-06-22 11:24:18937 return -1;
938}
Joshua Perazaf890e4b2019-01-03 19:19:02939#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18940
[email protected]eabbfb12013-04-05 23:28:35941void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52942 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33943 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35944}
945
estark3ba11132015-04-10 01:38:33946// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31947// SSLErrorHandler. Uses CertificateReportingService to send reports. The
948// service handles queueing and re-sending of failed reports. Each certificate
949// error creates a new instance of this class.
950class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33951 public:
meacerf43117a2016-12-27 21:02:31952 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12953 content::WebContents* web_contents)
954 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
955 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31956 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33957
958 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55959 void ReportInvalidCertificateChain(
960 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31961 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33962 }
963
964 private:
meacerf43117a2016-12-27 21:02:31965 CertificateReportingService* service_;
966
967 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33968};
969
brettw00899e62016-11-12 02:10:17970#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53971
972AppLoadedInTabSource ClassifyAppLoadedInTabSource(
973 const GURL& opener_url,
974 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58975 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
976 // The forbidden app URL was being opened by a non-extension page (e.g.
977 // http).
978 return APP_LOADED_IN_TAB_SOURCE_OTHER;
979 }
980
981 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53982 // The forbidden app URL was being opened by a different app or extension.
983 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
984 }
Lei Zhang7d0b0f42019-10-12 03:47:58985
986 // This platform app was trying to window.open() one of its own URLs.
987 if (opener_url ==
988 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
989 // Source was the background page.
990 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
991 }
992
993 // Source was a different page inside the app.
994 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53995}
[email protected]9c7656382014-08-08 21:02:30996
Darwin Huang6195d042021-02-12 22:36:00997// Returns true if there is is an extension matching `url` in
998// `render_process_id` with `permission`.
Charles Harrison34f67862017-08-22 01:04:17999//
Darwin Huang6195d042021-02-12 22:36:001000// GetExtensionOrAppByURL requires a full URL in order to match with a hosted
1001// app, even though normal extensions just use the host.
1002bool URLHasExtensionPermission(extensions::ProcessMap* process_map,
1003 extensions::ExtensionRegistry* registry,
1004 const GURL& url,
1005 int render_process_id,
1006 APIPermission::ID permission) {
1007 // Includes web URLs that are part of an extension's web extent.
csharrison95f01e922017-04-24 18:52:351008 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:171009 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:351010 return extension &&
Darwin Huang6195d042021-02-12 22:36:001011 extension->permissions_data()->HasAPIPermission(permission) &&
1012 process_map->Contains(extension->id(), render_process_id);
csharrison95f01e922017-04-24 18:52:351013}
Kevin Marshall32f99d7e2017-07-11 23:17:461014
csharrison95f01e922017-04-24 18:52:351015#endif
1016
Miyoung Shin6694b8e2020-06-18 01:38:171017mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler(
Alexander Cooperbc87af32020-07-15 15:59:451018 base::OnceCallback<content::WebContents*()> wc_getter) {
Miyoung Shin6694b8e2020-06-18 01:38:171019 mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler;
Hiroki Nakagawa7230e3412021-01-22 10:08:291020 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:571021 std::move(wc_getter).Run())
Darin Fishere41aab52020-01-29 18:31:231022 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
1023 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:121024}
1025
Julian Pastarmovb4773b82020-04-21 16:34:141026// Encapculates logic to determine if enterprise policies should be honored.
1027// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
1028// as a new central class to replace those checks is in the making.
1029bool ShouldHonorPolicies() {
1030#if defined(OS_WIN)
1031 bool is_enterprise_version =
1032 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
1033 return base::win::IsEnrolledToDomain() ||
1034 (base::win::IsDeviceRegisteredWithManagement() &&
1035 is_enterprise_version);
1036#else // defined(OS_WIN)
1037 // TODO(pastarmovj): Replace this with check for MacOS and the new management
1038 // service once it is ready.
1039 return true;
1040#endif // defined(OS_WIN)
1041}
1042
John Abd-El-Malek92bf3602019-07-31 02:25:481043void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:041044 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:481045 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451046 bool has_user_gesture,
1047 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:011048 // If there is no longer a WebContents, the request may have raced with tab
1049 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:041050 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:011051 if (!web_contents)
1052 return;
1053
Hiroki Nakagawa7230e3412021-01-22 10:08:291054 // Do not launch external requests attached to unswapped no-state prefetchers.
1055 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
1056 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
1057 web_contents);
1058 if (no_state_prefetch_contents) {
1059 no_state_prefetch_contents->Destroy(
1060 prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:011061 return;
1062 }
1063
Robbie McElrath1294d242019-05-31 20:46:221064 // Do not launch external requests for schemes that have a handler registered.
1065 ProtocolHandlerRegistry* protocol_handler_registry =
1066 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1067 web_contents->GetBrowserContext());
1068 if (protocol_handler_registry &&
1069 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1070 return;
1071
John Abd-El-Maleka67add82018-03-09 18:22:011072 bool is_whitelisted = false;
Aaron Colwellf94fd97a2020-07-21 19:37:081073 PolicyBlocklistService* service =
1074 PolicyBlocklistFactory::GetForBrowserContext(
Oleg Davydov5cfe7ab2019-02-01 12:27:191075 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:141076 if (ShouldHonorPolicies() && service) {
Aaron Colwellf94fd97a2020-07-21 19:37:081077 const policy::URLBlocklist::URLBlocklistState url_state =
1078 service->GetURLBlocklistState(url);
John Abd-El-Maleka67add82018-03-09 18:22:011079 is_whitelisted =
Aaron Colwellf94fd97a2020-07-21 19:37:081080 url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
John Abd-El-Maleka67add82018-03-09 18:22:011081 }
1082
1083 // If the URL is in whitelist, we launch it without asking the user and
1084 // without any additional security checks. Since the URL is whitelisted,
1085 // we assume it can be executed.
1086 if (is_whitelisted) {
1087 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1088 } else {
1089 ExternalProtocolHandler::LaunchUrl(
Lucas Furukawa Gadanie7649422021-02-03 03:04:321090 url, web_contents->GetMainFrame()->GetProcess()->GetID(),
1091 web_contents->GetMainFrame()->GetRenderViewHost()->GetRoutingID(),
1092 page_transition, has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011093 }
1094}
1095
Lukasz Anforowicz60d1253d2019-05-08 16:31:371096void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1097 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1098 // For renderer and utility (e.g. NetworkService) processes the switch is the
1099 // only available source, so below the combined (pref/policy + cmdline)
1100 // allowlist of secure origins is injected into |cmdline| for these other
1101 // processes.
1102 std::vector<std::string> allowlist =
1103 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1104 if (!allowlist.empty()) {
1105 cmdline->AppendSwitchASCII(
1106 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1107 base::JoinString(allowlist, ","));
1108 }
1109}
1110
Will Harris1b9b4152019-08-21 22:33:501111#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301112// Returns the full path to |module_name|. Both dev builds (where |module_name|
1113// is in the current executable's directory) and proper installs (where
1114// |module_name| is in a versioned sub-directory of the current executable's
1115// directory) are supported. The identified file is not guaranteed to exist.
Jan Wilken Dörrie852929ce2021-03-01 12:02:091116base::FilePath GetModulePath(base::WStringPiece module_name) {
Will Harrisc196ed942019-08-03 03:45:301117 base::FilePath exe_dir;
1118 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1119 DCHECK(has_path);
1120
1121 // Look for the module in a versioned sub-directory of the current
1122 // executable's directory and return the path if it can be read. This is the
1123 // expected location of modules for proper installs.
1124 const base::FilePath module_path =
1125 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1126 if (base::PathExists(module_path))
1127 return module_path;
1128
1129 // Otherwise, return the path to the module in the current executable's
1130 // directory. This is the expected location of modules for dev builds.
1131 return exe_dir.Append(module_name);
1132}
Will Harris1b9b4152019-08-21 22:33:501133#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1134 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301135
Lukasz Anforowicz7724d092019-10-03 23:50:211136void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281137 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1138 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211139 if (maybe_throttle)
1140 throttles->push_back(std::move(maybe_throttle));
1141}
1142
Chris Hamiltonab4722122020-05-13 18:01:281143void MaybeAddThrottles(
1144 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1145 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1146 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1147 std::make_move_iterator(additional.end()));
1148}
1149
Evan Stade1e71d6dd2019-10-29 03:04:491150// Returns whether |web_contents| is within a hosted app.
1151bool IsInHostedApp(WebContents* web_contents) {
1152#if BUILDFLAG(ENABLE_EXTENSIONS)
1153 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
Glen Robertson83263c72020-12-10 06:16:161154 return web_app::AppBrowserController::IsWebApp(browser);
Evan Stade1e71d6dd2019-10-29 03:04:491155#else
1156 return false;
1157#endif
1158}
1159
Lily Chenc2c9e9f2019-12-05 19:55:311160void MaybeRecordSameSiteCookieEngagementHistogram(
1161 content::RenderFrameHost* render_frame_host,
1162 blink::mojom::WebFeature feature) {
1163 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1164 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1165 return;
1166 }
1167
1168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1169 DCHECK(render_frame_host);
1170
1171 content::BrowserContext* browser_context =
1172 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1173 Profile* profile = Profile::FromBrowserContext(browser_context);
Evan Stade7a984802020-12-14 19:10:151174 auto* site_engagement_service =
1175 site_engagement::SiteEngagementService::Get(profile);
Lily Chenc2c9e9f2019-12-05 19:55:311176 if (!site_engagement_service)
1177 return;
1178
1179 blink::mojom::EngagementLevel engagement_level =
1180 site_engagement_service->GetEngagementLevel(
1181 render_frame_host->GetLastCommittedURL());
1182 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1183 UMA_HISTOGRAM_ENUMERATION(
1184 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1185 engagement_level);
1186 } else {
1187 UMA_HISTOGRAM_ENUMERATION(
1188 "Net.SameSiteBlockedCookieSiteEngagement."
1189 "CookieInsecureAndSameSiteNone",
1190 engagement_level);
1191 }
1192}
1193
Ken Rockot4408a0f2020-07-27 19:40:541194bool IsErrorPageAutoReloadEnabled() {
1195 const base::CommandLine& command_line =
1196 *base::CommandLine::ForCurrentProcess();
1197 if (command_line.HasSwitch(switches::kEnableAutomation))
1198 return false;
1199 if (command_line.HasSwitch(switches::kEnableAutoReload))
1200 return true;
1201 if (command_line.HasSwitch(switches::kDisableAutoReload))
1202 return false;
1203 return true;
1204}
1205
Thomas Lukaszewiczf87f3432021-01-21 17:20:051206bool IsTopChromeWebUIURL(const GURL& url) {
1207 return url.SchemeIs(content::kChromeUIScheme) &&
1208 base::EndsWith(url.host_piece(), chrome::kChromeUITopChromeDomain);
1209}
1210
[email protected]9dbfff12011-07-01 19:37:071211} // namespace
[email protected]c5dbef02011-05-13 05:06:091212
danakj5beedd02020-10-30 15:55:131213ChromeContentBrowserClient::ChromeContentBrowserClient() {
brettw4b461082016-11-19 18:55:161214#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551215 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401216#endif
[email protected]1deace22013-05-22 06:14:461217
Yuta Hijikata235fc62b2020-12-08 03:48:321218#if BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241219 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
Yuta Hijikata235fc62b2020-12-08 03:48:321220#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241221
dpapad8cc6e0f82021-02-05 09:50:521222#if !defined(OS_ANDROID)
1223 extra_parts_.push_back(new ChromeContentBrowserClientWebUIPart);
John Lee0ee748bf2019-12-11 21:35:441224#endif
1225
brettw00899e62016-11-12 02:10:171226#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131227 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271228#endif
bena06f7d62017-04-04 20:48:521229
Sigurdur Asgeirsson70696672019-02-08 16:14:511230 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401231}
1232
1233ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031234 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1235 delete extra_parts_[i];
1236 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401237}
1238
[email protected]bca18382012-06-25 19:15:231239// static
Chris Palmerac7d75642017-11-22 20:12:541240void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1241 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131242 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1243 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541244 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1245 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461246 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541247}
1248
1249// static
[email protected]37ca3fe02013-07-05 15:32:441250void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341251 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251252 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1253 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
Pavol Marko6adbea7f2018-02-20 16:35:281254 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1255 // user policy in addition to the same named ones in Local State (which are
1256 // used for mapping the command-line flags).
1257 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1258 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Clark DuVallaadc244c2020-06-06 03:47:141259 registry->RegisterListPref(
1260 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401261 registry->RegisterDictionaryPref(
1262 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041263 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101264#if !defined(OS_ANDROID)
1265 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561266 registry->RegisterListPref(prefs::kAutoplayWhitelist);
Yutaka Hiranoa1ab8aa2021-02-24 15:56:341267 registry->RegisterIntegerPref(prefs::kFetchKeepaliveDurationOnShutdown, 0);
François Beaufort4f8107d2018-03-05 12:12:101268#endif
Nicolas Arciniegafa9f4c92021-01-22 19:49:251269 registry->RegisterBooleanPref(prefs::kSSLErrorOverrideAllowed, true);
Nicolas Arciniega917107c2021-02-03 02:34:351270 registry->RegisterListPref(prefs::kSSLErrorOverrideAllowedForOrigins);
Carlos IL0806d682021-02-25 19:47:261271 registry->RegisterBooleanPref(
1272 prefs::kSuppressDifferentOriginSubframeJSDialogs, true);
Piotr Bialecki3fde5fa2021-01-23 01:08:031273#if defined(OS_ANDROID)
1274 registry->RegisterBooleanPref(prefs::kWebXRImmersiveArEnabled, true);
1275#endif
[email protected]bca18382012-06-25 19:15:231276}
1277
[email protected]eabbfb12013-04-05 23:28:351278// static
1279void ChromeContentBrowserClient::SetApplicationLocale(
1280 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481281 // The common case is that this function is called early in Chrome startup
1282 // before any threads are created or registered. When there are no threads,
1283 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001284 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331285 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481286 return;
1287 }
1288
1289 // Otherwise we're being called to change the locale. In this case set it on
1290 // the IO thread.
thestig00844cea2015-09-08 21:44:521291 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351292
Gabriel Charettee7cdc5cd2020-05-27 23:35:051293 content::GetIOThreadTaskRunner({})->PostTask(
1294 FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351295}
1296
Patrick Monette61dfef92019-05-30 23:06:271297std::unique_ptr<content::BrowserMainParts>
1298ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311299 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271300 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301301 // Construct the Main browser parts based on the OS type.
1302#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051303 main_parts =
danakj5beedd02020-10-30 15:55:131304 std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_);
Avi Drissman2e458df2020-07-29 16:24:311305#elif defined(OS_MAC)
Patrick Monette61dfef92019-05-30 23:06:271306 main_parts =
danakj5beedd02020-10-30 15:55:131307 std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401308#elif BUILDFLAG(IS_CHROMEOS_ASH)
Patrick Monette61dfef92019-05-30 23:06:271309 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
danakj5beedd02020-10-30 15:55:131310 parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401311#elif BUILDFLAG(IS_CHROMEOS_LACROS)
1312 main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(parameters,
1313 &startup_data_);
Yuta Hijikata235fc62b2020-12-08 03:48:321314#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
Patrick Monette61dfef92019-05-30 23:06:271315 main_parts =
danakj5beedd02020-10-30 15:55:131316 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_);
[email protected]6e677a342012-02-11 01:21:141317#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271318 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
danakj5beedd02020-10-30 15:55:131319 &startup_data_);
[email protected]b48c9182011-10-26 18:03:301320#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271321 main_parts =
danakj5beedd02020-10-30 15:55:131322 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_);
[email protected]f967b722011-09-07 00:58:041323#else
[email protected]b48c9182011-10-26 18:03:301324 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271325 main_parts =
danakj5beedd02020-10-30 15:55:131326 std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_);
[email protected]b48c9182011-10-26 18:03:301327#endif
1328
Xi Han9fd44002019-04-30 17:39:361329 bool add_profiles_extra_parts = true;
1330#if defined(OS_ANDROID)
danakj5beedd02020-10-30 15:55:131331 if (startup_data_.HasBuiltProfilePrefService())
Xi Han9fd44002019-04-30 17:39:361332 add_profiles_extra_parts = false;
1333#endif
1334 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271335 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031336
Xi Han9fd44002019-04-30 17:39:361337 // Construct additional browser parts. Stages are called in the order in
1338 // which they are added.
[email protected]c7480942011-11-08 19:18:271339#if defined(TOOLKIT_VIEWS)
Yuta Hijikata235fc62b2020-12-08 03:48:321340#if BUILDFLAG(IS_CHROMEOS_LACROS)
Antonio Gomesaa2603362020-10-24 12:20:181341 main_parts->AddParts(
1342 std::make_unique<ChromeBrowserMainExtraPartsViewsLacros>());
Yuta Hijikata235fc62b2020-12-08 03:48:321343// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
1344// of lacros-chrome is complete.
1345#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook42e933062020-07-06 20:56:121346 main_parts->AddParts(
1347 std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>());
estaded3aa0e82016-02-17 22:55:211348#else
James Cook42e933062020-07-06 20:56:121349 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>());
James Cookf9d34d22017-10-04 16:39:351350#endif
1351#endif
1352
Yuta Hijikata235fc62b2020-12-08 03:48:321353#if BUILDFLAG(IS_CHROMEOS_ASH)
James Cookf9d34d22017-10-04 16:39:351354 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
James Cook42e933062020-07-06 20:56:121355 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>());
skycea631e2016-12-16 21:52:221356#endif
[email protected]dc04be7c2012-03-15 23:57:491357
Maksim Sisov1686fc22020-06-17 07:59:201358#if defined(USE_X11) || defined(USE_OZONE)
James Cook42e933062020-07-06 20:56:121359 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>());
[email protected]e050ef142012-03-21 01:04:241360#endif
1361
James Cook42e933062020-07-06 20:56:121362 main_parts->AddParts(
Patrick Monettea4084692021-01-18 17:51:301363 std::make_unique<ChromeBrowserMainExtraPartsPerformanceMonitor>());
1364
1365 main_parts->AddParts(
James Cook42e933062020-07-06 20:56:121366 std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>());
Etienne Bergeron05d62532017-10-13 18:24:001367
James Cook42e933062020-07-06 20:56:121368 main_parts->AddParts(
1369 std::make_unique<ChromeBrowserMainExtraPartsProfiling>());
Albert J. Wong59d85acb2017-08-10 00:50:571370
James Cook42e933062020-07-06 20:56:121371 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>());
Sebastien Marchand8c0088102019-10-11 16:47:561372
Patrick Monette61dfef92019-05-30 23:06:271373 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041374
Zhenyao Mo73144652020-04-06 18:55:051375 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1376 // GpuDataManager initialization could pick up about:flags settings.
James Cook42e933062020-07-06 20:56:121377 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>());
Zhenyao Mo73144652020-04-06 18:55:051378
[email protected]50462bf02011-11-21 19:13:311379 return main_parts;
[email protected]f967b722011-09-07 00:58:041380}
1381
michaeln96f887e22015-04-13 23:58:311382void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091383 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021384 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211385 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121386 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291387
Robert Sesek466e43e2019-08-19 22:02:021388 InitNetworkContextsParentDirectory();
1389
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291390 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1391 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311392}
1393
falkenb09d443f2016-04-07 12:36:121394bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1395 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1396}
1397
Gabriel Charettec8cca992017-08-10 18:21:491398void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1399 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1400}
1401
John Abd-El-Malek9d57f9c2019-02-20 18:50:041402bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361403 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041404}
1405
[email protected]e94bbcb2012-09-07 05:33:571406std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191407 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571408 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531409 std::string partition_id;
1410
1411 // The partition ID for webview guest processes is the string value of its
1412 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451413 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531414 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171415#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501416 // The partition ID for extensions with isolated storage is treated similarly
1417 // to the above.
Aaron Colwell8c430642020-08-04 01:55:201418 else if (extensions::util::IsExtensionSiteWithIsolatedStorage(
1419 site, browser_context))
blundellf650ea02016-02-08 11:50:501420 partition_id = site.spec();
1421#endif
[email protected]1bc28312012-11-08 08:31:531422
[email protected]056efdc2013-04-06 00:14:531423 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531424 return partition_id;
1425}
1426
1427bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1428 content::BrowserContext* browser_context,
1429 const std::string& partition_id) {
1430 // The default ID is empty and is always valid.
1431 if (partition_id.empty())
1432 return true;
1433
1434 return GURL(partition_id).is_valid();
1435}
1436
Bret Sepulveda56652152020-06-24 14:47:131437content::StoragePartitionConfig
1438ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
[email protected]1bc28312012-11-08 08:31:531439 content::BrowserContext* browser_context,
Bret Sepulveda56652152020-06-24 14:47:131440 const GURL& site) {
[email protected]14acc642012-11-17 12:20:101441 // Default to the browser-wide storage partition and override based on |site|
1442 // below.
Bret Sepulveda56652152020-06-24 14:47:131443 content::StoragePartitionConfig storage_partition_config =
1444 content::StoragePartitionConfig::CreateDefault();
[email protected]14acc642012-11-17 12:20:101445
brettw00899e62016-11-12 02:10:171446#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell0ee22132020-06-23 00:28:411447 if (extensions::WebViewGuest::GetGuestPartitionConfigForSite(
Bret Sepulveda56652152020-06-24 14:47:131448 site, &storage_partition_config)) {
1449 return storage_partition_config;
Aaron Colwell0ee22132020-06-23 00:28:411450 }
[email protected]3f24f97c2013-11-17 21:53:331451
Aaron Colwell8c430642020-08-04 01:55:201452 if (site.SchemeIs(extensions::kExtensionScheme)) {
1453 // The host in an extension site URL is the extension_id.
Aaron Colwell0ee22132020-06-23 00:28:411454 CHECK(site.has_host());
Aaron Colwell8c430642020-08-04 01:55:201455 return extensions::util::GetStoragePartitionConfigForExtensionId(
1456 site.host(), browser_context);
[email protected]1df3d972014-06-11 04:55:181457 }
1458#endif
Bret Sepulveda56652152020-06-24 14:47:131459
1460 return storage_partition_config;
[email protected]d7c7c98a2012-07-12 21:27:441461}
1462
[email protected]38b098f2012-03-14 21:11:571463content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441464ChromeContentBrowserClient::GetWebContentsViewDelegate(
1465 content::WebContents* web_contents) {
Chris Hamiltonc3d5c0d12020-06-01 19:30:051466 if (auto* registry =
1467 performance_manager::PerformanceManagerRegistry::GetInstance()) {
Chris Hamilton4269bab2020-06-04 20:03:211468 registry->MaybeCreatePageNodeForWebContents(web_contents);
Chris Hamiltonc3d5c0d12020-06-01 19:30:051469 }
cm.sanchi2db24a82017-11-16 07:22:101470 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321471}
1472
Bo Liu4ade6b1b22017-11-28 02:26:351473bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1474#if defined(OS_ANDROID)
1475 const base::android::ApplicationState app_state =
1476 base::android::ApplicationStatusListener::GetState();
1477 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1478 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1479 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1480#else
1481 return true;
1482#endif
1483}
1484
[email protected]6f2862742013-12-20 07:53:191485void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231486 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301487 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
Darin Fisher8c84328c2019-07-23 02:50:001488
Darin Fisher09aa7222019-08-29 09:27:361489 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001490 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021491
grunell086a4112017-03-02 09:23:041492 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1493 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021494 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121495 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021496 host->SetUserData(
1497 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091498 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021499 audio_debug_recordings_handler));
1500
Nico Weberaf3b00b2017-09-11 17:58:171501#if BUILDFLAG(ENABLE_NACL)
Julie Jeongeun Kimae46b4e2021-01-07 11:38:141502 host->AddFilter(new nacl::NaClHostMessageFilter(
1503 host->GetID(), profile->IsOffTheRecord(), profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351504#endif
jeremyim364ac1182015-03-03 18:49:431505
Xiaohan Wang9b34281b2017-09-08 23:48:331506#if defined(OS_ANDROID)
1507 // Data cannot be persisted if the profile is off the record.
1508 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061509 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071510
1511 // Register CrashMemoryMetricsCollector to report oom related metrics.
1512 host->SetUserData(
1513 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1514 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331515#endif
1516
Jun Caidb3f93cc2018-07-09 21:54:551517 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061518 RendererUpdaterFactory::GetForProfile(original_profile)
1519 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071520
[email protected]a48ab7112014-08-01 16:48:031521 for (size_t i = 0; i < extra_parts_.size(); ++i)
1522 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141523}
1524
[email protected]3d7474ff2011-07-27 17:47:371525GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571526 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301527 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371528 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521529 if (!profile)
1530 return url;
1531
Marc Treib7d467b792017-12-04 13:31:031532#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291533 // If the input |url| should be assigned to the Instant renderer, make its
1534 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311535 // This needs to happen even if |url| corresponds to an isolated origin; see
1536 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131537 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1538 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031539#endif
[email protected]b3cb3a32013-07-31 01:32:291540
brettw00899e62016-11-12 02:10:171541#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301542 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1543 url);
[email protected]d5a74be2014-08-08 01:01:271544#else
1545 return url;
1546#endif
[email protected]36fb2c7c2011-04-04 15:49:081547}
1548
Alexander Yashkin6aedc6e2018-08-15 08:58:451549bool ChromeContentBrowserClient::
1550 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1551 content::BrowserContext* browser_context,
1552 content::SiteInstance* candidate_site_instance,
1553 bool is_main_frame,
1554 const GURL& candidate_url,
1555 const GURL& destination_url) {
1556 DCHECK(browser_context);
1557 DCHECK(candidate_site_instance);
1558#if BUILDFLAG(ENABLE_EXTENSIONS)
1559 return ChromeContentBrowserClientExtensionsPart::
1560 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1561 browser_context, candidate_site_instance, is_main_frame,
1562 candidate_url, destination_url);
1563#else
1564 return true;
1565#endif
1566}
1567
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521568bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411569#if defined(OS_ANDROID)
1570 return true;
Yuta Hijikata235fc62b2020-12-08 03:48:321571#elif BUILDFLAG(IS_CHROMEOS_ASH)
Xiyuan Xiafc9f38132019-08-02 00:51:421572 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411573#else
1574 return false;
1575#endif // defined(OS_ANDROID)
1576}
1577
[email protected]056ad2a2011-07-12 02:13:551578bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441579 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591580 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521581 Profile* profile = Profile::FromBrowserContext(browser_context);
1582 if (!profile)
1583 return false;
1584
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301585 // NTP should use process-per-site. This is a performance optimization to
1586 // reduce process count associated with NTP tabs.
Tibor Goldschwendt52e168c2020-06-01 22:17:441587 if (site_url == GURL(chrome::kChromeUINewTabURL) ||
1588 site_url == GURL(chrome::kChromeUINewTabPageURL)) {
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301589 return true;
Tibor Goldschwendt52e168c2020-06-01 22:17:441590 }
Peter Boström8e9b1632019-08-22 23:12:471591
1592 // The web footer experiment should share its renderer to not effectively
1593 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591594 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471595 return true;
1596
Marc Treib7d467b792017-12-04 13:31:031597#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591598 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521599 return true;
Marc Treib7d467b792017-12-04 13:31:031600#endif
[email protected]c5dec6292013-01-25 04:54:521601
brettw00899e62016-11-12 02:10:171602#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301603 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591604 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301605 return true;
[email protected]d5a74be2014-08-08 01:01:271606#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301607
1608 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1609 // (rather than process-per-site).
1610 return false;
[email protected]056ad2a2011-07-12 02:13:551611}
1612
Lukasz Anforowicz32d27122018-04-09 21:48:331613bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1614 content::BrowserContext* browser_context,
1615 const GURL& site_url) {
1616 Profile* profile = Profile::FromBrowserContext(browser_context);
1617 if (!profile)
1618 return false;
1619
Thomas Lukaszewiczf87f3432021-01-21 17:20:051620 // Top Chrome WebUI should share a RendererProcessHost. Return false here to
1621 // ensure the Spare Renderer is not assigned.
1622 if (IsTopChromeWebUIURL(site_url))
1623 return false;
1624
Lukasz Anforowicz32d27122018-04-09 21:48:331625#if !defined(OS_ANDROID)
1626 // Instant renderers should not use a spare process, because they require
1627 // passing switches::kInstantProcess to the renderer process when it
1628 // launches. A spare process is launched earlier, before it is known which
1629 // navigation will use it, so it lacks this flag.
1630 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1631 return false;
1632#endif
1633
1634#if BUILDFLAG(ENABLE_EXTENSIONS)
1635 return ChromeContentBrowserClientExtensionsPart::
1636 ShouldUseSpareRenderProcessHost(profile, site_url);
1637#else
1638 return true;
1639#endif
1640}
1641
nickcc0d9142015-10-14 16:27:101642bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421643 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101644 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421645 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171646#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101647 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421648 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101649 return true;
1650 }
1651#endif
1652 return false;
1653}
1654
Aaron Colwell8812a972020-10-02 23:36:561655bool ChromeContentBrowserClient::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461656 content::BrowserContext* browser_context,
1657 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171658#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell8812a972020-10-02 23:36:561659 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461660 browser_context, effective_site_url)) {
1661 return false;
1662 }
1663#endif
1664 return true;
creise5d6d1732015-08-25 19:47:061665}
1666
Nasko Oskov39023672020-05-06 17:31:141667bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1668 base::StringPiece scheme) {
1669 // Note: This method can be called from multiple threads. It is not safe to
1670 // assume it runs only on the UI thread.
1671
1672 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371673 // locked to chrome-search: origin. Locking to chrome-search would kill
1674 // processes upon legitimate requests for cookies from the search engine's
1675 // domain.
Nasko Oskov39023672020-05-06 17:31:141676 if (scheme == chrome::kChromeSearchScheme)
1677 return false;
1678
1679 // All other WebUIs must be locked to origin.
1680 return true;
1681}
1682
Maks Orlovich0e23e312019-07-16 13:13:561683bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021684 base::StringPiece scheme,
1685 bool is_embedded_origin_secure) {
Lily Chen2387bd92020-06-02 21:15:271686 // This is needed to bypass the normal SameSite rules for any chrome:// page
1687 // embedding a secure origin, regardless of the registrable domains of any
1688 // intervening frames. For example, this is needed for browser UI to interact
1689 // with SameSite cookies on accounts.google.com, which are used for logging
1690 // into Cloud Print from chrome://print, for displaying a list of available
1691 // accounts on the NTP (chrome://new-tab-page), etc.
Lily Chen0db055b2019-11-15 20:29:021692 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1693 return true;
Maks Orlovich0e23e312019-07-16 13:13:561694#if BUILDFLAG(ENABLE_EXTENSIONS)
1695 return scheme == extensions::kExtensionScheme;
1696#else
1697 return false;
1698#endif
1699}
1700
Lily Chen0db055b2019-11-15 20:29:021701bool ChromeContentBrowserClient::
1702 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1703 base::StringPiece scheme,
1704 bool is_embedded_origin_secure) {
1705 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1706}
1707
Xiaohan Wang15a07af2020-05-28 23:24:551708// TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
1709// implementation. Find a general solution to avoid code duplication.
1710std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
1711 content::BrowserContext* browser_context,
1712 const GURL& site_url) {
1713 // By default, use the |site_url| spec as the display name.
1714 std::string name = site_url.spec();
1715
1716#if BUILDFLAG(ENABLE_EXTENSIONS)
1717 // If |site_url| wraps a chrome extension ID, we can display the extension
1718 // name instead, which is more human-readable.
1719 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
1720 const extensions::Extension* extension =
1721 extensions::ExtensionRegistry::Get(browser_context)
1722 ->enabled_extensions()
1723 .GetExtensionOrAppByURL(site_url);
1724 if (extension)
1725 name = extension->name();
1726 }
1727#endif // BUILDFLAG(ENABLE_EXTENSIONS)
1728
1729 return name;
1730}
1731
Lukasz Anforowicz7097890d2019-11-20 21:49:221732void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021733 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591734 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021735 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221736 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071737#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221738 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021739 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071740#endif
1741}
1742
[email protected]73b718f2014-01-27 02:59:461743// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1744// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411745void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1746 std::vector<std::string>* additional_schemes) {
1747 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241748 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351749 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061750}
1751
alexmos94875b3b2017-03-16 22:19:011752void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1753 std::vector<std::string>* additional_schemes) {
1754 GetAdditionalWebUISchemes(additional_schemes);
1755
1756#if BUILDFLAG(ENABLE_EXTENSIONS)
1757 additional_schemes->push_back(extensions::kExtensionScheme);
1758#endif
1759}
1760
Arthur Hemeryc7b2e302021-02-18 11:16:121761void ChromeContentBrowserClient::GetAdditionalLocalAddressSpaceSchemes(
1762 std::vector<std::string>* additional_schemes) {
1763 additional_schemes->push_back(chrome::kChromeSearchScheme);
1764#if BUILDFLAG(ENABLE_EXTENSIONS)
1765 additional_schemes->push_back(extensions::kExtensionScheme);
1766#endif
1767
1768 // TODO(crbug.com/1167698): dom_distiller::kDomDistillerScheme looks like a
1769 // strong candidate. Verify if that makes sense.
1770}
1771
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521772bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011773 return webui::LogWebUIUrl(web_ui_url);
1774}
1775
John Abd-El-Malek04bfa8532018-07-12 05:28:221776bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1777 const url::Origin& origin) {
1778 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1779 origin);
1780}
1781
[email protected]46fb9442011-12-09 17:57:471782bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1783 return ProfileIOData::IsHandledURL(url);
1784}
1785
Frédéric Wang1eabba72020-10-23 15:36:551786bool ChromeContentBrowserClient::HasCustomSchemeHandler(
1787 content::BrowserContext* browser_context,
1788 const std::string& scheme) {
1789 if (ProtocolHandlerRegistry* protocol_handler_registry =
1790 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1791 browser_context)) {
1792 return protocol_handler_registry->IsHandledProtocol(scheme);
1793 }
1794
1795 return false;
1796}
1797
[email protected]c4365fa42013-05-14 01:08:241798bool ChromeContentBrowserClient::CanCommitURL(
1799 content::RenderProcessHost* process_host,
1800 const GURL& url) {
brettw00899e62016-11-12 02:10:171801#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441802 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1803 url);
[email protected]d5a74be2014-08-08 01:01:271804#else
1805 return true;
1806#endif
[email protected]c4365fa42013-05-14 01:08:241807}
1808
rdevlin.cronina32a0902016-11-09 15:50:201809void ChromeContentBrowserClient::OverrideNavigationParams(
Scott Violet5ae6c42e2020-10-28 02:47:371810 content::WebContents* web_contents,
rdevlin.cronina32a0902016-11-09 15:50:201811 SiteInstance* site_instance,
1812 ui::PageTransition* transition,
1813 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581814 content::Referrer* referrer,
1815 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201816 DCHECK(transition);
1817 DCHECK(is_renderer_initiated);
1818 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471819 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1820 // use for making security decisions 99.44% of the time, for detecting the NTP
1821 // it is reliable and the correct way. See http://crbug.com/624410.
1822 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201823 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581824 // Clicks on tiles of the new tab page should be treated as if a user
1825 // clicked on a bookmark. This is consistent with native implementations
1826 // like Android's. This also helps ensure that security features (like
1827 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1828 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201829 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1830 *is_renderer_initiated = false;
1831 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581832 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421833 }
Scott Violet5ae6c42e2020-10-28 02:47:371834#if defined(OS_ANDROID)
1835 if (web_contents) {
1836 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
1837 if (tab && tab->should_add_api2_transition_to_future_navigations()) {
1838 *transition = ui::PageTransitionFromInt(*transition |
1839 ui::PAGE_TRANSITION_FROM_API_2);
1840 }
1841 }
1842#endif
mastiza77db6992016-06-30 09:48:421843}
1844
Charles Reis29e9dd12017-09-28 00:59:151845bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1846 const GURL& url,
1847 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471848 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1849 // use for making security decisions 99.44% of the time, for detecting the NTP
1850 // it is reliable and the correct way. See http://crbug.com/624410.
1851 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1852 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151853}
1854
[email protected]2a5221b2011-09-27 23:07:311855bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301856 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311857 const GURL& site_url) {
1858 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301859 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441860 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521861 // share any host.
1862 if (!profile)
1863 return true;
1864
Marc Treib7895941d2017-11-28 12:37:021865#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141866 // Instant URLs should only be in the instant process and instant process
1867 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521868 InstantService* instant_service =
1869 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141870 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441871 bool is_instant_process =
1872 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141873 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131874 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141875 if (is_instant_process || should_be_in_instant_process)
1876 return is_instant_process && should_be_in_instant_process;
1877 }
Marc Treib7895941d2017-11-28 12:37:021878#endif
[email protected]c5dec6292013-01-25 04:54:521879
brettw00899e62016-11-12 02:10:171880#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131881 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1882 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271883#else
1884 return true;
1885#endif
[email protected]2a5221b2011-09-27 23:07:311886}
1887
[email protected]28c5d0b72014-05-13 08:19:591888bool ChromeContentBrowserClient::MayReuseHost(
1889 content::RenderProcessHost* process_host) {
Hiroki Nakagawab4cd18aa2021-01-25 18:11:011890 // If there is currently a no-state prefetcher in progress for the host
1891 // provided, it may not be shared. We require prefetchers to be by themselves
1892 // in a separate process so that we can monitor their resource usage.
1893 prerender::NoStatePrefetchManager* no_state_prefetch_manager =
1894 prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
drogerc1543152016-09-20 13:03:371895 process_host->GetBrowserContext());
Hiroki Nakagawab4cd18aa2021-01-25 18:11:011896 if (no_state_prefetch_manager &&
1897 !no_state_prefetch_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591898 return false;
1899 }
1900
1901 return true;
1902}
1903
[email protected]76411f412012-02-22 18:56:061904bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441905 content::BrowserContext* browser_context,
1906 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061907 // It has to be a valid URL for us to check for an extension.
1908 if (!url.is_valid())
1909 return false;
1910
Thomas Lukaszewiczf87f3432021-01-21 17:20:051911 // Top Chrome WebUI should try to share a RenderProcessHost with other
1912 // existing Top Chrome WebUI.
1913 if (IsTopChromeWebUIURL(url))
1914 return true;
1915
brettw00899e62016-11-12 02:10:171916#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061917 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131918 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441919 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271920#else
1921 return false;
1922#endif
[email protected]76411f412012-02-22 18:56:061923}
1924
Alex Moshchuk9c9e3882018-11-02 19:57:031925bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1926 content::RenderFrameHost* main_frame) {
1927#if BUILDFLAG(ENABLE_EXTENSIONS)
1928 return ChromeContentBrowserClientExtensionsPart::
1929 ShouldSubframesTryToReuseExistingProcess(main_frame);
1930#else
1931 return true;
1932#endif
1933}
1934
[email protected]6f371442011-11-09 06:45:461935void ChromeContentBrowserClient::SiteInstanceGotProcess(
1936 SiteInstance* site_instance) {
1937 CHECK(site_instance->HasProcess());
1938
Aran Gilmanf010bdd2019-08-28 19:55:441939 Profile* profile =
1940 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521941 if (!profile)
1942 return;
1943
Marc Treib7895941d2017-11-28 12:37:021944#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521945 // Remember the ID of the Instant process to signal the renderer process
1946 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131947 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1948 profile)) {
[email protected]c5dec6292013-01-25 04:54:521949 InstantService* instant_service =
1950 InstantServiceFactory::GetForProfile(profile);
1951 if (instant_service)
1952 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1953 }
Marc Treib7895941d2017-11-28 12:37:021954#endif
[email protected]c5dec6292013-01-25 04:54:521955
[email protected]a48ab7112014-08-01 16:48:031956 for (size_t i = 0; i < extra_parts_.size(); ++i)
1957 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461958}
1959
1960void ChromeContentBrowserClient::SiteInstanceDeleting(
1961 SiteInstance* site_instance) {
1962 if (!site_instance->HasProcess())
1963 return;
1964
[email protected]a48ab7112014-08-01 16:48:031965 for (size_t i = 0; i < extra_parts_.size(); ++i)
1966 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461967}
1968
[email protected]453f5432013-11-26 19:43:001969bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141970 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561971 const GURL& current_effective_url,
1972 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171973#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131974 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561975 ShouldSwapBrowsingInstancesForNavigation(
1976 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271977#else
1978 return false;
1979#endif
[email protected]e3daf3c2011-10-05 21:17:081980}
1981
Nasko Oskovd83b5712018-05-04 04:50:571982bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1983 // TODO(nasko): Consider supporting error page isolation in subframes if
1984 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381985 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571986}
1987
[email protected]3d831992013-07-04 01:13:291988bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1989 return !url.SchemeIs(chrome::kChromeNativeScheme);
1990}
1991
Alex Moshchukd252c192017-07-17 22:03:481992std::vector<url::Origin>
1993ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1994 std::vector<url::Origin> isolated_origin_list;
1995
Alex Moshchuk89352a72017-10-25 20:25:591996// Sign-in process isolation is not needed on Android, see
1997// https://crbug.com/739418.
1998#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381999 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:122000 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:592001#endif
Alex Moshchukd252c192017-07-17 22:03:482002
Alex Moshchuk81d2a29e2019-07-16 01:14:382003#if BUILDFLAG(ENABLE_EXTENSIONS)
2004 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
2005 GetOriginsRequiringDedicatedProcess();
2006 std::move(std::begin(origins_from_extensions),
2007 std::end(origins_from_extensions),
2008 std::back_inserter(isolated_origin_list));
2009#endif
2010
Alex Moshchuk51e1428b2020-04-22 18:00:542011 // Include additional origins preloaded with specific browser configurations,
2012 // if any. For example, this is used on Google Chrome for Android to preload
2013 // a list of important sites to isolate.
2014 auto built_in_origins =
2015 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
2016 std::move(std::begin(built_in_origins), std::end(built_in_origins),
2017 std::back_inserter(isolated_origin_list));
2018
Alex Moshchukd252c192017-07-17 22:03:482019 return isolated_origin_list;
2020}
2021
Lukasz Anforowicz5e201abd2018-03-24 00:41:062022bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:342023 return base::FeatureList::IsEnabled(features::kSitePerProcess);
2024}
2025
2026bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Clark DuVallaadc244c2020-06-06 03:47:142027 return site_isolation::SiteIsolationPolicy::
2028 ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:062029}
2030
Alex Moshchuk082b5f82019-03-14 01:34:162031std::vector<std::string>
2032ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
Clark DuVallaadc244c2020-06-06 03:47:142033 if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
Alex Moshchuk082b5f82019-03-14 01:34:162034 return {"Isolate Password Sites"};
2035 else
2036 return {};
2037}
2038
Alex Moshchuke256d562019-04-26 21:43:572039void ChromeContentBrowserClient::PersistIsolatedOrigin(
2040 content::BrowserContext* context,
2041 const url::Origin& origin) {
2042 DCHECK(!context->IsOffTheRecord());
2043 Profile* profile = Profile::FromBrowserContext(context);
2044 ListPrefUpdate update(profile->GetPrefs(),
Clark DuVallaadc244c2020-06-06 03:47:142045 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Alex Moshchuke256d562019-04-26 21:43:572046 base::ListValue* list = update.Get();
2047 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:362048 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:122049 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:572050}
2051
Ken Rockot314714c2017-11-05 23:36:242052bool ChromeContentBrowserClient::IsFileAccessAllowed(
2053 const base::FilePath& path,
2054 const base::FilePath& absolute_path,
2055 const base::FilePath& profile_path) {
2056 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2057 profile_path);
2058}
2059
[email protected]d2e1a0a2014-06-16 15:49:372060namespace {
2061
bmcquade5d2d9cf32015-06-19 17:42:282062void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2063 const base::CommandLine& browser_command_line,
2064 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522065 // List of field trials that modify the blink-settings command line flag. No
2066 // two field trials in the list should specify the same keys, otherwise one
2067 // field trial may overwrite another. See Source/core/frame/Settings.in in
2068 // Blink for the list of valid keys.
2069 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162070 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2071 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2072 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2073 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522074 };
2075
2076 std::vector<std::string> blink_settings;
2077 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2078 // Each blink-settings field trial should include a forcing_flag group,
2079 // to make sure that clients that specify the blink-settings flag on the
2080 // command line are excluded from the experiment groups. To make
2081 // sure we assign clients that specify this flag to the forcing_flag
2082 // group, we must call GetVariationParams for each field trial first
2083 // (for example, before checking HasSwitch() and returning), since
2084 // GetVariationParams has the side-effect of assigning the client to
2085 // a field trial group.
2086 std::map<std::string, std::string> params;
2087 if (variations::GetVariationParams(field_trial_name, &params)) {
2088 for (const auto& param : params) {
2089 blink_settings.push_back(base::StringPrintf(
2090 "%s=%s", param.first.c_str(), param.second.c_str()));
2091 }
2092 }
2093 }
pmeenan9ac669682015-08-17 14:57:032094
bmcquade9dd54cc2015-06-22 16:56:522095 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282096 return;
2097 }
2098
Gyuyoung Kima252d4a2020-09-16 07:20:312099 if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) ||
2100 command_line->HasSwitch(blink::switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032101 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522102 // blink-settings flag into a group with no params, and we return
2103 // above if no params were specified, so it's an error if we reach
2104 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282105 LOG(WARNING) << "Received field trial params, "
2106 "but blink-settings switch already specified.";
2107 return;
2108 }
2109
Gyuyoung Kima252d4a2020-09-16 07:20:312110 command_line->AppendSwitchASCII(blink::switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262111 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282112}
2113
[email protected]d2e1a0a2014-06-16 15:49:372114} // namespace
2115
[email protected]b80f68432011-05-02 17:22:302116void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172117 base::CommandLine* command_line,
2118 int child_process_id) {
Avi Drissman2e458df2020-07-29 16:24:312119#if defined(OS_MAC)
dcheng4af48582016-04-19 00:29:352120 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062121 GoogleUpdateSettings::LoadMetricsClientInfo();
2122 if (client_info) {
2123 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2124 client_info->client_id);
2125 }
2126#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022127#if defined(OS_ANDROID)
2128 bool enable_crash_reporter = true;
2129#else
Joshua Perazace68e2f2019-09-23 18:44:242130 bool enable_crash_reporter = false;
2131 if (crash_reporter::IsCrashpadEnabled()) {
Andreas Haasc02f4862021-02-11 10:19:312132 command_line->AppendSwitch(switches::kEnableCrashpad);
Joshua Perazace68e2f2019-09-23 18:44:242133 enable_crash_reporter = true;
2134
2135 int fd;
2136 pid_t pid;
2137 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2138 command_line->AppendSwitchASCII(
2139 crash_reporter::switches::kCrashpadHandlerPid,
2140 base::NumberToString(pid));
2141 }
2142 } else {
2143 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2144 }
Joshua Perazaf890e4b2019-01-03 19:19:022145#endif
2146 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512147 std::string switch_value;
dcheng4af48582016-04-19 00:29:352148 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532149 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512150 if (client_info)
2151 switch_value = client_info->client_id;
2152 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252153 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302154 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512155 switch_value);
[email protected]b80f68432011-05-02 17:22:302156 }
Mark Mentovaic67fa64f2015-03-24 14:00:062157#endif
[email protected]b80f68432011-05-02 17:22:302158
[email protected]f1933792011-06-14 00:49:342159 if (logging::DialogsAreSuppressed())
2160 command_line->AppendSwitch(switches::kNoErrorDialogs);
2161
[email protected]b80f68432011-05-02 17:22:302162 std::string process_type =
2163 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172164 const base::CommandLine& browser_command_line =
2165 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322166
[email protected]7c9b6f92013-09-10 18:11:352167 static const char* const kCommonSwitchNames[] = {
John Abd-El-Malekec1fc69e2021-01-28 19:14:412168 embedder_support::kUserAgent,
Aran Gilmanf010bdd2019-08-28 19:55:442169 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352170 };
2171 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372172 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322173
fqj15ff3f72015-10-09 19:20:022174 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432175 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312176 };
fqj15ff3f72015-10-09 19:20:022177 command_line->CopySwitchesFrom(browser_command_line,
2178 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372179 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312180
Yuta Hijikata235fc62b2020-12-08 03:48:322181#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]6bdc52272014-05-27 00:12:332182 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2183 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522184 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332185 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2186 homedir.value().c_str());
2187#endif
2188
[email protected]718eab62011-10-05 21:16:522189 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032190 content::RenderProcessHost* process =
2191 content::RenderProcessHost::FromID(child_process_id);
2192 Profile* profile =
2193 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442194 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032195 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442196 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2197 process, profile);
[email protected]a48ab7112014-08-01 16:48:032198 }
2199
Yuta Hijikata235fc62b2020-12-08 03:48:322200#if BUILDFLAG(IS_CHROMEOS_ASH)
Aran Gilmanf010bdd2019-08-28 19:55:442201 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2202 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302203 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442204 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2205 login_profile);
[email protected]b80f68432011-05-02 17:22:302206#endif
2207
Aran Gilmanf010bdd2019-08-28 19:55:442208 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222209 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372210 if (process) {
[email protected]a8d851f82011-12-21 00:32:372211 PrefService* prefs = profile->GetPrefs();
2212 // Currently this pref is only registered if applied via a policy.
2213 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2214 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2215 // Turn this policy into a command line switch.
2216 command_line->AppendSwitch(switches::kDisable3DAPIs);
2217 }
[email protected]718eab62011-10-05 21:16:522218
Bettinafd0c1102020-08-06 00:23:432219#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
2220 bool client_side_detection_enabled =
2221 safe_browsing::IsSafeBrowsingEnabled(*prefs) &&
Daniel Rubery33506f9f2020-10-07 00:28:132222 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2223 ::switches::kDisableClientSidePhishingDetection);
Bettinafd0c1102020-08-06 00:23:432224#if BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2225 client_side_detection_enabled &= base::FeatureList::IsEnabled(
2226 safe_browsing::kClientSideDetectionForAndroid);
2227#endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2228
[email protected]a8d851f82011-12-21 00:32:372229 // Disable client-side phishing detection in the renderer if it is
Bettinafd0c1102020-08-06 00:23:432230 // disabled in the Profile preferences, or by command line flag, or by not
2231 // being enabled on Android.
2232 if (!client_side_detection_enabled) {
[email protected]a8d851f82011-12-21 00:32:372233 command_line->AppendSwitch(
2234 switches::kDisableClientSidePhishingDetection);
2235 }
Bettinafd0c1102020-08-06 00:23:432236#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
[email protected]0045b0f42012-07-26 11:52:082237
vitalybukaa7ae5052014-09-26 04:11:132238 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2239 command_line->AppendSwitch(switches::kDisablePrintPreview);
2240
Marc Treib7895941d2017-11-28 12:37:022241#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522242 InstantService* instant_service =
2243 InstantServiceFactory::GetForProfile(profile);
2244 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542245 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522246 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542247 }
Marc Treib7895941d2017-11-28 12:37:022248#endif
fqjba8749c2015-10-29 15:33:072249
fqj38306f7b2015-11-02 16:59:062250 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542251 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432252 command_line->AppendSwitch(
2253 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542254 }
Daniel Vogelheim976f1c22017-11-22 16:26:032255
Lukasz Anforowicz60d1253d2019-05-08 16:31:372256 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2257
Katie Dillonc25ee5c92019-09-12 17:05:422258 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2259 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2260 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2261 }
Takashi Toyoshima128441462019-10-16 04:19:172262
Daniel Libbyc5bfd91f2020-03-07 03:44:102263 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2264 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2265 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2266 }
2267
Adrienne Walker297651292020-05-08 00:23:182268 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2269 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2270 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2271 }
Chris Hamilton65c41312020-06-10 13:14:402272
2273 // The IntensiveWakeUpThrottling feature is typically managed via a
2274 // base::Feature, but it has a managed policy override. The override is
2275 // communicated to blink via a custom command-line flag. See
2276 // PageSchedulerImpl for the other half of related logic.
2277 PrefService* local_state = g_browser_process->local_state();
2278 const PrefService::Preference* pref = local_state->FindPreference(
2279 policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled);
2280 if (pref && pref->IsManaged()) {
2281 command_line->AppendSwitchASCII(
2282 blink::switches::kIntensiveWakeUpThrottlingPolicy,
2283 pref->GetValue()->GetBool()
2284 ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable
2285 : blink::switches::
2286 kIntensiveWakeUpThrottlingPolicy_ForceDisable);
2287 }
Aaron Tagliaboschi8f3a28302020-06-24 03:08:262288
2289 // Same as above, but for the blink side of UserAgentClientHints
2290 if (!local_state->GetBoolean(
2291 policy::policy_prefs::kUserAgentClientHintsEnabled)) {
2292 command_line->AppendSwitch(
2293 blink::switches::kUserAgentClientHintDisable);
2294 }
Rakina Zata Amnic123bd22020-07-31 19:08:392295
Eric Lawrencea8a460c2020-11-06 21:10:422296 if (!local_state->GetBoolean(
2297 policy::policy_prefs::kTargetBlankImpliesNoOpener)) {
2298 command_line->AppendSwitch(
2299 switches::kDisableTargetBlankImpliesNoOpener);
2300 }
2301
Rakina Zata Amnic123bd22020-07-31 19:08:392302#if defined(OS_ANDROID)
2303 // Communicating to content/ for BackForwardCache.
2304 if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) &&
2305 !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) {
2306 command_line->AppendSwitch(switches::kDisableBackForwardCache);
2307 }
2308#endif // defined(OS_ANDROID)
[email protected]47c7ec82012-01-18 03:29:212309 }
[email protected]4287a3d2011-06-13 23:56:512310
Aran Gilmanf010bdd2019-08-28 19:55:442311 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2312 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282313
mdjonesa6b9e172016-09-23 16:24:302314#if defined(OS_ANDROID)
2315 // If the platform is Android, force the distillability service on.
2316 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2317#endif
2318
[email protected]47c7ec82012-01-18 03:29:212319 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512320 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192321 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412322 autofill::switches::kShowAutofillSignatures,
Yuta Hijikata235fc62b2020-12-08 03:48:322323#if BUILDFLAG(IS_CHROMEOS_ASH)
Chris Mumford6b1696b2019-01-25 02:54:302324 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2325#endif
brettw00899e62016-11-12 02:10:172326#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512327 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272328 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172329 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512330 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272331 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172332 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]5adb7742020-06-30 14:28:122333 extensions::switches::kAllowlistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282334#endif
estark4b003b332015-02-14 01:07:052335 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512336 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482337 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512338 switches::kCloudPrintXmppEndpoint,
dslomova893e972014-12-05 09:39:572339 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462340 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302341 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512342 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172343#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242344 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482345 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552346#endif
[email protected]ce304ce2013-02-22 21:54:452347 switches::kEnableNetBenchmarking,
Yuta Hijikata235fc62b2020-12-08 03:48:322348#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchukce6f8802020-01-30 09:30:342349 switches::kForceAppMode,
2350#endif
Nico Weberaf3b00b2017-09-11 17:58:172351#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592352 switches::kForcePNaClSubzero,
2353#endif
Marc Treibad33cf942017-08-24 11:19:002354 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032355 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512356 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102357 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322358 embedder_support::kOriginTrialDisabledFeatures,
2359 embedder_support::kOriginTrialDisabledTokens,
2360 embedder_support::kOriginTrialPublicKey,
wychene55687342015-11-13 20:17:032361 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092362 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512363 };
2364
2365 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372366 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172367 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172368#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382369 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442370 extensions::switches::kAllowHTTPBackgroundPage,
2371 extensions::switches::kEnableExperimentalExtensionApis,
2372 extensions::switches::kExtensionsOnChromeURLs,
[email protected]5adb7742020-06-30 14:28:122373 extensions::switches::kAllowlistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382374 };
2375
2376 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372377 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282378#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372379 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Ken Rockot4e805fd2020-10-01 03:07:392380 } else if (process_type == switches::kZygoteProcess) {
Yutaka Hirano93e924742020-11-11 10:40:132381 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
Nico Weberaf3b00b2017-09-11 17:58:172382#if BUILDFLAG(ENABLE_NACL)
Yutaka Hirano93e924742020-11-11 10:40:132383 static const char* const kSwitchNames[] = {
2384 switches::kEnableNaClDebug,
2385 switches::kEnableNaClNonSfiMode,
2386 switches::kForcePNaClSubzero,
2387 switches::kNaClDangerousNoSandboxNonSfi,
2388 };
[email protected]4287a3d2011-06-13 23:56:512389
Yutaka Hirano93e924742020-11-11 10:40:132390 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2391 base::size(kSwitchNames));
Bill Budge431f0b32020-10-27 21:31:382392#endif
James Cook247a8cb2020-12-22 23:09:512393#if BUILDFLAG(IS_CHROMEOS_LACROS)
2394 // Ensure zygote loads the resource bundle for the right locale.
2395 static const char* const kMoreSwitchNames[] = {switches::kLang};
2396 command_line->CopySwitchesFrom(browser_command_line, kMoreSwitchNames,
2397 base::size(kMoreSwitchNames));
2398#endif
[email protected]d56ecf922012-02-15 16:03:112399 } else if (process_type == switches::kGpuProcess) {
Corentin Walleze660b152020-07-15 16:07:542400 // If --ignore-gpu-blocklist is passed in, don't send in crash reports
[email protected]d56ecf922012-02-15 16:03:112401 // because GPU is expected to be unreliable.
Corentin Wallez49c0110d2020-11-17 10:15:162402 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) &&
[email protected]d56ecf922012-02-15 16:03:112403 !command_line->HasSwitch(switches::kDisableBreakpad))
2404 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302405 }
[email protected]6f08af82011-09-15 01:19:032406
Yuta Hijikata235fc62b2020-12-08 03:48:322407#if BUILDFLAG(IS_CHROMEOS_ASH)
Joshua Peraza30d8fc72019-08-19 17:24:302408 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112409 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292410 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112411 };
2412 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2413 base::size(kSwitchNames));
2414 }
2415#endif
2416
Mike Wittman67d63112020-09-19 00:33:462417 ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Mike Wittman0d21648f2020-09-30 19:05:082418 command_line);
Andrew Comminos66057672019-05-01 00:03:342419
Sean McAllister0d73ca3d2020-08-19 17:54:372420#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Andrew Comminos66057672019-05-01 00:03:342421 // Processes may only query perf_event_open with the BPF sandbox disabled.
2422 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
Robert Sesek7d0b49b2020-07-08 18:31:272423 command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
Andrew Comminos66057672019-05-01 00:03:342424 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2425 }
2426#endif
[email protected]b80f68432011-05-02 17:22:302427}
2428
Olivier Yiptong0daa93f2019-08-22 19:40:082429std::string
2430ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2431 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2432}
2433
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:592434download::QuarantineConnectionCallback
2435ChromeContentBrowserClient::GetQuarantineConnectionCallback() {
2436 return base::BindRepeating(
2437 &ChromeDownloadManagerDelegate::ConnectToQuarantineService);
2438}
2439
[email protected]b80f68432011-05-02 17:22:302440std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432441 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332442 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302443 return g_browser_process->GetApplicationLocale();
2444}
2445
[email protected]597a867b2011-11-18 18:31:202446std::string ChromeContentBrowserClient::GetAcceptLangs(
2447 content::BrowserContext* context) {
2448 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202449 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082450}
2451
Dana Fried34d580002019-04-24 20:05:482452gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492453 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482454 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082455}
2456
bengre8a146f2016-03-10 01:20:222457bool ChromeContentBrowserClient::IsDataSaverEnabled(
2458 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382459 if (!browser_context || browser_context->IsOffTheRecord())
2460 return false;
2461
Robert Ogdenc995d4fe2019-03-25 19:18:372462 Profile* profile = Profile::FromBrowserContext(browser_context);
2463 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412464 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2465 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222466}
2467
Kenichi Ishibashi46329872018-07-17 09:43:402468void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2469 content::BrowserContext* browser_context,
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:232470 blink::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402471 DCHECK(browser_context);
2472 DCHECK(out_prefs);
2473 renderer_preferences_util::UpdateFromSystemSettings(
2474 out_prefs, Profile::FromBrowserContext(browser_context));
2475}
2476
Clark DuVall5690e742019-07-17 18:26:172477bool ChromeContentBrowserClient::AllowAppCache(
2478 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172479 const GURL& site_for_cookies,
2480 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172481 content::BrowserContext* context) {
2482 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Clark DuVall7a051762021-02-12 20:22:352483 return embedder_support::AllowAppCache(
2484 manifest_url, site_for_cookies, top_frame_origin,
2485 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
2486 .get());
Clark DuVall5690e742019-07-17 18:26:172487}
2488
Alexander Timin17edc742020-04-23 18:22:182489content::AllowServiceWorkerResult
John Abd-El-Malek70810942020-10-27 05:14:382490ChromeContentBrowserClient::AllowServiceWorker(
Matt Falkenhagen7b509e52019-08-15 23:11:412491 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542492 const GURL& site_for_cookies,
2493 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412494 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182495 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412496 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542497 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412498
2499#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022500 // Check if this is an extension-related service worker, and, if so, if it's
2501 // allowed (this can return false if, e.g., the extension is disabled).
2502 // If it's not allowed, return immediately. We deliberately do *not* report
Carlos Caballerob4283202020-08-10 14:40:462503 // to the PageSpecificContentSettings, since the service worker is blocked
Matt Falkenhagena59e1cce2019-08-22 23:45:022504 // because of the extension, rather than because of the user's content
2505 // settings.
John Abd-El-Malek70810942020-10-27 05:14:382506 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
Matt Falkenhagena59e1cce2019-08-22 23:45:022507 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182508 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022509 }
Matt Falkenhagen7b509e52019-08-15 23:11:412510#endif
2511
2512 Profile* profile = Profile::FromBrowserContext(context);
Clark DuVall7a051762021-02-12 20:22:352513 return embedder_support::AllowServiceWorker(
2514 scope, site_for_cookies, top_frame_origin,
2515 CookieSettingsFactory::GetForProfile(profile).get(),
2516 HostContentSettingsMapFactory::GetForProfile(profile));
Matt Falkenhagen7b509e52019-08-15 23:11:412517}
2518
Jochen Eisinger0ff7645c2017-11-28 08:11:262519bool ChromeContentBrowserClient::AllowSharedWorker(
2520 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542521 const GURL& site_for_cookies,
2522 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262523 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372524 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262525 content::BrowserContext* context,
2526 int render_process_id,
2527 int render_frame_id) {
2528 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2529
2530 // Check if cookies are allowed.
Clark DuVall7a051762021-02-12 20:22:352531 bool allow = embedder_support::AllowSharedWorker(
2532 worker_url, site_for_cookies, top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262533 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Clark DuVall7a051762021-02-12 20:22:352534 .get());
Jochen Eisinger0ff7645c2017-11-28 08:11:262535
Carlos Caballerob4283202020-08-10 14:40:462536 content_settings::PageSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372537 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2538 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262539 return allow;
2540}
2541
Patrick Monette6cb099a2019-09-18 19:31:272542bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2543 const std::string& scheme) {
2544#if BUILDFLAG(ENABLE_EXTENSIONS)
2545 // Extensions are allowed to start cross-origin shared workers.
2546 if (scheme == extensions::kExtensionScheme)
2547 return true;
2548#endif
2549
2550 return false;
2551}
2552
Clark DuVallab63d142019-07-23 04:24:362553bool ChromeContentBrowserClient::AllowSignedExchange(
2554 content::BrowserContext* browser_context) {
2555 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2556 Profile* profile = Profile::FromBrowserContext(browser_context);
2557 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2558}
2559
[email protected]f917df22014-07-10 07:45:492560void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352561 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572562 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172563 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572564 base::OnceCallback<void(bool)> callback) {
Clark DuVall7a051762021-02-12 20:22:352565 bool allow = embedder_support::AllowWorkerFileSystem(
2566 url, CookieSettingsFactory::GetForProfile(
2567 Profile::FromBrowserContext(browser_context))
2568 .get());
brettw00899e62016-11-12 02:10:172569#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572570 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492571#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572572 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492573#endif
2574}
2575
brettw00899e62016-11-12 02:10:172576#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492577void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2578 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172579 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572580 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492581 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572582 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492583 std::map<int, int> process_map;
2584 std::map<int, int>::const_iterator it;
2585 bool has_web_view_guest = false;
2586 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172587 for (const auto& it : render_frames) {
2588 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492589 continue;
2590
Lukasz Anforowicz09060bdf72018-08-23 15:53:172591 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492592
Lukasz Anforowicz09060bdf72018-08-23 15:53:172593 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492594 has_web_view_guest = true;
2595 }
2596 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572597 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492598 return;
2599 }
[email protected]dffb9fc2014-07-16 04:14:022600 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492601 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492602
[email protected]140d6cd92014-08-12 18:26:462603 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572604 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2605 web_view_permission_helper->RequestFileSystemPermission(
2606 url, allow,
2607 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2608 weak_factory_.GetWeakPtr(), url, render_frames,
2609 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492610}
2611#endif
2612
2613void ChromeContentBrowserClient::FileSystemAccessed(
2614 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172615 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572616 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492617 bool allow) {
[email protected]62151052012-02-01 18:40:482618 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172619 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462620 content_settings::PageSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572621 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352622 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572623 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352624}
2625
[email protected]7c5ff9a2012-03-02 07:42:492626bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2627 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572628 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172629 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
Clark DuVall7a051762021-02-12 20:22:352630 bool allow = embedder_support::AllowWorkerIndexedDB(
2631 url, CookieSettingsFactory::GetForProfile(
2632 Profile::FromBrowserContext(browser_context))
2633 .get());
[email protected]7c5ff9a2012-03-02 07:42:492634
2635 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172636 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462637 content_settings::PageSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572638 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492639 }
2640
2641 return allow;
2642}
2643
Ben Kelly6b2e61c2019-03-14 16:06:292644bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2645 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572646 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292647 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
Clark DuVall7a051762021-02-12 20:22:352648 bool allow = embedder_support::AllowWorkerCacheStorage(
2649 url, CookieSettingsFactory::GetForProfile(
2650 Profile::FromBrowserContext(browser_context))
2651 .get());
Ben Kelly6b2e61c2019-03-14 16:06:292652
2653 // Record access to CacheStorage for potential display in UI.
2654 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462655 content_settings::PageSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572656 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292657 }
2658
2659 return allow;
2660}
2661
Joshua Bell1ebc8df2019-11-06 00:27:582662bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2663 const GURL& url,
2664 content::BrowserContext* browser_context,
2665 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
Clark DuVall7a051762021-02-12 20:22:352666 return embedder_support::AllowWorkerWebLocks(
2667 url, CookieSettingsFactory::GetForProfile(
2668 Profile::FromBrowserContext(browser_context))
2669 .get());
Joshua Bell1ebc8df2019-11-06 00:27:582670}
2671
jyasskinc993ce8d2016-03-31 00:38:342672ChromeContentBrowserClient::AllowWebBluetoothResult
2673ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452674 content::BrowserContext* browser_context,
2675 const url::Origin& requesting_origin,
2676 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342677 // TODO(crbug.com/598890): Don't disable if
2678 // base::CommandLine::ForCurrentProcess()->
2679 // HasSwitch(switches::kEnableWebBluetooth) is true.
2680 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272681 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342682 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272683 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342684 // The kill switch is enabled for this permission. Block requests.
2685 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2686 }
2687
jyasskin98bdd3992016-02-26 20:25:452688 const HostContentSettingsMap* const content_settings =
2689 HostContentSettingsMapFactory::GetForProfile(
2690 Profile::FromBrowserContext(browser_context));
2691
csharrisonaec2c542016-10-12 19:40:362692 if (content_settings->GetContentSetting(
2693 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:142694 ContentSettingsType::BLUETOOTH_GUARD) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342695 return AllowWebBluetoothResult::BLOCK_POLICY;
2696 }
2697 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452698}
2699
beaufort.francois01135bf2016-11-23 14:37:362700std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2701 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2702 "blocklist_additions");
scheib74250322016-04-07 03:32:212703}
2704
John Delaneyc2782792021-01-15 01:29:072705bool ChromeContentBrowserClient::IsConversionMeasurementAllowed(
Charlie Harrison071ac922020-06-25 19:11:222706 content::BrowserContext* browser_context) {
Charlie Harrison071ac922020-06-25 19:11:222707 Profile* profile = Profile::FromBrowserContext(browser_context);
John Delaneyc2782792021-01-15 01:29:072708 PrivacySandboxSettings* privacy_sandbox_settings =
2709 PrivacySandboxSettingsFactory::GetForProfile(profile);
2710
2711 return privacy_sandbox_settings &&
2712 privacy_sandbox_settings->IsPrivacySandboxAllowed();
2713}
2714
2715bool ChromeContentBrowserClient::IsConversionMeasurementOperationAllowed(
2716 content::BrowserContext* browser_context,
2717 ConversionMeasurementOperation operation,
2718 const url::Origin* impression_origin,
2719 const url::Origin* conversion_origin,
2720 const url::Origin* reporting_origin) {
2721 Profile* profile = Profile::FromBrowserContext(browser_context);
2722
2723 PrivacySandboxSettings* privacy_sandbox_settings =
2724 PrivacySandboxSettingsFactory::GetForProfile(profile);
2725 if (!privacy_sandbox_settings)
2726 return false;
2727
2728 switch (operation) {
2729 case ConversionMeasurementOperation::kImpression:
2730 DCHECK(impression_origin);
2731 DCHECK(reporting_origin);
2732 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2733 *impression_origin, *reporting_origin);
2734 case ConversionMeasurementOperation::kConversion:
2735 DCHECK(conversion_origin);
2736 DCHECK(reporting_origin);
2737 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2738 *conversion_origin, *reporting_origin);
2739 case ConversionMeasurementOperation::kReport:
2740 DCHECK(impression_origin);
2741 DCHECK(conversion_origin);
2742 DCHECK(reporting_origin);
2743 return privacy_sandbox_settings->ShouldSendConversionReport(
2744 *impression_origin, *conversion_origin, *reporting_origin);
2745 }
Charlie Harrison071ac922020-06-25 19:11:222746}
2747
Yuta Hijikata235fc62b2020-12-08 03:48:322748#if BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522749void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072750 content::BrowserContext* browser_context) {
2751 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2752 if (user_manager) {
2753 const user_manager::User* user =
2754 chromeos::ProfileHelper::Get()->GetUserByProfile(
2755 Profile::FromBrowserContext(browser_context));
2756 if (user && !user->username_hash().empty()) {
2757 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
Andreea Costinase1dd9e3a2020-09-22 11:43:352758 user->GetAccountId().GetUserEmail());
John Abd-El-Malek35bfaa52019-08-20 16:22:072759 }
2760 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332761}
2762#endif
2763
Reilly Grant19aaccd2018-07-16 22:06:372764scoped_refptr<network::SharedURLLoaderFactory>
2765ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2767 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2768
2769 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372770 return nullptr;
2771
Min Qinda0d55b2018-10-12 18:30:052772 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372773 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042774}
2775
Sean Gilhulyda1ee4b2018-11-13 21:56:092776network::mojom::NetworkContext*
2777ChromeContentBrowserClient::GetSystemNetworkContext() {
2778 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2779 DCHECK(g_browser_process->system_network_context_manager());
2780 return g_browser_process->system_network_context_manager()->GetContext();
2781}
2782
Andrew Moylan17329fc2017-09-25 07:43:302783std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2784 return google_apis::GetAPIKey();
2785}
2786
James Hollyer63eb7e0f2021-02-24 03:02:402787device::GeolocationSystemPermissionManager*
2788ChromeContentBrowserClient::GetLocationPermissionManager() {
2789#if defined(OS_MAC)
2790 return g_browser_process->platform_part()->location_permission_manager();
2791#else
2792 return nullptr;
2793#endif
2794}
2795
Ke He21ee87f2018-05-30 02:35:322796#if defined(OS_ANDROID)
2797bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2798 // Indicate that Chrome uses the GMS core location provider.
2799 return true;
2800}
2801#endif
2802
Yeolf3dc22ca2019-04-18 17:25:322803scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412804ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542805 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412806}
2807
Mythri Alle0b8de0d2018-10-22 11:06:222808content::GeneratedCodeCacheSettings
2809ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2810 content::BrowserContext* context) {
2811 base::FilePath cache_path;
2812 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2813 // If we pass 0 for size, disk_cache will pick a default size using the
2814 // heuristics based on available disk size. These are implemented in
2815 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162816 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132817 DCHECK(g_browser_process);
2818 PrefService* local_state = g_browser_process->local_state();
2819 if (local_state) {
2820 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2821 base::FilePath disk_cache_dir =
2822 local_state->GetFilePath(prefs::kDiskCacheDir);
2823 if (!disk_cache_dir.empty())
2824 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2825 }
Mythri Ab2486572019-06-13 14:48:162826 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222827}
2828
[email protected]848dd042011-06-04 18:24:032829void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262830 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172831 int cert_error,
2832 const net::SSLInfo& ssl_info,
2833 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232834 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222835 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262836 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262837 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232838 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142839 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022840 // have a context for making the right decision, so block the
2841 // request hard, without an info bar to allow showing the insecure
2842 // content.
estark719dde52016-08-09 03:14:272843 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262844 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022845 return;
2846 }
2847
Hiroki Nakagawa7230e3412021-01-22 10:08:292848 // If the tab is being no-state prefetched, cancel the prefetcher and the
2849 // request.
2850 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
2851 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
2852 web_contents);
2853 if (no_state_prefetch_contents) {
2854 no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272855 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262856 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272857 }
[email protected]09667f02014-01-06 15:37:572858 return;
[email protected]f9034cf2011-07-21 12:43:412859 }
2860
Erik Staaba65a6032019-11-27 22:23:262861 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282862 return;
[email protected]848dd042011-06-04 18:24:032863}
2864
Katie D1882617e2020-05-06 20:06:012865#if !defined(OS_ANDROID)
2866bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2867 const GURL main_page_url) {
2868 // Desktop Reader Mode pages should never load resources with certificate
2869 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2870 // on Android: the desktop version has its own security indicator and
2871 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2872 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2873 // pages).
2874 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2875}
2876#endif
2877
Alexander Hendrichbcf2616e2018-05-18 08:21:102878namespace {
2879
Pavol Markob211ab22019-01-23 20:03:042880certificate_matching::CertificatePrincipalPattern
2881ParseCertificatePrincipalPattern(const base::Value* pattern) {
2882 return certificate_matching::CertificatePrincipalPattern::
2883 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2884}
2885
Alexander Hendrichbcf2616e2018-05-18 08:21:102886// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452887// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102888// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2889std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2890 Profile* profile,
2891 const GURL& requesting_url,
2892 net::ClientCertIdentityList& client_certs) {
2893 HostContentSettingsMap* host_content_settings_map =
2894 HostContentSettingsMapFactory::GetForProfile(profile);
2895 std::unique_ptr<base::Value> setting =
2896 host_content_settings_map->GetWebsiteSetting(
2897 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142898 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102899
Pavol Markob211ab22019-01-23 20:03:042900 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102901 return nullptr;
2902
Alexander Hendrichbcf2616e2018-05-18 08:21:102903 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042904 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2905 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102906 // |setting_dict| has the wrong format (e.g. single filter instead of a
2907 // list of filters). This content setting is only provided by
2908 // the |PolicyProvider|, which should always set it to a valid format.
2909 // Therefore, delete the invalid value.
2910 host_content_settings_map->SetWebsiteSettingDefaultScope(
2911 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142912 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Pavol Markob211ab22019-01-23 20:03:042913 return nullptr;
2914 }
2915
2916 for (const base::Value& filter : filters->GetList()) {
2917 DCHECK(filter.is_dict());
2918
2919 auto issuer_pattern = ParseCertificatePrincipalPattern(
2920 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2921 auto subject_pattern = ParseCertificatePrincipalPattern(
2922 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2923 // Use the first certificate that is matched by the filter.
2924 for (auto& client_cert : client_certs) {
2925 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2926 subject_pattern.Matches(client_cert->certificate()->subject())) {
2927 return std::move(client_cert);
2928 }
2929 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102930 }
2931
2932 return nullptr;
2933}
2934
Prashant Nevase788dcee2020-10-30 19:00:172935#if !defined(OS_ANDROID)
2936blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
2937 ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
2938 switch (native_theme_scheme) {
2939 case ui::NativeTheme::PreferredColorScheme::kDark:
2940 return blink::mojom::PreferredColorScheme::kDark;
2941 case ui::NativeTheme::PreferredColorScheme::kLight:
2942 return blink::mojom::PreferredColorScheme::kLight;
2943 }
2944
2945 NOTREACHED();
2946}
2947#endif // !defined(OS_ANDROID)
2948
2949// Returns true if preferred color scheme is modified based on at least one of
2950// the following -
2951// |url| - Last committed url.
2952// |web_contents| - For Android based on IsNightModeEnabled().
2953// |native_theme| - For other platforms based on native theme scheme.
2954bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
2955 const GURL& url,
2956 WebContents* web_contents,
2957 const ui::NativeTheme* native_theme) {
2958 auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
2959
2960#if defined(OS_ANDROID)
2961 auto* delegate = TabAndroid::FromWebContents(web_contents)
2962 ? static_cast<android::TabWebContentsDelegateAndroid*>(
2963 web_contents->GetDelegate())
2964 : nullptr;
2965 if (delegate) {
2966 web_prefs->preferred_color_scheme =
2967 delegate->IsNightModeEnabled()
2968 ? blink::mojom::PreferredColorScheme::kDark
2969 : blink::mojom::PreferredColorScheme::kLight;
2970 }
2971#else
2972 // Update based on native theme scheme.
2973 web_prefs->preferred_color_scheme =
2974 ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
2975#endif // defined(OS_ANDROID)
2976
Alex Ilin85e8fd92020-12-01 14:07:182977 bool force_light = false;
Prashant Nevase788dcee2020-10-30 19:00:172978 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
2979 // disabled; some of the UI is not yet correctly themed.
2980 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
2981 // Update based on last committed url.
Alex Ilin85e8fd92020-12-01 14:07:182982 force_light |= url.SchemeIs(content::kChromeUIScheme);
Prashant Nevase788dcee2020-10-30 19:00:172983#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Ilin85e8fd92020-12-01 14:07:182984 force_light |= url.SchemeIs(extensions::kExtensionScheme) &&
2985 url.host_piece() == extension_misc::kPdfExtensionId;
Prashant Nevase788dcee2020-10-30 19:00:172986#endif
Alex Ilin85e8fd92020-12-01 14:07:182987 }
2988
2989 // Reauth WebUI doesn't support dark mode yet because it shares the dialog
2990 // with GAIA web contents that is not correctly themed.
2991 force_light |= url.SchemeIs(content::kChromeUIScheme) &&
2992 url.host_piece() == chrome::kChromeUISigninReauthHost;
2993
2994 if (force_light) {
2995 web_prefs->preferred_color_scheme =
2996 blink::mojom::PreferredColorScheme::kLight;
Prashant Nevase788dcee2020-10-30 19:00:172997 }
2998
2999 return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
3000}
3001
Alexander Hendrichbcf2616e2018-05-18 08:21:103002} // namespace
3003
Daniel McArdle85735f52019-06-25 03:27:063004base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:193005 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:403006 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:083007 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:353008 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
Hiroki Nakagawa7230e3412021-01-22 10:08:293009 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
3010 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
3011 web_contents);
3012 if (no_state_prefetch_contents) {
3013 no_state_prefetch_contents->Destroy(
[email protected]294084d2014-01-06 22:22:023014 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:063015 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:453016 }
3017
[email protected]791879c2013-12-17 07:22:413018 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
3019 DCHECK(requesting_url.is_valid())
3020 << "Invalid URL string: https://"
3021 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:453022
Pavol Marko230ea2c92017-12-03 22:35:443023 bool may_show_cert_selection = true;
3024
davidben3b8455ae72015-03-11 19:42:193025 Profile* profile =
3026 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Yuta Hijikata235fc62b2020-12-08 03:48:323027#if BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443028 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:253029 // On the sign-in profile, never show certificate selection to the user. A
3030 // client certificate is an identifier that can be stable for a long time,
3031 // so only the administrator is allowed to decide which endpoints should see
3032 // it.
3033 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:443034
3035 content::StoragePartition* storage_partition =
3036 content::BrowserContext::GetStoragePartition(
3037 profile, web_contents->GetSiteInstance());
3038 chromeos::login::SigninPartitionManager* signin_partition_manager =
3039 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
3040 profile);
3041
3042 // On the sign-in profile, only allow client certs in the context of the
3043 // sign-in frame.
3044 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
3045 storage_partition)) {
3046 LOG(WARNING)
3047 << "Client cert requested in sign-in profile in wrong context.";
3048 // Continue without client certificate. We do this to mimic the case of no
3049 // client certificate being present in the profile's certificate store.
3050 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063051 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443052 }
3053 VLOG(1) << "Client cert requested in sign-in profile.";
3054 }
Yuta Hijikata235fc62b2020-12-08 03:48:323055#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443056
Alexander Hendrichbcf2616e2018-05-18 08:21:103057 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
3058 AutoSelectCertificate(profile, requesting_url, client_certs);
3059 if (auto_selected_identity) {
3060 // The callback will own |auto_selected_identity| and |delegate|, keeping
3061 // them alive until after ContinueWithCertificate is called.
3062 scoped_refptr<net::X509Certificate> cert =
3063 auto_selected_identity->certificate();
3064 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
3065 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:583066 base::BindOnce(
3067 &content::ClientCertificateDelegate::ContinueWithCertificate,
3068 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:323069 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:063070 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:453071 }
3072
Pavol Marko230ea2c92017-12-03 22:35:443073 if (!may_show_cert_selection) {
3074 LOG(WARNING) << "No client cert matched by policy and user selection is "
3075 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:323076 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:443077 // Continue without client certificate. We do this to mimic the case of no
3078 // client certificate being present in the profile's certificate store.
3079 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063080 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443081 }
3082
Daniel McArdle85735f52019-06-25 03:27:063083 return chrome::ShowSSLClientCertificateSelector(
3084 web_contents, cert_request_info, std::move(client_certs),
3085 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:453086}
3087
[email protected]dc73a7b2012-03-25 15:27:183088content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:563089 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:183090}
3091
Adrienne Walker80d95f02020-02-07 22:37:043092content::FeatureObserverClient*
3093ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:243094 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:043095 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:053096}
3097
peterc26c6c62014-12-10 14:13:593098content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:023099ChromeContentBrowserClient::GetPlatformNotificationService(
3100 content::BrowserContext* browser_context) {
3101 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3102 Profile* profile = Profile::FromBrowserContext(browser_context);
3103 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:043104}
3105
[email protected]9f3fba52011-06-08 20:37:193106bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:353107 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:353108 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:573109 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:353110 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:033111 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233112 const GURL& target_url,
3113 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213114 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233115 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483116 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233117 bool user_gesture,
3118 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013119 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353120 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3121 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013122
csharrison95f01e922017-04-24 18:52:353123 content::WebContents* web_contents =
3124 content::WebContents::FromRenderFrameHost(opener);
3125 Profile* profile =
3126 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3127 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013128 *no_javascript_access = false;
3129
[email protected]9f3fba52011-06-08 20:37:193130 // If the opener is trying to create a background window but doesn't have
3131 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033132 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173133#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353134 auto* process_map = extensions::ProcessMap::Get(profile);
3135 auto* registry = extensions::ExtensionRegistry::Get(profile);
Darwin Huang6195d042021-02-12 22:36:003136 if (!URLHasExtensionPermission(process_map, registry, opener_url,
3137 opener->GetProcess()->GetID(),
3138 APIPermission::ID::kBackground)) {
[email protected]03b6d552012-03-29 04:03:013139 return false;
3140 }
3141
[email protected]7b54ca02012-03-02 18:06:533142 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3143 // return a recently installed Extension even if this CanCreateWindow call
3144 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013145 // because the permission check above would have caused an early return
3146 // already. We must use the full URL to find hosted apps, though, and not
3147 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553148 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353149 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293150 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013151 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023152#endif
[email protected]190e5e22013-07-27 05:59:233153
3154 return true;
[email protected]9f3fba52011-06-08 20:37:193155 }
[email protected]056efdc2013-04-06 00:14:533156
brettw00899e62016-11-12 02:10:173157#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463158 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353159 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233160 return true;
lazyboy04b75d32016-02-25 03:12:183161 }
3162
nick0fbc3922016-12-16 20:52:073163 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353164 // Intentionally duplicating |registry| code from above because we want to
3165 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3166 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183167 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353168 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143169 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533170 UMA_HISTOGRAM_ENUMERATION(
3171 "Extensions.AppLoadedInTab",
3172 ClassifyAppLoadedInTabSource(opener_url, extension),
3173 APP_LOADED_IN_TAB_SOURCE_MAX);
3174
3175 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163176 return false;
lazyboy5d5fede02016-03-10 04:10:143177 }
lazyboy04b75d32016-02-25 03:12:183178 }
[email protected]5940b0d2014-07-01 00:18:263179#endif
[email protected]190e5e22013-07-27 05:59:233180
Hiroki Nakagawa7230e3412021-01-22 10:08:293181 DCHECK(!prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:573182 web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023183
Aaron Colwell9dab1652019-12-09 18:29:493184 BlockedWindowParams blocked_params(
3185 target_url, source_origin, opener->GetSiteInstance(), referrer,
3186 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133187 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Clark DuVall8a020d622020-06-04 00:45:503188 return blocked_content::MaybeBlockPopup(
3189 web_contents, &opener_top_level_frame_url,
3190 std::make_unique<ChromePopupNavigationDelegate>(
3191 std::move(nav_params)),
3192 nullptr /*=open_url_params*/, blocked_params.features(),
3193 HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr;
[email protected]9f3fba52011-06-08 20:37:193194}
3195
[email protected]c52b2892012-03-07 11:01:023196content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443197ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003198 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513199}
3200
Yuta Hijikata235fc62b2020-12-08 03:48:323201#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D840d9532018-11-27 06:20:483202content::TtsControllerDelegate*
3203ChromeContentBrowserClient::GetTtsControllerDelegate() {
Scott Violet1644cf72020-06-24 04:51:553204 return TtsControllerDelegateImpl::GetInstance();
3205}
3206#endif
3207
3208content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
Katie D840d9532018-11-27 06:20:483209#if !defined(OS_ANDROID)
Scott Violete217e5e2020-06-22 19:18:223210 content::TtsController::GetInstance()->SetTtsEngineDelegate(
3211 TtsExtensionEngine::GetInstance());
Katie D840d9532018-11-27 06:20:483212#endif
Yuta Hijikata235fc62b2020-12-08 03:48:323213#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D4713ee42018-11-30 01:48:273214 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273215#else
3216 return nullptr;
3217#endif
3218}
3219
[email protected]64d69de42012-02-06 00:19:543220void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aaron Colwellbd02c6c2021-01-16 00:34:293221 WebContents* web_contents,
Aran Gilmanf010bdd2019-08-28 19:55:443222 WebPreferences* web_prefs) {
3223 Profile* profile =
Aaron Colwellbd02c6c2021-01-16 00:34:293224 Profile::FromBrowserContext(web_contents->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063225 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063226
aelias0df335a2017-03-02 23:43:513227// Fill font preferences. These are not registered on Android
3228// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453229#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193230 FontFamilyCache::FillFontFamilyMap(profile,
3231 prefs::kWebKitStandardFontFamilyMap,
3232 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443233 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193234 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443235 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193236 &web_prefs->serif_font_family_map);
3237 FontFamilyCache::FillFontFamilyMap(profile,
3238 prefs::kWebKitSansSerifFontFamilyMap,
3239 &web_prefs->sans_serif_font_family_map);
3240 FontFamilyCache::FillFontFamilyMap(profile,
3241 prefs::kWebKitCursiveFontFamilyMap,
3242 &web_prefs->cursive_font_family_map);
3243 FontFamilyCache::FillFontFamilyMap(profile,
3244 prefs::kWebKitFantasyFontFamilyMap,
3245 &web_prefs->fantasy_font_family_map);
3246 FontFamilyCache::FillFontFamilyMap(profile,
3247 prefs::kWebKitPictographFontFamilyMap,
3248 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063249
[email protected]64d69de42012-02-06 00:19:543250 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403251 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543252 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403253 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543254 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403255 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543256 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403257 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513258#endif
[email protected]f3986f82012-01-03 20:00:063259
[email protected]ddf72142012-05-22 04:52:403260 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063261
[email protected]64d69de42012-02-06 00:19:543262 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063263 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213264 web_prefs->javascript_can_access_clipboard =
3265 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543266 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063267
[email protected]ddf72142012-05-22 04:52:403268 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543269 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573270
Avi Drissman1aa6cb92019-01-23 15:58:383271 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543272 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573273
[email protected]ddf72142012-05-22 04:52:403274 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543275 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543276 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403277 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063278
Zhenyao Moa3fda9972017-09-16 01:34:403279 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3280 web_prefs->webgl1_enabled = false;
3281 web_prefs->webgl2_enabled = false;
3282 }
[email protected]f3986f82012-01-03 20:00:063283
[email protected]64d69de42012-02-06 00:19:543284 web_prefs->allow_running_insecure_content =
3285 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323286#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053287 web_prefs->font_scale_factor =
3288 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323289 web_prefs->force_enable_zoom =
3290 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493291#endif
Becky Zhoubbfbde32019-02-20 17:07:593292 web_prefs->force_dark_mode_enabled =
3293 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393294
Yuta Hijikata235fc62b2020-12-08 03:48:323295#if BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhallda2659142020-05-14 06:04:373296 web_prefs->always_show_focus =
3297 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
Alice Boxhalla9aafba42020-06-24 05:42:513298#else
3299 if (features::IsAccessibilityFocusHighlightEnabled()) {
3300 web_prefs->always_show_focus =
3301 prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled);
3302 }
Alice Boxhallda2659142020-05-14 06:04:373303#endif
3304
[email protected]af4256d52013-06-04 20:39:073305#if defined(OS_ANDROID)
3306 web_prefs->password_echo_enabled =
3307 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3308#else
[email protected]9d06d88d2012-02-23 22:37:083309 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073310#endif
3311
[email protected]64d69de42012-02-06 00:19:543312 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063313 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543314 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063315 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3316
brettw00899e62016-11-12 02:10:173317#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053318 std::string image_animation_policy =
3319 prefs->GetString(prefs::kAnimationPolicy);
Gyuyoung Kim3b4703d2020-09-18 00:25:493320 if (image_animation_policy == kAnimationPolicyOnce) {
je_julie.kim7fbb5a1a2015-02-09 17:26:053321 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573322 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
Gyuyoung Kim3b4703d2020-09-18 00:25:493323 } else if (image_animation_policy == kAnimationPolicyNone) {
Gyuyoung Kim1ac4ca782020-09-11 03:32:513324 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573325 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
Gyuyoung Kim3b4703d2020-09-18 00:25:493326 } else {
Gyuyoung Kim1e9d3c32020-10-12 14:04:573327 web_prefs->animation_policy =
3328 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
Gyuyoung Kim3b4703d2020-09-18 00:25:493329 }
je_julie.kim7fbb5a1a2015-02-09 17:26:053330#endif
3331
[email protected]f3986f82012-01-03 20:00:063332 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153333 web_prefs->default_encoding =
3334 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543335 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403336 prefs->ClearPref(prefs::kDefaultCharset);
3337 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063338 }
[email protected]64d69de42012-02-06 00:19:543339 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063340
mkwst05544102015-01-10 20:26:163341 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3342 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073343 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163344 web_prefs->strict_mixed_content_checking = true;
3345 web_prefs->strict_powerful_feature_restrictions = true;
3346 }
3347
Robert Ogdencf2872d2019-03-19 18:59:373348 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213349
Tarun Bansal333819e2018-05-15 16:38:423350 web_prefs->data_saver_holdback_web_api_enabled =
3351 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3352 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423353
Aaron Colwellbd02c6c2021-01-16 00:34:293354 if (web_contents) {
Ian Vollick6243dfe02018-03-08 01:08:533355#if defined(OS_ANDROID)
Aaron Colwellbd02c6c2021-01-16 00:34:293356 auto* delegate = TabAndroid::FromWebContents(web_contents)
Jinsuk Kima3d393ce2019-05-27 00:57:423357 ? static_cast<android::TabWebContentsDelegateAndroid*>(
Aaron Colwellbd02c6c2021-01-16 00:34:293358 web_contents->GetDelegate())
Jinsuk Kima3d393ce2019-05-27 00:57:423359 : nullptr;
3360 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133361 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423362 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133363
Mounir Lamouri9c99a1602018-07-05 15:01:443364 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423365 delegate->IsPictureInPictureEnabled();
zqzhang183dc822017-02-15 17:04:113366 }
Ian Vollick6243dfe02018-03-08 01:08:533367#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533368
Mounir Lamouri6926107f2019-01-31 18:17:433369 // web_app_scope value is platform specific.
3370#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423371 if (delegate)
3372 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433373#elif BUILDFLAG(ENABLE_EXTENSIONS)
3374 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253375 web_prefs->web_app_scope = GURL();
3376 // Set |web_app_scope| based on the app associated with the app window if
3377 // any. Note that the app associated with the window never changes, even
3378 // if the app navigates off scope. This is not a problem because we still
3379 // want to use the scope of the app associated with the window, not the
3380 // WebContents.
Aaron Colwellbd02c6c2021-01-16 00:34:293381 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
Alan Cutterd0bd51902019-05-22 04:15:233382 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593383 browser->app_controller()->HasAppId()) {
3384 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3385 const web_app::AppRegistrar& registrar =
3386 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3387 if (registrar.IsLocallyInstalled(app_id))
3388 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433389 }
Mounir Lamouri6926107f2019-01-31 18:17:433390 }
3391#endif
3392
Aaron Colwellbd02c6c2021-01-16 00:34:293393 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(web_contents);
zqzhang183dc822017-02-15 17:04:113394 }
zqzhang93e959d12017-03-16 13:10:203395
Aaron Colwellbd02c6c2021-01-16 00:34:293396 web_prefs->lazy_load_enabled =
3397 !web_contents || !web_contents->GetDelegate() ||
3398 web_contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003399
Scott Little878f7d6702018-05-31 22:09:063400 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3401 const char* param_name =
3402 web_prefs->data_saver_enabled
3403 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3404 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3405 "saver_enabled";
3406
3407 base::StringPairs pairs;
3408 base::SplitStringIntoKeyValuePairs(
3409 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3410 param_name),
3411 ':', ',', &pairs);
3412
3413 for (const auto& pair : pairs) {
3414 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3415 net::GetEffectiveConnectionTypeForName(pair.first);
3416 int value = 0;
3417 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223418 web_prefs->lazy_frame_loading_distance_thresholds_px[static_cast<
3419 EffectiveConnectionType>(effective_connection_type.value())] =
3420 value;
Scott Little878f7d6702018-05-31 22:09:063421 }
3422 }
3423 }
3424
rajendrantd8026342018-08-29 08:08:393425 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3426 const char* param_name =
3427 web_prefs->data_saver_enabled
3428 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3429 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3430 "saver_enabled";
3431
3432 base::StringPairs pairs;
3433 base::SplitStringIntoKeyValuePairs(
3434 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3435 param_name),
3436 ':', ',', &pairs);
3437
3438 for (const auto& pair : pairs) {
3439 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3440 net::GetEffectiveConnectionTypeForName(pair.first);
3441 int value = 0;
3442 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223443 web_prefs->lazy_image_loading_distance_thresholds_px[static_cast<
3444 EffectiveConnectionType>(effective_connection_type.value())] =
3445 value;
rajendrantd8026342018-08-29 08:08:393446 }
3447 }
rajendrant3daeae292019-09-20 07:57:543448
3449 pairs.clear();
3450 base::SplitStringIntoKeyValuePairs(
3451 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3452 "lazy_image_first_k_fully_load"),
3453 ':', ',', &pairs);
3454
3455 for (const auto& pair : pairs) {
3456 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3457 net::GetEffectiveConnectionTypeForName(pair.first);
3458 int value = 0;
3459 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223460 web_prefs->lazy_image_first_k_fully_load[static_cast<
3461 EffectiveConnectionType>(effective_connection_type.value())] =
rajendrant3daeae292019-09-20 07:57:543462 value;
3463 }
3464 }
rajendrantd8026342018-08-29 08:08:393465 }
3466
Tarun Bansald10f17a02018-09-13 00:23:173467 if (base::FeatureList::IsEnabled(
3468 features::kNetworkQualityEstimatorWebHoldback)) {
3469 std::string effective_connection_type_param =
3470 base::GetFieldTrialParamValueByFeature(
3471 features::kNetworkQualityEstimatorWebHoldback,
3472 "web_effective_connection_type_override");
3473
3474 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3475 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3476 DCHECK(effective_connection_type_param.empty() ||
3477 effective_connection_type);
3478 if (effective_connection_type) {
3479 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3480 effective_connection_type.value());
3481 web_prefs->network_quality_estimator_web_holdback =
Gyuyoung Kimd6d4f992020-11-20 14:13:223482 static_cast<EffectiveConnectionType>(
3483 effective_connection_type.value());
Tarun Bansald10f17a02018-09-13 00:23:173484 }
3485 }
3486
François Beaufort4f8107d2018-03-05 12:12:103487#if !defined(OS_ANDROID)
Aaron Colwellbd02c6c2021-01-16 00:34:293488 if (IsAutoplayAllowedByPolicy(web_contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593489 // If autoplay is allowed by policy then force the no user gesture required
3490 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103491 web_prefs->autoplay_policy =
Gyuyoung Kimf6c02a262020-10-13 01:36:133492 blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553493 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593494 web_prefs->autoplay_policy ==
Gyuyoung Kimf6c02a262020-10-13 01:36:133495 blink::mojom::AutoplayPolicy::
Gyuyoung Kim1ac4ca782020-09-11 03:32:513496 kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553497 // If the autoplay disable settings feature is enabled and the autoplay
3498 // policy is set to using the unified policy then set the default autoplay
3499 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593500 web_prefs->autoplay_policy =
3501 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
Gyuyoung Kimf6c02a262020-10-13 01:36:133502 ? blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired
3503 : blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103504 }
3505#endif // !defined(OS_ANDROID)
3506
Prashant Nevase788dcee2020-10-30 19:00:173507 switch (GetWebTheme()->GetPreferredContrast()) {
Alison Maher3b11e942020-10-27 17:17:503508 case ui::NativeTheme::PreferredContrast::kNoPreference:
3509 web_prefs->preferred_contrast =
3510 blink::mojom::PreferredContrast::kNoPreference;
3511 break;
3512 case ui::NativeTheme::PreferredContrast::kMore:
3513 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kMore;
3514 break;
3515 case ui::NativeTheme::PreferredContrast::kLess:
3516 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kLess;
3517 break;
3518 }
3519
Aaron Colwellbd02c6c2021-01-16 00:34:293520 UpdatePreferredColorScheme(
3521 web_prefs, web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL(),
3522 web_contents, GetWebTheme());
Elly Fong-Jonesf92897392019-01-24 16:05:493523
Rakina Zata Amni347b70902020-07-22 10:49:043524 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Alison Maher7f366dc62020-03-03 19:46:003525
Abigail Kleina81f2e22020-05-04 14:32:413526 base::Optional<ui::CaptionStyle> style =
3527 captions::GetCaptionStyleFromUserSettings(prefs,
3528 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213529 if (style) {
3530 web_prefs->text_track_background_color = style->background_color;
3531 web_prefs->text_track_text_color = style->text_color;
3532 web_prefs->text_track_text_size = style->text_size;
3533 web_prefs->text_track_text_shadow = style->text_shadow;
3534 web_prefs->text_track_font_family = style->font_family;
3535 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563536 web_prefs->text_track_window_color = style->window_color;
3537 web_prefs->text_track_window_padding = style->window_padding;
3538 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213539 }
Elly Fong-Jonesf92897392019-01-24 16:05:493540
Piotr Bialecki3fde5fa2021-01-23 01:08:033541#if defined(OS_ANDROID)
3542 // If the pref is not set, the default value (true) will be used:
3543 web_prefs->webxr_immersive_ar_allowed =
3544 prefs->GetBoolean(prefs::kWebXRImmersiveArEnabled);
3545#endif
3546
3547 for (ChromeContentBrowserClientParts* parts : extra_parts_)
3548 parts->OverrideWebkitPrefs(web_contents, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363549}
3550
Rakina Zata Amni347b70902020-07-22 10:49:043551bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation(
3552 WebContents* web_contents,
3553 WebPreferences* prefs) {
Prashant Nevase788dcee2020-10-30 19:00:173554 return UpdatePreferredColorScheme(prefs, web_contents->GetLastCommittedURL(),
3555 web_contents, GetWebTheme());
Rakina Zata Amni347b70902020-07-22 10:49:043556}
3557
[email protected]b8148ac2011-07-13 22:03:253558void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3559 BrowserURLHandler* handler) {
Nicolas Ouellet-Payeur5e6d2102020-08-21 16:28:413560 // The group policy NTP URL handler must be registered before the other NTP
3561 // URL handlers below. Also register it before the "parts" handlers, so the
3562 // NTP policy takes precedence over extensions that override the NTP.
3563 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3564 BrowserURLHandler::null_handler());
3565
[email protected]a48ab7112014-08-01 16:48:033566 for (size_t i = 0; i < extra_parts_.size(); ++i)
3567 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253568
Lukasz Anforowicz7b078792020-10-20 17:04:313569 // Handler to rewrite chrome://about and chrome://sync URLs.
3570 handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
[email protected]b8148ac2011-07-13 22:03:253571 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033572
zpengdb4a58e2017-01-10 17:40:323573#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033574 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353575 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033576 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453577#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033578 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133579 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3580 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453581#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033582
[email protected]b8148ac2011-07-13 22:03:253583 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313584 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3585 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253586}
3587
[email protected]650b2d52013-02-10 03:41:453588base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493589 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323590}
3591
[email protected]c9b6eb62011-10-18 20:49:393592std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3593 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3594}
3595
Dominik Röttsches47347832019-03-12 17:45:013596base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3597 base::FilePath user_data_dir;
3598 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3599 DCHECK(!user_data_dir.empty());
3600 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3601}
3602
jmadill57b52d42015-08-21 18:16:133603base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3604 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523605 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133606 DCHECK(!user_data_dir.empty());
3607 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3608}
3609
Khushal7ca0b782018-07-20 05:53:273610base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3611 base::FilePath user_data_dir;
3612 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3613 DCHECK(!user_data_dir.empty());
3614 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3615}
3616
[email protected]b7631cc2012-09-15 05:08:383617void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3618 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163619#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553620 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543621#endif
[email protected]b7631cc2012-09-15 05:08:383622}
3623
[email protected]0c7193742012-11-07 19:05:033624content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443625ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173626#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553627 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033628 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443629 nacl::NaClProcessHost* host =
3630 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3631 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033632 // Found the plugin.
3633 return host->browser_ppapi_host();
3634 }
3635 ++iter;
3636 }
[email protected]a56f8322014-07-16 21:13:553637#endif
Aran Gilmanf010bdd2019-08-28 19:55:443638 return nullptr;
[email protected]0c7193742012-11-07 19:05:033639}
3640
[email protected]38cd8f7f2012-06-15 22:06:073641bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583642 content::BrowserContext* browser_context,
3643 const GURL& url,
[email protected]dda54822013-06-15 01:26:393644 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123645 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163646#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553647 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193648 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403649#else
[email protected]a658d452012-03-02 12:45:293650 return false;
[email protected]93f72062013-05-29 20:29:403651#endif
[email protected]e461da2f2012-02-16 19:06:403652}
3653
adrian.belgund54465ba2016-05-18 10:03:583654bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3655 content::BrowserContext* browser_context,
3656 const GURL& url) {
brettw4b461082016-11-19 18:55:163657#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583658 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3659 browser_context, url);
3660#else
3661 return false;
3662#endif
3663}
3664
adrian.belgun5b341c72016-06-22 22:24:083665std::unique_ptr<content::VpnServiceProxy>
3666ChromeContentBrowserClient::GetVpnServiceProxy(
3667 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173668#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083669 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3670 browser_context);
3671#else
3672 return nullptr;
3673#endif
3674}
3675
Brett Wilson804e83c2017-08-18 22:57:333676std::unique_ptr<ui::SelectFilePolicy>
3677ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3678 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433679}
3680
[email protected]7d9424702013-04-14 13:14:163681void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3682 std::vector<std::string>* additional_allowed_schemes) {
3683 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3684 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483685 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293686 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033687 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3688 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3689 additional_allowed_schemes);
3690 }
[email protected]7d9424702013-04-14 13:14:163691}
3692
Ayu Ishiifbb1fad2020-06-22 20:15:073693void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist(
falkenad185092016-06-16 06:10:023694 std::set<std::string>* schemes) {
Ayu Ishiifbb1fad2020-06-22 20:15:073695 *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023696}
3697
[email protected]c79859b82014-03-20 22:43:553698void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313699 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033700 for (size_t i = 0; i < extra_parts_.size(); ++i)
3701 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553702}
3703
[email protected]f19bbf62013-07-09 01:22:323704void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313705 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533706 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003707 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3708 additional_backends) {
Yuta Hijikata235fc62b2020-12-08 03:48:323709#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]cd501a72014-08-22 19:58:313710 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313711 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313712 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093713 auto backend = std::make_unique<chromeos::FileSystemBackend>(
David Black8f8c1eb2020-12-09 04:02:233714 Profile::FromBrowserContext(browser_context),
Jeremy Romanec48d7a2018-03-01 17:35:093715 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3716 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473717 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093718 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3719 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053720 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3721 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343722 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3723 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473724 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323725 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313726 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003727 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313728#endif
[email protected]445b7db2013-08-02 04:58:273729
[email protected]a48ab7112014-08-01 16:48:033730 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3731 extra_parts_[i]->GetAdditionalFileSystemBackends(
3732 browser_context, storage_partition_path, additional_backends);
3733 }
[email protected]02250952013-04-24 23:52:533734}
3735
Avi Drissman2e458df2020-07-29 16:24:313736#if defined(OS_POSIX) && !defined(OS_MAC)
[email protected]a1733df2012-06-22 11:24:183737void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173738 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383739 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203740 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123741#if defined(OS_ANDROID)
3742 base::MemoryMappedFile::Region region;
3743 int fd = ui::GetMainAndroidPackFd(&region);
3744 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003745
Samuel Huang31eadf082019-08-28 19:50:433746 // For Android: Native resources for DFMs should only be used by the browser
3747 // process. Their file descriptors and memory mapped file regions are not
3748 // passed to child processes.
3749
jcivellie6f550742017-01-06 19:29:123750 fd = ui::GetCommonResourcesPackFd(&region);
3751 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393752
jcivellie6f550742017-01-06 19:29:123753 fd = ui::GetLocalePackFd(&region);
3754 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383755
zpeng368afac82017-07-17 18:47:453756 // Optional secondary locale .pak file.
3757 fd = ui::GetSecondaryLocalePackFd(&region);
3758 if (fd != -1) {
3759 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3760 }
3761
[email protected]09560f7f2014-06-10 18:40:283762 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523763 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283764 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023765#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383766 int crash_signal_fd = GetCrashSignalFD(command_line);
3767 if (crash_signal_fd >= 0) {
Ken Rockot69fbb962020-09-21 22:22:033768 mappings->Share(kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383769 }
jcivellie6f550742017-01-06 19:29:123770}
Avi Drissman2e458df2020-07-29 16:24:313771#endif // defined(OS_POSIX) && !defined(OS_MAC)
[email protected]b80f68432011-05-02 17:22:303772
[email protected]4a65826d2011-08-25 16:04:013773#if defined(OS_WIN)
Peter Kasting57fd6de42021-01-28 23:05:393774std::wstring ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Robert Sesek7d0b49b2020-07-08 18:31:273775 sandbox::policy::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033776 // TODO(wfh): Add support for more process types here. crbug.com/499523
3777 switch (sandbox_type) {
Robert Sesek7d0b49b2020-07-08 18:31:273778 case sandbox::policy::SandboxType::kRenderer:
Peter Kasting141279b2021-02-09 22:34:203779 return std::wstring(install_static::GetSandboxSidPrefix()) + L"129201922";
Robert Sesek7d0b49b2020-07-08 18:31:273780 case sandbox::policy::SandboxType::kUtility:
Peter Kasting141279b2021-02-09 22:34:203781 return std::wstring();
Robert Sesek7d0b49b2020-07-08 18:31:273782 case sandbox::policy::SandboxType::kGpu:
Peter Kasting141279b2021-02-09 22:34:203783 return std::wstring();
Robert Sesek7d0b49b2020-07-08 18:31:273784 case sandbox::policy::SandboxType::kPpapi:
Peter Kasting141279b2021-02-09 22:34:203785 return std::wstring(install_static::GetSandboxSidPrefix()) + L"129201925";
Robert Sesek7d0b49b2020-07-08 18:31:273786 case sandbox::policy::SandboxType::kNoSandbox:
3787 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3788 case sandbox::policy::SandboxType::kXrCompositing:
3789 case sandbox::policy::SandboxType::kNetwork:
3790 case sandbox::policy::SandboxType::kCdm:
3791 case sandbox::policy::SandboxType::kPrintCompositor:
3792 case sandbox::policy::SandboxType::kAudio:
3793 case sandbox::policy::SandboxType::kSpeechRecognition:
3794 case sandbox::policy::SandboxType::kProxyResolver:
3795 case sandbox::policy::SandboxType::kPdfConversion:
3796 case sandbox::policy::SandboxType::kSharingService:
3797 case sandbox::policy::SandboxType::kVideoCapture:
3798 case sandbox::policy::SandboxType::kIconReader:
Frank Li49bb6912020-09-30 18:05:523799 case sandbox::policy::SandboxType::kMediaFoundationCdm:
Alex Gough9ab468a6c32019-12-10 19:10:223800 // Should never reach here.
3801 CHECK(0);
Peter Kasting57fd6de42021-01-28 23:05:393802 return std::wstring();
wfh182da09c2015-06-24 19:23:033803 }
wfh182da09c2015-06-24 19:23:033804}
3805
Will Harrisaa8939b2021-01-26 21:54:393806// Note: Only use sparingly to add Chrome specific sandbox functionality here.
3807// Other code should reside in the content layer. Changes to this function
3808// should be reviewed by the security team.
3809bool ChromeContentBrowserClient::PreSpawnChild(
3810 sandbox::TargetPolicy* policy,
3811 sandbox::policy::SandboxType sandbox_type,
3812 ChildSpawnFlags flags) {
Will Harris3249aa32021-02-25 19:30:453813// Does not work under component build because all the component DLLs would need
3814// to be manually added and maintained. Does not work under ASAN build because
3815// ASAN has not yet fully initialized its instrumentation by the time the CIG
3816// intercepts run.
Will Harris1b9b4152019-08-21 22:33:503817#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris3249aa32021-02-25 19:30:453818 bool enforce_code_integrity = false;
Will Harrisc196ed942019-08-03 03:45:303819
Will Harris3249aa32021-02-25 19:30:453820 switch (sandbox_type) {
3821 case sandbox::policy::SandboxType::kRenderer:
3822 enforce_code_integrity =
3823 ((flags & ChildSpawnFlags::RENDERER_CODE_INTEGRITY) &&
3824 base::FeatureList::IsEnabled(kRendererCodeIntegrity));
3825 break;
Will Harrisaa8939b2021-01-26 21:54:393826 case sandbox::policy::SandboxType::kNetwork:
Will Harris3249aa32021-02-25 19:30:453827 enforce_code_integrity =
3828 base::FeatureList::IsEnabled(kNetworkServiceCodeIntegrity);
3829 break;
Will Harrisaa8939b2021-01-26 21:54:393830 case sandbox::policy::SandboxType::kUtility:
3831 case sandbox::policy::SandboxType::kGpu:
3832 case sandbox::policy::SandboxType::kPpapi:
3833 case sandbox::policy::SandboxType::kNoSandbox:
3834 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3835 case sandbox::policy::SandboxType::kXrCompositing:
3836 case sandbox::policy::SandboxType::kCdm:
3837 case sandbox::policy::SandboxType::kPrintCompositor:
3838 case sandbox::policy::SandboxType::kAudio:
3839 case sandbox::policy::SandboxType::kSpeechRecognition:
3840 case sandbox::policy::SandboxType::kProxyResolver:
3841 case sandbox::policy::SandboxType::kPdfConversion:
3842 case sandbox::policy::SandboxType::kSharingService:
3843 case sandbox::policy::SandboxType::kVideoCapture:
3844 case sandbox::policy::SandboxType::kIconReader:
3845 case sandbox::policy::SandboxType::kMediaFoundationCdm:
Will Harris3249aa32021-02-25 19:30:453846 break;
Will Harrisaa8939b2021-01-26 21:54:393847 }
Will Harris3249aa32021-02-25 19:30:453848
3849 if (!enforce_code_integrity)
3850 return true;
3851
3852 // Only enable signing mitigation if launching from chrome.exe.
3853 base::FilePath exe_path;
3854 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3855 return true;
3856 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3857 return true;
3858
3859 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3860 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
3861 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
3862 if (result != sandbox::SBOX_ALL_OK)
3863 return false;
3864
3865 // Allow loading Chrome's DLLs.
3866 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
3867 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3868 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3869 GetModulePath(dll).value().c_str());
3870 if (result != sandbox::SBOX_ALL_OK)
3871 return false;
3872 }
3873#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
3874 return true;
[email protected]34f48682013-03-20 00:30:183875}
Will Harris956e0ca2019-08-23 20:47:393876
3877bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3878 PrefService* local_state = g_browser_process->local_state();
3879 if (local_state &&
3880 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3881 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3882 return false;
3883 return true;
3884}
3885
Greg Thompson724aa4d92021-02-25 20:31:333886void ChromeContentBrowserClient::SessionEnding() {
3887 chrome::SessionEnding();
3888}
3889
wfhc91e9672016-01-27 00:14:203890#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013891
Lingqi Chi775e60752020-12-14 06:31:163892void ChromeContentBrowserClient::RegisterMojoBinderPoliciesForPrerendering(
3893 content::MojoBinderPolicyMap& policy_map) {
3894 // Changes to `policy_map` should be made in
3895 // RegisterChromeMojoBinderPoliciesForPrerendering() which requires security
3896 // review.
3897 RegisterChromeMojoBinderPoliciesForPrerendering(policy_map);
3898}
3899
peterbbcccc12015-02-11 22:23:333900void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373901 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333902 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293903 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083904 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373905
3906 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083907
zpengdb4a58e2017-01-10 17:40:323908#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223909 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293910 std::move(callback));
jam1c5a91492016-02-24 20:47:533911#else
cm.sanchi2522bc92017-12-04 08:04:133912 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3913 params.url, params.transition);
3914 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083915
3916 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293917 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333918#endif
mlamourieb40d552015-02-05 00:57:083919}
3920
zhaobinf3704f82017-01-12 07:19:363921content::ControllerPresentationServiceDelegate*
3922ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3923 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463924 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093925 return media_router::PresentationServiceDelegateImpl::
3926 GetOrCreateForWebContents(web_contents);
3927 }
haibinlu9e605a92015-06-06 03:45:093928 return nullptr;
3929}
3930
zhaobinf3704f82017-01-12 07:19:363931content::ReceiverPresentationServiceDelegate*
3932ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3933 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363934 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3935 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3936 // created for offscreen presentations. The WebContents must belong to
3937 // an incognito profile.
3938 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3939 FromWebContents(web_contents)) {
3940 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3941 return impl;
3942 }
3943 }
zhaobinf3704f82017-01-12 07:19:363944 return nullptr;
3945}
3946
avid6d88b912017-01-13 00:16:003947std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473948ChromeContentBrowserClient::CreateThrottlesForNavigation(
3949 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003950 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273951
bmcquadeb4556552017-03-24 22:24:373952 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3953 // that may delay or cancel navigations, so only NavigationThrottles that
3954 // don't delay or cancel navigations (e.g. throttles that are only observing
3955 // callbacks without affecting navigation behavior) should be added before
3956 // MetricsNavigationThrottle.
3957 if (handle->IsInMainFrame()) {
3958 throttles.push_back(
3959 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3960 }
3961
Yuta Hijikata235fc62b2020-12-08 03:48:323962#if BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063963 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283964 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3965 &throttles);
Yuta Hijikata235fc62b2020-12-08 03:48:323966#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063967
mmenkedb2637ff2017-03-30 23:59:423968#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213969 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283970 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
3971 &throttles);
mmenkedb2637ff2017-03-30 23:59:423972#endif
3973
clamy40c9e142015-09-29 11:18:473974#if defined(OS_ANDROID)
3975 // TODO(davidben): This is insufficient to integrate with prerender properly.
3976 // https://crbug.com/370595
Hiroki Nakagawa7230e3412021-01-22 10:08:293977 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
3978 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:573979 handle->GetWebContents());
Hiroki Nakagawa7230e3412021-01-22 10:08:293980 if (!no_state_prefetch_contents && handle->IsInMainFrame()) {
clamy40c9e142015-09-29 11:18:473981 throttles.push_back(
3982 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303983 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473984 }
Min Qin0ab0e162017-11-14 21:57:193985 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043986
3987#if BUILDFLAG(DFMIFY_DEV_UI)
3988 // If the DevUI DFM is already installed, then this is a no-op, except for the
3989 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:283990 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
3991 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:043992#endif // BUILDFLAG(DFMIFY_DEV_UI)
3993
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573994#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473995 if (handle->IsInMainFrame()) {
3996 // Redirect some navigations to apps that have registered matching URL
3997 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:283998 MaybeAddThrottle(
3999 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
4000 &throttles);
clamy40c9e142015-09-29 11:18:474001 }
4002#endif
clamy49678312015-10-22 21:59:004003
Yuta Hijikata235fc62b2020-12-08 03:48:324004#if BUILDFLAG(IS_CHROMEOS_ASH)
clamy49678312015-10-22 21:59:004005 // Check if we need to add merge session throttle. This throttle will postpone
4006 // loading of main frames.
4007 if (handle->IsInMainFrame()) {
4008 // Add interstitial page while merge session process (cookie reconstruction
4009 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4010 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024011 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4012 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004013 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4014 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4015 }
Maggie Caia2f03f52019-04-02 02:13:284016 }
4017#endif
djacobo21e56e02016-07-02 01:14:314018
Maggie Caia2f03f52019-04-02 02:13:284019#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:104020 auto url_to_apps_throttle =
Yuta Hijikata235fc62b2020-12-08 03:48:324021#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Cai53da9b42021-01-29 09:12:084022 apps::CommonAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284023#else
Maggie Caic08b7d42020-05-05 03:51:104024 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284025#endif
Maggie Caic08b7d42020-05-05 03:51:104026 if (url_to_apps_throttle)
4027 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004028#endif
4029
brettw00899e62016-11-12 02:10:174030#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004031 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094032 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514033
Chris Hamiltonab4722122020-05-13 18:01:284034 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
4035 ->GetUserScriptListener()
4036 ->CreateNavigationThrottle(handle),
4037 &throttles);
naskob9164c42016-06-07 01:21:354038#endif
4039
bauerb8f9c37742017-03-30 15:04:124040#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:214041 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284042 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
4043 &throttles);
bauerb8f9c37742017-03-30 15:04:124044#endif
4045
csharrisone985ebc2017-04-04 17:05:034046 content::WebContents* web_contents = handle->GetWebContents();
Colin Blundell0ec5d642020-10-06 17:29:524047 if (auto* throttle_manager =
4048 subresource_filter::ContentSubresourceFilterThrottleManager::
4049 FromWebContents(web_contents)) {
4050 throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles);
csharrisone985ebc2017-04-04 17:05:034051 }
4052
zhenw6edd49c2017-07-12 05:49:454053#if !defined(OS_ANDROID)
4054 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4055 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:284056 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
4057 MaybeCreateThrottleFor(handle),
4058 &throttles);
zhenw6edd49c2017-07-12 05:49:454059#endif
4060
Bettinafd0c1102020-08-06 00:23:434061#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Chris Hamiltonab4722122020-05-13 18:01:284062 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
4063 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:094064#endif
4065
Lukasz Anforowicz7724d092019-10-03 23:50:214066 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284067 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
4068 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:274069
Chris Hamiltonab4722122020-05-13 18:01:284070 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
4071 &throttles);
Amber Won6b5edc752017-08-17 19:23:544072
Chris Hamiltonab4722122020-05-13 18:01:284073 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:514074
Jonathan Mengedoht42a19bb2020-07-28 14:10:164075 MaybeAddThrottle(
4076 WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
4077 &throttles);
4078
Yann Dago3256b872021-01-13 18:48:034079 policy::PolicyService* policy_service = nullptr;
4080 Profile* profile = Profile::FromBrowserContext(
4081 handle->GetWebContents()->GetBrowserContext());
4082 if (profile && profile->GetProfilePolicyConnector())
4083 policy_service = profile->GetProfilePolicyConnector()->policy_service();
4084
Aaron Colwellf94fd97a2020-07-21 19:37:084085 throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
Yann Dago3256b872021-01-13 18:48:034086 handle, handle->GetWebContents()->GetBrowserContext(), policy_service));
Doug Turner9dcaf5962017-12-21 04:38:534087
Colin Blundelleaa7377bf2020-01-22 08:49:104088 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
4089 // the relevant extension API whenever an SSL interstitial is shown.
4090 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
4091 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:284092 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4093 handle,
4094 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Mustafa Emre Acer06028d792021-01-05 19:48:514095 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp),
4096 base::BindOnce(
4097 &TypedNavigationUpgradeThrottle::
4098 ShouldIgnoreInterstitialBecauseNavigationDefaultedToHttps)));
Lucas Garron94b16052017-11-11 01:58:124099
Emily Starkd6896cd32019-08-21 04:55:544100 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4101
Mustafa Emre Acer06028d792021-01-05 19:48:514102 if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) {
4103 MaybeAddThrottle(
4104 TypedNavigationUpgradeThrottle::MaybeCreateThrottleFor(handle),
4105 &throttles);
4106 }
4107
Dmitry Gozman57b92ce2017-12-28 22:24:544108#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284109 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4110 &throttles);
4111
4112 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4113 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544114#endif
4115
Carlos IL800e3502020-04-30 16:35:594116 throttles.push_back(
4117 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034118
Mustafa Emre Acer97be4752020-05-13 01:24:434119 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4120 throttles.push_back(
4121 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4122 handle));
4123 }
4124
Yuta Hijikata235fc62b2020-12-08 03:48:324125// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
4126// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:314127#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:324128 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Chris Hamiltonab4722122020-05-13 18:01:284129 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4130 MaybeCreateThrottleFor(handle),
4131 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134132#endif
4133
Yuta Hijikata235fc62b2020-12-08 03:48:324134#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchuk762c40d2020-05-11 15:10:374135 MaybeAddThrottle(
Henrique Ferreiro26ed25a2021-02-01 21:59:294136 ash::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
Chris Hamiltonab4722122020-05-13 18:01:284137 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374138#endif
4139
Chris Hamiltonab4722122020-05-13 18:01:284140 auto* performance_manager_registry =
4141 performance_manager::PerformanceManagerRegistry::GetInstance();
4142 if (performance_manager_registry) {
4143 MaybeAddThrottles(
4144 performance_manager_registry->CreateThrottlesForNavigation(handle),
4145 &throttles);
4146 }
4147
Carlos IL06e6c8c2020-07-28 00:25:194148 if (profile && profile->GetPrefs()) {
4149 MaybeAddThrottle(
4150 security_interstitials::InsecureFormNavigationThrottle::
4151 MaybeCreateNavigationThrottle(
4152 handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
4153 profile->GetPrefs()),
4154 &throttles);
4155 }
Carlos IL1a5edec2020-06-12 17:56:574156
Ken Rockot4408a0f2020-07-27 19:40:544157 if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) {
4158 MaybeAddThrottle(
4159 error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle),
4160 &throttles);
4161 }
4162
Liquan (Max) Gud648f452020-12-18 05:28:444163 MaybeAddThrottle(
4164 payments::PaymentHandlerNavigationThrottle::MaybeCreateThrottleFor(
4165 handle),
4166 &throttles);
Liquan (Max) Gud648f452020-12-18 05:28:444167
dchenge73d8520c2015-12-27 01:19:094168 return throttles;
clamy40c9e142015-09-29 11:18:474169}
4170
clamy1e5574e2016-09-29 16:48:444171std::unique_ptr<content::NavigationUIData>
4172ChromeContentBrowserClient::GetNavigationUIData(
4173 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094174 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444175}
4176
Xiaohan Wanga4e41842018-06-26 18:45:104177void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4178 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104179 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124180 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Jeffrey Kardatzke614424232020-12-12 00:54:064181#if (defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)) && \
4182 BUILDFLAG(ENABLE_LIBRARY_CDMS) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104183 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334184 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104185 }
4186#endif
4187}
4188
[email protected]487974a2014-06-13 16:49:014189content::DevToolsManagerDelegate*
4190ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354191#if defined(OS_ANDROID)
4192 return new DevToolsManagerDelegateAndroid();
4193#else
[email protected]487974a2014-06-13 16:49:014194 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354195#endif
[email protected]487974a2014-06-13 16:49:014196}
4197
Rayan Kanso411e84e2019-02-13 15:27:404198void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4199 content::BrowserContext* browser_context,
4200 int service,
4201 base::Time expiration_time) {
4202 Profile* profile = Profile::FromBrowserContext(browser_context);
4203 DCHECK(profile);
4204
4205 auto* pref_service = profile->GetPrefs();
4206 DCHECK(pref_service);
4207
4208 DictionaryPrefUpdate pref_update(
4209 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4210 base::DictionaryValue* exp_dict = pref_update.Get();
4211
4212 // Convert |expiration_time| to minutes since that is the most granular
4213 // option that returns an int. base::Value does not accept int64.
4214 int expiration_time_minutes =
4215 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4216 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4217}
4218
4219base::flat_map<int, base::Time>
4220ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4221 content::BrowserContext* browser_context) {
4222 Profile* profile = Profile::FromBrowserContext(browser_context);
4223 DCHECK(profile);
4224
4225 auto* pref_service = profile->GetPrefs();
4226 DCHECK(pref_service);
4227
4228 auto* expiration_dict = pref_service->GetDictionary(
4229 prefs::kDevToolsBackgroundServicesExpirationDict);
4230 DCHECK(expiration_dict);
4231
4232 base::flat_map<int, base::Time> expiration_times;
4233 for (const auto& it : *expiration_dict) {
4234 // key.
4235 int service = 0;
4236 bool did_convert = base::StringToInt(it.first, &service);
4237 DCHECK(did_convert);
4238
4239 // value.
4240 DCHECK(it.second->is_int());
4241 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4242 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4243
4244 expiration_times[service] = expiration_time;
4245 }
4246
4247 return expiration_times;
4248}
4249
oysteinec563c582015-02-13 19:19:524250content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524251 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524252}
4253
[email protected]a6868c22013-10-09 02:50:294254bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4255 content::BrowserContext* browser_context,
4256 const GURL& url) {
brettw4b461082016-11-19 18:55:164257#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554258 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194259 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294260#else
4261 return false;
4262#endif
4263}
4264
[email protected]aec5ed52014-06-20 07:51:424265bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4266 content::BrowserContext* browser_context,
4267 const GURL& url) {
brettw4b461082016-11-19 18:55:164268#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554269 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194270 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064271#else
4272 return false;
4273#endif
4274}
4275
mlamourif8c23a2002015-01-27 13:10:104276void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014277 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434278 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524279 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104280
4281 WebContents* web_contents =
4282 WebContents::FromRenderFrameHost(render_frame_host);
4283 DCHECK(web_contents);
4284
Hiroki Nakagawab4cd18aa2021-01-25 18:11:014285 prerender::NoStatePrefetchManager* no_state_prefetch_manager =
4286 prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
drogerc1543152016-09-20 13:03:374287 web_contents->GetBrowserContext());
Hiroki Nakagawab4cd18aa2021-01-25 18:11:014288 if (no_state_prefetch_manager &&
4289 no_state_prefetch_manager->IsWebContentsPrerendering(web_contents)) {
Collin Baker98457b52019-11-06 21:34:294290 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104291 }
4292}
4293
Robert Sesek466e43e2019-08-19 22:02:024294void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4295 base::FilePath user_data_dir;
4296 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4297 DCHECK(!user_data_dir.empty());
4298 network_contexts_parent_directory_.push_back(user_data_dir);
4299
4300 base::FilePath cache_dir;
4301 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4302 DCHECK(!cache_dir.empty());
4303 // On some platforms, the cache is a child of the user_data_dir so only
4304 // return the one path.
4305 if (!user_data_dir.IsParent(cache_dir))
4306 network_contexts_parent_directory_.push_back(cache_dir);
4307
4308 // If the cache location has been overridden by a switch or preference,
4309 // include that as well.
4310 if (auto* local_state = g_browser_process->local_state()) {
4311 base::FilePath pref_cache_dir =
4312 local_state->GetFilePath(prefs::kDiskCacheDir);
4313 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4314 network_contexts_parent_directory_.push_back(pref_cache_dir);
4315 }
4316}
4317
[email protected]30335fdf02014-02-26 19:51:274318void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174319 base::CommandLine* to_command_line,
4320 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544321 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274322#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544323 const version_info::Channel kMaxDisableEncryptionChannel =
4324 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274325#else
sdefresne6e883e42015-07-30 08:05:544326 const version_info::Channel kMaxDisableEncryptionChannel =
4327 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274328#endif
4329 if (channel <= kMaxDisableEncryptionChannel) {
4330 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444331 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274332 };
Avi Drissmand251e912018-12-26 15:46:374333 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4334 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274335 }
4336}
bashi933629552016-10-13 23:32:404337
miu54dca6c2016-11-17 10:59:384338#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4339void ChromeContentBrowserClient::CreateMediaRemoter(
4340 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504341 mojo::PendingRemote<media::mojom::RemotingSource> source,
4342 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384343 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504344 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384345}
4346#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464347
Michael Giuffrida6802ffe2017-09-29 03:40:254348base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4349 const base::CommandLine& command_line) {
4350 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164351}
4352
John Abd-El-Malek8efa11f2019-01-06 00:51:534353namespace {
4354// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024355class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534356 public:
4357 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174358 ProtocolHandlerRegistry* protocol_handler_registry)
Matt Falkenhagen7811fd42020-06-24 22:42:414359 : protocol_handler_registry_(protocol_handler_registry) {
4360 DCHECK(protocol_handler_registry);
4361 }
John Abd-El-Malek8efa11f2019-01-06 00:51:534362 ~ProtocolHandlerThrottle() override = default;
4363
4364 void WillStartRequest(network::ResourceRequest* request,
4365 bool* defer) override {
Tsuyoshi Horof0ebcdd2021-02-25 04:13:574366 // Don't translate the urn: scheme URL while loading the resource from the
4367 // specified web bundle.
4368 if (request->web_bundle_token_params &&
4369 request->url.SchemeIs(url::kUrnScheme)) {
4370 return;
4371 }
Robbie McElrath16aaed6c2019-06-04 00:50:294372 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534373 }
4374
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584375 void WillRedirectRequest(
4376 net::RedirectInfo* redirect_info,
4377 const network::mojom::URLResponseHead& response_head,
4378 bool* defer,
4379 std::vector<std::string>* to_be_removed_headers,
4380 net::HttpRequestHeaders* modified_headers,
4381 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294382 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534383 }
4384
4385 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294386 void TranslateUrl(GURL* url) {
4387 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4388 return;
4389 GURL translated_url = protocol_handler_registry_->Translate(*url);
4390 if (!translated_url.is_empty())
4391 *url = translated_url;
4392 }
4393
Clark DuValla411bda2019-08-02 03:09:174394 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534395};
4396} // namespace
4397
Minggang Wangf6840ecf2019-07-29 05:15:024398std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194399ChromeContentBrowserClient::CreateURLLoaderThrottles(
4400 const network::ResourceRequest& request,
4401 content::BrowserContext* browser_context,
4402 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4403 content::NavigationUIData* navigation_ui_data,
4404 int frame_tree_node_id) {
4405 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4406
Minggang Wangf6840ecf2019-07-29 05:15:024407 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194408
Matt Falkenhagen7811fd42020-06-24 22:42:414409 DCHECK(browser_context);
Clark DuVallfffa41e2019-06-25 20:27:194410 Profile* profile = Profile::FromBrowserContext(browser_context);
Matt Falkenhagen7811fd42020-06-24 22:42:414411 DCHECK(profile);
Clark DuVallfffa41e2019-06-25 20:27:194412
4413 ChromeNavigationUIData* chrome_navigation_ui_data =
4414 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4415
Bettinafd0c1102020-08-06 00:23:434416#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Josh Karlinaabf5102021-01-25 16:39:394417 bool matches_enterprise_whitelist = safe_browsing::IsURLAllowlistedByPolicy(
Clark DuVall5497288d2019-07-17 00:17:564418 request.url, *profile->GetPrefs());
4419 if (!matches_enterprise_whitelist) {
Xinghui Luf45d7ef72020-06-09 02:16:384420#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494421 auto* connectors_service =
4422 enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
4423 browser_context);
4424 bool has_valid_dm_token =
4425 connectors_service &&
4426 connectors_service->GetDMTokenForRealTimeUrlCheck().has_value();
4427 bool is_enterprise_lookup_enabled =
Xinghui Lucf23c902020-06-10 17:38:254428 safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494429 profile->GetPrefs(), has_valid_dm_token, profile->IsOffTheRecord());
Xinghui Lucf23c902020-06-10 17:38:254430#else
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494431 bool is_enterprise_lookup_enabled = false;
Xinghui Luf45d7ef72020-06-09 02:16:384432#endif
Xinghui Lucf23c902020-06-10 17:38:254433 bool is_consumer_lookup_enabled =
Xinghui Luf45d7ef72020-06-09 02:16:384434 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
4435 profile->GetPrefs(), profile->IsOffTheRecord(),
Xinghui Lucf23c902020-06-10 17:38:254436 g_browser_process->variations_service());
4437
4438 // |url_lookup_service| is used when real time url check is enabled.
4439 safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service =
4440 GetUrlLookupService(browser_context, is_enterprise_lookup_enabled,
4441 is_consumer_lookup_enabled);
Clark DuVall5497288d2019-07-17 00:17:564442 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4443 base::BindOnce(
4444 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534445 base::Unretained(this),
Xinghui Lucf23c902020-06-10 17:38:254446 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
4447 // Should check for enterprise when safe browsing is disabled.
4448 /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled),
Xinghui Lua142c102020-03-02 20:50:084449 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584450 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564451 }
Nico Weberbc5b06f2019-07-26 14:00:134452#endif
Clark DuVall5497288d2019-07-17 00:17:564453
dalykba7bbfc2019-12-18 19:59:214454#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4455 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014456 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4457 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214458#endif
4459
Clark DuVallfffa41e2019-06-25 20:27:194460 if (chrome_navigation_ui_data &&
Hiroki Nakagawa78ebf062021-01-20 16:23:534461 chrome_navigation_ui_data->is_no_state_prefetching()) {
Clark DuVallfffa41e2019-06-25 20:27:194462 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
Clark DuVallfffa41e2019-06-25 20:27:194463 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234464 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194465 }
4466
John Abd-El-Malek4f380d92020-02-19 16:43:364467#if defined(OS_ANDROID)
4468 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234469 bool night_mode_enabled = false;
Gang Wu325f03f42021-02-25 20:00:464470 bool is_tab_large_enough = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374471 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4472 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364473 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4474 if (web_contents) {
4475 auto* client_data_header_observer =
4476 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4477 web_contents);
4478 if (client_data_header_observer)
4479 client_data_header = client_data_header_observer->header();
Brandon Wylie21a88ac92020-05-15 02:49:234480
Brandon Wylief6bfdab2020-08-12 21:49:364481 auto* delegate =
4482 TabAndroid::FromWebContents(web_contents)
4483 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4484 web_contents->GetDelegate())
4485 : nullptr;
Gang Wu325f03f42021-02-25 20:00:464486 if (delegate) {
Brandon Wylief6bfdab2020-08-12 21:49:364487 night_mode_enabled = delegate->IsNightModeEnabled();
Gang Wu325f03f42021-02-25 20:00:464488 is_tab_large_enough = delegate->IsTabLargeEnoughForDesktopSite();
4489 }
Brandon Wylie21a88ac92020-05-15 02:49:234490 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374491 }
John Abd-El-Malek4f380d92020-02-19 16:43:364492#endif
4493
Clark DuVallfffa41e2019-06-25 20:27:194494 chrome::mojom::DynamicParams dynamic_params = {
4495 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4496 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274497 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4498 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364499#if defined(OS_ANDROID)
Gang Wu325f03f42021-02-25 20:00:464500 client_data_header, night_mode_enabled, is_tab_large_enough,
John Abd-El-Malek4f380d92020-02-19 16:43:364501#endif
Alex Clarke3ebd9772020-02-28 10:50:274502 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194503
Matt Falkenhagen7811fd42020-06-24 22:42:414504 {
4505 auto* factory =
4506 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context);
4507 // null in unit tests.
4508 if (factory)
4509 result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory));
4510 }
Clark DuVall8512cee62019-06-26 01:14:214511
Clark DuVall39c2cfc2019-06-25 21:49:284512#if BUILDFLAG(ENABLE_PLUGINS)
4513 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Julie Jeongeun Kim44dcfab2021-01-20 07:39:184514 request.destination, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284515#endif
4516
Robbie McElrath127ad2b2019-07-22 22:38:114517 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404518 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584519 auto signin_throttle =
4520 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114521 if (signin_throttle)
4522 result.push_back(std::move(signin_throttle));
4523
Clark DuVallfffa41e2019-06-25 20:27:194524 return result;
4525}
4526
Ken Rockot6414c4d92017-11-08 19:58:324527void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464528 int frame_tree_node_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314529 ukm::SourceIdObj ukm_source_id,
Ken Rockot6414c4d92017-11-08 19:58:324530 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324531#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Malekea006302018-05-10 05:50:464532 content::WebContents* web_contents =
4533 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414534#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174535 factories->emplace(
Ken Rockot6414c4d92017-11-08 19:58:324536 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574537 extensions::CreateExtensionNavigationURLLoaderFactory(
Maks Orlovich5408ddfc2020-07-28 23:07:354538 web_contents->GetBrowserContext(), ukm_source_id,
John Abd-El-Malekea006302018-05-10 05:50:464539 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414540#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Yuta Hijikata235fc62b2020-12-08 03:48:324541#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414542 Profile* profile =
4543 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354544 factories->emplace(content::kExternalFileScheme,
4545 chromeos::ExternalFileURLLoaderFactory::Create(
4546 profile, content::ChildProcessHost::kInvalidUniqueID));
Yuta Hijikata235fc62b2020-12-08 03:48:324547#endif // BUILDFLAG(IS_CHROMEOS_ASH)
4548#endif // BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
Ken Rockot6414c4d92017-11-08 19:58:324549}
4550
Ting Shao2dc60582019-07-15 04:43:364551void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344552 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4553 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174554 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawa1efa31d2019-10-01 22:36:344555 DCHECK(browser_context);
4556 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174557
4558#if BUILDFLAG(ENABLE_EXTENSIONS)
Hiroki Nakagawa1efa31d2019-10-01 22:36:344559 factories->emplace(
4560 extensions::kExtensionScheme,
4561 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4562 browser_context));
4563#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4564}
4565
4566void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364567 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4568 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174569 NonNetworkURLLoaderFactoryMap* factories) {
Ting Shao2dc60582019-07-15 04:43:364570 DCHECK(browser_context);
4571 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174572
4573#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364574 factories->emplace(
4575 extensions::kExtensionScheme,
4576 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4577 browser_context));
4578#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364579}
4580
Jay Civelli2578ebe2018-06-05 18:44:314581namespace {
4582
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384583// The SpecialAccessFileURLLoaderFactory provided to the extension background
4584// pages. Checks with the ChildProcessSecurityPolicy to validate the file
4585// access.
4586class SpecialAccessFileURLLoaderFactory
Lukasz Anforowicz25620d32021-01-27 22:03:444587 : public network::SelfDeletingURLLoaderFactory {
Jay Civelli2578ebe2018-06-05 18:44:314588 public:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384589 // Returns mojo::PendingRemote to a newly constructed
4590 // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
4591 // delete itself once there are no more receivers (including the receiver
4592 // associated with the returned mojo::PendingRemote and the receivers bound by
4593 // the Clone method).
4594 static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
4595 int child_id) {
4596 mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
4597
4598 // The SpecialAccessFileURLLoaderFactory will delete itself when there are
Lukasz Anforowicz25620d32021-01-27 22:03:444599 // no more receivers - see the
4600 // network::SelfDeletingURLLoaderFactory::OnDisconnect method.
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384601 new SpecialAccessFileURLLoaderFactory(
4602 child_id, pending_remote.InitWithNewPipeAndPassReceiver());
4603
4604 return pending_remote;
4605 }
Jay Civelli2578ebe2018-06-05 18:44:314606
4607 private:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384608 explicit SpecialAccessFileURLLoaderFactory(
4609 int child_id,
4610 mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
Lukasz Anforowicz25620d32021-01-27 22:03:444611 : network::SelfDeletingURLLoaderFactory(std::move(factory_receiver)),
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384612 child_id_(child_id) {}
4613
Jay Civelli2578ebe2018-06-05 18:44:314614 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274615 void CreateLoaderAndStart(
4616 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4617 int32_t routing_id,
4618 int32_t request_id,
4619 uint32_t options,
4620 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304621 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274622 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4623 override {
Jay Civelli2578ebe2018-06-05 18:44:314624 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4625 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304626 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4627 ->OnComplete(
4628 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314629 return;
4630 }
Yutaka Hiranodf83dca42020-01-07 06:24:554631 content::CreateFileURLLoaderBypassingSecurityChecks(
4632 request, std::move(loader), std::move(client),
4633 /*observer=*/nullptr,
4634 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314635 }
4636
Jay Civelli2578ebe2018-06-05 18:44:314637 int child_id_;
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384638 DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory);
Jay Civelli2578ebe2018-06-05 18:44:314639};
4640
Yuta Hijikata235fc62b2020-12-08 03:48:324641#if BUILDFLAG(IS_CHROMEOS_ASH)
Aya ElAttareb5fee12020-05-05 08:56:054642bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4643 PrefService* const local_state = g_browser_process->local_state();
4644 if (!local_state) // Sometimes it's not available in tests.
4645 return false;
4646
4647 const base::ListValue* disabled_system_features_pref =
4648 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4649 if (!disabled_system_features_pref)
4650 return false;
4651
4652 const auto disabled_system_features =
4653 disabled_system_features_pref->GetList();
4654 return base::Contains(disabled_system_features, base::Value(system_feature));
4655}
4656
4657bool IsSystemFeatureURLDisabled(const GURL& url) {
4658 if (!url.SchemeIs(content::kChromeUIScheme))
4659 return false;
4660
4661 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4662 // installation complete successfully.
4663 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4664 url.path() != "/pwa.html" &&
Anqing Zhaod99eda172020-11-30 13:49:494665 IsSystemFeatureDisabled(policy::SystemFeature::kOsSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054666 return true;
4667 }
4668
4669 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494670 IsSystemFeatureDisabled(policy::SystemFeature::kBrowserSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054671 return true;
4672 }
4673
Jesse Schettlerb7047f32020-09-18 14:50:404674 if (url.DomainIs(chromeos::kChromeUIScanningAppHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494675 IsSystemFeatureDisabled(policy::SystemFeature::kScanning)) {
Jesse Schettlerb7047f32020-09-18 14:50:404676 return true;
4677 }
4678
Jiewei Qian64237ac2021-02-01 02:49:504679 if (url.DomainIs(chromeos::kChromeUICameraAppHost) &&
4680 IsSystemFeatureDisabled(policy::SystemFeature::kCamera)) {
4681 return true;
4682 }
4683
Aya ElAttareb5fee12020-05-05 08:56:054684 return false;
4685}
4686#endif
Jay Civelli2578ebe2018-06-05 18:44:314687} // namespace
4688
Ken Rockot6414c4d92017-11-08 19:58:324689void ChromeContentBrowserClient::
4690 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464691 int render_process_id,
4692 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324693 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324694#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414695 content::RenderFrameHost* frame_host =
4696 RenderFrameHost::FromID(render_process_id, render_frame_id);
4697 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
Yuta Hijikata235fc62b2020-12-08 03:48:324698#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414699
Yuta Hijikata235fc62b2020-12-08 03:48:324700#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414701 if (web_contents) {
4702 Profile* profile =
4703 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354704 factories->emplace(content::kExternalFileScheme,
4705 chromeos::ExternalFileURLLoaderFactory::Create(
4706 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414707 }
Yuta Hijikata235fc62b2020-12-08 03:48:324708#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414709
Ken Rockot6414c4d92017-11-08 19:58:324710#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174711 factories->emplace(extensions::kExtensionScheme,
4712 extensions::CreateExtensionURLLoaderFactory(
4713 render_process_id, render_frame_id));
Chris Mumfordbae8a742018-03-01 23:02:234714
4715 // This logic should match
4716 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314717 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234718 return;
Jay Civellic9bbf72d2018-03-24 01:58:314719
4720 Profile* profile =
4721 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4722 InstantService* instant_service =
4723 InstantServiceFactory::GetForProfile(profile);
4724 // The test below matches what's done by ShouldServiceRequestIOThread in
4725 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464726 if (instant_service->IsInstantProcess(render_process_id)) {
Lukasz Anforowicz7f695532020-09-15 16:05:224727 factories->emplace(
Jay Civellic9bbf72d2018-03-24 01:58:314728 chrome::kChromeSearchScheme,
Lukasz Anforowicz7f695532020-09-15 16:05:224729 content::CreateWebUIURLLoaderFactory(
Jay Civellic9bbf72d2018-03-24 01:58:314730 frame_host, chrome::kChromeSearchScheme,
4731 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234732 }
Jay Civellic9bbf72d2018-03-24 01:58:314733
Chris Mumfordbae8a742018-03-01 23:02:234734 extensions::ChromeExtensionWebContentsObserver* web_observer =
4735 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4736 web_contents);
4737
Karan Bhatia91928572018-03-06 01:18:074738 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4739 // to the |web_contents|.
4740 if (!web_observer)
4741 return;
4742
Chris Mumfordbae8a742018-03-01 23:02:234743 const Extension* extension =
4744 web_observer->GetExtensionFromFrame(frame_host, false);
4745 if (!extension)
4746 return;
4747
Sam McNally7414eeb72018-09-03 04:05:304748 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234749 // Support for chrome:// scheme if appropriate.
4750 if ((extension->is_extension() || extension->is_platform_app()) &&
4751 Manifest::IsComponentLocation(extension->location())) {
4752 // Components of chrome that are implemented as extensions or platform apps
4753 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304754 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4755 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4756 }
4757 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4758 (extension->is_platform_app() &&
4759 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234760 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024761 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4762 // URLs. Hosted apps are not allowed because they are served via web servers
4763 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304764 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4765 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024766 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304767 }
4768 if (!allowed_webui_hosts.empty()) {
Lukasz Anforowicz7f695532020-09-15 16:05:224769 factories->emplace(content::kChromeUIScheme,
4770 content::CreateWebUIURLLoaderFactory(
4771 frame_host, content::kChromeUIScheme,
4772 std::move(allowed_webui_hosts)));
Chris Mumfordbae8a742018-03-01 23:02:234773 }
Jay Civelli2578ebe2018-06-05 18:44:314774
4775 // Extension with a background page get file access that gets approval from
4776 // ChildProcessSecurityPolicy.
4777 extensions::ExtensionHost* host =
4778 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4779 ->GetBackgroundHostForExtension(extension->id());
4780 if (host) {
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384781 factories->emplace(
Lukasz Anforowiczb7d8b542020-09-03 19:50:344782 url::kFileScheme,
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384783 SpecialAccessFileURLLoaderFactory::Create(render_process_id));
Jay Civelli2578ebe2018-06-05 18:44:314784 }
Chris Mumfordbae8a742018-03-01 23:02:234785#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324786}
4787
Ken Rockota0dfaca12018-02-15 07:26:254788bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214789 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254790 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384791 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444792 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264793 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004794 base::Optional<int64_t> navigation_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314795 ukm::SourceIdObj ukm_source_id,
Dominic Farolino1be897a2019-07-20 08:11:424796 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184797 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4798 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334799 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084800 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334801 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014802 bool use_proxy = false;
4803
Ken Rockota0dfaca12018-02-15 07:26:254804#if BUILDFLAG(ENABLE_EXTENSIONS)
4805 auto* web_request_api =
4806 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214807 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254808
4809 // NOTE: Some unit test environments do not initialize
4810 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014811 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124812 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384813 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004814 browser_context, frame, render_process_id, type,
Maks Orlovichf334d642020-09-21 22:19:594815 std::move(navigation_id), ukm_source_id, factory_receiver,
4816 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124817 if (bypass_redirect_checks)
4818 *bypass_redirect_checks = use_proxy_for_web_request;
4819 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014820 }
Ken Rockota0dfaca12018-02-15 07:26:254821#endif
Reilly Grant24bf8332018-08-27 21:55:014822
Reilly Grantcc22e602018-09-07 15:25:204823 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444824 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4825 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014826
Hiroki Nakagawa483686a92020-10-29 04:31:454827 auto* prefetch_proxy_service = PrefetchProxyServiceFactory::GetForProfile(
4828 Profile::FromBrowserContext(browser_context));
Robert Ogden31b234712020-06-04 22:51:214829 // |frame| is null when |type| is service worker.
Hiroki Nakagawa483686a92020-10-29 04:31:454830 if (frame && prefetch_proxy_service) {
4831 use_proxy |= prefetch_proxy_service->MaybeProxyURLLoaderFactory(
Robert Ogden8c53bc52020-06-19 21:24:184832 frame, render_process_id, type, factory_receiver);
Robert Ogden31b234712020-06-04 22:51:214833 }
4834
dalyk0018c16f2020-01-08 20:20:084835#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4836 if (disable_secure_dns) {
4837 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4838 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014839 web_contents &&
4840 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4841 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084842 ->is_captive_portal_window();
4843 }
4844#endif
4845
Reilly Grant24bf8332018-08-27 21:55:014846 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254847}
4848
Jian Lide7b43792018-06-01 23:22:134849std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4850ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4851 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144852 int frame_tree_node_id,
4853 const scoped_refptr<network::SharedURLLoaderFactory>&
4854 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134855 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4856 interceptors;
4857#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234858 interceptors.push_back(
4859 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4860 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134861#endif
Ryan Sturmaf523742019-01-16 00:15:454862
Robert Ogden6946ad42020-01-13 18:01:304863 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
Hiroki Nakagawa483686a92020-10-29 04:31:454864 interceptors.push_back(std::make_unique<PrefetchProxyURLLoaderInterceptor>(
4865 frame_tree_node_id));
Robert Ogden6946ad42020-01-13 18:01:304866 }
4867
Ryan Sturm8670b572020-10-21 18:45:304868 if (SearchPrefetchServiceIsEnabled()) {
4869 interceptors.push_back(std::make_unique<SearchPrefetchURLLoaderInterceptor>(
4870 frame_tree_node_id));
4871 }
4872
Jian Lide7b43792018-06-01 23:22:134873 return interceptors;
4874}
4875
Ryan Sturm6b2f6392020-12-09 21:46:004876content::ContentBrowserClient::URLLoaderRequestHandler
4877ChromeContentBrowserClient::
4878 CreateURLLoaderHandlerForServiceWorkerNavigationPreload(
4879 int frame_tree_node_id,
4880 const network::ResourceRequest& resource_request) {
4881 content::ContentBrowserClient::URLLoaderRequestHandler callback;
4882
4883 // If search prefetch is disabled, nothing needs to be handled.
4884 if (!SearchPrefetchServiceIsEnabled()) {
4885 return callback;
4886 }
4887
4888 std::unique_ptr<SearchPrefetchURLLoader> loader =
4889 SearchPrefetchURLLoaderInterceptor::MaybeCreateLoaderForRequest(
4890 resource_request, frame_tree_node_id);
4891 if (!loader) {
4892 return callback;
4893 }
4894
4895 auto* raw_loader = loader.get();
4896
4897 // Hand ownership of the loader to the callback, when it runs, mojo will
4898 // manage it. If the callback is deleted, the loader will be deleted.
4899 callback = raw_loader->ServingResponseHandler(std::move(loader));
4900 return callback;
4901}
4902
Yutaka Hirano8e0b4d432019-07-04 07:12:384903bool ChromeContentBrowserClient::WillInterceptWebSocket(
4904 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334905#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384906 if (!frame) {
4907 return false;
4908 }
4909 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334910 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4911 frame->GetProcess()->GetBrowserContext());
4912
4913 // NOTE: Some unit test environments do not initialize
4914 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4915 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384916 return false;
Yutaka Hirano36c94952018-05-30 21:33:334917
Yutaka Hirano8e0b4d432019-07-04 07:12:384918 return web_request_api->MayHaveProxies();
4919#else
4920 return false;
4921#endif
4922}
4923
4924void ChromeContentBrowserClient::CreateWebSocket(
4925 content::RenderFrameHost* frame,
4926 WebSocketFactory factory,
4927 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394928 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384929 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404930 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4931 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384932#if BUILDFLAG(ENABLE_EXTENSIONS)
4933 if (!frame) {
4934 return;
4935 }
4936 auto* web_request_api =
4937 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4938 frame->GetProcess()->GetBrowserContext());
4939
4940 DCHECK(web_request_api);
4941 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394942 site_for_cookies.RepresentativeUrl(),
4943 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334944#endif
4945}
4946
Maks Orlovich710d5e32019-07-09 20:16:454947bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464948 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454949 content::BrowserContext* browser_context,
Shuran Huangbd4d1692021-01-26 17:03:414950 const url::Origin& origin,
Shuran Huang92b415d72021-01-12 20:48:154951 const net::IsolationInfo& isolation_info,
Maks Orlovich710d5e32019-07-09 20:16:454952 bool is_service_worker,
4953 int process_id,
4954 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034955 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454956 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4957#if BUILDFLAG(ENABLE_EXTENSIONS)
Shuran Huangf20a28c2021-01-27 19:36:284958 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464959 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454960 extensions::ChromeExtensionCookies::Get(browser_context)
Shuran Huangbd4d1692021-01-26 17:03:414961 ->CreateRestrictedCookieManager(origin, isolation_info,
4962 std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454963 return true;
4964 }
4965#endif
4966 return false;
4967}
4968
Matt Menkeae4fdb12018-06-02 06:32:544969void ChromeContentBrowserClient::OnNetworkServiceCreated(
4970 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534971 PrefService* local_state;
4972 if (g_browser_process) {
4973 DCHECK(g_browser_process->local_state());
4974 local_state = g_browser_process->local_state();
4975 } else {
danakj5beedd02020-10-30 15:55:134976 DCHECK(startup_data_.chrome_feature_list_creator()->local_state());
4977 local_state = startup_data_.chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534978 }
4979
4980 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4981 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4982
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494983 // Create SystemNetworkContextManager if it has not been created yet. We need
4984 // to set up global NetworkService state before anything else uses it and this
4985 // is the first opportunity to initialize SystemNetworkContextManager with the
4986 // NetworkService.
4987 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534988 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074989
Min Qin8caab1d2018-10-03 17:28:134990 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544991 network_service);
4992}
4993
Matthew Denton8888ae52020-05-14 08:20:024994void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:254995 content::BrowserContext* context,
4996 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:024997 const base::FilePath& relative_partition_path,
4998 network::mojom::NetworkContextParams* network_context_params,
Matthew Denton6f6ca6ac2021-02-18 09:00:354999 cert_verifier::mojom::CertVerifierCreationParams*
5000 cert_verifier_creation_params) {
Glen Robertsoncbb40ac2020-11-23 04:04:045001 ProfileNetworkContextService* service =
5002 ProfileNetworkContextServiceFactory::GetForContext(context);
5003 if (service) {
5004 service->ConfigureNetworkContextParams(in_memory, relative_partition_path,
5005 network_context_params,
5006 cert_verifier_creation_params);
5007 } else {
5008 // Set default params.
5009 network_context_params->user_agent = GetUserAgent();
5010 network_context_params->accept_language = GetApplicationLocale();
5011 }
Ken Rockota0dfaca12018-02-15 07:26:255012}
5013
Robert Sesek34f68f312019-01-14 20:25:115014std::vector<base::FilePath>
5015ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:025016 DCHECK(!network_contexts_parent_directory_.empty());
5017 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:115018}
5019
John Abd-El-Malekc240cfc42020-07-08 12:22:445020base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() {
5021 auto platform_dict = net_log::GetPlatformConstantsForNetLog(
5022 base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
5023 chrome::GetChannelName());
5024 if (platform_dict)
5025 return std::move(*platform_dict);
5026 else
5027 return base::DictionaryValue();
5028}
5029
Min Qin75ed6df2017-12-01 20:39:155030bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135031 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155032#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5033 // It is OK to load the saved offline copy, in MHTML format.
5034 ChromeNavigationUIData* chrome_navigation_ui_data =
5035 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5036 if (!chrome_navigation_ui_data)
5037 return false;
5038 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5039 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5040 return offline_page_data && offline_page_data->is_offline_page();
5041#else
5042 return false;
5043#endif
5044}
5045
Min Qin30a78a12017-12-06 01:29:135046bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5047 const GURL& url,
5048 const std::string& mime_type) {
5049#if BUILDFLAG(ENABLE_EXTENSIONS)
5050 // Special-case user scripts to get downloaded instead of viewed.
5051 return extensions::UserScript::IsURLUserScript(url, mime_type);
5052#else
5053 return false;
5054#endif
5055}
5056
Donna Wu838ac362018-08-10 10:36:335057void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345058 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:045059 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:465060 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:345061 return;
5062
[email protected]95ebe7c2020-04-08 19:12:455063 CHECK(render_frame_host);
5064 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
5065 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:345066}
5067
Ovidio Henriquez3d729f62020-02-07 00:43:295068content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
5069 if (!bluetooth_delegate_)
5070 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
5071 return bluetooth_delegate_.get();
5072}
5073
Reilly Grant0d282322019-01-29 02:42:585074#if !defined(OS_ANDROID)
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:215075void ChromeContentBrowserClient::CreateDeviceInfoService(
5076 content::RenderFrameHost* render_frame_host,
5077 mojo::PendingReceiver<blink::mojom::DeviceAPIService> receiver) {
5078 DCHECK(render_frame_host);
5079 DeviceServiceImpl::Create(render_frame_host, std::move(receiver));
5080}
5081
Reilly Grant0d282322019-01-29 02:42:585082content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5083 if (!serial_delegate_)
5084 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5085 return serial_delegate_.get();
5086}
Matt Reynolds93616f9b2019-06-07 01:28:525087
5088content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5089 if (!hid_delegate_)
5090 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5091 return hid_delegate_.get();
5092}
Reilly Grant0d282322019-01-29 02:42:585093
Olivier Yiptong935e6c42020-11-21 01:28:235094content::FontAccessDelegate*
5095ChromeContentBrowserClient::GetFontAccessDelegate() {
5096 if (!font_access_delegate_)
5097 font_access_delegate_ = std::make_unique<ChromeFontAccessDelegate>();
5098 return static_cast<content::FontAccessDelegate*>(font_access_delegate_.get());
5099}
5100
Balazs Engedya7ff70982018-06-04 18:14:475101std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5102ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:335103 content::RenderFrameHost* render_frame_host) {
5104 return AuthenticatorRequestScheduler::CreateRequestDelegate(
5105 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:475106}
Nina Satragno8c832df2019-07-29 15:59:395107#endif
Balazs Engedya7ff70982018-06-04 18:14:475108
Jun Cai9409ded2018-01-30 00:19:465109std::unique_ptr<net::ClientCertStore>
5110ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:105111 content::BrowserContext* browser_context) {
5112 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:465113 ->CreateClientCertStore();
5114}
5115
David Benjamineced01fc2019-02-27 18:29:025116std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395117ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585118 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025119 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035120 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245121 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395122 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035123 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395124 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565125 LoginAuthRequiredCallback auth_required_callback) {
Andreea Costinas81218bf2021-01-08 11:48:145126#if BUILDFLAG(IS_CHROMEOS_ASH)
5127 policy::SystemProxyManager* system_proxy_manager =
5128 g_browser_process->platform_part()
5129 ->browser_policy_connector_chromeos()
5130 ->GetSystemProxyManager();
5131 // For Managed Guest Session and Kiosk devices, the credentials configured
5132 // via the policy SystemProxySettings may be used for proxy authentication.
5133 // Note: |system_proxy_manager| may be missing in tests.
5134 if (system_proxy_manager && system_proxy_manager->CanUsePolicyCredentials(
5135 auth_info, first_auth_attempt)) {
5136 return system_proxy_manager->CreateLoginDelegate(
5137 std::move(auth_required_callback));
5138 }
5139#endif // BUILDFLAG(IS_CHROMEOS_ASH)
5140
Emily Stark63c884f2020-05-12 03:55:285141 // For subresources, create a LoginHandler directly, which may show a login
5142 // prompt to the user. Main frame resources go through LoginTabHelper, which
5143 // manages a more complicated flow to avoid confusion about which website is
5144 // showing the prompt.
5145 if (is_request_for_main_frame) {
5146 LoginTabHelper::CreateForWebContents(web_contents);
5147 return LoginTabHelper::FromWebContents(web_contents)
5148 ->CreateAndStartMainFrameLoginDelegate(
5149 auth_info, web_contents, request_id, url, response_headers,
5150 std::move(auth_required_callback));
5151 }
5152 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
5153 auth_info, web_contents, std::move(auth_required_callback));
5154 login_handler->StartSubresource(request_id, url, response_headers);
5155 return login_handler;
Jun Caibc561f412018-02-28 18:41:395156}
5157
John Abd-El-Maleka67add82018-03-09 18:22:015158bool ChromeContentBrowserClient::HandleExternalProtocol(
5159 const GURL& url,
danakjf4b9e942019-11-29 15:43:045160 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015161 int child_id,
5162 content::NavigationUIData* navigation_data,
5163 bool is_main_frame,
5164 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455165 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:455166 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:105167 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015168#if BUILDFLAG(ENABLE_EXTENSIONS)
5169 // External protocols are disabled for guests. An exception is made for the
5170 // "mailto" protocol, so that pages that utilize it work properly in a
5171 // WebView.
5172 ChromeNavigationUIData* chrome_data =
5173 static_cast<ChromeNavigationUIData*>(navigation_data);
5174 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5175 (chrome_data &&
5176 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5177 !url.SchemeIs(url::kMailToScheme)) {
5178 return false;
5179 }
5180#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5181
5182#if defined(OS_ANDROID)
5183 // Main frame external protocols are handled by
5184 // InterceptNavigationResourceThrottle.
5185 if (is_main_frame)
5186 return false;
5187#endif // defined(ANDROID)
5188
Gabriel Charettee7cdc5cd2020-05-27 23:35:055189 content::GetUIThreadTaskRunner({})->PostTask(
5190 FROM_HERE,
danakjf4b9e942019-11-29 15:43:045191 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
5192 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:015193 return true;
5194}
5195
Jennifer Apacible4f854a82018-04-06 22:22:115196std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285197ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5198 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115199 // Note: content::OverlayWindow::Create() is defined by platform-specific
5200 // implementation in chrome/browser/ui/views. This layering hack, which goes
5201 // through //content and ContentBrowserClient, allows us to work around the
5202 // dependency constraints that disallow directly calling
5203 // chrome/browser/ui/views code either from here or from other code in
5204 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285205 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115206}
5207
Kunihiko Sakamoto19aa7082019-02-25 03:14:435208void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565209 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115210 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565211 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435212 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5213 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565214}
5215
dbeam25472e0c2017-06-23 19:02:315216// Static; handles rewriting Web UI URLs.
5217bool ChromeContentBrowserClient::HandleWebUI(
5218 GURL* url,
5219 content::BrowserContext* browser_context) {
Sanja Perisic6482cd32021-02-08 17:27:325220 DCHECK(browser_context);
5221
Dan Beam141c48932019-08-22 02:29:395222 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315223 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395224 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315225 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5226 chrome::kChromeUIHelpHost);
dbeam25472e0c2017-06-23 19:02:315227 }
5228
sauskib5f82762020-07-21 17:13:225229 // Replace deprecated cookie settings URL with the current version.
5230 if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) {
5231 *url = GURL(chrome::kChromeUICookieSettingsURL);
sauskib5f82762020-07-21 17:13:225232 }
5233
Hector Carmona566a20b2019-09-13 22:44:425234#if defined(OS_WIN)
5235 // TODO(crbug.com/1003960): Remove when issue is resolved.
5236 if (url->SchemeIs(content::kChromeUIScheme) &&
5237 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5238 url::Replacements<char> replacements;
5239 replacements.SetHost(
5240 chrome::kChromeUIWelcomeHost,
5241 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5242 *url = url->ReplaceComponents(replacements);
5243 return true;
5244 }
5245#endif // defined(OS_WIN)
5246
dbeam25472e0c2017-06-23 19:02:315247 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5248 browser_context, *url)) {
5249 return false;
5250 }
5251
Yuta Hijikata235fc62b2020-12-08 03:48:325252#if BUILDFLAG(IS_CHROMEOS_ASH)
dbeam25472e0c2017-06-23 19:02:315253 // Special case : in ChromeOS in Guest mode bookmarks and history are
5254 // disabled for security reasons. New tab page explains the reasons, so
5255 // we redirect user to new tab page.
5256 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5257 if (url->SchemeIs(content::kChromeUIScheme) &&
5258 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5259 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5260 // Rewrite with new tab URL
5261 *url = GURL(chrome::kChromeUINewTabURL);
5262 }
5263 }
Aya ElAttareb5fee12020-05-05 08:56:055264
5265 if (IsSystemFeatureURLDisabled(*url)) {
5266 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
5267 return true;
5268 }
5269
dbeam25472e0c2017-06-23 19:02:315270#endif
5271
5272 return true;
5273}
5274
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065275bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5276 content::BrowserContext* browser_context,
5277 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325278 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065279#if defined(OS_ANDROID)
5280 return false;
5281#else
5282 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5283 ->GetForBrowserContext(browser_context)
5284 ->ShowPaymentHandlerWindow(url, std::move(callback));
5285 return true;
5286#endif
5287}
5288
Dan Beam141c48932019-08-22 02:29:395289// static
dbeam25472e0c2017-06-23 19:02:315290bool ChromeContentBrowserClient::HandleWebUIReverse(
5291 GURL* url,
5292 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425293#if defined(OS_WIN)
5294 // TODO(crbug.com/1003960): Remove when issue is resolved.
5295 // No need to actually reverse-rewrite the URL, but return true to update the
5296 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5297 if (url->SchemeIs(content::kChromeUIScheme) &&
5298 url->host() == chrome::kChromeUIWelcomeHost) {
5299 return true;
5300 }
5301#endif // defined(OS_WIN)
5302
dbeam25472e0c2017-06-23 19:02:315303 // No need to actually reverse-rewrite the URL, but return true to update the
5304 // displayed URL when rewriting chrome://help to chrome://settings/help.
5305 return url->SchemeIs(content::kChromeUIScheme) &&
5306 url->host() == chrome::kChromeUISettingsHost;
5307}
5308
Alison Maher7f366dc62020-03-03 19:46:005309const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585310 return ui::NativeTheme::GetInstanceForWeb();
5311}
5312
Clark DuVall5497288d2019-07-17 00:17:565313scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505314ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Xinghui Lucf23c902020-06-10 17:38:255315 bool safe_browsing_enabled_for_profile,
5316 bool should_check_on_sb_disabled) {
Yuzhu Shen44094e22017-07-18 22:52:355317 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5318
Xinghui Lucf23c902020-06-10 17:38:255319 // Should not bypass safe browsing check if the check is for enterprise
5320 // lookup.
5321 if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled)
Yuzhu Shencb3011f62018-02-08 02:51:505322 return nullptr;
5323
Yuzhu Shen44094e22017-07-18 22:52:355324 // |safe_browsing_service_| may be unavailable in tests.
5325 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5326 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435327 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355328 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435329 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355330 }
5331
Clark DuVall5497288d2019-07-17 00:17:565332 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355333}
Daniel Vogelheim6008f572018-09-24 14:35:145334
Xinghui Lucf23c902020-06-10 17:38:255335safe_browsing::RealTimeUrlLookupServiceBase*
5336ChromeContentBrowserClient::GetUrlLookupService(
5337 content::BrowserContext* browser_context,
5338 bool is_enterprise_lookup_enabled,
5339 bool is_consumer_lookup_enabled) {
5340 // |safe_browsing_service_| may be unavailable in tests.
5341 if (!safe_browsing_service_) {
5342 return nullptr;
5343 }
5344
5345 Profile* profile = Profile::FromBrowserContext(browser_context);
5346
5347#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
5348 if (is_enterprise_lookup_enabled) {
5349 return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory::
5350 GetForProfile(profile);
5351 }
5352#endif
5353
5354 if (is_consumer_lookup_enabled) {
5355 return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
5356 profile);
5357 }
5358 return nullptr;
5359}
5360
Daniel Vogelheim6008f572018-09-24 14:35:145361base::Optional<std::string>
5362ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595363 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185364 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595365 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5366 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145367}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525368
Takashi Toyoshima5af383aa2019-07-22 15:24:225369bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525370 // We require --user-data-dir flag too so that no dangerous changes are made
5371 // in the user's regular profile.
5372 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5373 switches::kUserDataDir);
5374}
rajendrantfeea8592018-10-19 18:26:065375
5376void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5377 int32_t network_traffic_annotation_id_hash,
5378 int64_t recv_bytes,
5379 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035380 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5381 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5382 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5383 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065384 }
5385}
Ryan Sturmaa05092f2018-10-21 03:56:545386
Ken Rockot4e284d32020-03-06 06:26:495387base::FilePath
5388ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
Ken Rockota22aaa572020-10-14 18:46:145389 if (!g_browser_process || !g_browser_process->profile_manager())
5390 return base::FilePath();
Ken Rockot4e284d32020-03-06 06:26:495391 return g_browser_process->profile_manager()->user_data_dir();
5392}
5393
Guido Urdanetae02b5722020-07-22 05:58:215394bool ChromeContentBrowserClient::ShouldSandboxAudioService() {
5395 return IsAudioServiceSandboxEnabled();
5396}
5397
Robert Ogden30bbc9d2019-04-30 20:15:135398
Charlie Harrison650e11422018-12-04 00:37:265399
5400void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5401 content::RenderFrameHost* render_frame_host,
5402 blink::mojom::WebFeature feature) {
5403 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5404 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5405 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5406 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315407
5408 // For the SameSite-by-default-cookies related features, log
5409 // the site engagement score for the site whose cookie was blocked. This is to
5410 // gauge the user impact of the cookies being blocked.
5411 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265412}
Yutaka Hirano968d6252018-12-04 05:09:315413
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525414std::string ChromeContentBrowserClient::GetProduct() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415415 return embedder_support::GetProduct();
Yutaka Hirano968d6252018-12-04 05:09:315416}
5417
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525418std::string ChromeContentBrowserClient::GetUserAgent() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415419 return embedder_support::GetUserAgent();
Yutaka Hirano968d6252018-12-04 05:09:315420}
Sam McNallyd54e23f92019-01-16 04:42:395421
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525422blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415423 return embedder_support::GetUserAgentMetadata();
Mike West6e4cbb32019-02-13 09:40:175424}
5425
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525426base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275427 // This icon is available on Android, but adds 19KiB to the APK. Since it
5428 // isn't used on Android we exclude it to avoid bloat.
5429#if !defined(OS_ANDROID)
5430 return base::Optional<gfx::ImageSkia>(
5431 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5432 IDR_PRODUCT_LOGO_256));
5433#else
5434 return base::nullopt;
5435#endif
5436}
5437
Sam McNallyd54e23f92019-01-16 04:42:395438bool ChromeContentBrowserClient::IsBuiltinComponent(
5439 content::BrowserContext* browser_context,
5440 const url::Origin& origin) {
5441#if BUILDFLAG(ENABLE_EXTENSIONS)
5442 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5443 browser_context, origin);
5444#else
5445 return false;
5446#endif
5447}
Oleg Davydov2cc0167b2019-02-05 14:32:485448
Aaron Colwelle1908d982020-06-26 22:08:155449bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:485450 const GURL& url,
5451 content::BrowserContext* context) {
Aaron Colwellf94fd97a2020-07-21 19:37:085452 PolicyBlocklistService* service =
5453 PolicyBlocklistFactory::GetForBrowserContext(context);
Oleg Davydov2cc0167b2019-02-05 14:32:485454
Aaron Colwellf94fd97a2020-07-21 19:37:085455 using URLBlocklistState = policy::URLBlocklist::URLBlocklistState;
5456 URLBlocklistState blocklist_state = service->GetURLBlocklistState(url);
5457 return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST;
Oleg Davydov2cc0167b2019-02-05 14:32:485458}
Dominic Mazzoni21fb0282019-02-13 18:32:475459
5460ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5461 content::BrowserContext* browser_context) {
5462 Profile* profile = Profile::FromBrowserContext(browser_context);
5463 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5464}
Eric Karld6cd75b2019-03-14 22:01:365465
5466#if defined(OS_ANDROID)
5467content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525468ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335469 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425470 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365471 return WideColorGamutHeuristic::kUseDisplay;
5472 }
Khushal1fc0da52019-10-09 00:38:565473
5474 if (display::Display::HasForceDisplayColorProfile() &&
5475 display::Display::GetForcedDisplayColorProfile() ==
5476 gfx::ColorSpace::CreateDisplayP3D65()) {
5477 return WideColorGamutHeuristic::kUseDisplay;
5478 }
5479
Eric Karld6cd75b2019-03-14 22:01:365480 return WideColorGamutHeuristic::kNone;
5481}
5482#endif
Ehsan Karamad91413d72019-03-22 16:37:485483
5484base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435485ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465486 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485487 base::flat_set<std::string> mime_types;
5488#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465489 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485490 for (const auto& pair : map)
5491 mime_types.insert(pair.first);
5492#endif
5493 return mime_types;
5494}
Yao Xiaod06607b2019-05-02 23:16:365495
5496void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
Alex Turner5d3dd2572020-12-16 18:08:055497 content::WebContents* web_contents,
5498 content::RenderFrameHost* frame_host,
Yao Xiaod06607b2019-05-02 23:16:365499 bool user_gesture,
Yeunjoo Choi3df791a2021-02-17 07:07:255500 blink::NavigationDownloadPolicy* download_policy) {
Colin Blundell0ec5d642020-10-06 17:29:525501 const auto* throttle_manager = subresource_filter::
5502 ContentSubresourceFilterThrottleManager::FromWebContents(web_contents);
5503 if (throttle_manager && throttle_manager->IsFrameTaggedAsAd(frame_host)) {
Yeunjoo Choi3df791a2021-02-17 07:07:255504 download_policy->SetAllowed(blink::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365505 if (!user_gesture) {
5506 if (base::FeatureList::IsEnabled(
5507 blink::features::
5508 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5509 download_policy->SetDisallowed(
Yeunjoo Choi3df791a2021-02-17 07:07:255510 blink::NavigationDownloadType::kAdFrameNoGesture);
Yao Xiaod06607b2019-05-02 23:16:365511 } else {
5512 download_policy->SetAllowed(
Yeunjoo Choi3df791a2021-02-17 07:07:255513 blink::NavigationDownloadType::kAdFrameNoGesture);
Yao Xiaod06607b2019-05-02 23:16:365514 }
Yao Xiaod06607b2019-05-02 23:16:365515 }
5516 }
5517}
Jun Cai732a05e32019-05-29 19:34:195518
Yao Xiao3d1b19d2021-02-24 18:25:095519blink::mojom::InterestCohortPtr
5520ChromeContentBrowserClient::GetInterestCohortForJsApi(
Yao Xiaoc5436ad2021-01-12 00:22:305521 content::WebContents* web_contents,
Yao Xiao1e28cd42020-12-22 19:31:215522 const GURL& url,
5523 const base::Optional<url::Origin>& top_frame_origin) {
Yao Xiaoc5436ad2021-01-12 00:22:305524 federated_learning::FlocEligibilityObserver::GetOrCreateForCurrentDocument(
5525 web_contents->GetMainFrame())
5526 ->OnInterestCohortApiUsed();
5527
Yao Xiaoebed8c12020-09-26 07:51:205528 federated_learning::FlocIdProvider* floc_id_provider =
5529 federated_learning::FlocIdProviderFactory::GetForProfile(
Yao Xiaoc5436ad2021-01-12 00:22:305530 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
Yao Xiaoebed8c12020-09-26 07:51:205531
5532 if (!floc_id_provider)
Yao Xiao3d1b19d2021-02-24 18:25:095533 return blink::mojom::InterestCohort::New();
Yao Xiaoebed8c12020-09-26 07:51:205534
Yao Xiao1e28cd42020-12-22 19:31:215535 return floc_id_provider->GetInterestCohortForJsApi(url, top_frame_origin);
Yao Xiaoebed8c12020-09-26 07:51:205536}
5537
Jun Cai732a05e32019-05-29 19:34:195538bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5539 content::BrowserContext* browser_context,
5540 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525541 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195542 const HostContentSettingsMap* const content_settings =
5543 HostContentSettingsMapFactory::GetForProfile(
5544 Profile::FromBrowserContext(browser_context));
5545
5546 if (content_settings->GetContentSetting(
5547 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145548 ContentSettingsType::BLUETOOTH_SCANNING) == CONTENT_SETTING_BLOCK) {
Jun Cai732a05e32019-05-29 19:34:195549 return true;
5550 }
5551
5552 return false;
5553}
5554
5555void ChromeContentBrowserClient::BlockBluetoothScanning(
5556 content::BrowserContext* browser_context,
5557 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525558 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195559 HostContentSettingsMap* const content_settings =
5560 HostContentSettingsMapFactory::GetForProfile(
5561 Profile::FromBrowserContext(browser_context));
5562
5563 content_settings->SetContentSettingDefaultScope(
5564 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145565 ContentSettingsType::BLUETOOTH_SCANNING, CONTENT_SETTING_BLOCK);
Jun Cai732a05e32019-05-29 19:34:195566}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475567
Clark DuVall1635a6b02020-11-06 18:53:515568bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile(
5569 std::string* split_name) {
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475570#if defined(OS_ANDROID)
Clark DuVall1635a6b02020-11-06 18:53:515571 *split_name = "extra_icu";
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475572 return extra_icu::ModuleProvider::IsModuleInstalled();
5573#endif
5574 return false;
5575}
Guido Urdaneta4030d6a32019-10-17 09:38:165576
5577bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5578 content::BrowserContext* browser_context,
5579 const GURL& url,
5580 const GURL& site_for_cookies,
5581 const base::Optional<url::Origin>& top_frame_origin) {
5582 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5583 return CookieSettingsFactory::GetForProfile(
5584 Profile::FromBrowserContext(browser_context))
5585 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5586}
Sam Goto5cf068e82019-11-04 23:08:445587
5588#if !defined(OS_ANDROID)
5589void ChromeContentBrowserClient::FetchRemoteSms(
5590 content::BrowserContext* browser_context,
5591 const url::Origin& origin,
5592 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5593 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5594}
5595#endif
Roger Tawa03ffdbd2020-01-16 18:12:545596
Darwin Huang6195d042021-02-12 22:36:005597bool ChromeContentBrowserClient::IsClipboardPasteAllowed(
5598 content::RenderFrameHost* render_frame_host) {
5599 DCHECK(render_frame_host);
5600
5601 const GURL& url = render_frame_host->GetLastCommittedOrigin().GetURL();
5602 content::BrowserContext* browser_context =
5603 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
5604 Profile* profile = Profile::FromBrowserContext(browser_context);
5605 DCHECK(profile);
5606
5607 content::PermissionController* permission_controller =
5608 content::BrowserContext::GetPermissionController(browser_context);
5609 blink::mojom::PermissionStatus status =
5610 permission_controller->GetPermissionStatusForFrame(
5611 content::PermissionType::CLIPBOARD_READ_WRITE, render_frame_host,
5612 url);
5613
5614 // True if this paste is executed from an extension URL with read permission.
5615 bool is_extension_paste_allowed = false;
5616 // True if any active extension can use content scripts to read on this page.
5617 bool is_content_script_paste_allowed = false;
5618#if BUILDFLAG(ENABLE_EXTENSIONS)
5619 // TODO(https://crbug.com/982361): Provide proper browser-side content script
5620 // tracking below, possibly based on hooks like those in
5621 // URLLoaderFactoryManager's WillExecuteCode() and ReadyToCommitNavigation().
5622 // Until this is implemented, platforms supporting extensions (all platforms
5623 // except Android) will essentially no-op here and return true.
5624 is_content_script_paste_allowed = true;
5625 if (url.SchemeIs(extensions::kExtensionScheme)) {
5626 auto* process_map = extensions::ProcessMap::Get(profile);
5627 auto* registry = extensions::ExtensionRegistry::Get(profile);
5628 is_extension_paste_allowed = URLHasExtensionPermission(
5629 process_map, registry, url, render_frame_host->GetProcess()->GetID(),
5630 APIPermission::ID::kClipboardRead);
5631 }
5632#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5633 if (!is_extension_paste_allowed && !is_content_script_paste_allowed &&
5634 !render_frame_host->HasTransientUserActivation() &&
5635 status != blink::mojom::PermissionStatus::GRANTED) {
5636 // Paste requires either (1) origination from a chrome extension, (2) user
5637 // activation, or (3) granted web permission.
5638 return false;
5639 }
5640 return true;
5641}
5642
5643void ChromeContentBrowserClient::IsClipboardPasteContentAllowed(
Roger Tawa03ffdbd2020-01-16 18:12:545644 content::WebContents* web_contents,
5645 const GURL& url,
5646 const ui::ClipboardFormatType& data_type,
5647 const std::string& data,
Darwin Huang6195d042021-02-12 22:36:005648 IsClipboardPasteContentAllowedCallback callback) {
Roger Tawa03ffdbd2020-01-16 18:12:545649#if BUILDFLAG(FULL_SAFE_BROWSING)
5650 // Safe browsing does not support images, so accept without checking.
5651 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5652 // types when it is implemented.
Darwin Huang0024dbf2020-08-04 00:53:555653 if (data_type == ui::ClipboardFormatType::GetBitmapType()) {
Darwin Huang6195d042021-02-12 22:36:005654 std::move(callback).Run(ClipboardPasteContentAllowed(true));
Roger Tawa03ffdbd2020-01-16 18:12:545655 return;
5656 }
5657
5658 Profile* profile =
5659 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375660 enterprise_connectors::ContentAnalysisDelegate::Data dialog_data;
5661 if (enterprise_connectors::ContentAnalysisDelegate::IsEnabled(
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265662 profile, url, &dialog_data,
5663 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545664 dialog_data.text.push_back(base::UTF8ToUTF16(data));
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375665 enterprise_connectors::ContentAnalysisDelegate::CreateForWebContents(
Roger Tawa03ffdbd2020-01-16 18:12:545666 web_contents, std::move(dialog_data),
5667 base::BindOnce(
Darwin Huang6195d042021-02-12 22:36:005668 [](IsClipboardPasteContentAllowedCallback callback,
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375669 const enterprise_connectors::ContentAnalysisDelegate::Data& data,
5670 const enterprise_connectors::ContentAnalysisDelegate::Result&
Roger Tawa03ffdbd2020-01-16 18:12:545671 result) {
5672 std::move(callback).Run(
Darwin Huang6195d042021-02-12 22:36:005673 ClipboardPasteContentAllowed(result.text_results[0]));
Roger Tawa03ffdbd2020-01-16 18:12:545674 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245675 std::move(callback)),
5676 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545677 } else {
Darwin Huang6195d042021-02-12 22:36:005678 std::move(callback).Run(ClipboardPasteContentAllowed(true));
Roger Tawa03ffdbd2020-01-16 18:12:545679 }
5680#else
Darwin Huang6195d042021-02-12 22:36:005681 std::move(callback).Run(ClipboardPasteContentAllowed(true));
Roger Tawa03ffdbd2020-01-16 18:12:545682#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5683}
Lukasz Anforowicz4600ea32020-01-18 02:37:485684
5685#if BUILDFLAG(ENABLE_PLUGINS)
5686bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5687 const url::Origin& embedder_origin,
5688 const content::PepperPluginInfo& plugin_info) {
5689#if BUILDFLAG(ENABLE_PDF)
5690 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5691#if BUILDFLAG(ENABLE_EXTENSIONS)
5692 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5693 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5694 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5695 return true;
5696 }
5697#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5698
5699 // Allow embedding the internal PDF plugin in chrome://print.
5700 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5701 return true;
5702
5703 // Only allow the PDF plugin in the known, trustworthy origins that are
5704 // allowlisted above. See also https://crbug.com/520422 and
5705 // https://crbug.com/1027173.
5706 return false;
5707 }
5708#endif // BUILDFLAG(ENABLE_PDF)
5709
5710 return true;
5711}
5712#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565713
5714#if BUILDFLAG(ENABLE_VR)
5715content::XrIntegrationClient*
5716ChromeContentBrowserClient::GetXrIntegrationClient() {
5717 if (!xr_integration_client_)
5718 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
Peter Kasting796cde22020-11-18 21:06:535719 base::PassKey<ChromeContentBrowserClient>());
Alexander Cooperc8448702020-03-14 01:39:565720 return xr_integration_client_.get();
5721}
5722#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185723
5724bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5725 content::BrowserContext* browser_context) {
5726 auto* profile = Profile::FromBrowserContext(browser_context);
5727 auto* prefs = profile->GetPrefs();
5728
5729 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5730 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5731 return false;
5732 }
5733 if (base::FeatureList::IsEnabled(
5734 blink::features::kAppCacheRequireOriginTrial)) {
5735 return true;
5736 }
5737
5738 return false;
5739}
Yutaka Hirano3e613662020-06-02 02:59:345740
Hidehiko Abeeaffbbce2020-06-23 19:41:525741void ChromeContentBrowserClient::BindBrowserControlInterface(
Hidehiko Abe23e45e82020-08-25 08:41:485742 mojo::ScopedMessagePipeHandle pipe) {
Yuta Hijikata235fc62b2020-12-08 03:48:325743#if BUILDFLAG(IS_CHROMEOS_LACROS)
Hidehiko Abe23e45e82020-08-25 08:41:485744 chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(
Hidehiko Abe67fb6a82021-01-21 07:50:365745 mojo::PendingReceiver<crosapi::mojom::BrowserService>(std::move(pipe)));
Hidehiko Abeeaffbbce2020-06-23 19:41:525746#endif
5747}
5748
Yutaka Hirano3e613662020-06-02 02:59:345749bool ChromeContentBrowserClient::
5750 ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) {
5751#if BUILDFLAG(ENABLE_EXTENSIONS)
5752 return url.SchemeIs(extensions::kExtensionScheme);
5753#else
5754 return false;
5755#endif
5756}
John Abd-El-Malekdc026012020-06-15 23:28:565757
Titouan Rigoudycfc73552020-08-21 14:18:305758bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125759 content::BrowserContext* browser_context,
Titouan Rigoudyce223ab2021-01-27 16:08:025760 const url::Origin& origin) {
Titouan Rigoudycfc73552020-08-21 14:18:305761 return content_settings::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudyce223ab2021-01-27 16:08:025762 HostContentSettingsMapFactory::GetForProfile(browser_context), origin);
Titouan Rigoudy9c2c0142020-08-19 17:57:125763}
5764
John Abd-El-Malekdc026012020-06-15 23:28:565765ukm::UkmService* ChromeContentBrowserClient::GetUkmService() {
5766 return g_browser_process->GetMetricsServicesManager()->GetUkmService();
5767}
Evan Liu054dc082020-09-30 14:09:425768
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345769void ChromeContentBrowserClient::OnKeepaliveRequestStarted(
5770 content::BrowserContext* context) {
Yutaka Hirano93e924742020-11-11 10:40:135771#if !defined(OS_ANDROID)
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345772 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5773 // done.
5774 VLOG(1) << "OnKeepaliveRequestStarted: " << num_keepalive_requests_ << " ==> "
5775 << num_keepalive_requests_ + 1;
5776 ++num_keepalive_requests_;
5777 DCHECK_GT(num_keepalive_requests_, 0u);
5778
5779 if (!context) {
5780 // We somehow failed to associate the request and the BrowserContext. Bail
5781 // out.
5782 return;
5783 }
5784
5785 const auto now = base::TimeTicks::Now();
5786 const auto timeout = GetKeepaliveTimerTimeout(context);
5787 keepalive_deadline_ = std::max(keepalive_deadline_, now + timeout);
5788 if (keepalive_deadline_ > now && !keepalive_timer_.IsRunning()) {
Yutaka Hirano311a7412021-01-06 06:17:355789 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5790 // done.
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345791 VLOG(1) << "Starting a keepalive timer(" << timeout.InSecondsF()
5792 << " seconds)";
5793 keepalive_timer_.Start(
5794 FROM_HERE, keepalive_deadline_ - now,
5795 base::BindOnce(
5796 &ChromeContentBrowserClient::OnKeepaliveTimerFired,
5797 weak_factory_.GetWeakPtr(),
5798 std::make_unique<ScopedKeepAlive>(
5799 KeepAliveOrigin::BROWSER, KeepAliveRestartOption::DISABLED)));
Yutaka Hirano93e924742020-11-11 10:40:135800 }
5801#endif // !defined(OS_ANDROID)
5802}
5803
5804void ChromeContentBrowserClient::OnKeepaliveRequestFinished() {
5805#if !defined(OS_ANDROID)
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345806 DCHECK_GT(num_keepalive_requests_, 0u);
5807 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5808 // done.
5809 VLOG(1) << "OnKeepaliveRequestFinished: " << num_keepalive_requests_
5810 << " ==> " << num_keepalive_requests_ - 1;
5811 --num_keepalive_requests_;
5812 if (num_keepalive_requests_ == 0) {
Yutaka Hirano311a7412021-01-06 06:17:355813 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5814 // done.
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345815 VLOG(1) << "Stopping the keepalive timer";
5816 keepalive_timer_.Stop();
5817 // This deletes the keep alive handle attached to the timer function and
5818 // unblock the shutdown sequence.
Yutaka Hirano93e924742020-11-11 10:40:135819 }
5820#endif // !defined(OS_ANDROID)
5821}
5822
Evan Liu054dc082020-09-30 14:09:425823#if defined(OS_MAC)
5824bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters(
5825 sandbox::policy::SandboxType sandbox_type,
5826 sandbox::SeatbeltExecClient* client) {
5827 if (sandbox_type == sandbox::policy::SandboxType::kSpeechRecognition) {
5828 base::FilePath soda_component_path = speech::GetSodaDirectory();
5829 CHECK(!soda_component_path.empty());
5830 CHECK(client->SetParameter(
5831 sandbox::policy::SandboxMac::kSandboxSodaComponentPath,
5832 soda_component_path.value()));
5833
5834 base::FilePath soda_language_pack_path =
5835 speech::GetSodaLanguagePacksDirectory();
5836 CHECK(!soda_language_pack_path.empty());
5837 CHECK(client->SetParameter(
5838 sandbox::policy::SandboxMac::kSandboxSodaLanguagePackPath,
5839 soda_language_pack_path.value()));
5840 return true;
5841 }
5842
5843 return false;
5844}
5845
5846#endif // defined(OS_MAC)
Koji Ishii3cbd93a2020-10-16 13:48:025847
5848void ChromeContentBrowserClient::GetHyphenationDictionary(
5849 base::OnceCallback<void(const base::FilePath&)> callback) {
5850#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
5851 component_updater::HyphenationComponentInstallerPolicy::
5852 GetHyphenationDictionary(std::move(callback));
5853#endif
5854}
Rakina Zata Amniba3eecb2020-11-02 10:12:285855
5856bool ChromeContentBrowserClient::HasErrorPage(int http_status_code) {
5857 // Use an internal error page, if we have one for the status code.
5858 return error_page::LocalizedError::HasStrings(
5859 error_page::Error::kHttpErrorDomain, http_status_code);
5860}
Yutaka Hirano93e924742020-11-11 10:40:135861
Ken Buchanan7d688352020-12-05 05:45:575862std::unique_ptr<content::IdentityRequestDialogController>
5863ChromeContentBrowserClient::CreateIdentityRequestDialogController() {
5864 return std::make_unique<IdentityDialogController>();
5865}
5866
Carlos IL0806d682021-02-25 19:47:265867bool ChromeContentBrowserClient::SuppressDifferentOriginSubframeJSDialogs(
5868 content::BrowserContext* browser_context) {
5869 Profile* profile = Profile::FromBrowserContext(browser_context);
5870 if (!profile->GetPrefs()->GetBoolean(
5871 prefs::kSuppressDifferentOriginSubframeJSDialogs)) {
5872 return false;
5873 }
5874 return ContentBrowserClient::SuppressDifferentOriginSubframeJSDialogs(
5875 browser_context);
5876}
5877
Reid Kleckner4d3f21c2021-01-25 22:48:315878#if !defined(OS_ANDROID)
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345879base::TimeDelta ChromeContentBrowserClient::GetKeepaliveTimerTimeout(
5880 content::BrowserContext* context) {
5881 Profile* profile = Profile::FromBrowserContext(context);
5882 PrefService* prefs = profile->GetPrefs();
5883 if (!prefs) {
5884 return base::TimeDelta();
5885 }
5886
5887 const int seconds =
5888 prefs->GetInteger(prefs::kFetchKeepaliveDurationOnShutdown);
5889 // The preference is set only be the corresponding enterprise policy, and
5890 // we have minimum/maximum values on it.
5891 DCHECK_LE(0, seconds);
5892 DCHECK_LE(seconds, 5);
5893 return base::TimeDelta::FromSeconds(seconds);
5894}
5895
Yutaka Hirano93e924742020-11-11 10:40:135896void ChromeContentBrowserClient::OnKeepaliveTimerFired(
5897 std::unique_ptr<ScopedKeepAlive> keep_alive_handle) {
Yutaka Hirano311a7412021-01-06 06:17:355898 // TODO(crbug.com/1161996): Remove this entry once the investigation is done.
5899 VLOG(1) << "OnKeepaliveTimerFired";
Yutaka Hirano93e924742020-11-11 10:40:135900 const auto now = base::TimeTicks::Now();
Yutaka Hiranoa1ab8aa2021-02-24 15:56:345901 const auto then = keepalive_deadline_;
Yutaka Hirano93e924742020-11-11 10:40:135902 if (now < then) {
Yutaka Hirano311a7412021-01-06 06:17:355903 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5904 // done.
5905 VLOG(1) << "Extending keepalive timer";
Yutaka Hirano93e924742020-11-11 10:40:135906 keepalive_timer_.Start(
5907 FROM_HERE, then - now,
5908 base::BindOnce(&ChromeContentBrowserClient::OnKeepaliveTimerFired,
5909 weak_factory_.GetWeakPtr(),
5910 std::move(keep_alive_handle)));
5911 }
Yutaka Hirano93e924742020-11-11 10:40:135912}
Reid Kleckner4d3f21c2021-01-25 22:48:315913#endif