blob: f21470e91f424c908dd4c143a1411dd9ef8cb7cc [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"
msramek1c2b3ca2017-03-14 17:57:5648#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5149#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
Lingqi Chi775e60752020-12-14 06:31:1650#include "chrome/browser/chrome_content_browser_client_binder_policies.h"
[email protected]d5a74be2014-08-08 01:01:2751#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0952#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0853#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2254#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
55#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3056#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
57#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0658#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0859#include "chrome/browser/defaults.h"
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:2160#include "chrome/browser/device_api/device_service_impl.h"
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:5961#include "chrome/browser/download/chrome_download_manager_delegate.h"
[email protected]b1d97272013-08-17 13:38:4962#include "chrome/browser/download/download_prefs.h"
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:4963#include "chrome/browser/enterprise/connectors/connectors_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4564#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0165#include "chrome/browser/external_protocol/external_protocol_handler.h"
Yao Xiaoc5436ad2021-01-12 00:22:3066#include "chrome/browser/federated_learning/floc_eligibility_observer.h"
Yao Xiaoebed8c12020-09-26 07:51:2067#include "chrome/browser/federated_learning/floc_id_provider.h"
68#include "chrome/browser/federated_learning/floc_id_provider_factory.h"
Olivier Yiptong935e6c42020-11-21 01:28:2369#include "chrome/browser/font_access/chrome_font_access_delegate.h"
[email protected]354de9e2014-08-07 03:27:1970#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5371#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5272#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1073#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2774#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2775#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
Guido Urdanetae02b5722020-07-22 05:58:2176#include "chrome/browser/media/audio_service_util.h"
thakis678822e2017-04-20 17:20:3477#include "chrome/browser/media/router/media_router_feature.h"
Patrik Höglundb564859b2018-05-17 11:17:1678#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3679#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3680#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5681#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0482#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0583#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0784#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2385#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1086#include "chrome/browser/net/profile_network_context_service.h"
87#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5488#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0289#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5990#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5691#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0692#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5493#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5194#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Patrick Monettea4084692021-01-18 17:51:3095#include "chrome/browser/performance_monitor/chrome_browser_main_extra_parts_performance_monitor.h"
Adam Langley85339f62018-02-12 22:03:5696#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4297#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1198#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4899#include "chrome/browser/plugins/plugin_utils.h"
Liquan (Max) Gu4fd38d862021-01-15 02:14:51100#include "chrome/browser/policy/profile_policy_connector.h"
Hiroki Nakagawa7230e3412021-01-22 10:08:29101#include "chrome/browser/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h"
Hiroki Nakagawab4cd18aa2021-01-25 18:11:01102#include "chrome/browser/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
Hiroki Nakagawa483686a92020-10-29 04:31:45103#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_features.h"
104#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service.h"
105#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service_factory.h"
106#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_url_loader_interceptor.h"
Ryan Sturm8670b572020-10-21 18:45:30107#include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h"
108#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h"
109#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
Ryan Sturm6b2f6392020-12-09 21:46:00110#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader.h"
Ryan Sturm8670b572020-10-21 18:45:30111#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader_interceptor.h"
Ryan Sturmcc5071be2019-02-16 02:15:19112#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54113#include "chrome/browser/previews/previews_service.h"
114#include "chrome/browser/previews/previews_service_factory.h"
115#include "chrome/browser/previews/previews_ui_tab_helper.h"
John Delaneyc2782792021-01-15 01:29:07116#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings.h"
117#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
[email protected]7e75e4a2013-05-17 17:20:03118#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14119#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32120#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49121#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06122#include "chrome/browser/profiles/renderer_updater.h"
123#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56124#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
125#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44126#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38127#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40128#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45129#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31130#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
131#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24132#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43133#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00134#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40135#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35136#include "chrome/browser/safe_browsing/ui_manager.h"
137#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58138#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43139#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44140#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20141#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35142#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40143#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23144#include "chrome/browser/signin/identity_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:02145#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Colin Blundell13e92ec2020-01-27 09:47:38146#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Chris Thompsone2e073d42020-07-23 12:33:45147#include "chrome/browser/ssl/sct_reporting_service.h"
148#include "chrome/browser/ssl/sct_reporting_service_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32149#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07150#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Mustafa Emre Acer06028d792021-01-05 19:48:51151#include "chrome/browser/ssl/typed_navigation_upgrade_throttle.h"
meacer4ef065e2015-01-09 03:21:35152#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45153#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52154#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19155#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44156#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Clark DuVall8a020d622020-06-04 00:45:50157#include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h"
Charles Harrison6dd11d282017-10-03 06:14:51158#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08159#include "chrome/browser/ui/browser_navigator.h"
160#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43161#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39162#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54163#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28164#include "chrome/browser/ui/login/login_tab_helper.h"
Jonathan Mengedoht42a19bb2020-07-28 14:10:16165#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56166#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25167#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44168#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58169#include "chrome/browser/ui/ui_features.h"
Ken Buchanan7d688352020-12-05 05:45:57170#include "chrome/browser/ui/webid/identity_dialog_controller.h"
[email protected]863f70a2012-01-27 02:05:50171#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01172#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45173#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53174#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25175#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59176#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23177#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22178#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01179#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48180#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51181#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14182#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22183#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30184#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02185#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50186#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34187#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37188#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12189#include "chrome/common/pref_names.h"
Mike Wittman67d63112020-09-19 00:33:46190#include "chrome/common/profiler/thread_profiler_configuration.h"
nigeltao7cd8d5582016-12-12 06:05:28191#include "chrome/common/renderer_configuration.mojom.h"
Ayu Ishiifbb1fad2020-06-22 20:15:07192#include "chrome/common/secure_origin_allowlist.h"
[email protected]c5dbef02011-05-13 05:06:09193#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47194#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37195#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18196#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30197#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12198#include "components/autofill/core/common/autofill_switches.h"
Clark DuVall8a020d622020-06-04 00:45:50199#include "components/blocked_content/popup_blocker.h"
Clark DuVallf5189252020-04-15 22:33:34200#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53201#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51202#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49203#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44204#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04205#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48206#include "components/cloud_devices/common/cloud_devices_switches.h"
Carlos Caballerob4283202020-08-10 14:40:46207#include "components/content_settings/browser/page_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16208#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09209#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16210#include "components/content_settings/core/browser/host_content_settings_map.h"
Titouan Rigoudy9c2c0142020-08-19 17:57:12211#include "components/content_settings/core/browser/private_network_settings.h"
mukai077089f2014-09-11 18:41:52212#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45213#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08214#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03215#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54216#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28217#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43218#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09219#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03220#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24221#include "components/dom_distiller/core/url_constants.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"
Sophie Changff1fc382019-08-21 16:30:21260#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54261#include "components/previews/content/previews_decider_impl.h"
262#include "components/previews/content/previews_ui_service.h"
263#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54264#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45265#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43266#include "components/previews/core/previews_switches.h"
Nico Weberbc5b06f2019-07-26 14:00:13267#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47268#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
269#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
270#include "components/safe_browsing/core/browser/url_checker_delegate.h"
271#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
272#include "components/safe_browsing/core/db/database_manager.h"
273#include "components/safe_browsing/core/features.h"
274#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58275#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Carlos IL1a5edec2020-06-12 17:56:57276#include "components/security_interstitials/content/insecure_form_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14277#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49278#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48279#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49280#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23281#include "components/signin/public/identity_manager/identity_manager.h"
Liquan (Max) Gu4fd38d862021-01-15 02:14:51282#include "components/site_engagement/content/site_engagement_service.h"
Clark DuVallaadc244c2020-06-06 03:47:14283#include "components/site_isolation/pref_names.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54284#include "components/site_isolation/preloaded_isolated_origins.h"
Clark DuVallaadc244c2020-06-06 03:47:14285#include "components/site_isolation/site_isolation_policy.h"
csharrisone985ebc2017-04-04 17:05:03286#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17287#include "components/translate/core/common/translate_switches.h"
Maks Orlovich5408ddfc2020-07-28 23:07:35288#include "components/ukm/content/source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21289#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28290#include "components/variations/variations_associated_data.h"
Ben Goldberger72533cd2020-07-21 16:11:38291#include "components/variations/variations_ids_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46292#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22293#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39294#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33295#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43296#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30297#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38298#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28299#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03300#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31301#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41302#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09303#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03304#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59305#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19306#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31307#include "content/public/browser/file_url_loader.h"
Olivier Yiptong935e6c42020-11-21 01:28:23308#include "content/public/browser/font_access_delegate.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35309#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47310#include "content/public/browser/navigation_handle.h"
311#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11312#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50313#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30314#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33315#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05316#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54317#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34318#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48319#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27320#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13321#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08322#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19323#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21324#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23325#include "content/public/browser/web_ui_url_loader_factory.h"
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:21326#include "content/public/common/bindings_policy.h"
[email protected]e0ada9c2012-03-20 03:54:43327#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18328#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56329#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40330#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02331#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18332#include "content/public/common/network_service_util.h"
Chris Mumfordbae8a742018-03-01 23:02:23333#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44334#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31335#include "content/public/common/user_agent.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56336#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43337#include "device/vr/buildflags/buildflags.h"
Karandeep Bhatiaae5d9f32020-07-17 02:52:34338#include "extensions/browser/process_map.h"
Scott Violetc8240b02018-03-08 22:03:59339#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48340#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30341#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28342#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18343#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04344#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31345#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44346#include "media/media_buildflags.h"
347#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12348#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42349#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52350#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08351#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53352#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51353#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58354#include "net/base/mime_util.h"
Jun Cai9409ded2018-01-30 00:19:46355#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57356#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48357#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14358#include "ppapi/buildflags/buildflags.h"
Scott Violet318a55f2018-03-30 19:08:19359#include "printing/buildflags/buildflags.h"
Guido Urdanetae02b5722020-07-22 05:58:21360#include "sandbox/policy/features.h"
Robert Sesek7d0b49b2020-07-08 18:31:27361#include "sandbox/policy/sandbox_type.h"
362#include "sandbox/policy/switches.h"
Yue Ru Sun03a6990a2020-10-24 18:04:31363#include "services/metrics/public/cpp/ukm_source_id.h"
Takashi Toyoshima128441462019-10-16 04:19:17364#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37365#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50366#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50367#include "services/network/public/cpp/resource_request.h"
Lukasz Anforowicz25620d32021-01-27 22:03:44368#include "services/network/public/cpp/self_deleting_url_loader_factory.h"
Ken Rockotcebdf9c82019-05-28 20:33:03369#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06370#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02371#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02372#include "third_party/blink/public/common/features.h"
Minggang Wangb2f82902020-08-25 16:07:09373#include "third_party/blink/public/common/loader/referrer_utils.h"
Minggang Wangf6840ecf2019-07-29 05:15:02374#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:23375#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
Chris Hamilton65c41312020-06-10 13:14:40376#include "third_party/blink/public/common/switches.h"
Lily Chenc2c9e9f2019-12-05 19:55:31377#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17378#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Gyuyoung Kim1e9d3c32020-10-12 14:04:57379#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h"
Koji Ishii3cbd93a2020-10-16 13:48:02380#include "third_party/blink/public/public_buildflags.h"
Evan Liu7cdbf8872019-06-19 16:47:21381#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26382#include "third_party/widevine/cdm/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54383#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39384#include "ui/base/l10n/l10n_util.h"
Scott Violet5ae6c42e2020-10-28 02:47:37385#include "ui/base/page_transition_types.h"
[email protected]ac55e292011-06-24 05:16:08386#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35387#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56388#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21389#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49390#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57391#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45392#include "url/gurl.h"
393#include "url/origin.h"
Olya Kalitova78ae04932020-09-21 11:26:06394#include "url/third_party/mozilla/url_parse.h"
395#include "url/url_constants.h"
[email protected]d977f9c2011-03-14 16:10:26396
[email protected]b48c9182011-10-26 18:03:30397#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20398#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14399#include "base/win/win_util.h"
400#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38401#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36402#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18403#include "sandbox/win/src/sandbox_policy.h"
Avi Drissman2e458df2020-07-29 16:24:31404#elif defined(OS_MAC)
[email protected]199fc7a2011-09-28 22:45:38405#include "chrome/browser/chrome_browser_main_mac.h"
Evan Liu054dc082020-09-30 14:09:42406#include "components/soda/constants.h"
407#include "sandbox/mac/seatbelt_exec.h"
408#include "sandbox/policy/mac/sandbox_mac.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32409#elif BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhallda2659142020-05-14 06:04:37410#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42411#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30412#include "chrome/app/chrome_crash_reporter_client.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"
clamy49678312015-10-22 21:59:00425#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
426#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44427#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39428#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31429#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33430#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05431#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Andreea Costinas81218bf2021-01-08 11:48:14432#include "chrome/browser/chromeos/policy/system_proxy_manager.h"
Pavol Marko230ea2c92017-12-03 22:35:44433#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34434#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10435#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36436#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27437#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31438#include "chrome/browser/ui/browser_dialogs.h"
Jesse Schettlerb7047f32020-09-18 14:50:40439#include "chromeos/components/scanning/url_constants.h"
Steven Bennetts38e9bde22019-01-03 17:31:10440#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21441#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10442#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50443#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05444#include "components/policy/core/common/policy_pref_names.h"
445#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07446#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58447#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50448#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32449#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
[email protected]b48c9182011-10-26 18:03:30450#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09451#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35452#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23453#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45454#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47455#include "chrome/android/modules/extra_icu/provider/module_provider.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36456#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36457#include "chrome/browser/android/devtools_manager_delegate_android.h"
458#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
459#include "chrome/browser/android/service_tab_launcher.h"
460#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42461#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09462#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56463#include "chrome/browser/download/android/available_offline_content_provider.h"
464#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23465#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07466#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38467#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11468#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07469#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47470#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36471#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54472#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00473#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36474#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45475#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04476#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45477#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30478#elif defined(OS_POSIX)
479#include "chrome/browser/chrome_browser_main_posix.h"
480#endif
481
Yuta Hijikata235fc62b2020-12-08 03:48:32482#if !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51483#include "ui/accessibility/accessibility_features.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32484#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51485
tmartinofb341882017-02-10 19:36:53486#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40487#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36488#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54489#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59490#include "chrome/browser/media/unified_autoplay_config.h"
Zach Trudocc4aa4d2020-09-21 22:19:45491#include "chrome/browser/policy/dm_token_utils.h"
Marc Treib7895941d2017-11-28 12:37:02492#include "chrome/browser/search/instant_service.h"
493#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46494#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51495#include "chrome/browser/ui/browser.h"
496#include "chrome/browser/ui/browser_finder.h"
497#include "chrome/browser/ui/browser_list.h"
498#include "chrome/browser/ui/browser_window.h"
Conley Owensaafcf122018-02-26 18:53:51499#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39500#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
501#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43502#include "chrome/common/importer/profile_import.mojom.h"
Glen Robertson8a825ae4f2020-09-16 06:50:08503#include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897
Maggie Caia2f03f52019-04-02 02:13:28504#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36505
Yuta Hijikata235fc62b2020-12-08 03:48:32506// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
507// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:31508#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:32509 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52510#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
511#endif
512
Sean McAllister0d73ca3d2020-08-19 17:54:37513#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Rohit Rao92f84b6a2020-03-25 14:57:50514#include "components/crash/core/app/crash_switches.h"
515#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24516#endif
517
Avi Drissman2e458df2020-07-29 16:24:31518#if defined(OS_POSIX) && !defined(OS_MAC)
Joshua Perazaf890e4b2019-01-03 19:19:02519#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02520#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50521#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02522#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13523#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43524#endif
[email protected]b80f68432011-05-02 17:22:30525
Maggie Caia2f03f52019-04-02 02:13:28526// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
527// single navigation throttle to display the intent picker on all platforms.
528#if !defined(OS_ANDROID)
Yuta Hijikata235fc62b2020-12-08 03:48:32529#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Caia2f03f52019-04-02 02:13:28530#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51531#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28532#else
533#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
534#endif
535#endif
536
[email protected]e8b6ca02013-07-10 18:00:51537#if defined(TOOLKIT_VIEWS)
538#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
539#endif
540
Yuta Hijikata235fc62b2020-12-08 03:48:32541// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
542// of lacros-chrome is complete.
543#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
estaded3aa0e82016-02-17 22:55:21544#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51545#endif
546
Mohsen Izadif1958f22019-01-18 20:29:31547#if defined(USE_OZONE)
548#include "ui/ozone/public/ozone_platform.h"
549#endif
550
Maksim Sisov1686fc22020-06-17 07:59:20551#if defined(USE_X11) || defined(USE_OZONE)
552#include "chrome/browser/chrome_browser_main_extra_parts_ozone.h"
[email protected]e8b6ca02013-07-10 18:00:51553#endif
554
brettwab78fef2016-10-12 02:56:05555#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10556#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38557#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19558#endif
559
Nico Weberaf3b00b2017-09-11 17:58:17560#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55561#include "components/nacl/browser/nacl_browser.h"
562#include "components/nacl/browser/nacl_host_message_filter.h"
563#include "components/nacl/browser/nacl_process_host.h"
564#include "components/nacl/common/nacl_process_type.h"
565#include "components/nacl/common/nacl_switches.h"
566#endif
567
brettw00899e62016-11-12 02:10:17568#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05569#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20570#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27571#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23572#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32573#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51574#include "chrome/browser/extensions/user_script_listener.h"
thestig2dbee717e2014-09-05 14:54:28575#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49576#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46577#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39578#include "components/guest_view/browser/guest_view_base.h"
579#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25580#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31581#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35582#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32583#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12584#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57585#include "extensions/browser/extension_system.h"
Aaron Colwell8c430642020-08-04 01:55:20586#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48587#include "extensions/browser/guest_view/web_view/web_view_guest.h"
588#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
589#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31590#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27591#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28592#include "extensions/common/extension.h"
593#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13594#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28595#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33596#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28597#include "extensions/common/permissions/permissions_data.h"
598#include "extensions/common/permissions/socket_permission.h"
599#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34600#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25601
brettw4b461082016-11-19 18:55:16602#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55603#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39604#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55605#endif
606
bauerb8f9c37742017-03-30 15:04:12607#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
608#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
609#endif
610
Yuta Hijikata235fc62b2020-12-08 03:48:32611#if BUILDFLAG(IS_CHROMEOS_ASH)
Henrique Ferreiro53d4dc42021-01-27 01:02:38612#include "chrome/browser/ash/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06613#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
Scott Violet1644cf72020-06-24 04:51:55614#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32615#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:06616
thakis678822e2017-04-20 17:20:34617#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38618#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09619#endif
620
Xiaohan Wanga4e41842018-06-26 18:45:10621#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49622#include "chrome/browser/media/output_protection_impl.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06623#if BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10624#include "third_party/widevine/cdm/widevine_cdm_common.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06625#if defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)
626#include "chrome/browser/media/widevine_hardware_caps.h"
Xiaohan Wanga4e41842018-06-26 18:45:10627#endif
Jeffrey Kardatzke614424232020-12-12 00:54:06628#endif // BUILDFLAG(ENABLE_WIDEVINE)
629#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wanga4e41842018-06-26 18:45:10630
mmenkedb2637ff2017-03-30 23:59:42631#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
632#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
633#endif
634
Bettinafd0c1102020-08-06 00:23:43635#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Daniel Ruberya1611e32019-04-24 21:38:35636#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32637#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35638#endif
639
Glen Robertson8a825ae4f2020-09-16 06:50:08640#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
641#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897
642#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897
643#endif
644
Jian Lide7b43792018-06-01 23:22:13645#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54646#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13647#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
648#endif
649
Will Cassella40837ba2019-07-01 21:32:00650#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Glen Robertson8a825ae4f2020-09-16 06:50:08651#include "device/vr/public/mojom/isolated_xr_service.mojom.h" // nogncheck crbug.com/1125897
Bill Orreb429222018-08-08 21:14:43652#endif
653
John Lee0ee748bf2019-12-11 21:35:44654#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
655#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
656#endif
657
Roger Tawa03ffdbd2020-01-16 18:12:54658#if BUILDFLAG(FULL_SAFE_BROWSING)
Dominique Fauteux-Chapleau71912992020-10-22 18:15:37659#include "chrome/browser/enterprise/connectors/content_analysis_delegate.h"
Roger Tawa03ffdbd2020-01-16 18:12:54660#endif
661
Alexander Cooperc8448702020-03-14 01:39:56662#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23663#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56664#endif
665
Yuta Hijikata235fc62b2020-12-08 03:48:32666#if BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook70fee9862020-11-18 17:28:40667#include "chrome/browser/chrome_browser_main_parts_lacros.h"
Antonio Gomesaa2603362020-10-24 12:20:18668#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_lacros.h"
James Cook92730252020-07-22 01:57:26669#include "chromeos/lacros/lacros_chrome_service_impl.h"
James Cook247a8cb2020-12-22 23:09:51670#include "ui/base/ui_base_switches.h"
Hidehiko Abeeaffbbce2020-06-23 19:41:52671#endif
672
Koji Ishii3cbd93a2020-10-16 13:48:02673#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
674#include "chrome/browser/component_updater/hyphenation_component_installer.h"
675#endif
676
[email protected]c7abd422012-09-25 00:20:08677using base::FileDescriptor;
Gyuyoung Kimd6d4f992020-11-20 14:13:22678using blink::mojom::EffectiveConnectionType;
Gyuyoung Kim1ac4ca782020-09-11 03:32:51679using blink::web_pref::WebPreferences;
[email protected]631bb742011-11-02 11:29:39680using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31681using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13682using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59683using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00684using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02685using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11686using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33687using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13688using content::WebContents;
[email protected]593d2a72013-07-26 08:48:38689using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39690
[email protected]0daaebfe2014-03-15 00:09:05691#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20692using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05693#endif
694
brettw00899e62016-11-12 02:10:17695#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28696using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27697using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28698using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28699using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27700#endif
701
brettw4b461082016-11-19 18:55:16702#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55703using plugins::ChromeContentBrowserClientPluginsPart;
704#endif
705
[email protected]c5dbef02011-05-13 05:06:09706namespace {
707
Will Harris1b9b4152019-08-21 22:33:50708#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30709// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
710// running on Windows 10 1511 and above. See
711// https://blogs.windows.com/blog/tag/code-integrity-guard/.
712const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35713 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50714#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
715 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30716
Nicolas Arciniegafa9f4c92021-01-22 19:49:25717bool IsSSLErrorOverrideAllowedForUrl(const GURL& request_url,
718 PrefService* prefs) {
719 DCHECK(request_url.SchemeIsCryptographic());
720
721 if (!prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed))
722 return false;
723
724 if (!prefs->GetList(prefs::kSSLErrorOverrideAllowedForUrls))
725 return true;
726
727 base::Value::ConstListView allow_list_urls =
728 prefs->GetList(prefs::kSSLErrorOverrideAllowedForUrls)->GetList();
729 if (allow_list_urls.empty())
730 return true;
731
732 for (auto const& value : allow_list_urls) {
733 ContentSettingsPattern pattern =
734 ContentSettingsPattern::FromString(value.GetString());
735 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
736 continue;
737 if (pattern.Matches(request_url))
738 return true;
739 }
740
741 return false;
742}
743
Colin Blundell9ee731dd2020-01-23 10:42:38744// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
745// parameters.
746void HandleSSLErrorWrapper(
747 content::WebContents* web_contents,
748 int cert_error,
749 const net::SSLInfo& ssl_info,
750 const GURL& request_url,
751 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38752 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
753 Profile* profile =
754 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Scott Violet2fb481102020-07-27 00:23:54755 // Profile should always outlive a WebContents
756 DCHECK(profile);
Colin Blundell9ee731dd2020-01-23 10:42:38757
Colin Blundell27331f92020-02-05 21:13:01758 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51759
760#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
761 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
762#endif
763
Colin Blundell9ee731dd2020-01-23 10:42:38764 SSLErrorHandler::HandleSSLError(
765 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53766 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51767 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38768 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Nicolas Arciniegafa9f4c92021-01-22 19:49:25769 IsSSLErrorOverrideAllowedForUrl(request_url, profile->GetPrefs()));
Colin Blundell9ee731dd2020-01-23 10:42:38770}
771
lazyboy5d5fede02016-03-10 04:10:14772enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53773 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14774 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53775
776 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14777 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53778
779 // An extension or app tried to load a resource of a different platform app in
780 // a tab.
781 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
782
783 // A non-app and non-extension page tried to load a platform app in a tab.
784 APP_LOADED_IN_TAB_SOURCE_OTHER,
785
lazyboy5d5fede02016-03-10 04:10:14786 APP_LOADED_IN_TAB_SOURCE_MAX
787};
788
Lei Zhang2cfceac2018-11-14 19:36:33789// Cached version of the locale so we can return the locale on the I/O
790// thread.
791std::string& GetIOThreadApplicationLocale() {
792 static base::NoDestructor<std::string> s;
793 return *s;
794}
795
[email protected]f8f93eb2012-09-25 03:06:24796// Returns a copy of the given url with its host set to given host and path set
797// to given path. Other parts of the url will be the same.
798GURL ReplaceURLHostAndPath(const GURL& url,
799 const std::string& host,
800 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05801 url::Replacements<char> replacements;
802 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
803 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24804 return url.ReplaceComponents(replacements);
805}
806
madfbd10852017-01-20 03:15:33807// Handles the rewriting of the new tab page URL based on group policy.
808bool HandleNewTabPageLocationOverride(
809 GURL* url,
810 content::BrowserContext* browser_context) {
811 if (!url->SchemeIs(content::kChromeUIScheme) ||
812 url->host() != chrome::kChromeUINewTabHost)
813 return false;
814
815 Profile* profile = Profile::FromBrowserContext(browser_context);
816 std::string ntp_location =
817 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
818 if (ntp_location.empty())
819 return false;
Olya Kalitova78ae04932020-09-21 11:26:06820 url::Component scheme;
821 if (!url::ExtractScheme(ntp_location.data(),
822 static_cast<int>(ntp_location.length()), &scheme)) {
823 ntp_location = base::StrCat(
824 {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location});
825 }
madfbd10852017-01-20 03:15:33826
827 *url = GURL(ntp_location);
828 return true;
829}
830
Becca Hughesfe8c32c2018-03-21 13:36:56831#if !defined(OS_ANDROID)
832// Check if the current url is whitelisted based on a list of whitelisted urls.
833bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57834 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56835 // Only check on HTTP and HTTPS pages.
836 if (!current_url.SchemeIsHTTPOrHTTPS())
837 return false;
838
839 for (auto const& value : whitelisted_urls) {
840 ContentSettingsPattern pattern =
841 ContentSettingsPattern::FromString(value.GetString());
842 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
843 continue;
844 if (pattern.Matches(current_url))
845 return true;
846 }
847
848 return false;
849}
850
851// Check if autoplay is allowed by policy configuration.
852bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
853 PrefService* prefs) {
854 DCHECK(prefs);
855
856 // Check if we have globally allowed autoplay by policy.
857 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
858 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
859 return true;
860 }
861
862 if (!contents)
863 return false;
864
865 // Check if the current URL matches a URL pattern on the whitelist.
866 const base::ListValue* autoplay_whitelist =
867 prefs->GetList(prefs::kAutoplayWhitelist);
868 return autoplay_whitelist &&
869 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
870 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
871}
872#endif
873
Joshua Perazaf890e4b2019-01-03 19:19:02874#if defined(OS_ANDROID)
875int GetCrashSignalFD(const base::CommandLine& command_line) {
876 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
877}
Avi Drissman2e458df2020-07-29 16:24:31878#elif defined(OS_POSIX) && !defined(OS_MAC)
[email protected]0b818f72013-10-22 00:11:03879breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
880 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02881 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52882 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02883 {
884 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31885 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03886 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50887 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02888 crash_handler->StartUploaderThread();
889 return crash_handler;
890 }
891}
892
avi3ef9ec9e2014-12-22 22:50:17893int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24894 if (crash_reporter::IsCrashpadEnabled()) {
895 int fd;
896 pid_t pid;
897 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
898 }
899
[email protected]9de4da52014-05-24 12:26:50900 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39901 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31902 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02903 if (!crash_handler)
904 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18905 return crash_handler->GetDeathSignalSocket();
906 }
907
908 std::string process_type =
909 command_line.GetSwitchValueASCII(switches::kProcessType);
910
[email protected]779dd282013-10-19 15:57:02911 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31912 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02913 if (!crash_handler)
914 crash_handler = CreateCrashHandlerHost(process_type);
915 return crash_handler->GetDeathSignalSocket();
916 }
[email protected]a1733df2012-06-22 11:24:18917
[email protected]779dd282013-10-19 15:57:02918 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31919 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02920 if (!crash_handler)
921 crash_handler = CreateCrashHandlerHost(process_type);
922 return crash_handler->GetDeathSignalSocket();
923 }
[email protected]a1733df2012-06-22 11:24:18924
[email protected]779dd282013-10-19 15:57:02925 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31926 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02927 if (!crash_handler)
928 crash_handler = CreateCrashHandlerHost(process_type);
929 return crash_handler->GetDeathSignalSocket();
930 }
[email protected]a1733df2012-06-22 11:24:18931
James Cook9207cc12017-10-19 17:08:39932 if (process_type == switches::kUtilityProcess) {
933 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
934 if (!crash_handler)
935 crash_handler = CreateCrashHandlerHost(process_type);
936 return crash_handler->GetDeathSignalSocket();
937 }
938
[email protected]a1733df2012-06-22 11:24:18939 return -1;
940}
Joshua Perazaf890e4b2019-01-03 19:19:02941#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18942
[email protected]eabbfb12013-04-05 23:28:35943void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52944 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33945 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35946}
947
estark3ba11132015-04-10 01:38:33948// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31949// SSLErrorHandler. Uses CertificateReportingService to send reports. The
950// service handles queueing and re-sending of failed reports. Each certificate
951// error creates a new instance of this class.
952class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33953 public:
meacerf43117a2016-12-27 21:02:31954 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12955 content::WebContents* web_contents)
956 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
957 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31958 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33959
960 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55961 void ReportInvalidCertificateChain(
962 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31963 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33964 }
965
966 private:
meacerf43117a2016-12-27 21:02:31967 CertificateReportingService* service_;
968
969 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33970};
971
brettw00899e62016-11-12 02:10:17972#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53973
974AppLoadedInTabSource ClassifyAppLoadedInTabSource(
975 const GURL& opener_url,
976 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58977 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
978 // The forbidden app URL was being opened by a non-extension page (e.g.
979 // http).
980 return APP_LOADED_IN_TAB_SOURCE_OTHER;
981 }
982
983 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53984 // The forbidden app URL was being opened by a different app or extension.
985 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
986 }
Lei Zhang7d0b0f42019-10-12 03:47:58987
988 // This platform app was trying to window.open() one of its own URLs.
989 if (opener_url ==
990 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
991 // Source was the background page.
992 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
993 }
994
995 // Source was a different page inside the app.
996 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53997}
[email protected]9c7656382014-08-08 21:02:30998
Charles Harrison34f67862017-08-22 01:04:17999// Returns true if there is is an extension matching |url| in
1000// |opener_render_process_id| with APIPermission::kBackground.
1001//
1002// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
1003// hosted app, even though normal extensions just use the host.
1004bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:351005 extensions::ProcessMap* process_map,
1006 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:171007 const GURL& url,
csharrison95f01e922017-04-24 18:52:351008 int opener_render_process_id) {
1009 // Note: includes web URLs that are part of an extension's web extent.
1010 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:171011 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:351012 return extension &&
1013 extension->permissions_data()->HasAPIPermission(
1014 APIPermission::kBackground) &&
1015 process_map->Contains(extension->id(), opener_render_process_id);
1016}
Kevin Marshall32f99d7e2017-07-11 23:17:461017
csharrison95f01e922017-04-24 18:52:351018#endif
1019
Miyoung Shin6694b8e2020-06-18 01:38:171020mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler(
Alexander Cooperbc87af32020-07-15 15:59:451021 base::OnceCallback<content::WebContents*()> wc_getter) {
Miyoung Shin6694b8e2020-06-18 01:38:171022 mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler;
Hiroki Nakagawa7230e3412021-01-22 10:08:291023 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:571024 std::move(wc_getter).Run())
Darin Fishere41aab52020-01-29 18:31:231025 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
1026 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:121027}
1028
Julian Pastarmovb4773b82020-04-21 16:34:141029// Encapculates logic to determine if enterprise policies should be honored.
1030// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
1031// as a new central class to replace those checks is in the making.
1032bool ShouldHonorPolicies() {
1033#if defined(OS_WIN)
1034 bool is_enterprise_version =
1035 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
1036 return base::win::IsEnrolledToDomain() ||
1037 (base::win::IsDeviceRegisteredWithManagement() &&
1038 is_enterprise_version);
1039#else // defined(OS_WIN)
1040 // TODO(pastarmovj): Replace this with check for MacOS and the new management
1041 // service once it is ready.
1042 return true;
1043#endif // defined(OS_WIN)
1044}
1045
John Abd-El-Malek92bf3602019-07-31 02:25:481046void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:041047 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:481048 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451049 bool has_user_gesture,
1050 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:011051 // If there is no longer a WebContents, the request may have raced with tab
1052 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:041053 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:011054 if (!web_contents)
1055 return;
1056
Hiroki Nakagawa7230e3412021-01-22 10:08:291057 // Do not launch external requests attached to unswapped no-state prefetchers.
1058 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
1059 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
1060 web_contents);
1061 if (no_state_prefetch_contents) {
1062 no_state_prefetch_contents->Destroy(
1063 prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:011064 return;
1065 }
1066
Robbie McElrath1294d242019-05-31 20:46:221067 // Do not launch external requests for schemes that have a handler registered.
1068 ProtocolHandlerRegistry* protocol_handler_registry =
1069 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1070 web_contents->GetBrowserContext());
1071 if (protocol_handler_registry &&
1072 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1073 return;
1074
John Abd-El-Maleka67add82018-03-09 18:22:011075 bool is_whitelisted = false;
Aaron Colwellf94fd97a2020-07-21 19:37:081076 PolicyBlocklistService* service =
1077 PolicyBlocklistFactory::GetForBrowserContext(
Oleg Davydov5cfe7ab2019-02-01 12:27:191078 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:141079 if (ShouldHonorPolicies() && service) {
Aaron Colwellf94fd97a2020-07-21 19:37:081080 const policy::URLBlocklist::URLBlocklistState url_state =
1081 service->GetURLBlocklistState(url);
John Abd-El-Maleka67add82018-03-09 18:22:011082 is_whitelisted =
Aaron Colwellf94fd97a2020-07-21 19:37:081083 url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
John Abd-El-Maleka67add82018-03-09 18:22:011084 }
1085
1086 // If the URL is in whitelist, we launch it without asking the user and
1087 // without any additional security checks. Since the URL is whitelisted,
1088 // we assume it can be executed.
1089 if (is_whitelisted) {
1090 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1091 } else {
1092 ExternalProtocolHandler::LaunchUrl(
1093 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1094 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451095 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011096 }
1097}
1098
Lukasz Anforowicz60d1253d2019-05-08 16:31:371099void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1100 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1101 // For renderer and utility (e.g. NetworkService) processes the switch is the
1102 // only available source, so below the combined (pref/policy + cmdline)
1103 // allowlist of secure origins is injected into |cmdline| for these other
1104 // processes.
1105 std::vector<std::string> allowlist =
1106 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1107 if (!allowlist.empty()) {
1108 cmdline->AppendSwitchASCII(
1109 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1110 base::JoinString(allowlist, ","));
1111 }
1112}
1113
Will Harris1b9b4152019-08-21 22:33:501114#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301115// Returns the full path to |module_name|. Both dev builds (where |module_name|
1116// is in the current executable's directory) and proper installs (where
1117// |module_name| is in a versioned sub-directory of the current executable's
1118// directory) are supported. The identified file is not guaranteed to exist.
1119base::FilePath GetModulePath(base::StringPiece16 module_name) {
1120 base::FilePath exe_dir;
1121 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1122 DCHECK(has_path);
1123
1124 // Look for the module in a versioned sub-directory of the current
1125 // executable's directory and return the path if it can be read. This is the
1126 // expected location of modules for proper installs.
1127 const base::FilePath module_path =
1128 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1129 if (base::PathExists(module_path))
1130 return module_path;
1131
1132 // Otherwise, return the path to the module in the current executable's
1133 // directory. This is the expected location of modules for dev builds.
1134 return exe_dir.Append(module_name);
1135}
Will Harris1b9b4152019-08-21 22:33:501136#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1137 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301138
Lukasz Anforowicz7724d092019-10-03 23:50:211139void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281140 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1141 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211142 if (maybe_throttle)
1143 throttles->push_back(std::move(maybe_throttle));
1144}
1145
Chris Hamiltonab4722122020-05-13 18:01:281146void MaybeAddThrottles(
1147 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1148 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1149 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1150 std::make_move_iterator(additional.end()));
1151}
1152
Evan Stade1e71d6dd2019-10-29 03:04:491153// Returns whether |web_contents| is within a hosted app.
1154bool IsInHostedApp(WebContents* web_contents) {
1155#if BUILDFLAG(ENABLE_EXTENSIONS)
1156 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
Glen Robertson83263c72020-12-10 06:16:161157 return web_app::AppBrowserController::IsWebApp(browser);
Evan Stade1e71d6dd2019-10-29 03:04:491158#else
1159 return false;
1160#endif
1161}
1162
Lily Chenc2c9e9f2019-12-05 19:55:311163void MaybeRecordSameSiteCookieEngagementHistogram(
1164 content::RenderFrameHost* render_frame_host,
1165 blink::mojom::WebFeature feature) {
1166 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1167 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1168 return;
1169 }
1170
1171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1172 DCHECK(render_frame_host);
1173
1174 content::BrowserContext* browser_context =
1175 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1176 Profile* profile = Profile::FromBrowserContext(browser_context);
Evan Stade7a984802020-12-14 19:10:151177 auto* site_engagement_service =
1178 site_engagement::SiteEngagementService::Get(profile);
Lily Chenc2c9e9f2019-12-05 19:55:311179 if (!site_engagement_service)
1180 return;
1181
1182 blink::mojom::EngagementLevel engagement_level =
1183 site_engagement_service->GetEngagementLevel(
1184 render_frame_host->GetLastCommittedURL());
1185 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1186 UMA_HISTOGRAM_ENUMERATION(
1187 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1188 engagement_level);
1189 } else {
1190 UMA_HISTOGRAM_ENUMERATION(
1191 "Net.SameSiteBlockedCookieSiteEngagement."
1192 "CookieInsecureAndSameSiteNone",
1193 engagement_level);
1194 }
1195}
1196
Ken Rockot4408a0f2020-07-27 19:40:541197bool IsErrorPageAutoReloadEnabled() {
1198 const base::CommandLine& command_line =
1199 *base::CommandLine::ForCurrentProcess();
1200 if (command_line.HasSwitch(switches::kEnableAutomation))
1201 return false;
1202 if (command_line.HasSwitch(switches::kEnableAutoReload))
1203 return true;
1204 if (command_line.HasSwitch(switches::kDisableAutoReload))
1205 return false;
1206 return true;
1207}
1208
Thomas Lukaszewiczf87f3432021-01-21 17:20:051209bool IsTopChromeWebUIURL(const GURL& url) {
1210 return url.SchemeIs(content::kChromeUIScheme) &&
1211 base::EndsWith(url.host_piece(), chrome::kChromeUITopChromeDomain);
1212}
1213
[email protected]9dbfff12011-07-01 19:37:071214} // namespace
[email protected]c5dbef02011-05-13 05:06:091215
Yutaka Hirano311a7412021-01-06 06:17:351216#if !defined(OS_ANDROID)
1217base::TimeDelta GetKeepaliveTimerTimeout() {
1218 constexpr base::TimeDelta kDefaultValue = base::TimeDelta::FromSeconds(1);
1219
1220 const int seconds = base::GetFieldTrialParamByFeatureAsInt(
1221 features::kShutdownSupportForKeepalive, "timeout", -1);
1222 if (seconds < 0 || seconds > 60) {
1223 return kDefaultValue;
1224 }
1225 return base::TimeDelta::FromSeconds(seconds);
1226}
1227#endif
1228
danakj5beedd02020-10-30 15:55:131229ChromeContentBrowserClient::ChromeContentBrowserClient() {
brettw4b461082016-11-19 18:55:161230#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551231 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401232#endif
[email protected]1deace22013-05-22 06:14:461233
Yuta Hijikata235fc62b2020-12-08 03:48:321234#if BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241235 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
Yuta Hijikata235fc62b2020-12-08 03:48:321236#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241237
John Lee0ee748bf2019-12-11 21:35:441238#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1239 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1240#endif
1241
brettw00899e62016-11-12 02:10:171242#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131243 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271244#endif
bena06f7d62017-04-04 20:48:521245
Sigurdur Asgeirsson70696672019-02-08 16:14:511246 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401247}
1248
1249ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031250 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1251 delete extra_parts_[i];
1252 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401253}
1254
[email protected]bca18382012-06-25 19:15:231255// static
Chris Palmerac7d75642017-11-22 20:12:541256void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1257 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131258 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1259 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541260 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1261 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461262 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541263}
1264
1265// static
[email protected]37ca3fe02013-07-05 15:32:441266void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341267 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251268 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1269 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
Pavol Marko6adbea7f2018-02-20 16:35:281270 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1271 // user policy in addition to the same named ones in Local State (which are
1272 // used for mapping the command-line flags).
1273 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1274 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Clark DuVallaadc244c2020-06-06 03:47:141275 registry->RegisterListPref(
1276 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401277 registry->RegisterDictionaryPref(
1278 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041279 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101280#if !defined(OS_ANDROID)
1281 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561282 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101283#endif
Nicolas Arciniegafa9f4c92021-01-22 19:49:251284 registry->RegisterBooleanPref(prefs::kSSLErrorOverrideAllowed, true);
1285 registry->RegisterListPref(prefs::kSSLErrorOverrideAllowedForUrls);
Piotr Bialecki3fde5fa2021-01-23 01:08:031286#if defined(OS_ANDROID)
1287 registry->RegisterBooleanPref(prefs::kWebXRImmersiveArEnabled, true);
1288#endif
[email protected]bca18382012-06-25 19:15:231289}
1290
[email protected]eabbfb12013-04-05 23:28:351291// static
1292void ChromeContentBrowserClient::SetApplicationLocale(
1293 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481294 // The common case is that this function is called early in Chrome startup
1295 // before any threads are created or registered. When there are no threads,
1296 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001297 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331298 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481299 return;
1300 }
1301
1302 // Otherwise we're being called to change the locale. In this case set it on
1303 // the IO thread.
thestig00844cea2015-09-08 21:44:521304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351305
Gabriel Charettee7cdc5cd2020-05-27 23:35:051306 content::GetIOThreadTaskRunner({})->PostTask(
1307 FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351308}
1309
Patrick Monette61dfef92019-05-30 23:06:271310std::unique_ptr<content::BrowserMainParts>
1311ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311312 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271313 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301314 // Construct the Main browser parts based on the OS type.
1315#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051316 main_parts =
danakj5beedd02020-10-30 15:55:131317 std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_);
Avi Drissman2e458df2020-07-29 16:24:311318#elif defined(OS_MAC)
Patrick Monette61dfef92019-05-30 23:06:271319 main_parts =
danakj5beedd02020-10-30 15:55:131320 std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401321#elif BUILDFLAG(IS_CHROMEOS_ASH)
Patrick Monette61dfef92019-05-30 23:06:271322 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
danakj5beedd02020-10-30 15:55:131323 parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401324#elif BUILDFLAG(IS_CHROMEOS_LACROS)
1325 main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(parameters,
1326 &startup_data_);
Yuta Hijikata235fc62b2020-12-08 03:48:321327#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
Patrick Monette61dfef92019-05-30 23:06:271328 main_parts =
danakj5beedd02020-10-30 15:55:131329 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_);
[email protected]6e677a342012-02-11 01:21:141330#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271331 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
danakj5beedd02020-10-30 15:55:131332 &startup_data_);
[email protected]b48c9182011-10-26 18:03:301333#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271334 main_parts =
danakj5beedd02020-10-30 15:55:131335 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_);
[email protected]f967b722011-09-07 00:58:041336#else
[email protected]b48c9182011-10-26 18:03:301337 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271338 main_parts =
danakj5beedd02020-10-30 15:55:131339 std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_);
[email protected]b48c9182011-10-26 18:03:301340#endif
1341
Xi Han9fd44002019-04-30 17:39:361342 bool add_profiles_extra_parts = true;
1343#if defined(OS_ANDROID)
danakj5beedd02020-10-30 15:55:131344 if (startup_data_.HasBuiltProfilePrefService())
Xi Han9fd44002019-04-30 17:39:361345 add_profiles_extra_parts = false;
1346#endif
1347 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271348 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031349
Xi Han9fd44002019-04-30 17:39:361350 // Construct additional browser parts. Stages are called in the order in
1351 // which they are added.
[email protected]c7480942011-11-08 19:18:271352#if defined(TOOLKIT_VIEWS)
Yuta Hijikata235fc62b2020-12-08 03:48:321353#if BUILDFLAG(IS_CHROMEOS_LACROS)
Antonio Gomesaa2603362020-10-24 12:20:181354 main_parts->AddParts(
1355 std::make_unique<ChromeBrowserMainExtraPartsViewsLacros>());
Yuta Hijikata235fc62b2020-12-08 03:48:321356// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
1357// of lacros-chrome is complete.
1358#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook42e933062020-07-06 20:56:121359 main_parts->AddParts(
1360 std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>());
estaded3aa0e82016-02-17 22:55:211361#else
James Cook42e933062020-07-06 20:56:121362 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>());
James Cookf9d34d22017-10-04 16:39:351363#endif
1364#endif
1365
Yuta Hijikata235fc62b2020-12-08 03:48:321366#if BUILDFLAG(IS_CHROMEOS_ASH)
James Cookf9d34d22017-10-04 16:39:351367 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
James Cook42e933062020-07-06 20:56:121368 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>());
skycea631e2016-12-16 21:52:221369#endif
[email protected]dc04be7c2012-03-15 23:57:491370
Maksim Sisov1686fc22020-06-17 07:59:201371#if defined(USE_X11) || defined(USE_OZONE)
James Cook42e933062020-07-06 20:56:121372 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>());
[email protected]e050ef142012-03-21 01:04:241373#endif
1374
James Cook42e933062020-07-06 20:56:121375 main_parts->AddParts(
Patrick Monettea4084692021-01-18 17:51:301376 std::make_unique<ChromeBrowserMainExtraPartsPerformanceMonitor>());
1377
1378 main_parts->AddParts(
James Cook42e933062020-07-06 20:56:121379 std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>());
Etienne Bergeron05d62532017-10-13 18:24:001380
James Cook42e933062020-07-06 20:56:121381 main_parts->AddParts(
1382 std::make_unique<ChromeBrowserMainExtraPartsProfiling>());
Albert J. Wong59d85acb2017-08-10 00:50:571383
James Cook42e933062020-07-06 20:56:121384 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>());
Sebastien Marchand8c0088102019-10-11 16:47:561385
Patrick Monette61dfef92019-05-30 23:06:271386 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041387
Zhenyao Mo73144652020-04-06 18:55:051388 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1389 // GpuDataManager initialization could pick up about:flags settings.
James Cook42e933062020-07-06 20:56:121390 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>());
Zhenyao Mo73144652020-04-06 18:55:051391
[email protected]50462bf02011-11-21 19:13:311392 return main_parts;
[email protected]f967b722011-09-07 00:58:041393}
1394
michaeln96f887e22015-04-13 23:58:311395void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091396 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021397 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211398 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121399 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291400
Robert Sesek466e43e2019-08-19 22:02:021401 InitNetworkContextsParentDirectory();
1402
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291403 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1404 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311405}
1406
falkenb09d443f2016-04-07 12:36:121407bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1408 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1409}
1410
Gabriel Charettec8cca992017-08-10 18:21:491411void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1412 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1413}
1414
John Abd-El-Malek9d57f9c2019-02-20 18:50:041415bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361416 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041417}
1418
[email protected]e94bbcb2012-09-07 05:33:571419std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191420 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571421 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531422 std::string partition_id;
1423
1424 // The partition ID for webview guest processes is the string value of its
1425 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451426 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531427 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171428#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501429 // The partition ID for extensions with isolated storage is treated similarly
1430 // to the above.
Aaron Colwell8c430642020-08-04 01:55:201431 else if (extensions::util::IsExtensionSiteWithIsolatedStorage(
1432 site, browser_context))
blundellf650ea02016-02-08 11:50:501433 partition_id = site.spec();
1434#endif
[email protected]1bc28312012-11-08 08:31:531435
[email protected]056efdc2013-04-06 00:14:531436 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531437 return partition_id;
1438}
1439
1440bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1441 content::BrowserContext* browser_context,
1442 const std::string& partition_id) {
1443 // The default ID is empty and is always valid.
1444 if (partition_id.empty())
1445 return true;
1446
1447 return GURL(partition_id).is_valid();
1448}
1449
Bret Sepulveda56652152020-06-24 14:47:131450content::StoragePartitionConfig
1451ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
[email protected]1bc28312012-11-08 08:31:531452 content::BrowserContext* browser_context,
Bret Sepulveda56652152020-06-24 14:47:131453 const GURL& site) {
[email protected]14acc642012-11-17 12:20:101454 // Default to the browser-wide storage partition and override based on |site|
1455 // below.
Bret Sepulveda56652152020-06-24 14:47:131456 content::StoragePartitionConfig storage_partition_config =
1457 content::StoragePartitionConfig::CreateDefault();
[email protected]14acc642012-11-17 12:20:101458
brettw00899e62016-11-12 02:10:171459#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell0ee22132020-06-23 00:28:411460 if (extensions::WebViewGuest::GetGuestPartitionConfigForSite(
Bret Sepulveda56652152020-06-24 14:47:131461 site, &storage_partition_config)) {
1462 return storage_partition_config;
Aaron Colwell0ee22132020-06-23 00:28:411463 }
[email protected]3f24f97c2013-11-17 21:53:331464
Aaron Colwell8c430642020-08-04 01:55:201465 if (site.SchemeIs(extensions::kExtensionScheme)) {
1466 // The host in an extension site URL is the extension_id.
Aaron Colwell0ee22132020-06-23 00:28:411467 CHECK(site.has_host());
Aaron Colwell8c430642020-08-04 01:55:201468 return extensions::util::GetStoragePartitionConfigForExtensionId(
1469 site.host(), browser_context);
[email protected]1df3d972014-06-11 04:55:181470 }
1471#endif
Bret Sepulveda56652152020-06-24 14:47:131472
1473 return storage_partition_config;
[email protected]d7c7c98a2012-07-12 21:27:441474}
1475
[email protected]38b098f2012-03-14 21:11:571476content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441477ChromeContentBrowserClient::GetWebContentsViewDelegate(
1478 content::WebContents* web_contents) {
Chris Hamiltonc3d5c0d12020-06-01 19:30:051479 if (auto* registry =
1480 performance_manager::PerformanceManagerRegistry::GetInstance()) {
Chris Hamilton4269bab2020-06-04 20:03:211481 registry->MaybeCreatePageNodeForWebContents(web_contents);
Chris Hamiltonc3d5c0d12020-06-01 19:30:051482 }
cm.sanchi2db24a82017-11-16 07:22:101483 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321484}
1485
Bo Liu4ade6b1b22017-11-28 02:26:351486bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1487#if defined(OS_ANDROID)
1488 const base::android::ApplicationState app_state =
1489 base::android::ApplicationStatusListener::GetState();
1490 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1491 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1492 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1493#else
1494 return true;
1495#endif
1496}
1497
[email protected]6f2862742013-12-20 07:53:191498void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231499 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301500 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
Darin Fisher8c84328c2019-07-23 02:50:001501
Darin Fisher09aa7222019-08-29 09:27:361502 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001503 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021504
grunell086a4112017-03-02 09:23:041505 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1506 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021507 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121508 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021509 host->SetUserData(
1510 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091511 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021512 audio_debug_recordings_handler));
1513
Nico Weberaf3b00b2017-09-11 17:58:171514#if BUILDFLAG(ENABLE_NACL)
Julie Jeongeun Kimae46b4e2021-01-07 11:38:141515 host->AddFilter(new nacl::NaClHostMessageFilter(
1516 host->GetID(), profile->IsOffTheRecord(), profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351517#endif
jeremyim364ac1182015-03-03 18:49:431518
Xiaohan Wang9b34281b2017-09-08 23:48:331519#if defined(OS_ANDROID)
1520 // Data cannot be persisted if the profile is off the record.
1521 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061522 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071523
1524 // Register CrashMemoryMetricsCollector to report oom related metrics.
1525 host->SetUserData(
1526 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1527 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331528#endif
1529
Jun Caidb3f93cc2018-07-09 21:54:551530 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061531 RendererUpdaterFactory::GetForProfile(original_profile)
1532 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071533
[email protected]a48ab7112014-08-01 16:48:031534 for (size_t i = 0; i < extra_parts_.size(); ++i)
1535 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141536}
1537
[email protected]3d7474ff2011-07-27 17:47:371538GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571539 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301540 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371541 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521542 if (!profile)
1543 return url;
1544
Marc Treib7d467b792017-12-04 13:31:031545#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291546 // If the input |url| should be assigned to the Instant renderer, make its
1547 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311548 // This needs to happen even if |url| corresponds to an isolated origin; see
1549 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131550 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1551 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031552#endif
[email protected]b3cb3a32013-07-31 01:32:291553
brettw00899e62016-11-12 02:10:171554#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301555 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1556 url);
[email protected]d5a74be2014-08-08 01:01:271557#else
1558 return url;
1559#endif
[email protected]36fb2c7c2011-04-04 15:49:081560}
1561
Alexander Yashkin6aedc6e2018-08-15 08:58:451562bool ChromeContentBrowserClient::
1563 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1564 content::BrowserContext* browser_context,
1565 content::SiteInstance* candidate_site_instance,
1566 bool is_main_frame,
1567 const GURL& candidate_url,
1568 const GURL& destination_url) {
1569 DCHECK(browser_context);
1570 DCHECK(candidate_site_instance);
1571#if BUILDFLAG(ENABLE_EXTENSIONS)
1572 return ChromeContentBrowserClientExtensionsPart::
1573 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1574 browser_context, candidate_site_instance, is_main_frame,
1575 candidate_url, destination_url);
1576#else
1577 return true;
1578#endif
1579}
1580
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521581bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411582#if defined(OS_ANDROID)
1583 return true;
Yuta Hijikata235fc62b2020-12-08 03:48:321584#elif BUILDFLAG(IS_CHROMEOS_ASH)
Xiyuan Xiafc9f38132019-08-02 00:51:421585 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411586#else
1587 return false;
1588#endif // defined(OS_ANDROID)
1589}
1590
[email protected]056ad2a2011-07-12 02:13:551591bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441592 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591593 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521594 Profile* profile = Profile::FromBrowserContext(browser_context);
1595 if (!profile)
1596 return false;
1597
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301598 // NTP should use process-per-site. This is a performance optimization to
1599 // reduce process count associated with NTP tabs.
Tibor Goldschwendt52e168c2020-06-01 22:17:441600 if (site_url == GURL(chrome::kChromeUINewTabURL) ||
1601 site_url == GURL(chrome::kChromeUINewTabPageURL)) {
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301602 return true;
Tibor Goldschwendt52e168c2020-06-01 22:17:441603 }
Peter Boström8e9b1632019-08-22 23:12:471604
1605 // The web footer experiment should share its renderer to not effectively
1606 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591607 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471608 return true;
1609
Marc Treib7d467b792017-12-04 13:31:031610#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591611 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521612 return true;
Marc Treib7d467b792017-12-04 13:31:031613#endif
[email protected]c5dec6292013-01-25 04:54:521614
brettw00899e62016-11-12 02:10:171615#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301616 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591617 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301618 return true;
[email protected]d5a74be2014-08-08 01:01:271619#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301620
1621 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1622 // (rather than process-per-site).
1623 return false;
[email protected]056ad2a2011-07-12 02:13:551624}
1625
Lukasz Anforowicz32d27122018-04-09 21:48:331626bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1627 content::BrowserContext* browser_context,
1628 const GURL& site_url) {
1629 Profile* profile = Profile::FromBrowserContext(browser_context);
1630 if (!profile)
1631 return false;
1632
Thomas Lukaszewiczf87f3432021-01-21 17:20:051633 // Top Chrome WebUI should share a RendererProcessHost. Return false here to
1634 // ensure the Spare Renderer is not assigned.
1635 if (IsTopChromeWebUIURL(site_url))
1636 return false;
1637
Lukasz Anforowicz32d27122018-04-09 21:48:331638#if !defined(OS_ANDROID)
1639 // Instant renderers should not use a spare process, because they require
1640 // passing switches::kInstantProcess to the renderer process when it
1641 // launches. A spare process is launched earlier, before it is known which
1642 // navigation will use it, so it lacks this flag.
1643 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1644 return false;
1645#endif
1646
1647#if BUILDFLAG(ENABLE_EXTENSIONS)
1648 return ChromeContentBrowserClientExtensionsPart::
1649 ShouldUseSpareRenderProcessHost(profile, site_url);
1650#else
1651 return true;
1652#endif
1653}
1654
nickcc0d9142015-10-14 16:27:101655bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421656 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101657 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421658 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171659#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101660 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421661 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101662 return true;
1663 }
1664#endif
1665 return false;
1666}
1667
Aaron Colwell8812a972020-10-02 23:36:561668bool ChromeContentBrowserClient::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461669 content::BrowserContext* browser_context,
1670 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171671#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell8812a972020-10-02 23:36:561672 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461673 browser_context, effective_site_url)) {
1674 return false;
1675 }
1676#endif
1677 return true;
creise5d6d1732015-08-25 19:47:061678}
1679
Nasko Oskov39023672020-05-06 17:31:141680bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1681 base::StringPiece scheme) {
1682 // Note: This method can be called from multiple threads. It is not safe to
1683 // assume it runs only on the UI thread.
1684
1685 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371686 // locked to chrome-search: origin. Locking to chrome-search would kill
1687 // processes upon legitimate requests for cookies from the search engine's
1688 // domain.
Nasko Oskov39023672020-05-06 17:31:141689 if (scheme == chrome::kChromeSearchScheme)
1690 return false;
1691
1692 // All other WebUIs must be locked to origin.
1693 return true;
1694}
1695
Maks Orlovich0e23e312019-07-16 13:13:561696bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021697 base::StringPiece scheme,
1698 bool is_embedded_origin_secure) {
Lily Chen2387bd92020-06-02 21:15:271699 // This is needed to bypass the normal SameSite rules for any chrome:// page
1700 // embedding a secure origin, regardless of the registrable domains of any
1701 // intervening frames. For example, this is needed for browser UI to interact
1702 // with SameSite cookies on accounts.google.com, which are used for logging
1703 // into Cloud Print from chrome://print, for displaying a list of available
1704 // accounts on the NTP (chrome://new-tab-page), etc.
Lily Chen0db055b2019-11-15 20:29:021705 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1706 return true;
Maks Orlovich0e23e312019-07-16 13:13:561707#if BUILDFLAG(ENABLE_EXTENSIONS)
1708 return scheme == extensions::kExtensionScheme;
1709#else
1710 return false;
1711#endif
1712}
1713
Lily Chen0db055b2019-11-15 20:29:021714bool ChromeContentBrowserClient::
1715 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1716 base::StringPiece scheme,
1717 bool is_embedded_origin_secure) {
1718 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1719}
1720
Xiaohan Wang15a07af2020-05-28 23:24:551721// TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
1722// implementation. Find a general solution to avoid code duplication.
1723std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
1724 content::BrowserContext* browser_context,
1725 const GURL& site_url) {
1726 // By default, use the |site_url| spec as the display name.
1727 std::string name = site_url.spec();
1728
1729#if BUILDFLAG(ENABLE_EXTENSIONS)
1730 // If |site_url| wraps a chrome extension ID, we can display the extension
1731 // name instead, which is more human-readable.
1732 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
1733 const extensions::Extension* extension =
1734 extensions::ExtensionRegistry::Get(browser_context)
1735 ->enabled_extensions()
1736 .GetExtensionOrAppByURL(site_url);
1737 if (extension)
1738 name = extension->name();
1739 }
1740#endif // BUILDFLAG(ENABLE_EXTENSIONS)
1741
1742 return name;
1743}
1744
Lukasz Anforowicz7097890d2019-11-20 21:49:221745void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021746 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591747 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021748 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221749 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071750#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221751 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021752 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071753#endif
1754}
1755
[email protected]73b718f2014-01-27 02:59:461756// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1757// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411758void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1759 std::vector<std::string>* additional_schemes) {
1760 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241761 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351762 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061763}
1764
alexmos94875b3b2017-03-16 22:19:011765void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1766 std::vector<std::string>* additional_schemes) {
1767 GetAdditionalWebUISchemes(additional_schemes);
1768
1769#if BUILDFLAG(ENABLE_EXTENSIONS)
1770 additional_schemes->push_back(extensions::kExtensionScheme);
1771#endif
1772}
1773
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521774bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011775 return webui::LogWebUIUrl(web_ui_url);
1776}
1777
John Abd-El-Malek04bfa8532018-07-12 05:28:221778bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1779 const url::Origin& origin) {
1780 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1781 origin);
1782}
1783
[email protected]46fb9442011-12-09 17:57:471784bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1785 return ProfileIOData::IsHandledURL(url);
1786}
1787
Frédéric Wang1eabba72020-10-23 15:36:551788bool ChromeContentBrowserClient::HasCustomSchemeHandler(
1789 content::BrowserContext* browser_context,
1790 const std::string& scheme) {
1791 if (ProtocolHandlerRegistry* protocol_handler_registry =
1792 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1793 browser_context)) {
1794 return protocol_handler_registry->IsHandledProtocol(scheme);
1795 }
1796
1797 return false;
1798}
1799
[email protected]c4365fa42013-05-14 01:08:241800bool ChromeContentBrowserClient::CanCommitURL(
1801 content::RenderProcessHost* process_host,
1802 const GURL& url) {
brettw00899e62016-11-12 02:10:171803#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441804 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1805 url);
[email protected]d5a74be2014-08-08 01:01:271806#else
1807 return true;
1808#endif
[email protected]c4365fa42013-05-14 01:08:241809}
1810
rdevlin.cronina32a0902016-11-09 15:50:201811void ChromeContentBrowserClient::OverrideNavigationParams(
Scott Violet5ae6c42e2020-10-28 02:47:371812 content::WebContents* web_contents,
rdevlin.cronina32a0902016-11-09 15:50:201813 SiteInstance* site_instance,
1814 ui::PageTransition* transition,
1815 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581816 content::Referrer* referrer,
1817 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201818 DCHECK(transition);
1819 DCHECK(is_renderer_initiated);
1820 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471821 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1822 // use for making security decisions 99.44% of the time, for detecting the NTP
1823 // it is reliable and the correct way. See http://crbug.com/624410.
1824 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201825 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581826 // Clicks on tiles of the new tab page should be treated as if a user
1827 // clicked on a bookmark. This is consistent with native implementations
1828 // like Android's. This also helps ensure that security features (like
1829 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1830 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201831 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1832 *is_renderer_initiated = false;
1833 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581834 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421835 }
Scott Violet5ae6c42e2020-10-28 02:47:371836#if defined(OS_ANDROID)
1837 if (web_contents) {
1838 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
1839 if (tab && tab->should_add_api2_transition_to_future_navigations()) {
1840 *transition = ui::PageTransitionFromInt(*transition |
1841 ui::PAGE_TRANSITION_FROM_API_2);
1842 }
1843 }
1844#endif
mastiza77db6992016-06-30 09:48:421845}
1846
Charles Reis29e9dd12017-09-28 00:59:151847bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1848 const GURL& url,
1849 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471850 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1851 // use for making security decisions 99.44% of the time, for detecting the NTP
1852 // it is reliable and the correct way. See http://crbug.com/624410.
1853 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1854 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151855}
1856
[email protected]2a5221b2011-09-27 23:07:311857bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301858 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311859 const GURL& site_url) {
1860 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301861 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441862 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521863 // share any host.
1864 if (!profile)
1865 return true;
1866
Marc Treib7895941d2017-11-28 12:37:021867#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141868 // Instant URLs should only be in the instant process and instant process
1869 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521870 InstantService* instant_service =
1871 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141872 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441873 bool is_instant_process =
1874 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141875 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131876 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141877 if (is_instant_process || should_be_in_instant_process)
1878 return is_instant_process && should_be_in_instant_process;
1879 }
Marc Treib7895941d2017-11-28 12:37:021880#endif
[email protected]c5dec6292013-01-25 04:54:521881
brettw00899e62016-11-12 02:10:171882#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131883 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1884 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271885#else
1886 return true;
1887#endif
[email protected]2a5221b2011-09-27 23:07:311888}
1889
[email protected]28c5d0b72014-05-13 08:19:591890bool ChromeContentBrowserClient::MayReuseHost(
1891 content::RenderProcessHost* process_host) {
Hiroki Nakagawab4cd18aa2021-01-25 18:11:011892 // If there is currently a no-state prefetcher in progress for the host
1893 // provided, it may not be shared. We require prefetchers to be by themselves
1894 // in a separate process so that we can monitor their resource usage.
1895 prerender::NoStatePrefetchManager* no_state_prefetch_manager =
1896 prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
drogerc1543152016-09-20 13:03:371897 process_host->GetBrowserContext());
Hiroki Nakagawab4cd18aa2021-01-25 18:11:011898 if (no_state_prefetch_manager &&
1899 !no_state_prefetch_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591900 return false;
1901 }
1902
1903 return true;
1904}
1905
[email protected]76411f412012-02-22 18:56:061906bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441907 content::BrowserContext* browser_context,
1908 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061909 // It has to be a valid URL for us to check for an extension.
1910 if (!url.is_valid())
1911 return false;
1912
Thomas Lukaszewiczf87f3432021-01-21 17:20:051913 // Top Chrome WebUI should try to share a RenderProcessHost with other
1914 // existing Top Chrome WebUI.
1915 if (IsTopChromeWebUIURL(url))
1916 return true;
1917
brettw00899e62016-11-12 02:10:171918#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061919 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131920 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441921 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271922#else
1923 return false;
1924#endif
[email protected]76411f412012-02-22 18:56:061925}
1926
Alex Moshchuk9c9e3882018-11-02 19:57:031927bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1928 content::RenderFrameHost* main_frame) {
1929#if BUILDFLAG(ENABLE_EXTENSIONS)
1930 return ChromeContentBrowserClientExtensionsPart::
1931 ShouldSubframesTryToReuseExistingProcess(main_frame);
1932#else
1933 return true;
1934#endif
1935}
1936
[email protected]6f371442011-11-09 06:45:461937void ChromeContentBrowserClient::SiteInstanceGotProcess(
1938 SiteInstance* site_instance) {
1939 CHECK(site_instance->HasProcess());
1940
Aran Gilmanf010bdd2019-08-28 19:55:441941 Profile* profile =
1942 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521943 if (!profile)
1944 return;
1945
Marc Treib7895941d2017-11-28 12:37:021946#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521947 // Remember the ID of the Instant process to signal the renderer process
1948 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131949 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1950 profile)) {
[email protected]c5dec6292013-01-25 04:54:521951 InstantService* instant_service =
1952 InstantServiceFactory::GetForProfile(profile);
1953 if (instant_service)
1954 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1955 }
Marc Treib7895941d2017-11-28 12:37:021956#endif
[email protected]c5dec6292013-01-25 04:54:521957
[email protected]a48ab7112014-08-01 16:48:031958 for (size_t i = 0; i < extra_parts_.size(); ++i)
1959 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461960}
1961
1962void ChromeContentBrowserClient::SiteInstanceDeleting(
1963 SiteInstance* site_instance) {
1964 if (!site_instance->HasProcess())
1965 return;
1966
[email protected]a48ab7112014-08-01 16:48:031967 for (size_t i = 0; i < extra_parts_.size(); ++i)
1968 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461969}
1970
[email protected]453f5432013-11-26 19:43:001971bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141972 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561973 const GURL& current_effective_url,
1974 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171975#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131976 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561977 ShouldSwapBrowsingInstancesForNavigation(
1978 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271979#else
1980 return false;
1981#endif
[email protected]e3daf3c2011-10-05 21:17:081982}
1983
Nasko Oskovd83b5712018-05-04 04:50:571984bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1985 // TODO(nasko): Consider supporting error page isolation in subframes if
1986 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381987 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571988}
1989
[email protected]3d831992013-07-04 01:13:291990bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1991 return !url.SchemeIs(chrome::kChromeNativeScheme);
1992}
1993
Alex Moshchukd252c192017-07-17 22:03:481994std::vector<url::Origin>
1995ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1996 std::vector<url::Origin> isolated_origin_list;
1997
Alex Moshchuk89352a72017-10-25 20:25:591998// Sign-in process isolation is not needed on Android, see
1999// https://crbug.com/739418.
2000#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:382001 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:122002 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:592003#endif
Alex Moshchukd252c192017-07-17 22:03:482004
Alex Moshchuk81d2a29e2019-07-16 01:14:382005#if BUILDFLAG(ENABLE_EXTENSIONS)
2006 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
2007 GetOriginsRequiringDedicatedProcess();
2008 std::move(std::begin(origins_from_extensions),
2009 std::end(origins_from_extensions),
2010 std::back_inserter(isolated_origin_list));
2011#endif
2012
Alex Moshchuk51e1428b2020-04-22 18:00:542013 // Include additional origins preloaded with specific browser configurations,
2014 // if any. For example, this is used on Google Chrome for Android to preload
2015 // a list of important sites to isolate.
2016 auto built_in_origins =
2017 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
2018 std::move(std::begin(built_in_origins), std::end(built_in_origins),
2019 std::back_inserter(isolated_origin_list));
2020
Alex Moshchukd252c192017-07-17 22:03:482021 return isolated_origin_list;
2022}
2023
Lukasz Anforowicz5e201abd2018-03-24 00:41:062024bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:342025 return base::FeatureList::IsEnabled(features::kSitePerProcess);
2026}
2027
2028bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Clark DuVallaadc244c2020-06-06 03:47:142029 return site_isolation::SiteIsolationPolicy::
2030 ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:062031}
2032
Alex Moshchuk082b5f82019-03-14 01:34:162033std::vector<std::string>
2034ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
Clark DuVallaadc244c2020-06-06 03:47:142035 if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
Alex Moshchuk082b5f82019-03-14 01:34:162036 return {"Isolate Password Sites"};
2037 else
2038 return {};
2039}
2040
Alex Moshchuke256d562019-04-26 21:43:572041void ChromeContentBrowserClient::PersistIsolatedOrigin(
2042 content::BrowserContext* context,
2043 const url::Origin& origin) {
2044 DCHECK(!context->IsOffTheRecord());
2045 Profile* profile = Profile::FromBrowserContext(context);
2046 ListPrefUpdate update(profile->GetPrefs(),
Clark DuVallaadc244c2020-06-06 03:47:142047 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Alex Moshchuke256d562019-04-26 21:43:572048 base::ListValue* list = update.Get();
2049 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:362050 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:122051 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:572052}
2053
Ken Rockot314714c2017-11-05 23:36:242054bool ChromeContentBrowserClient::IsFileAccessAllowed(
2055 const base::FilePath& path,
2056 const base::FilePath& absolute_path,
2057 const base::FilePath& profile_path) {
2058 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2059 profile_path);
2060}
2061
[email protected]d2e1a0a2014-06-16 15:49:372062namespace {
2063
bmcquade5d2d9cf32015-06-19 17:42:282064void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2065 const base::CommandLine& browser_command_line,
2066 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522067 // List of field trials that modify the blink-settings command line flag. No
2068 // two field trials in the list should specify the same keys, otherwise one
2069 // field trial may overwrite another. See Source/core/frame/Settings.in in
2070 // Blink for the list of valid keys.
2071 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162072 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2073 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2074 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2075 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522076 };
2077
2078 std::vector<std::string> blink_settings;
2079 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2080 // Each blink-settings field trial should include a forcing_flag group,
2081 // to make sure that clients that specify the blink-settings flag on the
2082 // command line are excluded from the experiment groups. To make
2083 // sure we assign clients that specify this flag to the forcing_flag
2084 // group, we must call GetVariationParams for each field trial first
2085 // (for example, before checking HasSwitch() and returning), since
2086 // GetVariationParams has the side-effect of assigning the client to
2087 // a field trial group.
2088 std::map<std::string, std::string> params;
2089 if (variations::GetVariationParams(field_trial_name, &params)) {
2090 for (const auto& param : params) {
2091 blink_settings.push_back(base::StringPrintf(
2092 "%s=%s", param.first.c_str(), param.second.c_str()));
2093 }
2094 }
2095 }
pmeenan9ac669682015-08-17 14:57:032096
bmcquade9dd54cc2015-06-22 16:56:522097 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282098 return;
2099 }
2100
Gyuyoung Kima252d4a2020-09-16 07:20:312101 if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) ||
2102 command_line->HasSwitch(blink::switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032103 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522104 // blink-settings flag into a group with no params, and we return
2105 // above if no params were specified, so it's an error if we reach
2106 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282107 LOG(WARNING) << "Received field trial params, "
2108 "but blink-settings switch already specified.";
2109 return;
2110 }
2111
Gyuyoung Kima252d4a2020-09-16 07:20:312112 command_line->AppendSwitchASCII(blink::switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262113 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282114}
2115
[email protected]d2e1a0a2014-06-16 15:49:372116} // namespace
2117
[email protected]b80f68432011-05-02 17:22:302118void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172119 base::CommandLine* command_line,
2120 int child_process_id) {
Avi Drissman2e458df2020-07-29 16:24:312121#if defined(OS_MAC)
dcheng4af48582016-04-19 00:29:352122 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062123 GoogleUpdateSettings::LoadMetricsClientInfo();
2124 if (client_info) {
2125 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2126 client_info->client_id);
2127 }
2128#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022129#if defined(OS_ANDROID)
2130 bool enable_crash_reporter = true;
2131#else
Joshua Perazace68e2f2019-09-23 18:44:242132 bool enable_crash_reporter = false;
2133 if (crash_reporter::IsCrashpadEnabled()) {
2134 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2135 enable_crash_reporter = true;
2136
2137 int fd;
2138 pid_t pid;
2139 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2140 command_line->AppendSwitchASCII(
2141 crash_reporter::switches::kCrashpadHandlerPid,
2142 base::NumberToString(pid));
2143 }
2144 } else {
2145 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2146 }
Joshua Perazaf890e4b2019-01-03 19:19:022147#endif
2148 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512149 std::string switch_value;
dcheng4af48582016-04-19 00:29:352150 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532151 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512152 if (client_info)
2153 switch_value = client_info->client_id;
2154 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252155 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302156 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512157 switch_value);
[email protected]b80f68432011-05-02 17:22:302158 }
Mark Mentovaic67fa64f2015-03-24 14:00:062159#endif
[email protected]b80f68432011-05-02 17:22:302160
[email protected]f1933792011-06-14 00:49:342161 if (logging::DialogsAreSuppressed())
2162 command_line->AppendSwitch(switches::kNoErrorDialogs);
2163
[email protected]b80f68432011-05-02 17:22:302164 std::string process_type =
2165 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172166 const base::CommandLine& browser_command_line =
2167 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322168
[email protected]7c9b6f92013-09-10 18:11:352169 static const char* const kCommonSwitchNames[] = {
John Abd-El-Malekec1fc69e2021-01-28 19:14:412170 embedder_support::kUserAgent,
Aran Gilmanf010bdd2019-08-28 19:55:442171 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352172 };
2173 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372174 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322175
fqj15ff3f72015-10-09 19:20:022176 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432177 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312178 };
fqj15ff3f72015-10-09 19:20:022179 command_line->CopySwitchesFrom(browser_command_line,
2180 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372181 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312182
Yuta Hijikata235fc62b2020-12-08 03:48:322183#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]6bdc52272014-05-27 00:12:332184 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2185 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522186 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332187 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2188 homedir.value().c_str());
2189#endif
2190
[email protected]718eab62011-10-05 21:16:522191 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032192 content::RenderProcessHost* process =
2193 content::RenderProcessHost::FromID(child_process_id);
2194 Profile* profile =
2195 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442196 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032197 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442198 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2199 process, profile);
[email protected]a48ab7112014-08-01 16:48:032200 }
2201
Yuta Hijikata235fc62b2020-12-08 03:48:322202#if BUILDFLAG(IS_CHROMEOS_ASH)
Aran Gilmanf010bdd2019-08-28 19:55:442203 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2204 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302205 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442206 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2207 login_profile);
[email protected]b80f68432011-05-02 17:22:302208#endif
2209
Aran Gilmanf010bdd2019-08-28 19:55:442210 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222211 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372212 if (process) {
[email protected]a8d851f82011-12-21 00:32:372213 PrefService* prefs = profile->GetPrefs();
2214 // Currently this pref is only registered if applied via a policy.
2215 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2216 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2217 // Turn this policy into a command line switch.
2218 command_line->AppendSwitch(switches::kDisable3DAPIs);
2219 }
[email protected]718eab62011-10-05 21:16:522220
Bettinafd0c1102020-08-06 00:23:432221#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
2222 bool client_side_detection_enabled =
2223 safe_browsing::IsSafeBrowsingEnabled(*prefs) &&
Daniel Rubery33506f9f2020-10-07 00:28:132224 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2225 ::switches::kDisableClientSidePhishingDetection);
Bettinafd0c1102020-08-06 00:23:432226#if BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2227 client_side_detection_enabled &= base::FeatureList::IsEnabled(
2228 safe_browsing::kClientSideDetectionForAndroid);
2229#endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2230
[email protected]a8d851f82011-12-21 00:32:372231 // Disable client-side phishing detection in the renderer if it is
Bettinafd0c1102020-08-06 00:23:432232 // disabled in the Profile preferences, or by command line flag, or by not
2233 // being enabled on Android.
2234 if (!client_side_detection_enabled) {
[email protected]a8d851f82011-12-21 00:32:372235 command_line->AppendSwitch(
2236 switches::kDisableClientSidePhishingDetection);
2237 }
Bettinafd0c1102020-08-06 00:23:432238#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
[email protected]0045b0f42012-07-26 11:52:082239
vitalybukaa7ae5052014-09-26 04:11:132240 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2241 command_line->AppendSwitch(switches::kDisablePrintPreview);
2242
Marc Treib7895941d2017-11-28 12:37:022243#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522244 InstantService* instant_service =
2245 InstantServiceFactory::GetForProfile(profile);
2246 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542247 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522248 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542249 }
Marc Treib7895941d2017-11-28 12:37:022250#endif
fqjba8749c2015-10-29 15:33:072251
fqj38306f7b2015-11-02 16:59:062252 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542253 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432254 command_line->AppendSwitch(
2255 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542256 }
Daniel Vogelheim976f1c22017-11-22 16:26:032257
Lukasz Anforowicz60d1253d2019-05-08 16:31:372258 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2259
Katie Dillonc25ee5c92019-09-12 17:05:422260 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2261 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2262 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2263 }
Takashi Toyoshima128441462019-10-16 04:19:172264
Daniel Libbyc5bfd91f2020-03-07 03:44:102265 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2266 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2267 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2268 }
2269
Adrienne Walker297651292020-05-08 00:23:182270 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2271 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2272 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2273 }
Chris Hamilton65c41312020-06-10 13:14:402274
2275 // The IntensiveWakeUpThrottling feature is typically managed via a
2276 // base::Feature, but it has a managed policy override. The override is
2277 // communicated to blink via a custom command-line flag. See
2278 // PageSchedulerImpl for the other half of related logic.
2279 PrefService* local_state = g_browser_process->local_state();
2280 const PrefService::Preference* pref = local_state->FindPreference(
2281 policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled);
2282 if (pref && pref->IsManaged()) {
2283 command_line->AppendSwitchASCII(
2284 blink::switches::kIntensiveWakeUpThrottlingPolicy,
2285 pref->GetValue()->GetBool()
2286 ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable
2287 : blink::switches::
2288 kIntensiveWakeUpThrottlingPolicy_ForceDisable);
2289 }
Aaron Tagliaboschi8f3a28302020-06-24 03:08:262290
2291 // Same as above, but for the blink side of UserAgentClientHints
2292 if (!local_state->GetBoolean(
2293 policy::policy_prefs::kUserAgentClientHintsEnabled)) {
2294 command_line->AppendSwitch(
2295 blink::switches::kUserAgentClientHintDisable);
2296 }
Rakina Zata Amnic123bd22020-07-31 19:08:392297
Eric Lawrencea8a460c2020-11-06 21:10:422298 if (!local_state->GetBoolean(
2299 policy::policy_prefs::kTargetBlankImpliesNoOpener)) {
2300 command_line->AppendSwitch(
2301 switches::kDisableTargetBlankImpliesNoOpener);
2302 }
2303
Rakina Zata Amnic123bd22020-07-31 19:08:392304#if defined(OS_ANDROID)
2305 // Communicating to content/ for BackForwardCache.
2306 if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) &&
2307 !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) {
2308 command_line->AppendSwitch(switches::kDisableBackForwardCache);
2309 }
2310#endif // defined(OS_ANDROID)
[email protected]47c7ec82012-01-18 03:29:212311 }
[email protected]4287a3d2011-06-13 23:56:512312
Aran Gilmanf010bdd2019-08-28 19:55:442313 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2314 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282315
mdjonesa6b9e172016-09-23 16:24:302316#if defined(OS_ANDROID)
2317 // If the platform is Android, force the distillability service on.
2318 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2319#endif
2320
[email protected]47c7ec82012-01-18 03:29:212321 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512322 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192323 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412324 autofill::switches::kShowAutofillSignatures,
Yuta Hijikata235fc62b2020-12-08 03:48:322325#if BUILDFLAG(IS_CHROMEOS_ASH)
Chris Mumford6b1696b2019-01-25 02:54:302326 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2327#endif
brettw00899e62016-11-12 02:10:172328#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512329 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272330 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172331 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512332 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272333 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172334 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]5adb7742020-06-30 14:28:122335 extensions::switches::kAllowlistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282336#endif
estark4b003b332015-02-14 01:07:052337 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512338 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482339 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512340 switches::kCloudPrintXmppEndpoint,
dslomova893e972014-12-05 09:39:572341 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462342 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302343 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512344 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172345#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242346 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482347 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552348#endif
[email protected]ce304ce2013-02-22 21:54:452349 switches::kEnableNetBenchmarking,
Yuta Hijikata235fc62b2020-12-08 03:48:322350#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchukce6f8802020-01-30 09:30:342351 switches::kForceAppMode,
2352#endif
Nico Weberaf3b00b2017-09-11 17:58:172353#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592354 switches::kForcePNaClSubzero,
2355#endif
Marc Treibad33cf942017-08-24 11:19:002356 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032357 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512358 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102359 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322360 embedder_support::kOriginTrialDisabledFeatures,
2361 embedder_support::kOriginTrialDisabledTokens,
2362 embedder_support::kOriginTrialPublicKey,
wychene55687342015-11-13 20:17:032363 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092364 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512365 };
2366
2367 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372368 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172369 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172370#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382371 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442372 extensions::switches::kAllowHTTPBackgroundPage,
2373 extensions::switches::kEnableExperimentalExtensionApis,
2374 extensions::switches::kExtensionsOnChromeURLs,
[email protected]5adb7742020-06-30 14:28:122375 extensions::switches::kAllowlistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382376 };
2377
2378 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372379 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282380#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372381 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Ken Rockot4e805fd2020-10-01 03:07:392382 } else if (process_type == switches::kZygoteProcess) {
Yutaka Hirano93e924742020-11-11 10:40:132383 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
Nico Weberaf3b00b2017-09-11 17:58:172384#if BUILDFLAG(ENABLE_NACL)
Yutaka Hirano93e924742020-11-11 10:40:132385 static const char* const kSwitchNames[] = {
2386 switches::kEnableNaClDebug,
2387 switches::kEnableNaClNonSfiMode,
2388 switches::kForcePNaClSubzero,
2389 switches::kNaClDangerousNoSandboxNonSfi,
2390 };
[email protected]4287a3d2011-06-13 23:56:512391
Yutaka Hirano93e924742020-11-11 10:40:132392 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2393 base::size(kSwitchNames));
Bill Budge431f0b32020-10-27 21:31:382394#endif
James Cook247a8cb2020-12-22 23:09:512395#if BUILDFLAG(IS_CHROMEOS_LACROS)
2396 // Ensure zygote loads the resource bundle for the right locale.
2397 static const char* const kMoreSwitchNames[] = {switches::kLang};
2398 command_line->CopySwitchesFrom(browser_command_line, kMoreSwitchNames,
2399 base::size(kMoreSwitchNames));
2400#endif
[email protected]d56ecf922012-02-15 16:03:112401 } else if (process_type == switches::kGpuProcess) {
Corentin Walleze660b152020-07-15 16:07:542402 // If --ignore-gpu-blocklist is passed in, don't send in crash reports
[email protected]d56ecf922012-02-15 16:03:112403 // because GPU is expected to be unreliable.
Corentin Wallez49c0110d2020-11-17 10:15:162404 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) &&
[email protected]d56ecf922012-02-15 16:03:112405 !command_line->HasSwitch(switches::kDisableBreakpad))
2406 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302407 }
[email protected]6f08af82011-09-15 01:19:032408
Yuta Hijikata235fc62b2020-12-08 03:48:322409#if BUILDFLAG(IS_CHROMEOS_ASH)
Joshua Peraza30d8fc72019-08-19 17:24:302410 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112411 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292412 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112413 };
2414 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2415 base::size(kSwitchNames));
2416 }
2417#endif
2418
Mike Wittman67d63112020-09-19 00:33:462419 ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Mike Wittman0d21648f2020-09-30 19:05:082420 command_line);
Andrew Comminos66057672019-05-01 00:03:342421
Sean McAllister0d73ca3d2020-08-19 17:54:372422#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Andrew Comminos66057672019-05-01 00:03:342423 // Processes may only query perf_event_open with the BPF sandbox disabled.
2424 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
Robert Sesek7d0b49b2020-07-08 18:31:272425 command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
Andrew Comminos66057672019-05-01 00:03:342426 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2427 }
2428#endif
[email protected]b80f68432011-05-02 17:22:302429}
2430
Olivier Yiptong0daa93f2019-08-22 19:40:082431std::string
2432ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2433 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2434}
2435
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:592436download::QuarantineConnectionCallback
2437ChromeContentBrowserClient::GetQuarantineConnectionCallback() {
2438 return base::BindRepeating(
2439 &ChromeDownloadManagerDelegate::ConnectToQuarantineService);
2440}
2441
[email protected]b80f68432011-05-02 17:22:302442std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432443 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332444 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302445 return g_browser_process->GetApplicationLocale();
2446}
2447
[email protected]597a867b2011-11-18 18:31:202448std::string ChromeContentBrowserClient::GetAcceptLangs(
2449 content::BrowserContext* context) {
2450 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202451 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082452}
2453
Dana Fried34d580002019-04-24 20:05:482454gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492455 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482456 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082457}
2458
bengre8a146f2016-03-10 01:20:222459bool ChromeContentBrowserClient::IsDataSaverEnabled(
2460 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382461 if (!browser_context || browser_context->IsOffTheRecord())
2462 return false;
2463
Robert Ogdenc995d4fe2019-03-25 19:18:372464 Profile* profile = Profile::FromBrowserContext(browser_context);
2465 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412466 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2467 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222468}
2469
Kenichi Ishibashi46329872018-07-17 09:43:402470void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2471 content::BrowserContext* browser_context,
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:232472 blink::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402473 DCHECK(browser_context);
2474 DCHECK(out_prefs);
2475 renderer_preferences_util::UpdateFromSystemSettings(
2476 out_prefs, Profile::FromBrowserContext(browser_context));
2477}
2478
Clark DuVall5690e742019-07-17 18:26:172479bool ChromeContentBrowserClient::AllowAppCache(
2480 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172481 const GURL& site_for_cookies,
2482 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172483 content::BrowserContext* context) {
2484 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2485 return CookieSettingsFactory::GetForProfile(
2486 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172487 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172488}
2489
Alexander Timin17edc742020-04-23 18:22:182490content::AllowServiceWorkerResult
John Abd-El-Malek70810942020-10-27 05:14:382491ChromeContentBrowserClient::AllowServiceWorker(
Matt Falkenhagen7b509e52019-08-15 23:11:412492 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542493 const GURL& site_for_cookies,
2494 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412495 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182496 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412497 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542498 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412499
2500#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022501 // Check if this is an extension-related service worker, and, if so, if it's
2502 // allowed (this can return false if, e.g., the extension is disabled).
2503 // If it's not allowed, return immediately. We deliberately do *not* report
Carlos Caballerob4283202020-08-10 14:40:462504 // to the PageSpecificContentSettings, since the service worker is blocked
Matt Falkenhagena59e1cce2019-08-22 23:45:022505 // because of the extension, rather than because of the user's content
2506 // settings.
John Abd-El-Malek70810942020-10-27 05:14:382507 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
Matt Falkenhagena59e1cce2019-08-22 23:45:022508 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182509 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022510 }
Matt Falkenhagen7b509e52019-08-15 23:11:412511#endif
2512
2513 Profile* profile = Profile::FromBrowserContext(context);
2514
2515 // Check if JavaScript is allowed.
2516 content_settings::SettingInfo info;
2517 std::unique_ptr<base::Value> value =
2518 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452519 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Illia Klimov48f643c2020-11-05 20:06:142520 &info);
Matt Falkenhagen7b509e52019-08-15 23:11:412521 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2522 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2523
2524 // Check if cookies are allowed.
2525 bool allow_cookies =
2526 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542527 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412528
Alexander Timin17edc742020-04-23 18:22:182529 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2530 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412531}
2532
Jochen Eisinger0ff7645c2017-11-28 08:11:262533bool ChromeContentBrowserClient::AllowSharedWorker(
2534 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542535 const GURL& site_for_cookies,
2536 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262537 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372538 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262539 content::BrowserContext* context,
2540 int render_process_id,
2541 int render_frame_id) {
2542 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2543
2544 // Check if cookies are allowed.
2545 bool allow =
2546 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542547 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2548 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262549
Carlos Caballerob4283202020-08-10 14:40:462550 content_settings::PageSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372551 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2552 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262553 return allow;
2554}
2555
Patrick Monette6cb099a2019-09-18 19:31:272556bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2557 const std::string& scheme) {
2558#if BUILDFLAG(ENABLE_EXTENSIONS)
2559 // Extensions are allowed to start cross-origin shared workers.
2560 if (scheme == extensions::kExtensionScheme)
2561 return true;
2562#endif
2563
2564 return false;
2565}
2566
Clark DuVallab63d142019-07-23 04:24:362567bool ChromeContentBrowserClient::AllowSignedExchange(
2568 content::BrowserContext* browser_context) {
2569 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2570 Profile* profile = Profile::FromBrowserContext(browser_context);
2571 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2572}
2573
[email protected]f917df22014-07-10 07:45:492574void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352575 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572576 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172577 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572578 base::OnceCallback<void(bool)> callback) {
2579 Profile* profile = Profile::FromBrowserContext(browser_context);
2580 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172581 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352582
brettw00899e62016-11-12 02:10:172583#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572584 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492585#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572586 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492587#endif
2588}
2589
brettw00899e62016-11-12 02:10:172590#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492591void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2592 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172593 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572594 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492595 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572596 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492597 std::map<int, int> process_map;
2598 std::map<int, int>::const_iterator it;
2599 bool has_web_view_guest = false;
2600 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172601 for (const auto& it : render_frames) {
2602 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492603 continue;
2604
Lukasz Anforowicz09060bdf72018-08-23 15:53:172605 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492606
Lukasz Anforowicz09060bdf72018-08-23 15:53:172607 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492608 has_web_view_guest = true;
2609 }
2610 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572611 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492612 return;
2613 }
[email protected]dffb9fc2014-07-16 04:14:022614 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492615 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492616
[email protected]140d6cd92014-08-12 18:26:462617 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572618 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2619 web_view_permission_helper->RequestFileSystemPermission(
2620 url, allow,
2621 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2622 weak_factory_.GetWeakPtr(), url, render_frames,
2623 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492624}
2625#endif
2626
2627void ChromeContentBrowserClient::FileSystemAccessed(
2628 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172629 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572630 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492631 bool allow) {
[email protected]62151052012-02-01 18:40:482632 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172633 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462634 content_settings::PageSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572635 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352636 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572637 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352638}
2639
[email protected]7c5ff9a2012-03-02 07:42:492640bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2641 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572642 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172643 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572644 Profile* profile = Profile::FromBrowserContext(browser_context);
2645 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2646
Christian Dullweber77740152020-05-12 09:54:172647 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492648
2649 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172650 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462651 content_settings::PageSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572652 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492653 }
2654
2655 return allow;
2656}
2657
Ben Kelly6b2e61c2019-03-14 16:06:292658bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2659 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572660 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292661 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572662 Profile* profile = Profile::FromBrowserContext(browser_context);
2663 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172664 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292665
2666 // Record access to CacheStorage for potential display in UI.
2667 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462668 content_settings::PageSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572669 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292670 }
2671
2672 return allow;
2673}
2674
Joshua Bell1ebc8df2019-11-06 00:27:582675bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2676 const GURL& url,
2677 content::BrowserContext* browser_context,
2678 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2679 Profile* profile = Profile::FromBrowserContext(browser_context);
2680 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172681 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582682}
2683
jyasskinc993ce8d2016-03-31 00:38:342684ChromeContentBrowserClient::AllowWebBluetoothResult
2685ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452686 content::BrowserContext* browser_context,
2687 const url::Origin& requesting_origin,
2688 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342689 // TODO(crbug.com/598890): Don't disable if
2690 // base::CommandLine::ForCurrentProcess()->
2691 // HasSwitch(switches::kEnableWebBluetooth) is true.
2692 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272693 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342694 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272695 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342696 // The kill switch is enabled for this permission. Block requests.
2697 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2698 }
2699
jyasskin98bdd3992016-02-26 20:25:452700 const HostContentSettingsMap* const content_settings =
2701 HostContentSettingsMapFactory::GetForProfile(
2702 Profile::FromBrowserContext(browser_context));
2703
csharrisonaec2c542016-10-12 19:40:362704 if (content_settings->GetContentSetting(
2705 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:142706 ContentSettingsType::BLUETOOTH_GUARD) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342707 return AllowWebBluetoothResult::BLOCK_POLICY;
2708 }
2709 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452710}
2711
beaufort.francois01135bf2016-11-23 14:37:362712std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2713 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2714 "blocklist_additions");
scheib74250322016-04-07 03:32:212715}
2716
John Delaneyc2782792021-01-15 01:29:072717bool ChromeContentBrowserClient::IsConversionMeasurementAllowed(
Charlie Harrison071ac922020-06-25 19:11:222718 content::BrowserContext* browser_context) {
Charlie Harrison071ac922020-06-25 19:11:222719 Profile* profile = Profile::FromBrowserContext(browser_context);
John Delaneyc2782792021-01-15 01:29:072720 PrivacySandboxSettings* privacy_sandbox_settings =
2721 PrivacySandboxSettingsFactory::GetForProfile(profile);
2722
2723 return privacy_sandbox_settings &&
2724 privacy_sandbox_settings->IsPrivacySandboxAllowed();
2725}
2726
2727bool ChromeContentBrowserClient::IsConversionMeasurementOperationAllowed(
2728 content::BrowserContext* browser_context,
2729 ConversionMeasurementOperation operation,
2730 const url::Origin* impression_origin,
2731 const url::Origin* conversion_origin,
2732 const url::Origin* reporting_origin) {
2733 Profile* profile = Profile::FromBrowserContext(browser_context);
2734
2735 PrivacySandboxSettings* privacy_sandbox_settings =
2736 PrivacySandboxSettingsFactory::GetForProfile(profile);
2737 if (!privacy_sandbox_settings)
2738 return false;
2739
2740 switch (operation) {
2741 case ConversionMeasurementOperation::kImpression:
2742 DCHECK(impression_origin);
2743 DCHECK(reporting_origin);
2744 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2745 *impression_origin, *reporting_origin);
2746 case ConversionMeasurementOperation::kConversion:
2747 DCHECK(conversion_origin);
2748 DCHECK(reporting_origin);
2749 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2750 *conversion_origin, *reporting_origin);
2751 case ConversionMeasurementOperation::kReport:
2752 DCHECK(impression_origin);
2753 DCHECK(conversion_origin);
2754 DCHECK(reporting_origin);
2755 return privacy_sandbox_settings->ShouldSendConversionReport(
2756 *impression_origin, *conversion_origin, *reporting_origin);
2757 }
Charlie Harrison071ac922020-06-25 19:11:222758}
2759
Yuta Hijikata235fc62b2020-12-08 03:48:322760#if BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522761void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072762 content::BrowserContext* browser_context) {
2763 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2764 if (user_manager) {
2765 const user_manager::User* user =
2766 chromeos::ProfileHelper::Get()->GetUserByProfile(
2767 Profile::FromBrowserContext(browser_context));
2768 if (user && !user->username_hash().empty()) {
2769 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
Andreea Costinase1dd9e3a2020-09-22 11:43:352770 user->GetAccountId().GetUserEmail());
John Abd-El-Malek35bfaa52019-08-20 16:22:072771 }
2772 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332773}
2774#endif
2775
Reilly Grant19aaccd2018-07-16 22:06:372776scoped_refptr<network::SharedURLLoaderFactory>
2777ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2779 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2780
2781 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372782 return nullptr;
2783
Min Qinda0d55b2018-10-12 18:30:052784 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372785 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042786}
2787
Sean Gilhulyda1ee4b2018-11-13 21:56:092788network::mojom::NetworkContext*
2789ChromeContentBrowserClient::GetSystemNetworkContext() {
2790 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2791 DCHECK(g_browser_process->system_network_context_manager());
2792 return g_browser_process->system_network_context_manager()->GetContext();
2793}
2794
Andrew Moylan17329fc2017-09-25 07:43:302795std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2796 return google_apis::GetAPIKey();
2797}
2798
Ke He21ee87f2018-05-30 02:35:322799#if defined(OS_ANDROID)
2800bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2801 // Indicate that Chrome uses the GMS core location provider.
2802 return true;
2803}
2804#endif
2805
Yeolf3dc22ca2019-04-18 17:25:322806scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412807ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542808 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412809}
2810
Mythri Alle0b8de0d2018-10-22 11:06:222811content::GeneratedCodeCacheSettings
2812ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2813 content::BrowserContext* context) {
2814 base::FilePath cache_path;
2815 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2816 // If we pass 0 for size, disk_cache will pick a default size using the
2817 // heuristics based on available disk size. These are implemented in
2818 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162819 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132820 DCHECK(g_browser_process);
2821 PrefService* local_state = g_browser_process->local_state();
2822 if (local_state) {
2823 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2824 base::FilePath disk_cache_dir =
2825 local_state->GetFilePath(prefs::kDiskCacheDir);
2826 if (!disk_cache_dir.empty())
2827 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2828 }
Mythri Ab2486572019-06-13 14:48:162829 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222830}
2831
[email protected]848dd042011-06-04 18:24:032832void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262833 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172834 int cert_error,
2835 const net::SSLInfo& ssl_info,
2836 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232837 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222838 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262839 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262840 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232841 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142842 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022843 // have a context for making the right decision, so block the
2844 // request hard, without an info bar to allow showing the insecure
2845 // content.
estark719dde52016-08-09 03:14:272846 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262847 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022848 return;
2849 }
2850
Hiroki Nakagawa7230e3412021-01-22 10:08:292851 // If the tab is being no-state prefetched, cancel the prefetcher and the
2852 // request.
2853 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
2854 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
2855 web_contents);
2856 if (no_state_prefetch_contents) {
2857 no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272858 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262859 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272860 }
[email protected]09667f02014-01-06 15:37:572861 return;
[email protected]f9034cf2011-07-21 12:43:412862 }
2863
Erik Staaba65a6032019-11-27 22:23:262864 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282865 return;
[email protected]848dd042011-06-04 18:24:032866}
2867
Katie D1882617e2020-05-06 20:06:012868#if !defined(OS_ANDROID)
2869bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2870 const GURL main_page_url) {
2871 // Desktop Reader Mode pages should never load resources with certificate
2872 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2873 // on Android: the desktop version has its own security indicator and
2874 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2875 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2876 // pages).
2877 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2878}
2879#endif
2880
Alexander Hendrichbcf2616e2018-05-18 08:21:102881namespace {
2882
Pavol Markob211ab22019-01-23 20:03:042883certificate_matching::CertificatePrincipalPattern
2884ParseCertificatePrincipalPattern(const base::Value* pattern) {
2885 return certificate_matching::CertificatePrincipalPattern::
2886 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2887}
2888
Alexander Hendrichbcf2616e2018-05-18 08:21:102889// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452890// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102891// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2892std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2893 Profile* profile,
2894 const GURL& requesting_url,
2895 net::ClientCertIdentityList& client_certs) {
2896 HostContentSettingsMap* host_content_settings_map =
2897 HostContentSettingsMapFactory::GetForProfile(profile);
2898 std::unique_ptr<base::Value> setting =
2899 host_content_settings_map->GetWebsiteSetting(
2900 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142901 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102902
Pavol Markob211ab22019-01-23 20:03:042903 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102904 return nullptr;
2905
Alexander Hendrichbcf2616e2018-05-18 08:21:102906 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042907 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2908 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102909 // |setting_dict| has the wrong format (e.g. single filter instead of a
2910 // list of filters). This content setting is only provided by
2911 // the |PolicyProvider|, which should always set it to a valid format.
2912 // Therefore, delete the invalid value.
2913 host_content_settings_map->SetWebsiteSettingDefaultScope(
2914 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142915 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Pavol Markob211ab22019-01-23 20:03:042916 return nullptr;
2917 }
2918
2919 for (const base::Value& filter : filters->GetList()) {
2920 DCHECK(filter.is_dict());
2921
2922 auto issuer_pattern = ParseCertificatePrincipalPattern(
2923 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2924 auto subject_pattern = ParseCertificatePrincipalPattern(
2925 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2926 // Use the first certificate that is matched by the filter.
2927 for (auto& client_cert : client_certs) {
2928 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2929 subject_pattern.Matches(client_cert->certificate()->subject())) {
2930 return std::move(client_cert);
2931 }
2932 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102933 }
2934
2935 return nullptr;
2936}
2937
Prashant Nevase788dcee2020-10-30 19:00:172938#if !defined(OS_ANDROID)
2939blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
2940 ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
2941 switch (native_theme_scheme) {
2942 case ui::NativeTheme::PreferredColorScheme::kDark:
2943 return blink::mojom::PreferredColorScheme::kDark;
2944 case ui::NativeTheme::PreferredColorScheme::kLight:
2945 return blink::mojom::PreferredColorScheme::kLight;
2946 }
2947
2948 NOTREACHED();
2949}
2950#endif // !defined(OS_ANDROID)
2951
2952// Returns true if preferred color scheme is modified based on at least one of
2953// the following -
2954// |url| - Last committed url.
2955// |web_contents| - For Android based on IsNightModeEnabled().
2956// |native_theme| - For other platforms based on native theme scheme.
2957bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
2958 const GURL& url,
2959 WebContents* web_contents,
2960 const ui::NativeTheme* native_theme) {
2961 auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
2962
2963#if defined(OS_ANDROID)
2964 auto* delegate = TabAndroid::FromWebContents(web_contents)
2965 ? static_cast<android::TabWebContentsDelegateAndroid*>(
2966 web_contents->GetDelegate())
2967 : nullptr;
2968 if (delegate) {
2969 web_prefs->preferred_color_scheme =
2970 delegate->IsNightModeEnabled()
2971 ? blink::mojom::PreferredColorScheme::kDark
2972 : blink::mojom::PreferredColorScheme::kLight;
2973 }
2974#else
2975 // Update based on native theme scheme.
2976 web_prefs->preferred_color_scheme =
2977 ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
2978#endif // defined(OS_ANDROID)
2979
Alex Ilin85e8fd92020-12-01 14:07:182980 bool force_light = false;
Prashant Nevase788dcee2020-10-30 19:00:172981 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
2982 // disabled; some of the UI is not yet correctly themed.
2983 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
2984 // Update based on last committed url.
Alex Ilin85e8fd92020-12-01 14:07:182985 force_light |= url.SchemeIs(content::kChromeUIScheme);
Prashant Nevase788dcee2020-10-30 19:00:172986#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Ilin85e8fd92020-12-01 14:07:182987 force_light |= url.SchemeIs(extensions::kExtensionScheme) &&
2988 url.host_piece() == extension_misc::kPdfExtensionId;
Prashant Nevase788dcee2020-10-30 19:00:172989#endif
Alex Ilin85e8fd92020-12-01 14:07:182990 }
2991
2992 // Reauth WebUI doesn't support dark mode yet because it shares the dialog
2993 // with GAIA web contents that is not correctly themed.
2994 force_light |= url.SchemeIs(content::kChromeUIScheme) &&
2995 url.host_piece() == chrome::kChromeUISigninReauthHost;
2996
2997 if (force_light) {
2998 web_prefs->preferred_color_scheme =
2999 blink::mojom::PreferredColorScheme::kLight;
Prashant Nevase788dcee2020-10-30 19:00:173000 }
3001
3002 return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
3003}
3004
Alexander Hendrichbcf2616e2018-05-18 08:21:103005} // namespace
3006
Daniel McArdle85735f52019-06-25 03:27:063007base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:193008 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:403009 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:083010 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:353011 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
Hiroki Nakagawa7230e3412021-01-22 10:08:293012 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
3013 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
3014 web_contents);
3015 if (no_state_prefetch_contents) {
3016 no_state_prefetch_contents->Destroy(
[email protected]294084d2014-01-06 22:22:023017 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:063018 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:453019 }
3020
[email protected]791879c2013-12-17 07:22:413021 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
3022 DCHECK(requesting_url.is_valid())
3023 << "Invalid URL string: https://"
3024 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:453025
Pavol Marko230ea2c92017-12-03 22:35:443026 bool may_show_cert_selection = true;
3027
davidben3b8455ae72015-03-11 19:42:193028 Profile* profile =
3029 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Yuta Hijikata235fc62b2020-12-08 03:48:323030#if BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443031 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:253032 // On the sign-in profile, never show certificate selection to the user. A
3033 // client certificate is an identifier that can be stable for a long time,
3034 // so only the administrator is allowed to decide which endpoints should see
3035 // it.
3036 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:443037
3038 content::StoragePartition* storage_partition =
3039 content::BrowserContext::GetStoragePartition(
3040 profile, web_contents->GetSiteInstance());
3041 chromeos::login::SigninPartitionManager* signin_partition_manager =
3042 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
3043 profile);
3044
3045 // On the sign-in profile, only allow client certs in the context of the
3046 // sign-in frame.
3047 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
3048 storage_partition)) {
3049 LOG(WARNING)
3050 << "Client cert requested in sign-in profile in wrong context.";
3051 // Continue without client certificate. We do this to mimic the case of no
3052 // client certificate being present in the profile's certificate store.
3053 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063054 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443055 }
3056 VLOG(1) << "Client cert requested in sign-in profile.";
3057 }
Yuta Hijikata235fc62b2020-12-08 03:48:323058#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443059
Alexander Hendrichbcf2616e2018-05-18 08:21:103060 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
3061 AutoSelectCertificate(profile, requesting_url, client_certs);
3062 if (auto_selected_identity) {
3063 // The callback will own |auto_selected_identity| and |delegate|, keeping
3064 // them alive until after ContinueWithCertificate is called.
3065 scoped_refptr<net::X509Certificate> cert =
3066 auto_selected_identity->certificate();
3067 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
3068 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:583069 base::BindOnce(
3070 &content::ClientCertificateDelegate::ContinueWithCertificate,
3071 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:323072 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:063073 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:453074 }
3075
Pavol Marko230ea2c92017-12-03 22:35:443076 if (!may_show_cert_selection) {
3077 LOG(WARNING) << "No client cert matched by policy and user selection is "
3078 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:323079 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:443080 // Continue without client certificate. We do this to mimic the case of no
3081 // client certificate being present in the profile's certificate store.
3082 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063083 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443084 }
3085
Daniel McArdle85735f52019-06-25 03:27:063086 return chrome::ShowSSLClientCertificateSelector(
3087 web_contents, cert_request_info, std::move(client_certs),
3088 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:453089}
3090
[email protected]dc73a7b2012-03-25 15:27:183091content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:563092 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:183093}
3094
Adrienne Walker80d95f02020-02-07 22:37:043095content::FeatureObserverClient*
3096ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:243097 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:043098 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:053099}
3100
peterc26c6c62014-12-10 14:13:593101content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:023102ChromeContentBrowserClient::GetPlatformNotificationService(
3103 content::BrowserContext* browser_context) {
3104 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3105 Profile* profile = Profile::FromBrowserContext(browser_context);
3106 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:043107}
3108
[email protected]9f3fba52011-06-08 20:37:193109bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:353110 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:353111 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:573112 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:353113 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:033114 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233115 const GURL& target_url,
3116 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213117 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233118 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483119 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233120 bool user_gesture,
3121 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013122 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353123 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3124 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013125
csharrison95f01e922017-04-24 18:52:353126 content::WebContents* web_contents =
3127 content::WebContents::FromRenderFrameHost(opener);
3128 Profile* profile =
3129 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3130 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013131 *no_javascript_access = false;
3132
[email protected]9f3fba52011-06-08 20:37:193133 // If the opener is trying to create a background window but doesn't have
3134 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033135 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173136#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353137 auto* process_map = extensions::ProcessMap::Get(profile);
3138 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173139 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3140 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013141 return false;
3142 }
3143
[email protected]7b54ca02012-03-02 18:06:533144 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3145 // return a recently installed Extension even if this CanCreateWindow call
3146 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013147 // because the permission check above would have caused an early return
3148 // already. We must use the full URL to find hosted apps, though, and not
3149 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553150 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353151 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293152 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013153 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023154#endif
[email protected]190e5e22013-07-27 05:59:233155
3156 return true;
[email protected]9f3fba52011-06-08 20:37:193157 }
[email protected]056efdc2013-04-06 00:14:533158
brettw00899e62016-11-12 02:10:173159#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463160 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353161 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233162 return true;
lazyboy04b75d32016-02-25 03:12:183163 }
3164
nick0fbc3922016-12-16 20:52:073165 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353166 // Intentionally duplicating |registry| code from above because we want to
3167 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3168 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183169 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353170 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143171 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533172 UMA_HISTOGRAM_ENUMERATION(
3173 "Extensions.AppLoadedInTab",
3174 ClassifyAppLoadedInTabSource(opener_url, extension),
3175 APP_LOADED_IN_TAB_SOURCE_MAX);
3176
3177 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163178 return false;
lazyboy5d5fede02016-03-10 04:10:143179 }
lazyboy04b75d32016-02-25 03:12:183180 }
[email protected]5940b0d2014-07-01 00:18:263181#endif
[email protected]190e5e22013-07-27 05:59:233182
Hiroki Nakagawa7230e3412021-01-22 10:08:293183 DCHECK(!prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:573184 web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023185
Aaron Colwell9dab1652019-12-09 18:29:493186 BlockedWindowParams blocked_params(
3187 target_url, source_origin, opener->GetSiteInstance(), referrer,
3188 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133189 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Clark DuVall8a020d622020-06-04 00:45:503190 return blocked_content::MaybeBlockPopup(
3191 web_contents, &opener_top_level_frame_url,
3192 std::make_unique<ChromePopupNavigationDelegate>(
3193 std::move(nav_params)),
3194 nullptr /*=open_url_params*/, blocked_params.features(),
3195 HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr;
[email protected]9f3fba52011-06-08 20:37:193196}
3197
[email protected]c52b2892012-03-07 11:01:023198content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443199ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003200 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513201}
3202
Yuta Hijikata235fc62b2020-12-08 03:48:323203#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D840d9532018-11-27 06:20:483204content::TtsControllerDelegate*
3205ChromeContentBrowserClient::GetTtsControllerDelegate() {
Scott Violet1644cf72020-06-24 04:51:553206 return TtsControllerDelegateImpl::GetInstance();
3207}
3208#endif
3209
3210content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
Katie D840d9532018-11-27 06:20:483211#if !defined(OS_ANDROID)
Scott Violete217e5e2020-06-22 19:18:223212 content::TtsController::GetInstance()->SetTtsEngineDelegate(
3213 TtsExtensionEngine::GetInstance());
Katie D840d9532018-11-27 06:20:483214#endif
Yuta Hijikata235fc62b2020-12-08 03:48:323215#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D4713ee42018-11-30 01:48:273216 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273217#else
3218 return nullptr;
3219#endif
3220}
3221
[email protected]64d69de42012-02-06 00:19:543222void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aaron Colwellbd02c6c2021-01-16 00:34:293223 WebContents* web_contents,
Aran Gilmanf010bdd2019-08-28 19:55:443224 WebPreferences* web_prefs) {
3225 Profile* profile =
Aaron Colwellbd02c6c2021-01-16 00:34:293226 Profile::FromBrowserContext(web_contents->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063227 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063228
aelias0df335a2017-03-02 23:43:513229// Fill font preferences. These are not registered on Android
3230// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453231#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193232 FontFamilyCache::FillFontFamilyMap(profile,
3233 prefs::kWebKitStandardFontFamilyMap,
3234 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443235 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193236 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443237 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193238 &web_prefs->serif_font_family_map);
3239 FontFamilyCache::FillFontFamilyMap(profile,
3240 prefs::kWebKitSansSerifFontFamilyMap,
3241 &web_prefs->sans_serif_font_family_map);
3242 FontFamilyCache::FillFontFamilyMap(profile,
3243 prefs::kWebKitCursiveFontFamilyMap,
3244 &web_prefs->cursive_font_family_map);
3245 FontFamilyCache::FillFontFamilyMap(profile,
3246 prefs::kWebKitFantasyFontFamilyMap,
3247 &web_prefs->fantasy_font_family_map);
3248 FontFamilyCache::FillFontFamilyMap(profile,
3249 prefs::kWebKitPictographFontFamilyMap,
3250 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063251
[email protected]64d69de42012-02-06 00:19:543252 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403253 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543254 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403255 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543256 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403257 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543258 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403259 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513260#endif
[email protected]f3986f82012-01-03 20:00:063261
[email protected]ddf72142012-05-22 04:52:403262 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063263
[email protected]64d69de42012-02-06 00:19:543264 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063265 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213266 web_prefs->javascript_can_access_clipboard =
3267 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543268 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063269
[email protected]ddf72142012-05-22 04:52:403270 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543271 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573272
Avi Drissman1aa6cb92019-01-23 15:58:383273 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543274 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573275
[email protected]ddf72142012-05-22 04:52:403276 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543277 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543278 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403279 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063280
Zhenyao Moa3fda9972017-09-16 01:34:403281 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3282 web_prefs->webgl1_enabled = false;
3283 web_prefs->webgl2_enabled = false;
3284 }
[email protected]f3986f82012-01-03 20:00:063285
[email protected]64d69de42012-02-06 00:19:543286 web_prefs->allow_running_insecure_content =
3287 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323288#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053289 web_prefs->font_scale_factor =
3290 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323291 web_prefs->force_enable_zoom =
3292 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493293#endif
Becky Zhoubbfbde32019-02-20 17:07:593294 web_prefs->force_dark_mode_enabled =
3295 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393296
Yuta Hijikata235fc62b2020-12-08 03:48:323297#if BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhallda2659142020-05-14 06:04:373298 web_prefs->always_show_focus =
3299 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
Alice Boxhalla9aafba42020-06-24 05:42:513300#else
3301 if (features::IsAccessibilityFocusHighlightEnabled()) {
3302 web_prefs->always_show_focus =
3303 prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled);
3304 }
Alice Boxhallda2659142020-05-14 06:04:373305#endif
3306
[email protected]af4256d52013-06-04 20:39:073307#if defined(OS_ANDROID)
3308 web_prefs->password_echo_enabled =
3309 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3310#else
[email protected]9d06d88d2012-02-23 22:37:083311 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073312#endif
3313
[email protected]64d69de42012-02-06 00:19:543314 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063315 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543316 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063317 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3318
brettw00899e62016-11-12 02:10:173319#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053320 std::string image_animation_policy =
3321 prefs->GetString(prefs::kAnimationPolicy);
Gyuyoung Kim3b4703d2020-09-18 00:25:493322 if (image_animation_policy == kAnimationPolicyOnce) {
je_julie.kim7fbb5a1a2015-02-09 17:26:053323 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573324 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
Gyuyoung Kim3b4703d2020-09-18 00:25:493325 } else if (image_animation_policy == kAnimationPolicyNone) {
Gyuyoung Kim1ac4ca782020-09-11 03:32:513326 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573327 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
Gyuyoung Kim3b4703d2020-09-18 00:25:493328 } else {
Gyuyoung Kim1e9d3c32020-10-12 14:04:573329 web_prefs->animation_policy =
3330 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
Gyuyoung Kim3b4703d2020-09-18 00:25:493331 }
je_julie.kim7fbb5a1a2015-02-09 17:26:053332#endif
3333
[email protected]f3986f82012-01-03 20:00:063334 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153335 web_prefs->default_encoding =
3336 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543337 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403338 prefs->ClearPref(prefs::kDefaultCharset);
3339 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063340 }
[email protected]64d69de42012-02-06 00:19:543341 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063342
mkwst05544102015-01-10 20:26:163343 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3344 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073345 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163346 web_prefs->strict_mixed_content_checking = true;
3347 web_prefs->strict_powerful_feature_restrictions = true;
3348 }
3349
Robert Ogdencf2872d2019-03-19 18:59:373350 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213351
Tarun Bansal333819e2018-05-15 16:38:423352 web_prefs->data_saver_holdback_web_api_enabled =
3353 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3354 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423355
Aaron Colwellbd02c6c2021-01-16 00:34:293356 if (web_contents) {
Ian Vollick6243dfe02018-03-08 01:08:533357#if defined(OS_ANDROID)
Aaron Colwellbd02c6c2021-01-16 00:34:293358 auto* delegate = TabAndroid::FromWebContents(web_contents)
Jinsuk Kima3d393ce2019-05-27 00:57:423359 ? static_cast<android::TabWebContentsDelegateAndroid*>(
Aaron Colwellbd02c6c2021-01-16 00:34:293360 web_contents->GetDelegate())
Jinsuk Kima3d393ce2019-05-27 00:57:423361 : nullptr;
3362 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133363 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423364 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133365
Mounir Lamouri9c99a1602018-07-05 15:01:443366 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423367 delegate->IsPictureInPictureEnabled();
zqzhang183dc822017-02-15 17:04:113368 }
Ian Vollick6243dfe02018-03-08 01:08:533369#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533370
Mounir Lamouri6926107f2019-01-31 18:17:433371 // web_app_scope value is platform specific.
3372#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423373 if (delegate)
3374 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433375#elif BUILDFLAG(ENABLE_EXTENSIONS)
3376 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253377 web_prefs->web_app_scope = GURL();
3378 // Set |web_app_scope| based on the app associated with the app window if
3379 // any. Note that the app associated with the window never changes, even
3380 // if the app navigates off scope. This is not a problem because we still
3381 // want to use the scope of the app associated with the window, not the
3382 // WebContents.
Aaron Colwellbd02c6c2021-01-16 00:34:293383 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
Alan Cutterd0bd51902019-05-22 04:15:233384 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593385 browser->app_controller()->HasAppId()) {
3386 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3387 const web_app::AppRegistrar& registrar =
3388 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3389 if (registrar.IsLocallyInstalled(app_id))
3390 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433391 }
Mounir Lamouri6926107f2019-01-31 18:17:433392 }
3393#endif
3394
Aaron Colwellbd02c6c2021-01-16 00:34:293395 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(web_contents);
zqzhang183dc822017-02-15 17:04:113396 }
zqzhang93e959d12017-03-16 13:10:203397
Aaron Colwellbd02c6c2021-01-16 00:34:293398 web_prefs->lazy_load_enabled =
3399 !web_contents || !web_contents->GetDelegate() ||
3400 web_contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003401
Scott Little878f7d6702018-05-31 22:09:063402 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3403 const char* param_name =
3404 web_prefs->data_saver_enabled
3405 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3406 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3407 "saver_enabled";
3408
3409 base::StringPairs pairs;
3410 base::SplitStringIntoKeyValuePairs(
3411 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3412 param_name),
3413 ':', ',', &pairs);
3414
3415 for (const auto& pair : pairs) {
3416 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3417 net::GetEffectiveConnectionTypeForName(pair.first);
3418 int value = 0;
3419 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223420 web_prefs->lazy_frame_loading_distance_thresholds_px[static_cast<
3421 EffectiveConnectionType>(effective_connection_type.value())] =
3422 value;
Scott Little878f7d6702018-05-31 22:09:063423 }
3424 }
3425 }
3426
rajendrantd8026342018-08-29 08:08:393427 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3428 const char* param_name =
3429 web_prefs->data_saver_enabled
3430 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3431 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3432 "saver_enabled";
3433
3434 base::StringPairs pairs;
3435 base::SplitStringIntoKeyValuePairs(
3436 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3437 param_name),
3438 ':', ',', &pairs);
3439
3440 for (const auto& pair : pairs) {
3441 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3442 net::GetEffectiveConnectionTypeForName(pair.first);
3443 int value = 0;
3444 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223445 web_prefs->lazy_image_loading_distance_thresholds_px[static_cast<
3446 EffectiveConnectionType>(effective_connection_type.value())] =
3447 value;
rajendrantd8026342018-08-29 08:08:393448 }
3449 }
rajendrant3daeae292019-09-20 07:57:543450
3451 pairs.clear();
3452 base::SplitStringIntoKeyValuePairs(
3453 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3454 "lazy_image_first_k_fully_load"),
3455 ':', ',', &pairs);
3456
3457 for (const auto& pair : pairs) {
3458 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3459 net::GetEffectiveConnectionTypeForName(pair.first);
3460 int value = 0;
3461 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223462 web_prefs->lazy_image_first_k_fully_load[static_cast<
3463 EffectiveConnectionType>(effective_connection_type.value())] =
rajendrant3daeae292019-09-20 07:57:543464 value;
3465 }
3466 }
rajendrantd8026342018-08-29 08:08:393467 }
3468
Tarun Bansald10f17a02018-09-13 00:23:173469 if (base::FeatureList::IsEnabled(
3470 features::kNetworkQualityEstimatorWebHoldback)) {
3471 std::string effective_connection_type_param =
3472 base::GetFieldTrialParamValueByFeature(
3473 features::kNetworkQualityEstimatorWebHoldback,
3474 "web_effective_connection_type_override");
3475
3476 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3477 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3478 DCHECK(effective_connection_type_param.empty() ||
3479 effective_connection_type);
3480 if (effective_connection_type) {
3481 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3482 effective_connection_type.value());
3483 web_prefs->network_quality_estimator_web_holdback =
Gyuyoung Kimd6d4f992020-11-20 14:13:223484 static_cast<EffectiveConnectionType>(
3485 effective_connection_type.value());
Tarun Bansald10f17a02018-09-13 00:23:173486 }
3487 }
3488
François Beaufort4f8107d2018-03-05 12:12:103489#if !defined(OS_ANDROID)
Aaron Colwellbd02c6c2021-01-16 00:34:293490 if (IsAutoplayAllowedByPolicy(web_contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593491 // If autoplay is allowed by policy then force the no user gesture required
3492 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103493 web_prefs->autoplay_policy =
Gyuyoung Kimf6c02a262020-10-13 01:36:133494 blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553495 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593496 web_prefs->autoplay_policy ==
Gyuyoung Kimf6c02a262020-10-13 01:36:133497 blink::mojom::AutoplayPolicy::
Gyuyoung Kim1ac4ca782020-09-11 03:32:513498 kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553499 // If the autoplay disable settings feature is enabled and the autoplay
3500 // policy is set to using the unified policy then set the default autoplay
3501 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593502 web_prefs->autoplay_policy =
3503 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
Gyuyoung Kimf6c02a262020-10-13 01:36:133504 ? blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired
3505 : blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103506 }
3507#endif // !defined(OS_ANDROID)
3508
Prashant Nevase788dcee2020-10-30 19:00:173509 switch (GetWebTheme()->GetPreferredContrast()) {
Alison Maher3b11e942020-10-27 17:17:503510 case ui::NativeTheme::PreferredContrast::kNoPreference:
3511 web_prefs->preferred_contrast =
3512 blink::mojom::PreferredContrast::kNoPreference;
3513 break;
3514 case ui::NativeTheme::PreferredContrast::kMore:
3515 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kMore;
3516 break;
3517 case ui::NativeTheme::PreferredContrast::kLess:
3518 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kLess;
3519 break;
3520 }
3521
Aaron Colwellbd02c6c2021-01-16 00:34:293522 UpdatePreferredColorScheme(
3523 web_prefs, web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL(),
3524 web_contents, GetWebTheme());
Elly Fong-Jonesf92897392019-01-24 16:05:493525
Rakina Zata Amni347b70902020-07-22 10:49:043526 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Alison Maher7f366dc62020-03-03 19:46:003527
Abigail Kleina81f2e22020-05-04 14:32:413528 base::Optional<ui::CaptionStyle> style =
3529 captions::GetCaptionStyleFromUserSettings(prefs,
3530 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213531 if (style) {
3532 web_prefs->text_track_background_color = style->background_color;
3533 web_prefs->text_track_text_color = style->text_color;
3534 web_prefs->text_track_text_size = style->text_size;
3535 web_prefs->text_track_text_shadow = style->text_shadow;
3536 web_prefs->text_track_font_family = style->font_family;
3537 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563538 web_prefs->text_track_window_color = style->window_color;
3539 web_prefs->text_track_window_padding = style->window_padding;
3540 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213541 }
Elly Fong-Jonesf92897392019-01-24 16:05:493542
Piotr Bialecki3fde5fa2021-01-23 01:08:033543#if defined(OS_ANDROID)
3544 // If the pref is not set, the default value (true) will be used:
3545 web_prefs->webxr_immersive_ar_allowed =
3546 prefs->GetBoolean(prefs::kWebXRImmersiveArEnabled);
3547#endif
3548
3549 for (ChromeContentBrowserClientParts* parts : extra_parts_)
3550 parts->OverrideWebkitPrefs(web_contents, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363551}
3552
Rakina Zata Amni347b70902020-07-22 10:49:043553bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation(
3554 WebContents* web_contents,
3555 WebPreferences* prefs) {
Prashant Nevase788dcee2020-10-30 19:00:173556 return UpdatePreferredColorScheme(prefs, web_contents->GetLastCommittedURL(),
3557 web_contents, GetWebTheme());
Rakina Zata Amni347b70902020-07-22 10:49:043558}
3559
[email protected]b8148ac2011-07-13 22:03:253560void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3561 BrowserURLHandler* handler) {
Nicolas Ouellet-Payeur5e6d2102020-08-21 16:28:413562 // The group policy NTP URL handler must be registered before the other NTP
3563 // URL handlers below. Also register it before the "parts" handlers, so the
3564 // NTP policy takes precedence over extensions that override the NTP.
3565 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3566 BrowserURLHandler::null_handler());
3567
[email protected]a48ab7112014-08-01 16:48:033568 for (size_t i = 0; i < extra_parts_.size(); ++i)
3569 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253570
Lukasz Anforowicz7b078792020-10-20 17:04:313571 // Handler to rewrite chrome://about and chrome://sync URLs.
3572 handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
[email protected]b8148ac2011-07-13 22:03:253573 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033574
zpengdb4a58e2017-01-10 17:40:323575#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033576 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353577 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033578 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453579#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033580 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133581 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3582 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453583#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033584
[email protected]b8148ac2011-07-13 22:03:253585 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313586 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3587 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253588}
3589
[email protected]650b2d52013-02-10 03:41:453590base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493591 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323592}
3593
[email protected]c9b6eb62011-10-18 20:49:393594std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3595 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3596}
3597
Dominik Röttsches47347832019-03-12 17:45:013598base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3599 base::FilePath user_data_dir;
3600 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3601 DCHECK(!user_data_dir.empty());
3602 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3603}
3604
jmadill57b52d42015-08-21 18:16:133605base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3606 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523607 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133608 DCHECK(!user_data_dir.empty());
3609 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3610}
3611
Khushal7ca0b782018-07-20 05:53:273612base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3613 base::FilePath user_data_dir;
3614 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3615 DCHECK(!user_data_dir.empty());
3616 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3617}
3618
[email protected]b7631cc2012-09-15 05:08:383619void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3620 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163621#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553622 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543623#endif
[email protected]b7631cc2012-09-15 05:08:383624}
3625
[email protected]0c7193742012-11-07 19:05:033626content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443627ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173628#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553629 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033630 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443631 nacl::NaClProcessHost* host =
3632 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3633 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033634 // Found the plugin.
3635 return host->browser_ppapi_host();
3636 }
3637 ++iter;
3638 }
[email protected]a56f8322014-07-16 21:13:553639#endif
Aran Gilmanf010bdd2019-08-28 19:55:443640 return nullptr;
[email protected]0c7193742012-11-07 19:05:033641}
3642
[email protected]38cd8f7f2012-06-15 22:06:073643bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583644 content::BrowserContext* browser_context,
3645 const GURL& url,
[email protected]dda54822013-06-15 01:26:393646 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123647 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163648#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553649 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193650 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403651#else
[email protected]a658d452012-03-02 12:45:293652 return false;
[email protected]93f72062013-05-29 20:29:403653#endif
[email protected]e461da2f2012-02-16 19:06:403654}
3655
adrian.belgund54465ba2016-05-18 10:03:583656bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3657 content::BrowserContext* browser_context,
3658 const GURL& url) {
brettw4b461082016-11-19 18:55:163659#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583660 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3661 browser_context, url);
3662#else
3663 return false;
3664#endif
3665}
3666
adrian.belgun5b341c72016-06-22 22:24:083667std::unique_ptr<content::VpnServiceProxy>
3668ChromeContentBrowserClient::GetVpnServiceProxy(
3669 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173670#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083671 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3672 browser_context);
3673#else
3674 return nullptr;
3675#endif
3676}
3677
Brett Wilson804e83c2017-08-18 22:57:333678std::unique_ptr<ui::SelectFilePolicy>
3679ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3680 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433681}
3682
[email protected]7d9424702013-04-14 13:14:163683void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3684 std::vector<std::string>* additional_allowed_schemes) {
3685 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3686 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483687 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293688 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033689 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3690 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3691 additional_allowed_schemes);
3692 }
[email protected]7d9424702013-04-14 13:14:163693}
3694
Ayu Ishiifbb1fad2020-06-22 20:15:073695void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist(
falkenad185092016-06-16 06:10:023696 std::set<std::string>* schemes) {
Ayu Ishiifbb1fad2020-06-22 20:15:073697 *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023698}
3699
[email protected]c79859b82014-03-20 22:43:553700void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313701 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033702 for (size_t i = 0; i < extra_parts_.size(); ++i)
3703 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553704}
3705
[email protected]f19bbf62013-07-09 01:22:323706void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313707 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533708 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003709 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3710 additional_backends) {
Yuta Hijikata235fc62b2020-12-08 03:48:323711#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]cd501a72014-08-22 19:58:313712 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313713 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313714 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093715 auto backend = std::make_unique<chromeos::FileSystemBackend>(
David Black8f8c1eb2020-12-09 04:02:233716 Profile::FromBrowserContext(browser_context),
Jeremy Romanec48d7a2018-03-01 17:35:093717 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3718 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473719 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093720 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3721 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053722 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3723 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343724 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3725 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473726 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323727 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313728 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003729 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313730#endif
[email protected]445b7db2013-08-02 04:58:273731
[email protected]a48ab7112014-08-01 16:48:033732 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3733 extra_parts_[i]->GetAdditionalFileSystemBackends(
3734 browser_context, storage_partition_path, additional_backends);
3735 }
[email protected]02250952013-04-24 23:52:533736}
3737
Avi Drissman2e458df2020-07-29 16:24:313738#if defined(OS_POSIX) && !defined(OS_MAC)
[email protected]a1733df2012-06-22 11:24:183739void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173740 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383741 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203742 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123743#if defined(OS_ANDROID)
3744 base::MemoryMappedFile::Region region;
3745 int fd = ui::GetMainAndroidPackFd(&region);
3746 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003747
Samuel Huang31eadf082019-08-28 19:50:433748 // For Android: Native resources for DFMs should only be used by the browser
3749 // process. Their file descriptors and memory mapped file regions are not
3750 // passed to child processes.
3751
jcivellie6f550742017-01-06 19:29:123752 fd = ui::GetCommonResourcesPackFd(&region);
3753 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393754
jcivellie6f550742017-01-06 19:29:123755 fd = ui::GetLocalePackFd(&region);
3756 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383757
zpeng368afac82017-07-17 18:47:453758 // Optional secondary locale .pak file.
3759 fd = ui::GetSecondaryLocalePackFd(&region);
3760 if (fd != -1) {
3761 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3762 }
3763
[email protected]09560f7f2014-06-10 18:40:283764 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523765 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283766 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023767#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383768 int crash_signal_fd = GetCrashSignalFD(command_line);
3769 if (crash_signal_fd >= 0) {
Ken Rockot69fbb962020-09-21 22:22:033770 mappings->Share(kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383771 }
jcivellie6f550742017-01-06 19:29:123772}
Avi Drissman2e458df2020-07-29 16:24:313773#endif // defined(OS_POSIX) && !defined(OS_MAC)
[email protected]b80f68432011-05-02 17:22:303774
[email protected]4a65826d2011-08-25 16:04:013775#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033776base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Robert Sesek7d0b49b2020-07-08 18:31:273777 sandbox::policy::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033778 // TODO(wfh): Add support for more process types here. crbug.com/499523
3779 switch (sandbox_type) {
Robert Sesek7d0b49b2020-07-08 18:31:273780 case sandbox::policy::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363781 return base::string16(install_static::GetSandboxSidPrefix()) +
3782 L"129201922";
Robert Sesek7d0b49b2020-07-08 18:31:273783 case sandbox::policy::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033784 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273785 case sandbox::policy::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033786 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273787 case sandbox::policy::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363788 return base::string16(install_static::GetSandboxSidPrefix()) +
3789 L"129201925";
Robert Sesek7d0b49b2020-07-08 18:31:273790 case sandbox::policy::SandboxType::kNoSandbox:
3791 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3792 case sandbox::policy::SandboxType::kXrCompositing:
3793 case sandbox::policy::SandboxType::kNetwork:
3794 case sandbox::policy::SandboxType::kCdm:
3795 case sandbox::policy::SandboxType::kPrintCompositor:
3796 case sandbox::policy::SandboxType::kAudio:
3797 case sandbox::policy::SandboxType::kSpeechRecognition:
3798 case sandbox::policy::SandboxType::kProxyResolver:
3799 case sandbox::policy::SandboxType::kPdfConversion:
3800 case sandbox::policy::SandboxType::kSharingService:
3801 case sandbox::policy::SandboxType::kVideoCapture:
3802 case sandbox::policy::SandboxType::kIconReader:
Frank Li49bb6912020-09-30 18:05:523803 case sandbox::policy::SandboxType::kMediaFoundationCdm:
Alex Gough9ab468a6c32019-12-10 19:10:223804 // Should never reach here.
3805 CHECK(0);
wfh182da09c2015-06-24 19:23:033806 return base::string16();
wfh182da09c2015-06-24 19:23:033807 }
wfh182da09c2015-06-24 19:23:033808}
3809
Will Harrisaa8939b2021-01-26 21:54:393810// Note: Only use sparingly to add Chrome specific sandbox functionality here.
3811// Other code should reside in the content layer. Changes to this function
3812// should be reviewed by the security team.
3813bool ChromeContentBrowserClient::PreSpawnChild(
3814 sandbox::TargetPolicy* policy,
3815 sandbox::policy::SandboxType sandbox_type,
3816 ChildSpawnFlags flags) {
3817 switch (sandbox_type) {
3818 case sandbox::policy::SandboxType::kRenderer: {
3819 // Does not work under component build because all the component DLLs
3820 // would need to be manually added and maintained. Does not work under
3821 // ASAN build because ASAN has not yet fully initialized its
3822 // instrumentation by the time the CIG intercepts run.
Will Harris1b9b4152019-08-21 22:33:503823#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisaa8939b2021-01-26 21:54:393824 if ((flags & ChildSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3825 return true;
3826 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3827 return true;
Will Harrisc196ed942019-08-03 03:45:303828
Will Harrisaa8939b2021-01-26 21:54:393829 // Only enable signing mitigation if launching from chrome.exe.
3830 base::FilePath exe_path;
3831 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3832 return true;
3833 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3834 return true;
Will Harrisc196ed942019-08-03 03:45:303835
Will Harrisaa8939b2021-01-26 21:54:393836 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3837 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
3838 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
3839 if (result != sandbox::SBOX_ALL_OK)
3840 return false;
Will Harrisc196ed942019-08-03 03:45:303841
Will Harrisaa8939b2021-01-26 21:54:393842 // Allow loading Chrome's DLLs.
3843 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
3844 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3845 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3846 GetModulePath(dll).value().c_str());
3847 if (result != sandbox::SBOX_ALL_OK)
3848 return false;
3849 }
3850 return true;
Will Harris1b9b4152019-08-21 22:33:503851#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisaa8939b2021-01-26 21:54:393852 return true;
3853 }
3854 case sandbox::policy::SandboxType::kNetwork:
3855 case sandbox::policy::SandboxType::kUtility:
3856 case sandbox::policy::SandboxType::kGpu:
3857 case sandbox::policy::SandboxType::kPpapi:
3858 case sandbox::policy::SandboxType::kNoSandbox:
3859 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3860 case sandbox::policy::SandboxType::kXrCompositing:
3861 case sandbox::policy::SandboxType::kCdm:
3862 case sandbox::policy::SandboxType::kPrintCompositor:
3863 case sandbox::policy::SandboxType::kAudio:
3864 case sandbox::policy::SandboxType::kSpeechRecognition:
3865 case sandbox::policy::SandboxType::kProxyResolver:
3866 case sandbox::policy::SandboxType::kPdfConversion:
3867 case sandbox::policy::SandboxType::kSharingService:
3868 case sandbox::policy::SandboxType::kVideoCapture:
3869 case sandbox::policy::SandboxType::kIconReader:
3870 case sandbox::policy::SandboxType::kMediaFoundationCdm:
3871 return true;
3872 }
[email protected]34f48682013-03-20 00:30:183873}
Will Harris956e0ca2019-08-23 20:47:393874
3875bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3876 PrefService* local_state = g_browser_process->local_state();
3877 if (local_state &&
3878 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3879 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3880 return false;
3881 return true;
3882}
3883
wfhc91e9672016-01-27 00:14:203884#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013885
Lingqi Chi775e60752020-12-14 06:31:163886void ChromeContentBrowserClient::RegisterMojoBinderPoliciesForPrerendering(
3887 content::MojoBinderPolicyMap& policy_map) {
3888 // Changes to `policy_map` should be made in
3889 // RegisterChromeMojoBinderPoliciesForPrerendering() which requires security
3890 // review.
3891 RegisterChromeMojoBinderPoliciesForPrerendering(policy_map);
3892}
3893
peterbbcccc12015-02-11 22:23:333894void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373895 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333896 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293897 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083898 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373899
3900 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083901
zpengdb4a58e2017-01-10 17:40:323902#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223903 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293904 std::move(callback));
jam1c5a91492016-02-24 20:47:533905#else
cm.sanchi2522bc92017-12-04 08:04:133906 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3907 params.url, params.transition);
3908 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083909
3910 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293911 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333912#endif
mlamourieb40d552015-02-05 00:57:083913}
3914
zhaobinf3704f82017-01-12 07:19:363915content::ControllerPresentationServiceDelegate*
3916ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3917 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463918 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093919 return media_router::PresentationServiceDelegateImpl::
3920 GetOrCreateForWebContents(web_contents);
3921 }
haibinlu9e605a92015-06-06 03:45:093922 return nullptr;
3923}
3924
zhaobinf3704f82017-01-12 07:19:363925content::ReceiverPresentationServiceDelegate*
3926ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3927 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363928 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3929 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3930 // created for offscreen presentations. The WebContents must belong to
3931 // an incognito profile.
3932 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3933 FromWebContents(web_contents)) {
3934 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3935 return impl;
3936 }
3937 }
zhaobinf3704f82017-01-12 07:19:363938 return nullptr;
3939}
3940
avid6d88b912017-01-13 00:16:003941std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473942ChromeContentBrowserClient::CreateThrottlesForNavigation(
3943 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003944 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273945
bmcquadeb4556552017-03-24 22:24:373946 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3947 // that may delay or cancel navigations, so only NavigationThrottles that
3948 // don't delay or cancel navigations (e.g. throttles that are only observing
3949 // callbacks without affecting navigation behavior) should be added before
3950 // MetricsNavigationThrottle.
3951 if (handle->IsInMainFrame()) {
3952 throttles.push_back(
3953 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3954 }
3955
Yuta Hijikata235fc62b2020-12-08 03:48:323956#if BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063957 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283958 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3959 &throttles);
Yuta Hijikata235fc62b2020-12-08 03:48:323960#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063961
mmenkedb2637ff2017-03-30 23:59:423962#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213963 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283964 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
3965 &throttles);
mmenkedb2637ff2017-03-30 23:59:423966#endif
3967
clamy40c9e142015-09-29 11:18:473968#if defined(OS_ANDROID)
3969 // TODO(davidben): This is insufficient to integrate with prerender properly.
3970 // https://crbug.com/370595
Hiroki Nakagawa7230e3412021-01-22 10:08:293971 prerender::NoStatePrefetchContents* no_state_prefetch_contents =
3972 prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents(
Mugdha Lakhani2c6b23af2020-07-31 14:55:573973 handle->GetWebContents());
Hiroki Nakagawa7230e3412021-01-22 10:08:293974 if (!no_state_prefetch_contents && handle->IsInMainFrame()) {
clamy40c9e142015-09-29 11:18:473975 throttles.push_back(
3976 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303977 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473978 }
Min Qin0ab0e162017-11-14 21:57:193979 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043980
3981#if BUILDFLAG(DFMIFY_DEV_UI)
3982 // If the DevUI DFM is already installed, then this is a no-op, except for the
3983 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:283984 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
3985 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:043986#endif // BUILDFLAG(DFMIFY_DEV_UI)
3987
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573988#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473989 if (handle->IsInMainFrame()) {
3990 // Redirect some navigations to apps that have registered matching URL
3991 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:283992 MaybeAddThrottle(
3993 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
3994 &throttles);
clamy40c9e142015-09-29 11:18:473995 }
3996#endif
clamy49678312015-10-22 21:59:003997
Yuta Hijikata235fc62b2020-12-08 03:48:323998#if BUILDFLAG(IS_CHROMEOS_ASH)
clamy49678312015-10-22 21:59:003999 // Check if we need to add merge session throttle. This throttle will postpone
4000 // loading of main frames.
4001 if (handle->IsInMainFrame()) {
4002 // Add interstitial page while merge session process (cookie reconstruction
4003 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4004 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024005 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4006 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004007 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4008 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4009 }
Maggie Caia2f03f52019-04-02 02:13:284010 }
4011#endif
djacobo21e56e02016-07-02 01:14:314012
Maggie Caia2f03f52019-04-02 02:13:284013#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:104014 auto url_to_apps_throttle =
Yuta Hijikata235fc62b2020-12-08 03:48:324015#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Caic08b7d42020-05-05 03:51:104016 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
4017 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
4018 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284019#else
Maggie Caic08b7d42020-05-05 03:51:104020 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284021#endif
Maggie Caic08b7d42020-05-05 03:51:104022 if (url_to_apps_throttle)
4023 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004024#endif
4025
brettw00899e62016-11-12 02:10:174026#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004027 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094028 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514029
Chris Hamiltonab4722122020-05-13 18:01:284030 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
4031 ->GetUserScriptListener()
4032 ->CreateNavigationThrottle(handle),
4033 &throttles);
naskob9164c42016-06-07 01:21:354034#endif
4035
bauerb8f9c37742017-03-30 15:04:124036#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:214037 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284038 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
4039 &throttles);
bauerb8f9c37742017-03-30 15:04:124040#endif
4041
csharrisone985ebc2017-04-04 17:05:034042 content::WebContents* web_contents = handle->GetWebContents();
Colin Blundell0ec5d642020-10-06 17:29:524043 if (auto* throttle_manager =
4044 subresource_filter::ContentSubresourceFilterThrottleManager::
4045 FromWebContents(web_contents)) {
4046 throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles);
csharrisone985ebc2017-04-04 17:05:034047 }
4048
zhenw6edd49c2017-07-12 05:49:454049#if !defined(OS_ANDROID)
4050 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4051 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:284052 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
4053 MaybeCreateThrottleFor(handle),
4054 &throttles);
zhenw6edd49c2017-07-12 05:49:454055#endif
4056
Bettinafd0c1102020-08-06 00:23:434057#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Chris Hamiltonab4722122020-05-13 18:01:284058 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
4059 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:094060#endif
4061
Lukasz Anforowicz7724d092019-10-03 23:50:214062 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284063 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
4064 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:274065
Chris Hamiltonab4722122020-05-13 18:01:284066 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
4067 &throttles);
Amber Won6b5edc752017-08-17 19:23:544068
Chris Hamiltonab4722122020-05-13 18:01:284069 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:514070
Jonathan Mengedoht42a19bb2020-07-28 14:10:164071 MaybeAddThrottle(
4072 WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
4073 &throttles);
4074
Yann Dago3256b872021-01-13 18:48:034075 policy::PolicyService* policy_service = nullptr;
4076 Profile* profile = Profile::FromBrowserContext(
4077 handle->GetWebContents()->GetBrowserContext());
4078 if (profile && profile->GetProfilePolicyConnector())
4079 policy_service = profile->GetProfilePolicyConnector()->policy_service();
4080
Aaron Colwellf94fd97a2020-07-21 19:37:084081 throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
Yann Dago3256b872021-01-13 18:48:034082 handle, handle->GetWebContents()->GetBrowserContext(), policy_service));
Doug Turner9dcaf5962017-12-21 04:38:534083
Colin Blundelleaa7377bf2020-01-22 08:49:104084 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
4085 // the relevant extension API whenever an SSL interstitial is shown.
4086 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
4087 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:284088 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4089 handle,
4090 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Mustafa Emre Acer06028d792021-01-05 19:48:514091 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp),
4092 base::BindOnce(
4093 &TypedNavigationUpgradeThrottle::
4094 ShouldIgnoreInterstitialBecauseNavigationDefaultedToHttps)));
Lucas Garron94b16052017-11-11 01:58:124095
Emily Starkd6896cd32019-08-21 04:55:544096 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4097
Mustafa Emre Acer06028d792021-01-05 19:48:514098 if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) {
4099 MaybeAddThrottle(
4100 TypedNavigationUpgradeThrottle::MaybeCreateThrottleFor(handle),
4101 &throttles);
4102 }
4103
Dmitry Gozman57b92ce2017-12-28 22:24:544104#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284105 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4106 &throttles);
4107
4108 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4109 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544110#endif
4111
Carlos IL800e3502020-04-30 16:35:594112 throttles.push_back(
4113 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034114
Mustafa Emre Acer97be4752020-05-13 01:24:434115 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4116 throttles.push_back(
4117 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4118 handle));
4119 }
4120
Yuta Hijikata235fc62b2020-12-08 03:48:324121// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
4122// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:314123#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:324124 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Chris Hamiltonab4722122020-05-13 18:01:284125 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4126 MaybeCreateThrottleFor(handle),
4127 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134128#endif
4129
Yuta Hijikata235fc62b2020-12-08 03:48:324130#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchuk762c40d2020-05-11 15:10:374131 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284132 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
4133 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374134#endif
4135
Chris Hamiltonab4722122020-05-13 18:01:284136 auto* performance_manager_registry =
4137 performance_manager::PerformanceManagerRegistry::GetInstance();
4138 if (performance_manager_registry) {
4139 MaybeAddThrottles(
4140 performance_manager_registry->CreateThrottlesForNavigation(handle),
4141 &throttles);
4142 }
4143
Carlos IL06e6c8c2020-07-28 00:25:194144 if (profile && profile->GetPrefs()) {
4145 MaybeAddThrottle(
4146 security_interstitials::InsecureFormNavigationThrottle::
4147 MaybeCreateNavigationThrottle(
4148 handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
4149 profile->GetPrefs()),
4150 &throttles);
4151 }
Carlos IL1a5edec2020-06-12 17:56:574152
Ken Rockot4408a0f2020-07-27 19:40:544153 if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) {
4154 MaybeAddThrottle(
4155 error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle),
4156 &throttles);
4157 }
4158
Liquan (Max) Gud648f452020-12-18 05:28:444159 MaybeAddThrottle(
4160 payments::PaymentHandlerNavigationThrottle::MaybeCreateThrottleFor(
4161 handle),
4162 &throttles);
Liquan (Max) Gud648f452020-12-18 05:28:444163
dchenge73d8520c2015-12-27 01:19:094164 return throttles;
clamy40c9e142015-09-29 11:18:474165}
4166
clamy1e5574e2016-09-29 16:48:444167std::unique_ptr<content::NavigationUIData>
4168ChromeContentBrowserClient::GetNavigationUIData(
4169 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094170 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444171}
4172
Xiaohan Wanga4e41842018-06-26 18:45:104173void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4174 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104175 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124176 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Jeffrey Kardatzke614424232020-12-12 00:54:064177#if (defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)) && \
4178 BUILDFLAG(ENABLE_LIBRARY_CDMS) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104179 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334180 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104181 }
4182#endif
4183}
4184
[email protected]487974a2014-06-13 16:49:014185content::DevToolsManagerDelegate*
4186ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354187#if defined(OS_ANDROID)
4188 return new DevToolsManagerDelegateAndroid();
4189#else
[email protected]487974a2014-06-13 16:49:014190 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354191#endif
[email protected]487974a2014-06-13 16:49:014192}
4193
Rayan Kanso411e84e2019-02-13 15:27:404194void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4195 content::BrowserContext* browser_context,
4196 int service,
4197 base::Time expiration_time) {
4198 Profile* profile = Profile::FromBrowserContext(browser_context);
4199 DCHECK(profile);
4200
4201 auto* pref_service = profile->GetPrefs();
4202 DCHECK(pref_service);
4203
4204 DictionaryPrefUpdate pref_update(
4205 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4206 base::DictionaryValue* exp_dict = pref_update.Get();
4207
4208 // Convert |expiration_time| to minutes since that is the most granular
4209 // option that returns an int. base::Value does not accept int64.
4210 int expiration_time_minutes =
4211 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4212 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4213}
4214
4215base::flat_map<int, base::Time>
4216ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4217 content::BrowserContext* browser_context) {
4218 Profile* profile = Profile::FromBrowserContext(browser_context);
4219 DCHECK(profile);
4220
4221 auto* pref_service = profile->GetPrefs();
4222 DCHECK(pref_service);
4223
4224 auto* expiration_dict = pref_service->GetDictionary(
4225 prefs::kDevToolsBackgroundServicesExpirationDict);
4226 DCHECK(expiration_dict);
4227
4228 base::flat_map<int, base::Time> expiration_times;
4229 for (const auto& it : *expiration_dict) {
4230 // key.
4231 int service = 0;
4232 bool did_convert = base::StringToInt(it.first, &service);
4233 DCHECK(did_convert);
4234
4235 // value.
4236 DCHECK(it.second->is_int());
4237 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4238 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4239
4240 expiration_times[service] = expiration_time;
4241 }
4242
4243 return expiration_times;
4244}
4245
oysteinec563c582015-02-13 19:19:524246content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524247 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524248}
4249
[email protected]a6868c22013-10-09 02:50:294250bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4251 content::BrowserContext* browser_context,
4252 const GURL& url) {
brettw4b461082016-11-19 18:55:164253#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554254 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194255 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294256#else
4257 return false;
4258#endif
4259}
4260
[email protected]aec5ed52014-06-20 07:51:424261bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4262 content::BrowserContext* browser_context,
4263 const GURL& url) {
brettw4b461082016-11-19 18:55:164264#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554265 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194266 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064267#else
4268 return false;
4269#endif
4270}
4271
mlamourif8c23a2002015-01-27 13:10:104272void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014273 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434274 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524275 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104276
4277 WebContents* web_contents =
4278 WebContents::FromRenderFrameHost(render_frame_host);
4279 DCHECK(web_contents);
4280
Hiroki Nakagawab4cd18aa2021-01-25 18:11:014281 prerender::NoStatePrefetchManager* no_state_prefetch_manager =
4282 prerender::NoStatePrefetchManagerFactory::GetForBrowserContext(
drogerc1543152016-09-20 13:03:374283 web_contents->GetBrowserContext());
Hiroki Nakagawab4cd18aa2021-01-25 18:11:014284 if (no_state_prefetch_manager &&
4285 no_state_prefetch_manager->IsWebContentsPrerendering(web_contents)) {
Collin Baker98457b52019-11-06 21:34:294286 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104287 }
4288}
4289
Robert Sesek466e43e2019-08-19 22:02:024290void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4291 base::FilePath user_data_dir;
4292 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4293 DCHECK(!user_data_dir.empty());
4294 network_contexts_parent_directory_.push_back(user_data_dir);
4295
4296 base::FilePath cache_dir;
4297 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4298 DCHECK(!cache_dir.empty());
4299 // On some platforms, the cache is a child of the user_data_dir so only
4300 // return the one path.
4301 if (!user_data_dir.IsParent(cache_dir))
4302 network_contexts_parent_directory_.push_back(cache_dir);
4303
4304 // If the cache location has been overridden by a switch or preference,
4305 // include that as well.
4306 if (auto* local_state = g_browser_process->local_state()) {
4307 base::FilePath pref_cache_dir =
4308 local_state->GetFilePath(prefs::kDiskCacheDir);
4309 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4310 network_contexts_parent_directory_.push_back(pref_cache_dir);
4311 }
4312}
4313
[email protected]30335fdf02014-02-26 19:51:274314void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174315 base::CommandLine* to_command_line,
4316 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544317 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274318#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544319 const version_info::Channel kMaxDisableEncryptionChannel =
4320 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274321#else
sdefresne6e883e42015-07-30 08:05:544322 const version_info::Channel kMaxDisableEncryptionChannel =
4323 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274324#endif
4325 if (channel <= kMaxDisableEncryptionChannel) {
4326 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444327 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274328 };
Avi Drissmand251e912018-12-26 15:46:374329 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4330 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274331 }
4332}
bashi933629552016-10-13 23:32:404333
miu54dca6c2016-11-17 10:59:384334#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4335void ChromeContentBrowserClient::CreateMediaRemoter(
4336 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504337 mojo::PendingRemote<media::mojom::RemotingSource> source,
4338 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384339 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504340 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384341}
4342#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464343
Michael Giuffrida6802ffe2017-09-29 03:40:254344base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4345 const base::CommandLine& command_line) {
4346 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164347}
4348
John Abd-El-Malek8efa11f2019-01-06 00:51:534349namespace {
4350// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024351class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534352 public:
4353 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174354 ProtocolHandlerRegistry* protocol_handler_registry)
Matt Falkenhagen7811fd42020-06-24 22:42:414355 : protocol_handler_registry_(protocol_handler_registry) {
4356 DCHECK(protocol_handler_registry);
4357 }
John Abd-El-Malek8efa11f2019-01-06 00:51:534358 ~ProtocolHandlerThrottle() override = default;
4359
4360 void WillStartRequest(network::ResourceRequest* request,
4361 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294362 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534363 }
4364
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584365 void WillRedirectRequest(
4366 net::RedirectInfo* redirect_info,
4367 const network::mojom::URLResponseHead& response_head,
4368 bool* defer,
4369 std::vector<std::string>* to_be_removed_headers,
4370 net::HttpRequestHeaders* modified_headers,
4371 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294372 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534373 }
4374
4375 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294376 void TranslateUrl(GURL* url) {
4377 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4378 return;
4379 GURL translated_url = protocol_handler_registry_->Translate(*url);
4380 if (!translated_url.is_empty())
4381 *url = translated_url;
4382 }
4383
Clark DuValla411bda2019-08-02 03:09:174384 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534385};
4386} // namespace
4387
Minggang Wangf6840ecf2019-07-29 05:15:024388std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194389ChromeContentBrowserClient::CreateURLLoaderThrottles(
4390 const network::ResourceRequest& request,
4391 content::BrowserContext* browser_context,
4392 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4393 content::NavigationUIData* navigation_ui_data,
4394 int frame_tree_node_id) {
4395 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4396
Minggang Wangf6840ecf2019-07-29 05:15:024397 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194398
Matt Falkenhagen7811fd42020-06-24 22:42:414399 DCHECK(browser_context);
Clark DuVallfffa41e2019-06-25 20:27:194400 Profile* profile = Profile::FromBrowserContext(browser_context);
Matt Falkenhagen7811fd42020-06-24 22:42:414401 DCHECK(profile);
Clark DuVallfffa41e2019-06-25 20:27:194402
4403 ChromeNavigationUIData* chrome_navigation_ui_data =
4404 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4405
Bettinafd0c1102020-08-06 00:23:434406#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Josh Karlinaabf5102021-01-25 16:39:394407 bool matches_enterprise_whitelist = safe_browsing::IsURLAllowlistedByPolicy(
Clark DuVall5497288d2019-07-17 00:17:564408 request.url, *profile->GetPrefs());
4409 if (!matches_enterprise_whitelist) {
Xinghui Luf45d7ef72020-06-09 02:16:384410#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494411 auto* connectors_service =
4412 enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
4413 browser_context);
4414 bool has_valid_dm_token =
4415 connectors_service &&
4416 connectors_service->GetDMTokenForRealTimeUrlCheck().has_value();
4417 bool is_enterprise_lookup_enabled =
Xinghui Lucf23c902020-06-10 17:38:254418 safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494419 profile->GetPrefs(), has_valid_dm_token, profile->IsOffTheRecord());
Xinghui Lucf23c902020-06-10 17:38:254420#else
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494421 bool is_enterprise_lookup_enabled = false;
Xinghui Luf45d7ef72020-06-09 02:16:384422#endif
Xinghui Lucf23c902020-06-10 17:38:254423 bool is_consumer_lookup_enabled =
Xinghui Luf45d7ef72020-06-09 02:16:384424 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
4425 profile->GetPrefs(), profile->IsOffTheRecord(),
Xinghui Lucf23c902020-06-10 17:38:254426 g_browser_process->variations_service());
4427
4428 // |url_lookup_service| is used when real time url check is enabled.
4429 safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service =
4430 GetUrlLookupService(browser_context, is_enterprise_lookup_enabled,
4431 is_consumer_lookup_enabled);
Clark DuVall5497288d2019-07-17 00:17:564432 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4433 base::BindOnce(
4434 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534435 base::Unretained(this),
Xinghui Lucf23c902020-06-10 17:38:254436 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
4437 // Should check for enterprise when safe browsing is disabled.
4438 /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled),
Xinghui Lua142c102020-03-02 20:50:084439 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584440 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564441 }
Nico Weberbc5b06f2019-07-26 14:00:134442#endif
Clark DuVall5497288d2019-07-17 00:17:564443
dalykba7bbfc2019-12-18 19:59:214444#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4445 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014446 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4447 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214448#endif
4449
Clark DuVallfffa41e2019-06-25 20:27:194450 if (chrome_navigation_ui_data &&
Hiroki Nakagawa78ebf062021-01-20 16:23:534451 chrome_navigation_ui_data->is_no_state_prefetching()) {
Clark DuVallfffa41e2019-06-25 20:27:194452 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
Clark DuVallfffa41e2019-06-25 20:27:194453 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234454 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194455 }
4456
John Abd-El-Malek4f380d92020-02-19 16:43:364457#if defined(OS_ANDROID)
4458 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234459 bool night_mode_enabled = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374460 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4461 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364462 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4463 if (web_contents) {
4464 auto* client_data_header_observer =
4465 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4466 web_contents);
4467 if (client_data_header_observer)
4468 client_data_header = client_data_header_observer->header();
Brandon Wylie21a88ac92020-05-15 02:49:234469
Brandon Wylief6bfdab2020-08-12 21:49:364470 auto* delegate =
4471 TabAndroid::FromWebContents(web_contents)
4472 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4473 web_contents->GetDelegate())
4474 : nullptr;
4475 if (delegate)
4476 night_mode_enabled = delegate->IsNightModeEnabled();
Brandon Wylie21a88ac92020-05-15 02:49:234477 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374478 }
John Abd-El-Malek4f380d92020-02-19 16:43:364479#endif
4480
Clark DuVallfffa41e2019-06-25 20:27:194481 chrome::mojom::DynamicParams dynamic_params = {
4482 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4483 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274484 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4485 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364486#if defined(OS_ANDROID)
Brandon Wylie21a88ac92020-05-15 02:49:234487 client_data_header, night_mode_enabled,
John Abd-El-Malek4f380d92020-02-19 16:43:364488#endif
Alex Clarke3ebd9772020-02-28 10:50:274489 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194490
Matt Falkenhagen7811fd42020-06-24 22:42:414491 {
4492 auto* factory =
4493 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context);
4494 // null in unit tests.
4495 if (factory)
4496 result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory));
4497 }
Clark DuVall8512cee62019-06-26 01:14:214498
Clark DuVall39c2cfc2019-06-25 21:49:284499#if BUILDFLAG(ENABLE_PLUGINS)
4500 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Julie Jeongeun Kim44dcfab2021-01-20 07:39:184501 request.destination, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284502#endif
4503
Robbie McElrath127ad2b2019-07-22 22:38:114504 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404505 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584506 auto signin_throttle =
4507 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114508 if (signin_throttle)
4509 result.push_back(std::move(signin_throttle));
4510
Clark DuVallfffa41e2019-06-25 20:27:194511 return result;
4512}
4513
Ken Rockot6414c4d92017-11-08 19:58:324514void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464515 int frame_tree_node_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314516 ukm::SourceIdObj ukm_source_id,
Ken Rockot6414c4d92017-11-08 19:58:324517 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324518#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Malekea006302018-05-10 05:50:464519 content::WebContents* web_contents =
4520 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414521#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174522 factories->emplace(
Ken Rockot6414c4d92017-11-08 19:58:324523 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574524 extensions::CreateExtensionNavigationURLLoaderFactory(
Maks Orlovich5408ddfc2020-07-28 23:07:354525 web_contents->GetBrowserContext(), ukm_source_id,
John Abd-El-Malekea006302018-05-10 05:50:464526 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414527#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Yuta Hijikata235fc62b2020-12-08 03:48:324528#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414529 Profile* profile =
4530 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354531 factories->emplace(content::kExternalFileScheme,
4532 chromeos::ExternalFileURLLoaderFactory::Create(
4533 profile, content::ChildProcessHost::kInvalidUniqueID));
Yuta Hijikata235fc62b2020-12-08 03:48:324534#endif // BUILDFLAG(IS_CHROMEOS_ASH)
4535#endif // BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
Ken Rockot6414c4d92017-11-08 19:58:324536}
4537
Ting Shao2dc60582019-07-15 04:43:364538void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344539 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4540 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174541 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawa1efa31d2019-10-01 22:36:344542 DCHECK(browser_context);
4543 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174544
4545#if BUILDFLAG(ENABLE_EXTENSIONS)
Hiroki Nakagawa1efa31d2019-10-01 22:36:344546 factories->emplace(
4547 extensions::kExtensionScheme,
4548 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4549 browser_context));
4550#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4551}
4552
4553void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364554 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4555 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174556 NonNetworkURLLoaderFactoryMap* factories) {
Ting Shao2dc60582019-07-15 04:43:364557 DCHECK(browser_context);
4558 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174559
4560#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364561 factories->emplace(
4562 extensions::kExtensionScheme,
4563 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4564 browser_context));
4565#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364566}
4567
Jay Civelli2578ebe2018-06-05 18:44:314568namespace {
4569
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384570// The SpecialAccessFileURLLoaderFactory provided to the extension background
4571// pages. Checks with the ChildProcessSecurityPolicy to validate the file
4572// access.
4573class SpecialAccessFileURLLoaderFactory
Lukasz Anforowicz25620d32021-01-27 22:03:444574 : public network::SelfDeletingURLLoaderFactory {
Jay Civelli2578ebe2018-06-05 18:44:314575 public:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384576 // Returns mojo::PendingRemote to a newly constructed
4577 // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
4578 // delete itself once there are no more receivers (including the receiver
4579 // associated with the returned mojo::PendingRemote and the receivers bound by
4580 // the Clone method).
4581 static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
4582 int child_id) {
4583 mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
4584
4585 // The SpecialAccessFileURLLoaderFactory will delete itself when there are
Lukasz Anforowicz25620d32021-01-27 22:03:444586 // no more receivers - see the
4587 // network::SelfDeletingURLLoaderFactory::OnDisconnect method.
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384588 new SpecialAccessFileURLLoaderFactory(
4589 child_id, pending_remote.InitWithNewPipeAndPassReceiver());
4590
4591 return pending_remote;
4592 }
Jay Civelli2578ebe2018-06-05 18:44:314593
4594 private:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384595 explicit SpecialAccessFileURLLoaderFactory(
4596 int child_id,
4597 mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
Lukasz Anforowicz25620d32021-01-27 22:03:444598 : network::SelfDeletingURLLoaderFactory(std::move(factory_receiver)),
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384599 child_id_(child_id) {}
4600
Jay Civelli2578ebe2018-06-05 18:44:314601 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274602 void CreateLoaderAndStart(
4603 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4604 int32_t routing_id,
4605 int32_t request_id,
4606 uint32_t options,
4607 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304608 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274609 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4610 override {
Jay Civelli2578ebe2018-06-05 18:44:314611 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4612 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304613 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4614 ->OnComplete(
4615 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314616 return;
4617 }
Yutaka Hiranodf83dca42020-01-07 06:24:554618 content::CreateFileURLLoaderBypassingSecurityChecks(
4619 request, std::move(loader), std::move(client),
4620 /*observer=*/nullptr,
4621 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314622 }
4623
Jay Civelli2578ebe2018-06-05 18:44:314624 int child_id_;
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384625 DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory);
Jay Civelli2578ebe2018-06-05 18:44:314626};
4627
Yuta Hijikata235fc62b2020-12-08 03:48:324628#if BUILDFLAG(IS_CHROMEOS_ASH)
Aya ElAttareb5fee12020-05-05 08:56:054629bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4630 PrefService* const local_state = g_browser_process->local_state();
4631 if (!local_state) // Sometimes it's not available in tests.
4632 return false;
4633
4634 const base::ListValue* disabled_system_features_pref =
4635 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4636 if (!disabled_system_features_pref)
4637 return false;
4638
4639 const auto disabled_system_features =
4640 disabled_system_features_pref->GetList();
4641 return base::Contains(disabled_system_features, base::Value(system_feature));
4642}
4643
4644bool IsSystemFeatureURLDisabled(const GURL& url) {
4645 if (!url.SchemeIs(content::kChromeUIScheme))
4646 return false;
4647
4648 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4649 // installation complete successfully.
4650 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4651 url.path() != "/pwa.html" &&
Anqing Zhaod99eda172020-11-30 13:49:494652 IsSystemFeatureDisabled(policy::SystemFeature::kOsSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054653 return true;
4654 }
4655
4656 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494657 IsSystemFeatureDisabled(policy::SystemFeature::kBrowserSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054658 return true;
4659 }
4660
Jesse Schettlerb7047f32020-09-18 14:50:404661 if (url.DomainIs(chromeos::kChromeUIScanningAppHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494662 IsSystemFeatureDisabled(policy::SystemFeature::kScanning)) {
Jesse Schettlerb7047f32020-09-18 14:50:404663 return true;
4664 }
4665
Aya ElAttareb5fee12020-05-05 08:56:054666 return false;
4667}
4668#endif
Jay Civelli2578ebe2018-06-05 18:44:314669} // namespace
4670
Ken Rockot6414c4d92017-11-08 19:58:324671void ChromeContentBrowserClient::
4672 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464673 int render_process_id,
4674 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324675 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324676#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414677 content::RenderFrameHost* frame_host =
4678 RenderFrameHost::FromID(render_process_id, render_frame_id);
4679 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
Yuta Hijikata235fc62b2020-12-08 03:48:324680#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414681
Yuta Hijikata235fc62b2020-12-08 03:48:324682#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414683 if (web_contents) {
4684 Profile* profile =
4685 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354686 factories->emplace(content::kExternalFileScheme,
4687 chromeos::ExternalFileURLLoaderFactory::Create(
4688 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414689 }
Yuta Hijikata235fc62b2020-12-08 03:48:324690#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414691
Ken Rockot6414c4d92017-11-08 19:58:324692#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174693 factories->emplace(extensions::kExtensionScheme,
4694 extensions::CreateExtensionURLLoaderFactory(
4695 render_process_id, render_frame_id));
Chris Mumfordbae8a742018-03-01 23:02:234696
4697 // This logic should match
4698 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314699 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234700 return;
Jay Civellic9bbf72d2018-03-24 01:58:314701
4702 Profile* profile =
4703 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4704 InstantService* instant_service =
4705 InstantServiceFactory::GetForProfile(profile);
4706 // The test below matches what's done by ShouldServiceRequestIOThread in
4707 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464708 if (instant_service->IsInstantProcess(render_process_id)) {
Lukasz Anforowicz7f695532020-09-15 16:05:224709 factories->emplace(
Jay Civellic9bbf72d2018-03-24 01:58:314710 chrome::kChromeSearchScheme,
Lukasz Anforowicz7f695532020-09-15 16:05:224711 content::CreateWebUIURLLoaderFactory(
Jay Civellic9bbf72d2018-03-24 01:58:314712 frame_host, chrome::kChromeSearchScheme,
4713 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234714 }
Jay Civellic9bbf72d2018-03-24 01:58:314715
Chris Mumfordbae8a742018-03-01 23:02:234716 extensions::ChromeExtensionWebContentsObserver* web_observer =
4717 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4718 web_contents);
4719
Karan Bhatia91928572018-03-06 01:18:074720 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4721 // to the |web_contents|.
4722 if (!web_observer)
4723 return;
4724
Chris Mumfordbae8a742018-03-01 23:02:234725 const Extension* extension =
4726 web_observer->GetExtensionFromFrame(frame_host, false);
4727 if (!extension)
4728 return;
4729
Sam McNally7414eeb72018-09-03 04:05:304730 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234731 // Support for chrome:// scheme if appropriate.
4732 if ((extension->is_extension() || extension->is_platform_app()) &&
4733 Manifest::IsComponentLocation(extension->location())) {
4734 // Components of chrome that are implemented as extensions or platform apps
4735 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304736 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4737 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4738 }
4739 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4740 (extension->is_platform_app() &&
4741 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234742 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024743 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4744 // URLs. Hosted apps are not allowed because they are served via web servers
4745 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304746 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4747 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024748 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304749 }
4750 if (!allowed_webui_hosts.empty()) {
Lukasz Anforowicz7f695532020-09-15 16:05:224751 factories->emplace(content::kChromeUIScheme,
4752 content::CreateWebUIURLLoaderFactory(
4753 frame_host, content::kChromeUIScheme,
4754 std::move(allowed_webui_hosts)));
Chris Mumfordbae8a742018-03-01 23:02:234755 }
Jay Civelli2578ebe2018-06-05 18:44:314756
4757 // Extension with a background page get file access that gets approval from
4758 // ChildProcessSecurityPolicy.
4759 extensions::ExtensionHost* host =
4760 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4761 ->GetBackgroundHostForExtension(extension->id());
4762 if (host) {
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384763 factories->emplace(
Lukasz Anforowiczb7d8b542020-09-03 19:50:344764 url::kFileScheme,
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384765 SpecialAccessFileURLLoaderFactory::Create(render_process_id));
Jay Civelli2578ebe2018-06-05 18:44:314766 }
Chris Mumfordbae8a742018-03-01 23:02:234767#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324768}
4769
Ken Rockota0dfaca12018-02-15 07:26:254770bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214771 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254772 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384773 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444774 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264775 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004776 base::Optional<int64_t> navigation_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314777 ukm::SourceIdObj ukm_source_id,
Dominic Farolino1be897a2019-07-20 08:11:424778 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184779 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4780 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334781 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084782 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334783 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014784 bool use_proxy = false;
4785
Ken Rockota0dfaca12018-02-15 07:26:254786#if BUILDFLAG(ENABLE_EXTENSIONS)
4787 auto* web_request_api =
4788 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214789 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254790
4791 // NOTE: Some unit test environments do not initialize
4792 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014793 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124794 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384795 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004796 browser_context, frame, render_process_id, type,
Maks Orlovichf334d642020-09-21 22:19:594797 std::move(navigation_id), ukm_source_id, factory_receiver,
4798 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124799 if (bypass_redirect_checks)
4800 *bypass_redirect_checks = use_proxy_for_web_request;
4801 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014802 }
Ken Rockota0dfaca12018-02-15 07:26:254803#endif
Reilly Grant24bf8332018-08-27 21:55:014804
Reilly Grantcc22e602018-09-07 15:25:204805 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444806 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4807 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014808
Hiroki Nakagawa483686a92020-10-29 04:31:454809 auto* prefetch_proxy_service = PrefetchProxyServiceFactory::GetForProfile(
4810 Profile::FromBrowserContext(browser_context));
Robert Ogden31b234712020-06-04 22:51:214811 // |frame| is null when |type| is service worker.
Hiroki Nakagawa483686a92020-10-29 04:31:454812 if (frame && prefetch_proxy_service) {
4813 use_proxy |= prefetch_proxy_service->MaybeProxyURLLoaderFactory(
Robert Ogden8c53bc52020-06-19 21:24:184814 frame, render_process_id, type, factory_receiver);
Robert Ogden31b234712020-06-04 22:51:214815 }
4816
dalyk0018c16f2020-01-08 20:20:084817#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4818 if (disable_secure_dns) {
4819 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4820 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014821 web_contents &&
4822 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4823 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084824 ->is_captive_portal_window();
4825 }
4826#endif
4827
Reilly Grant24bf8332018-08-27 21:55:014828 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254829}
4830
Jian Lide7b43792018-06-01 23:22:134831std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4832ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4833 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144834 int frame_tree_node_id,
4835 const scoped_refptr<network::SharedURLLoaderFactory>&
4836 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134837 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4838 interceptors;
4839#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234840 interceptors.push_back(
4841 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4842 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134843#endif
Ryan Sturmaf523742019-01-16 00:15:454844
Robert Ogden6946ad42020-01-13 18:01:304845 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
Hiroki Nakagawa483686a92020-10-29 04:31:454846 interceptors.push_back(std::make_unique<PrefetchProxyURLLoaderInterceptor>(
4847 frame_tree_node_id));
Robert Ogden6946ad42020-01-13 18:01:304848 }
4849
Ryan Sturm8670b572020-10-21 18:45:304850 if (SearchPrefetchServiceIsEnabled()) {
4851 interceptors.push_back(std::make_unique<SearchPrefetchURLLoaderInterceptor>(
4852 frame_tree_node_id));
4853 }
4854
Jian Lide7b43792018-06-01 23:22:134855 return interceptors;
4856}
4857
Ryan Sturm6b2f6392020-12-09 21:46:004858content::ContentBrowserClient::URLLoaderRequestHandler
4859ChromeContentBrowserClient::
4860 CreateURLLoaderHandlerForServiceWorkerNavigationPreload(
4861 int frame_tree_node_id,
4862 const network::ResourceRequest& resource_request) {
4863 content::ContentBrowserClient::URLLoaderRequestHandler callback;
4864
4865 // If search prefetch is disabled, nothing needs to be handled.
4866 if (!SearchPrefetchServiceIsEnabled()) {
4867 return callback;
4868 }
4869
4870 std::unique_ptr<SearchPrefetchURLLoader> loader =
4871 SearchPrefetchURLLoaderInterceptor::MaybeCreateLoaderForRequest(
4872 resource_request, frame_tree_node_id);
4873 if (!loader) {
4874 return callback;
4875 }
4876
4877 auto* raw_loader = loader.get();
4878
4879 // Hand ownership of the loader to the callback, when it runs, mojo will
4880 // manage it. If the callback is deleted, the loader will be deleted.
4881 callback = raw_loader->ServingResponseHandler(std::move(loader));
4882 return callback;
4883}
4884
Yutaka Hirano8e0b4d432019-07-04 07:12:384885bool ChromeContentBrowserClient::WillInterceptWebSocket(
4886 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334887#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384888 if (!frame) {
4889 return false;
4890 }
4891 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334892 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4893 frame->GetProcess()->GetBrowserContext());
4894
4895 // NOTE: Some unit test environments do not initialize
4896 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4897 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384898 return false;
Yutaka Hirano36c94952018-05-30 21:33:334899
Yutaka Hirano8e0b4d432019-07-04 07:12:384900 return web_request_api->MayHaveProxies();
4901#else
4902 return false;
4903#endif
4904}
4905
4906void ChromeContentBrowserClient::CreateWebSocket(
4907 content::RenderFrameHost* frame,
4908 WebSocketFactory factory,
4909 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394910 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384911 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404912 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4913 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384914#if BUILDFLAG(ENABLE_EXTENSIONS)
4915 if (!frame) {
4916 return;
4917 }
4918 auto* web_request_api =
4919 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4920 frame->GetProcess()->GetBrowserContext());
4921
4922 DCHECK(web_request_api);
4923 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394924 site_for_cookies.RepresentativeUrl(),
4925 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334926#endif
4927}
4928
Maks Orlovich710d5e32019-07-09 20:16:454929bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464930 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454931 content::BrowserContext* browser_context,
Shuran Huangbd4d1692021-01-26 17:03:414932 const url::Origin& origin,
Shuran Huang92b415d72021-01-12 20:48:154933 const net::IsolationInfo& isolation_info,
Maks Orlovich710d5e32019-07-09 20:16:454934 bool is_service_worker,
4935 int process_id,
4936 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034937 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454938 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4939#if BUILDFLAG(ENABLE_EXTENSIONS)
Shuran Huangf20a28c2021-01-27 19:36:284940 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464941 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454942 extensions::ChromeExtensionCookies::Get(browser_context)
Shuran Huangbd4d1692021-01-26 17:03:414943 ->CreateRestrictedCookieManager(origin, isolation_info,
4944 std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454945 return true;
4946 }
4947#endif
4948 return false;
4949}
4950
Matt Menkeae4fdb12018-06-02 06:32:544951void ChromeContentBrowserClient::OnNetworkServiceCreated(
4952 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534953 PrefService* local_state;
4954 if (g_browser_process) {
4955 DCHECK(g_browser_process->local_state());
4956 local_state = g_browser_process->local_state();
4957 } else {
danakj5beedd02020-10-30 15:55:134958 DCHECK(startup_data_.chrome_feature_list_creator()->local_state());
4959 local_state = startup_data_.chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534960 }
4961
4962 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4963 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4964
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494965 // Create SystemNetworkContextManager if it has not been created yet. We need
4966 // to set up global NetworkService state before anything else uses it and this
4967 // is the first opportunity to initialize SystemNetworkContextManager with the
4968 // NetworkService.
4969 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534970 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074971
Min Qin8caab1d2018-10-03 17:28:134972 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544973 network_service);
4974}
4975
Matthew Denton8888ae52020-05-14 08:20:024976void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:254977 content::BrowserContext* context,
4978 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:024979 const base::FilePath& relative_partition_path,
4980 network::mojom::NetworkContextParams* network_context_params,
4981 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
Glen Robertsoncbb40ac2020-11-23 04:04:044982 ProfileNetworkContextService* service =
4983 ProfileNetworkContextServiceFactory::GetForContext(context);
4984 if (service) {
4985 service->ConfigureNetworkContextParams(in_memory, relative_partition_path,
4986 network_context_params,
4987 cert_verifier_creation_params);
4988 } else {
4989 // Set default params.
4990 network_context_params->user_agent = GetUserAgent();
4991 network_context_params->accept_language = GetApplicationLocale();
4992 }
Ken Rockota0dfaca12018-02-15 07:26:254993}
4994
Robert Sesek34f68f312019-01-14 20:25:114995std::vector<base::FilePath>
4996ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024997 DCHECK(!network_contexts_parent_directory_.empty());
4998 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114999}
5000
John Abd-El-Malekc240cfc42020-07-08 12:22:445001base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() {
5002 auto platform_dict = net_log::GetPlatformConstantsForNetLog(
5003 base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
5004 chrome::GetChannelName());
5005 if (platform_dict)
5006 return std::move(*platform_dict);
5007 else
5008 return base::DictionaryValue();
5009}
5010
Min Qin75ed6df2017-12-01 20:39:155011bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135012 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155013#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5014 // It is OK to load the saved offline copy, in MHTML format.
5015 ChromeNavigationUIData* chrome_navigation_ui_data =
5016 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5017 if (!chrome_navigation_ui_data)
5018 return false;
5019 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5020 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5021 return offline_page_data && offline_page_data->is_offline_page();
5022#else
5023 return false;
5024#endif
5025}
5026
Min Qin30a78a12017-12-06 01:29:135027bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5028 const GURL& url,
5029 const std::string& mime_type) {
5030#if BUILDFLAG(ENABLE_EXTENSIONS)
5031 // Special-case user scripts to get downloaded instead of viewed.
5032 return extensions::UserScript::IsURLUserScript(url, mime_type);
5033#else
5034 return false;
5035#endif
5036}
5037
Donna Wu838ac362018-08-10 10:36:335038void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345039 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:045040 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:465041 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:345042 return;
5043
[email protected]95ebe7c2020-04-08 19:12:455044 CHECK(render_frame_host);
5045 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
5046 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:345047}
5048
Ovidio Henriquez3d729f62020-02-07 00:43:295049content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
5050 if (!bluetooth_delegate_)
5051 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
5052 return bluetooth_delegate_.get();
5053}
5054
Reilly Grant0d282322019-01-29 02:42:585055#if !defined(OS_ANDROID)
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:215056void ChromeContentBrowserClient::CreateDeviceInfoService(
5057 content::RenderFrameHost* render_frame_host,
5058 mojo::PendingReceiver<blink::mojom::DeviceAPIService> receiver) {
5059 DCHECK(render_frame_host);
5060 DeviceServiceImpl::Create(render_frame_host, std::move(receiver));
5061}
5062
Reilly Grant0d282322019-01-29 02:42:585063content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5064 if (!serial_delegate_)
5065 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5066 return serial_delegate_.get();
5067}
Matt Reynolds93616f9b2019-06-07 01:28:525068
5069content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5070 if (!hid_delegate_)
5071 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5072 return hid_delegate_.get();
5073}
Reilly Grant0d282322019-01-29 02:42:585074
Olivier Yiptong935e6c42020-11-21 01:28:235075content::FontAccessDelegate*
5076ChromeContentBrowserClient::GetFontAccessDelegate() {
5077 if (!font_access_delegate_)
5078 font_access_delegate_ = std::make_unique<ChromeFontAccessDelegate>();
5079 return static_cast<content::FontAccessDelegate*>(font_access_delegate_.get());
5080}
5081
Balazs Engedya7ff70982018-06-04 18:14:475082std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5083ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:335084 content::RenderFrameHost* render_frame_host) {
5085 return AuthenticatorRequestScheduler::CreateRequestDelegate(
5086 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:475087}
Nina Satragno8c832df2019-07-29 15:59:395088#endif
Balazs Engedya7ff70982018-06-04 18:14:475089
Jun Cai9409ded2018-01-30 00:19:465090std::unique_ptr<net::ClientCertStore>
5091ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:105092 content::BrowserContext* browser_context) {
5093 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:465094 ->CreateClientCertStore();
5095}
5096
David Benjamineced01fc2019-02-27 18:29:025097std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395098ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585099 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025100 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035101 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245102 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395103 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035104 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395105 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565106 LoginAuthRequiredCallback auth_required_callback) {
Andreea Costinas81218bf2021-01-08 11:48:145107#if BUILDFLAG(IS_CHROMEOS_ASH)
5108 policy::SystemProxyManager* system_proxy_manager =
5109 g_browser_process->platform_part()
5110 ->browser_policy_connector_chromeos()
5111 ->GetSystemProxyManager();
5112 // For Managed Guest Session and Kiosk devices, the credentials configured
5113 // via the policy SystemProxySettings may be used for proxy authentication.
5114 // Note: |system_proxy_manager| may be missing in tests.
5115 if (system_proxy_manager && system_proxy_manager->CanUsePolicyCredentials(
5116 auth_info, first_auth_attempt)) {
5117 return system_proxy_manager->CreateLoginDelegate(
5118 std::move(auth_required_callback));
5119 }
5120#endif // BUILDFLAG(IS_CHROMEOS_ASH)
5121
Emily Stark63c884f2020-05-12 03:55:285122 // For subresources, create a LoginHandler directly, which may show a login
5123 // prompt to the user. Main frame resources go through LoginTabHelper, which
5124 // manages a more complicated flow to avoid confusion about which website is
5125 // showing the prompt.
5126 if (is_request_for_main_frame) {
5127 LoginTabHelper::CreateForWebContents(web_contents);
5128 return LoginTabHelper::FromWebContents(web_contents)
5129 ->CreateAndStartMainFrameLoginDelegate(
5130 auth_info, web_contents, request_id, url, response_headers,
5131 std::move(auth_required_callback));
5132 }
5133 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
5134 auth_info, web_contents, std::move(auth_required_callback));
5135 login_handler->StartSubresource(request_id, url, response_headers);
5136 return login_handler;
Jun Caibc561f412018-02-28 18:41:395137}
5138
John Abd-El-Maleka67add82018-03-09 18:22:015139bool ChromeContentBrowserClient::HandleExternalProtocol(
5140 const GURL& url,
danakjf4b9e942019-11-29 15:43:045141 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015142 int child_id,
5143 content::NavigationUIData* navigation_data,
5144 bool is_main_frame,
5145 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455146 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:455147 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:105148 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015149#if BUILDFLAG(ENABLE_EXTENSIONS)
5150 // External protocols are disabled for guests. An exception is made for the
5151 // "mailto" protocol, so that pages that utilize it work properly in a
5152 // WebView.
5153 ChromeNavigationUIData* chrome_data =
5154 static_cast<ChromeNavigationUIData*>(navigation_data);
5155 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5156 (chrome_data &&
5157 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5158 !url.SchemeIs(url::kMailToScheme)) {
5159 return false;
5160 }
5161#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5162
5163#if defined(OS_ANDROID)
5164 // Main frame external protocols are handled by
5165 // InterceptNavigationResourceThrottle.
5166 if (is_main_frame)
5167 return false;
5168#endif // defined(ANDROID)
5169
Gabriel Charettee7cdc5cd2020-05-27 23:35:055170 content::GetUIThreadTaskRunner({})->PostTask(
5171 FROM_HERE,
danakjf4b9e942019-11-29 15:43:045172 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
5173 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:015174 return true;
5175}
5176
Jennifer Apacible4f854a82018-04-06 22:22:115177std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285178ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5179 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115180 // Note: content::OverlayWindow::Create() is defined by platform-specific
5181 // implementation in chrome/browser/ui/views. This layering hack, which goes
5182 // through //content and ContentBrowserClient, allows us to work around the
5183 // dependency constraints that disallow directly calling
5184 // chrome/browser/ui/views code either from here or from other code in
5185 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285186 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115187}
5188
Kunihiko Sakamoto19aa7082019-02-25 03:14:435189void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565190 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115191 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565192 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435193 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5194 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565195}
5196
dbeam25472e0c2017-06-23 19:02:315197// Static; handles rewriting Web UI URLs.
5198bool ChromeContentBrowserClient::HandleWebUI(
5199 GURL* url,
5200 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:395201 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315202 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395203 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315204 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5205 chrome::kChromeUIHelpHost);
5206 return true; // Return true to update the displayed URL.
5207 }
5208
sauskib5f82762020-07-21 17:13:225209 // Replace deprecated cookie settings URL with the current version.
5210 if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) {
5211 *url = GURL(chrome::kChromeUICookieSettingsURL);
5212 return true;
5213 }
5214
Hector Carmona566a20b2019-09-13 22:44:425215#if defined(OS_WIN)
5216 // TODO(crbug.com/1003960): Remove when issue is resolved.
5217 if (url->SchemeIs(content::kChromeUIScheme) &&
5218 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5219 url::Replacements<char> replacements;
5220 replacements.SetHost(
5221 chrome::kChromeUIWelcomeHost,
5222 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5223 *url = url->ReplaceComponents(replacements);
5224 return true;
5225 }
5226#endif // defined(OS_WIN)
5227
dbeam25472e0c2017-06-23 19:02:315228 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5229 browser_context, *url)) {
5230 return false;
5231 }
5232
Yuta Hijikata235fc62b2020-12-08 03:48:325233#if BUILDFLAG(IS_CHROMEOS_ASH)
dbeam25472e0c2017-06-23 19:02:315234 // Special case : in ChromeOS in Guest mode bookmarks and history are
5235 // disabled for security reasons. New tab page explains the reasons, so
5236 // we redirect user to new tab page.
5237 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5238 if (url->SchemeIs(content::kChromeUIScheme) &&
5239 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5240 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5241 // Rewrite with new tab URL
5242 *url = GURL(chrome::kChromeUINewTabURL);
5243 }
5244 }
Aya ElAttareb5fee12020-05-05 08:56:055245
5246 if (IsSystemFeatureURLDisabled(*url)) {
5247 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
5248 return true;
5249 }
5250
dbeam25472e0c2017-06-23 19:02:315251#endif
5252
5253 return true;
5254}
5255
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065256bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5257 content::BrowserContext* browser_context,
5258 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325259 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065260#if defined(OS_ANDROID)
5261 return false;
5262#else
5263 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5264 ->GetForBrowserContext(browser_context)
5265 ->ShowPaymentHandlerWindow(url, std::move(callback));
5266 return true;
5267#endif
5268}
5269
Dan Beam141c48932019-08-22 02:29:395270// static
dbeam25472e0c2017-06-23 19:02:315271bool ChromeContentBrowserClient::HandleWebUIReverse(
5272 GURL* url,
5273 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425274#if defined(OS_WIN)
5275 // TODO(crbug.com/1003960): Remove when issue is resolved.
5276 // No need to actually reverse-rewrite the URL, but return true to update the
5277 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5278 if (url->SchemeIs(content::kChromeUIScheme) &&
5279 url->host() == chrome::kChromeUIWelcomeHost) {
5280 return true;
5281 }
5282#endif // defined(OS_WIN)
5283
dbeam25472e0c2017-06-23 19:02:315284 // No need to actually reverse-rewrite the URL, but return true to update the
5285 // displayed URL when rewriting chrome://help to chrome://settings/help.
5286 return url->SchemeIs(content::kChromeUIScheme) &&
5287 url->host() == chrome::kChromeUISettingsHost;
5288}
5289
Alison Maher7f366dc62020-03-03 19:46:005290const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585291 return ui::NativeTheme::GetInstanceForWeb();
5292}
5293
Clark DuVall5497288d2019-07-17 00:17:565294scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505295ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Xinghui Lucf23c902020-06-10 17:38:255296 bool safe_browsing_enabled_for_profile,
5297 bool should_check_on_sb_disabled) {
Yuzhu Shen44094e22017-07-18 22:52:355298 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5299
Xinghui Lucf23c902020-06-10 17:38:255300 // Should not bypass safe browsing check if the check is for enterprise
5301 // lookup.
5302 if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled)
Yuzhu Shencb3011f62018-02-08 02:51:505303 return nullptr;
5304
Yuzhu Shen44094e22017-07-18 22:52:355305 // |safe_browsing_service_| may be unavailable in tests.
5306 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5307 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435308 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355309 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435310 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355311 }
5312
Clark DuVall5497288d2019-07-17 00:17:565313 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355314}
Daniel Vogelheim6008f572018-09-24 14:35:145315
Xinghui Lucf23c902020-06-10 17:38:255316safe_browsing::RealTimeUrlLookupServiceBase*
5317ChromeContentBrowserClient::GetUrlLookupService(
5318 content::BrowserContext* browser_context,
5319 bool is_enterprise_lookup_enabled,
5320 bool is_consumer_lookup_enabled) {
5321 // |safe_browsing_service_| may be unavailable in tests.
5322 if (!safe_browsing_service_) {
5323 return nullptr;
5324 }
5325
5326 Profile* profile = Profile::FromBrowserContext(browser_context);
5327
5328#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
5329 if (is_enterprise_lookup_enabled) {
5330 return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory::
5331 GetForProfile(profile);
5332 }
5333#endif
5334
5335 if (is_consumer_lookup_enabled) {
5336 return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
5337 profile);
5338 }
5339 return nullptr;
5340}
5341
Daniel Vogelheim6008f572018-09-24 14:35:145342base::Optional<std::string>
5343ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595344 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185345 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595346 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5347 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145348}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525349
Takashi Toyoshima5af383aa2019-07-22 15:24:225350bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525351 // We require --user-data-dir flag too so that no dangerous changes are made
5352 // in the user's regular profile.
5353 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5354 switches::kUserDataDir);
5355}
rajendrantfeea8592018-10-19 18:26:065356
5357void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5358 int32_t network_traffic_annotation_id_hash,
5359 int64_t recv_bytes,
5360 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035361 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5362 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5363 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5364 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065365 }
5366}
Ryan Sturmaa05092f2018-10-21 03:56:545367
Ken Rockot4e284d32020-03-06 06:26:495368base::FilePath
5369ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
Ken Rockota22aaa572020-10-14 18:46:145370 if (!g_browser_process || !g_browser_process->profile_manager())
5371 return base::FilePath();
Ken Rockot4e284d32020-03-06 06:26:495372 return g_browser_process->profile_manager()->user_data_dir();
5373}
5374
Guido Urdanetae02b5722020-07-22 05:58:215375bool ChromeContentBrowserClient::ShouldSandboxAudioService() {
5376 return IsAudioServiceSandboxEnabled();
5377}
5378
Hiroki Nakagawa41366152020-07-27 18:31:405379blink::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5380 blink::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395381 content::NavigationHandle* navigation_handle,
5382 const GURL& current_navigation_url) {
Sophie Changc4ddda6772020-07-15 15:08:325383 return DetermineAllowedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135384 initial_state, navigation_handle, current_navigation_url);
Robert Ogden30bbc9d2019-04-30 20:15:135385}
5386
Hiroki Nakagawa41366152020-07-27 18:31:405387blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135388ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405389 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135390 content::NavigationHandle* navigation_handle,
5391 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545392 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295393 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215394
Ryan Sturmaa05092f2018-10-21 03:56:545395 // If this is not a main frame, return the initial state. If there are no
5396 // previews in the state, return the state as is.
5397 if (!navigation_handle->IsInMainFrame() ||
5398 navigation_handle->IsSameDocument()) {
5399 return initial_state;
5400 }
5401
Robert Ogdena994eb42019-02-14 19:15:085402 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405403 return blink::PreviewsTypes::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085404
Doug Arnettb3b99bc2019-08-09 16:55:565405 // Check if initial state specifies no previews should be considered.
Hiroki Nakagawa41366152020-07-27 18:31:405406 if (initial_state == blink::PreviewsTypes::PREVIEWS_OFF)
Doug Arnettb3b99bc2019-08-09 16:55:565407 return initial_state;
5408
Robert Ogdena994eb42019-02-14 19:15:085409 // Do not allow previews on POST navigations since the primary opt-out
5410 // mechanism is to reload the page. Because POST navigations are not
5411 // idempotent, we do not want to show a preview on a POST navigation where
5412 // opting out would cause another navigation, i.e.: a reload.
5413 if (navigation_handle->IsPost())
Hiroki Nakagawa41366152020-07-27 18:31:405414 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395415
5416 content::WebContents* web_contents = navigation_handle->GetWebContents();
5417 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5418
Ryan Sturmda2a0e02018-10-25 01:52:215419 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545420
5421 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5422 Profile::FromBrowserContext(browser_context));
5423 auto* data_reduction_proxy_settings =
5424 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5425 browser_context);
5426 // If the profile does not support previews or Data Saver, do not turn on
5427 // Previews.
5428 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355429 !data_reduction_proxy_settings) {
Hiroki Nakagawa41366152020-07-27 18:31:405430 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545431 }
5432
5433 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215434 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545435 // If this tab does not have a PreviewsUITabHelper, no preview should be
5436 // served.
5437 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405438 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545439
5440 DCHECK(!browser_context->IsOffTheRecord());
5441
5442 // Other previews objects should all exist and be initialized if we have made
5443 // it past earlier checks.
5444 previews::PreviewsDeciderImpl* previews_decider_impl =
5445 previews_service->previews_ui_service()->previews_decider_impl();
5446 DCHECK(previews_decider_impl);
5447
Ryan Sturm647d1d92018-11-07 15:41:395448 // Start with an unspecified state.
Hiroki Nakagawa41366152020-07-27 18:31:405449 blink::PreviewsState previews_state =
5450 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturmaa05092f2018-10-21 03:56:545451
Ryan Sturm647d1d92018-11-07 15:41:395452 previews::PreviewsUserData* previews_data =
5453 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5454
5455 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315456 // previews) and cannot re-evaluate PreviewsState once previews triggering
5457 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375458 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315459 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395460 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375461 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395462 } else {
5463 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5464 navigation_handle, previews_decider_impl->GeneratePageId());
5465 }
5466
5467 DCHECK(previews_data);
5468
Sophie Changa71fa5d2019-11-19 23:53:515469 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545470 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315471 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355472 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5473 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545474
Hiroki Nakagawa41366152020-07-27 18:31:405475 if (previews_state & blink::PreviewsTypes::PREVIEWS_OFF) {
5476 previews_data->set_allowed_previews_state(
5477 blink::PreviewsTypes::PREVIEWS_OFF);
5478 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545479 }
5480
Hiroki Nakagawa41366152020-07-27 18:31:405481 if (previews_state & blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM) {
5482 previews_data->set_allowed_previews_state(
5483 blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM);
5484 return blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM;
Ryan Sturmaa05092f2018-10-21 03:56:545485 }
5486
5487 // At this point, if no Preview is allowed, don't allow previews.
Hiroki Nakagawa41366152020-07-27 18:31:405488 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
5489 previews_data->set_allowed_previews_state(
5490 blink::PreviewsTypes::PREVIEWS_OFF);
5491 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395492 }
5493
Hiroki Nakagawa41366152020-07-27 18:31:405494 blink::PreviewsState embedder_state =
5495 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturm647d1d92018-11-07 15:41:395496 if (delegate) {
5497 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5498 }
Ryan Sturmaa05092f2018-10-21 03:56:545499
5500 // If the allowed previews are limited by the embedder, ensure previews honors
5501 // those limits.
Hiroki Nakagawa41366152020-07-27 18:31:405502 if (embedder_state != blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
Ryan Sturm647d1d92018-11-07 15:41:395503 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545504 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
Hiroki Nakagawa41366152020-07-27 18:31:405505 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED)
5506 previews_state = blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545507 }
Ryan Sturm647d1d92018-11-07 15:41:395508 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545509 return previews_state;
5510}
5511
5512// static
Hiroki Nakagawa41366152020-07-27 18:31:405513blink::PreviewsState
Ryan Sturmaa05092f2018-10-21 03:56:545514ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5515 const GURL& url,
5516 data_reduction_proxy::DataReductionProxyData* drp_data,
5517 previews::PreviewsUserData* previews_user_data,
5518 const previews::PreviewsDecider* previews_decider,
Hiroki Nakagawa41366152020-07-27 18:31:405519 blink::PreviewsState initial_state,
Ryan Sturm737bd1d2019-02-28 01:38:055520 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545521 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5522 if (!previews::HasEnabledPreviews(initial_state))
Hiroki Nakagawa41366152020-07-27 18:31:405523 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545524
Ryan Sturmaa05092f2018-10-21 03:56:545525 // Check the various other client previews types.
5526 return previews::DetermineCommittedClientPreviewsState(
Sophie Changc4ddda6772020-07-15 15:08:325527 previews_user_data, url, initial_state, previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055528 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545529}
5530
Hiroki Nakagawa41366152020-07-27 18:31:405531blink::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5532 blink::PreviewsState initial_state,
Ryan Sturmaa05092f2018-10-21 03:56:545533 content::NavigationHandle* navigation_handle,
5534 const net::HttpResponseHeaders* response_headers) {
Hiroki Nakagawa41366152020-07-27 18:31:405535 blink::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135536 initial_state, navigation_handle, response_headers);
5537
5538 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5539}
5540
Hiroki Nakagawa41366152020-07-27 18:31:405541blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135542ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405543 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135544 content::NavigationHandle* navigation_handle,
5545 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545546 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arthursonzogni90bb0922020-05-28 09:22:235547 DCHECK(!navigation_handle->HasCommitted());
5548
Ryan Sturmaa05092f2018-10-21 03:56:545549 // Only support HTTP and HTTPS.
arthursonzogni90bb0922020-05-28 09:22:235550 if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405551 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545552
5553 // If this is not a main frame, return the initial state. If there are no
5554 // previews in the state, return the state as is.
5555 if (!previews::HasEnabledPreviews(initial_state) ||
5556 !navigation_handle->IsInMainFrame() ||
5557 navigation_handle->IsSameDocument()) {
5558 return initial_state;
5559 }
5560
5561 // WebContents that don't have a PreviewsUITabHelper are not supported.
5562 PreviewsUITabHelper* ui_tab_helper =
5563 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5564 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405565 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545566
5567 // If we did not previously create a PreviewsUserData, do not go any further.
5568 previews::PreviewsUserData* previews_user_data =
5569 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5570 if (!previews_user_data)
Hiroki Nakagawa41366152020-07-27 18:31:405571 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545572
5573 PreviewsService* previews_service =
5574 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5575 navigation_handle->GetWebContents()->GetBrowserContext()));
5576
5577 if (!previews_service || !previews_service->previews_ui_service())
Hiroki Nakagawa41366152020-07-27 18:31:405578 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545579
Ryan Sturmaa05092f2018-10-21 03:56:545580 // Annotate request if no-transform directive found in response headers.
5581 if (response_headers &&
5582 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265583 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545584 }
5585
5586 previews::PreviewsDeciderImpl* previews_decider_impl =
5587 previews_service->previews_ui_service()->previews_decider_impl();
5588 DCHECK(previews_decider_impl);
5589
Clark DuVall9c5a72cc2018-10-25 01:29:215590 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5591 auto* settings =
5592 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5593 navigation_handle->GetWebContents()->GetBrowserContext());
5594 if (settings) {
5595 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5596 // does not yet have all the response information.
5597 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5598 response_headers);
5599 }
Ryan Sturmaa05092f2018-10-21 03:56:545600
5601 // Determine effective PreviewsState for this committed main frame response.
Hiroki Nakagawa41366152020-07-27 18:31:405602 blink::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215603 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055604 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545605
5606 // Double check that we never serve a preview when we have a
5607 // cache-control:no-transform directive.
5608 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5609 !previews::HasEnabledPreviews(committed_state));
5610
Robert Ogdended292c6f2019-05-03 22:44:515611 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545612 previews_user_data->set_committed_previews_state(committed_state);
5613
5614 previews::PreviewsType committed_type =
5615 previews::GetMainFramePreviewsType(committed_state);
5616
5617 // Capture committed previews type, if any, in PreviewsUserData.
5618 // Note: this is for the subset of previews types that are decided upon
5619 // navigation commit. Previews types that are determined prior to
5620 // navigation (such as for offline pages or for redirecting to another
5621 // url), are not set here.
5622 previews_user_data->SetCommittedPreviewsType(committed_type);
5623
5624 // Log the commit decision.
5625 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5626 previews_decider_impl->LogPreviewDecisionMade(
5627 (previews_user_data->cache_control_no_transform_directive()
5628 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5629 : previews::PreviewsEligibilityReason::COMMITTED),
5630 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055631 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055632 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545633
5634 return committed_state;
5635}
Charlie Harrison650e11422018-12-04 00:37:265636
5637void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5638 content::RenderFrameHost* render_frame_host,
5639 blink::mojom::WebFeature feature) {
5640 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5641 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5642 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5643 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315644
5645 // For the SameSite-by-default-cookies related features, log
5646 // the site engagement score for the site whose cookie was blocked. This is to
5647 // gauge the user impact of the cookies being blocked.
5648 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265649}
Yutaka Hirano968d6252018-12-04 05:09:315650
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525651std::string ChromeContentBrowserClient::GetProduct() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415652 return embedder_support::GetProduct();
Yutaka Hirano968d6252018-12-04 05:09:315653}
5654
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525655std::string ChromeContentBrowserClient::GetUserAgent() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415656 return embedder_support::GetUserAgent();
Yutaka Hirano968d6252018-12-04 05:09:315657}
Sam McNallyd54e23f92019-01-16 04:42:395658
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525659blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
John Abd-El-Malekec1fc69e2021-01-28 19:14:415660 return embedder_support::GetUserAgentMetadata();
Mike West6e4cbb32019-02-13 09:40:175661}
5662
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525663base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275664 // This icon is available on Android, but adds 19KiB to the APK. Since it
5665 // isn't used on Android we exclude it to avoid bloat.
5666#if !defined(OS_ANDROID)
5667 return base::Optional<gfx::ImageSkia>(
5668 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5669 IDR_PRODUCT_LOGO_256));
5670#else
5671 return base::nullopt;
5672#endif
5673}
5674
Sam McNallyd54e23f92019-01-16 04:42:395675bool ChromeContentBrowserClient::IsBuiltinComponent(
5676 content::BrowserContext* browser_context,
5677 const url::Origin& origin) {
5678#if BUILDFLAG(ENABLE_EXTENSIONS)
5679 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5680 browser_context, origin);
5681#else
5682 return false;
5683#endif
5684}
Oleg Davydov2cc0167b2019-02-05 14:32:485685
Aaron Colwelle1908d982020-06-26 22:08:155686bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:485687 const GURL& url,
5688 content::BrowserContext* context) {
Aaron Colwellf94fd97a2020-07-21 19:37:085689 PolicyBlocklistService* service =
5690 PolicyBlocklistFactory::GetForBrowserContext(context);
Oleg Davydov2cc0167b2019-02-05 14:32:485691
Aaron Colwellf94fd97a2020-07-21 19:37:085692 using URLBlocklistState = policy::URLBlocklist::URLBlocklistState;
5693 URLBlocklistState blocklist_state = service->GetURLBlocklistState(url);
5694 return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST;
Oleg Davydov2cc0167b2019-02-05 14:32:485695}
Dominic Mazzoni21fb0282019-02-13 18:32:475696
5697ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5698 content::BrowserContext* browser_context) {
5699 Profile* profile = Profile::FromBrowserContext(browser_context);
5700 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5701}
Eric Karld6cd75b2019-03-14 22:01:365702
5703#if defined(OS_ANDROID)
5704content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525705ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335706 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425707 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365708 return WideColorGamutHeuristic::kUseDisplay;
5709 }
Khushal1fc0da52019-10-09 00:38:565710
5711 if (display::Display::HasForceDisplayColorProfile() &&
5712 display::Display::GetForcedDisplayColorProfile() ==
5713 gfx::ColorSpace::CreateDisplayP3D65()) {
5714 return WideColorGamutHeuristic::kUseDisplay;
5715 }
5716
Eric Karld6cd75b2019-03-14 22:01:365717 return WideColorGamutHeuristic::kNone;
5718}
5719#endif
Ehsan Karamad91413d72019-03-22 16:37:485720
5721base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435722ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465723 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485724 base::flat_set<std::string> mime_types;
5725#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465726 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485727 for (const auto& pair : map)
5728 mime_types.insert(pair.first);
5729#endif
5730 return mime_types;
5731}
Yao Xiaod06607b2019-05-02 23:16:365732
5733void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
Alex Turner5d3dd2572020-12-16 18:08:055734 content::WebContents* web_contents,
5735 content::RenderFrameHost* frame_host,
Yao Xiaod06607b2019-05-02 23:16:365736 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525737 content::NavigationDownloadPolicy* download_policy) {
Colin Blundell0ec5d642020-10-06 17:29:525738 const auto* throttle_manager = subresource_filter::
5739 ContentSubresourceFilterThrottleManager::FromWebContents(web_contents);
5740 if (throttle_manager && throttle_manager->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045741 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365742 if (!user_gesture) {
5743 if (base::FeatureList::IsEnabled(
5744 blink::features::
5745 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5746 download_policy->SetDisallowed(
5747 content::NavigationDownloadType::kAdFrameNoGesture);
5748 } else {
5749 download_policy->SetAllowed(
5750 content::NavigationDownloadType::kAdFrameNoGesture);
5751 }
Yao Xiaod06607b2019-05-02 23:16:365752 }
5753 }
5754}
Jun Cai732a05e32019-05-29 19:34:195755
Yao Xiaoebed8c12020-09-26 07:51:205756std::string ChromeContentBrowserClient::GetInterestCohortForJsApi(
Yao Xiaoc5436ad2021-01-12 00:22:305757 content::WebContents* web_contents,
Yao Xiao1e28cd42020-12-22 19:31:215758 const GURL& url,
5759 const base::Optional<url::Origin>& top_frame_origin) {
Yao Xiaoc5436ad2021-01-12 00:22:305760 federated_learning::FlocEligibilityObserver::GetOrCreateForCurrentDocument(
5761 web_contents->GetMainFrame())
5762 ->OnInterestCohortApiUsed();
5763
Yao Xiaoebed8c12020-09-26 07:51:205764 federated_learning::FlocIdProvider* floc_id_provider =
5765 federated_learning::FlocIdProviderFactory::GetForProfile(
Yao Xiaoc5436ad2021-01-12 00:22:305766 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
Yao Xiaoebed8c12020-09-26 07:51:205767
5768 if (!floc_id_provider)
5769 return std::string();
5770
Yao Xiao1e28cd42020-12-22 19:31:215771 return floc_id_provider->GetInterestCohortForJsApi(url, top_frame_origin);
Yao Xiaoebed8c12020-09-26 07:51:205772}
5773
Jun Cai732a05e32019-05-29 19:34:195774bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5775 content::BrowserContext* browser_context,
5776 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525777 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195778 const HostContentSettingsMap* const content_settings =
5779 HostContentSettingsMapFactory::GetForProfile(
5780 Profile::FromBrowserContext(browser_context));
5781
5782 if (content_settings->GetContentSetting(
5783 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145784 ContentSettingsType::BLUETOOTH_SCANNING) == CONTENT_SETTING_BLOCK) {
Jun Cai732a05e32019-05-29 19:34:195785 return true;
5786 }
5787
5788 return false;
5789}
5790
5791void ChromeContentBrowserClient::BlockBluetoothScanning(
5792 content::BrowserContext* browser_context,
5793 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525794 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195795 HostContentSettingsMap* const content_settings =
5796 HostContentSettingsMapFactory::GetForProfile(
5797 Profile::FromBrowserContext(browser_context));
5798
5799 content_settings->SetContentSettingDefaultScope(
5800 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145801 ContentSettingsType::BLUETOOTH_SCANNING, CONTENT_SETTING_BLOCK);
Jun Cai732a05e32019-05-29 19:34:195802}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475803
Clark DuVall1635a6b02020-11-06 18:53:515804bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile(
5805 std::string* split_name) {
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475806#if defined(OS_ANDROID)
Clark DuVall1635a6b02020-11-06 18:53:515807 *split_name = "extra_icu";
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475808 return extra_icu::ModuleProvider::IsModuleInstalled();
5809#endif
5810 return false;
5811}
Guido Urdaneta4030d6a32019-10-17 09:38:165812
5813bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5814 content::BrowserContext* browser_context,
5815 const GURL& url,
5816 const GURL& site_for_cookies,
5817 const base::Optional<url::Origin>& top_frame_origin) {
5818 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5819 return CookieSettingsFactory::GetForProfile(
5820 Profile::FromBrowserContext(browser_context))
5821 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5822}
Sam Goto5cf068e82019-11-04 23:08:445823
5824#if !defined(OS_ANDROID)
5825void ChromeContentBrowserClient::FetchRemoteSms(
5826 content::BrowserContext* browser_context,
5827 const url::Origin& origin,
5828 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5829 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5830}
5831#endif
Roger Tawa03ffdbd2020-01-16 18:12:545832
5833void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5834 content::WebContents* web_contents,
5835 const GURL& url,
5836 const ui::ClipboardFormatType& data_type,
5837 const std::string& data,
5838 IsClipboardPasteAllowedCallback callback) {
5839#if BUILDFLAG(FULL_SAFE_BROWSING)
5840 // Safe browsing does not support images, so accept without checking.
5841 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5842 // types when it is implemented.
Darwin Huang0024dbf2020-08-04 00:53:555843 if (data_type == ui::ClipboardFormatType::GetBitmapType()) {
Roger Tawa03ffdbd2020-01-16 18:12:545844 std::move(callback).Run(ClipboardPasteAllowed(true));
5845 return;
5846 }
5847
5848 Profile* profile =
5849 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375850 enterprise_connectors::ContentAnalysisDelegate::Data dialog_data;
5851 if (enterprise_connectors::ContentAnalysisDelegate::IsEnabled(
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265852 profile, url, &dialog_data,
5853 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545854 dialog_data.text.push_back(base::UTF8ToUTF16(data));
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375855 enterprise_connectors::ContentAnalysisDelegate::CreateForWebContents(
Roger Tawa03ffdbd2020-01-16 18:12:545856 web_contents, std::move(dialog_data),
5857 base::BindOnce(
5858 [](IsClipboardPasteAllowedCallback callback,
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375859 const enterprise_connectors::ContentAnalysisDelegate::Data& data,
5860 const enterprise_connectors::ContentAnalysisDelegate::Result&
Roger Tawa03ffdbd2020-01-16 18:12:545861 result) {
5862 std::move(callback).Run(
5863 ClipboardPasteAllowed(result.text_results[0]));
5864 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245865 std::move(callback)),
5866 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545867 } else {
5868 std::move(callback).Run(ClipboardPasteAllowed(true));
5869 }
5870#else
5871 std::move(callback).Run(ClipboardPasteAllowed(true));
5872#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5873}
Lukasz Anforowicz4600ea32020-01-18 02:37:485874
5875#if BUILDFLAG(ENABLE_PLUGINS)
5876bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5877 const url::Origin& embedder_origin,
5878 const content::PepperPluginInfo& plugin_info) {
5879#if BUILDFLAG(ENABLE_PDF)
5880 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5881#if BUILDFLAG(ENABLE_EXTENSIONS)
5882 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5883 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5884 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5885 return true;
5886 }
5887#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5888
5889 // Allow embedding the internal PDF plugin in chrome://print.
5890 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5891 return true;
5892
5893 // Only allow the PDF plugin in the known, trustworthy origins that are
5894 // allowlisted above. See also https://crbug.com/520422 and
5895 // https://crbug.com/1027173.
5896 return false;
5897 }
5898#endif // BUILDFLAG(ENABLE_PDF)
5899
5900 return true;
5901}
5902#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565903
5904#if BUILDFLAG(ENABLE_VR)
5905content::XrIntegrationClient*
5906ChromeContentBrowserClient::GetXrIntegrationClient() {
5907 if (!xr_integration_client_)
5908 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
Peter Kasting796cde22020-11-18 21:06:535909 base::PassKey<ChromeContentBrowserClient>());
Alexander Cooperc8448702020-03-14 01:39:565910 return xr_integration_client_.get();
5911}
5912#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185913
5914bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5915 content::BrowserContext* browser_context) {
5916 auto* profile = Profile::FromBrowserContext(browser_context);
5917 auto* prefs = profile->GetPrefs();
5918
5919 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5920 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5921 return false;
5922 }
5923 if (base::FeatureList::IsEnabled(
5924 blink::features::kAppCacheRequireOriginTrial)) {
5925 return true;
5926 }
5927
5928 return false;
5929}
Yutaka Hirano3e613662020-06-02 02:59:345930
Hidehiko Abeeaffbbce2020-06-23 19:41:525931void ChromeContentBrowserClient::BindBrowserControlInterface(
Hidehiko Abe23e45e82020-08-25 08:41:485932 mojo::ScopedMessagePipeHandle pipe) {
Yuta Hijikata235fc62b2020-12-08 03:48:325933#if BUILDFLAG(IS_CHROMEOS_LACROS)
Hidehiko Abe23e45e82020-08-25 08:41:485934 chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(
Hidehiko Abe67fb6a82021-01-21 07:50:365935 mojo::PendingReceiver<crosapi::mojom::BrowserService>(std::move(pipe)));
Hidehiko Abeeaffbbce2020-06-23 19:41:525936#endif
5937}
5938
Yutaka Hirano3e613662020-06-02 02:59:345939bool ChromeContentBrowserClient::
5940 ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) {
5941#if BUILDFLAG(ENABLE_EXTENSIONS)
5942 return url.SchemeIs(extensions::kExtensionScheme);
5943#else
5944 return false;
5945#endif
5946}
John Abd-El-Malekdc026012020-06-15 23:28:565947
Titouan Rigoudycfc73552020-08-21 14:18:305948bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125949 content::BrowserContext* browser_context,
Titouan Rigoudyce223ab2021-01-27 16:08:025950 const url::Origin& origin) {
Titouan Rigoudycfc73552020-08-21 14:18:305951 return content_settings::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudyce223ab2021-01-27 16:08:025952 HostContentSettingsMapFactory::GetForProfile(browser_context), origin);
Titouan Rigoudy9c2c0142020-08-19 17:57:125953}
5954
John Abd-El-Malekdc026012020-06-15 23:28:565955ukm::UkmService* ChromeContentBrowserClient::GetUkmService() {
5956 return g_browser_process->GetMetricsServicesManager()->GetUkmService();
5957}
Evan Liu054dc082020-09-30 14:09:425958
Yutaka Hirano93e924742020-11-11 10:40:135959void ChromeContentBrowserClient::OnKeepaliveRequestStarted() {
5960#if !defined(OS_ANDROID)
5961 if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) {
Yutaka Hirano311a7412021-01-06 06:17:355962 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5963 // done.
5964 VLOG(1) << "OnKeepaliveRequestStarted: " << num_keepalive_requests_
5965 << " ==> " << num_keepalive_requests_ + 1;
Yutaka Hirano93e924742020-11-11 10:40:135966 ++num_keepalive_requests_;
5967
5968 DCHECK_GT(num_keepalive_requests_, 0u);
5969 last_keepalive_request_time_ = base::TimeTicks::Now();
5970 if (!keepalive_timer_.IsRunning()) {
Yutaka Hirano311a7412021-01-06 06:17:355971 const auto timeout = GetKeepaliveTimerTimeout();
5972 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5973 // done.
5974 VLOG(1) << "Starting a keepalive timer(" << timeout.InSecondsF()
5975 << " seconds)";
Yutaka Hirano93e924742020-11-11 10:40:135976 keepalive_timer_.Start(
Yutaka Hirano311a7412021-01-06 06:17:355977 FROM_HERE, timeout,
Yutaka Hirano93e924742020-11-11 10:40:135978 base::BindOnce(
5979 &ChromeContentBrowserClient::OnKeepaliveTimerFired,
5980 weak_factory_.GetWeakPtr(),
5981 std::make_unique<ScopedKeepAlive>(
5982 KeepAliveOrigin::BROWSER, KeepAliveRestartOption::DISABLED)));
5983 }
5984 }
5985#endif // !defined(OS_ANDROID)
5986}
5987
5988void ChromeContentBrowserClient::OnKeepaliveRequestFinished() {
5989#if !defined(OS_ANDROID)
5990 if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) {
5991 DCHECK_GT(num_keepalive_requests_, 0u);
Yutaka Hirano311a7412021-01-06 06:17:355992 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5993 // done.
5994 VLOG(1) << "OnKeepaliveRequestFinished: " << num_keepalive_requests_
5995 << " ==> " << num_keepalive_requests_ - 1;
Yutaka Hirano93e924742020-11-11 10:40:135996 --num_keepalive_requests_;
5997 if (num_keepalive_requests_ == 0) {
Yutaka Hirano311a7412021-01-06 06:17:355998 // TODO(crbug.com/1161996): Remove this entry once the investigation is
5999 // done.
6000 VLOG(1) << "Stopping the keepalive timer";
Yutaka Hirano93e924742020-11-11 10:40:136001 keepalive_timer_.Stop();
6002 // This deletes the keep alive handle attached to the timer function and
6003 // unblock the shutdown sequence.
6004 }
6005 }
6006#endif // !defined(OS_ANDROID)
6007}
6008
Evan Liu054dc082020-09-30 14:09:426009#if defined(OS_MAC)
6010bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters(
6011 sandbox::policy::SandboxType sandbox_type,
6012 sandbox::SeatbeltExecClient* client) {
6013 if (sandbox_type == sandbox::policy::SandboxType::kSpeechRecognition) {
6014 base::FilePath soda_component_path = speech::GetSodaDirectory();
6015 CHECK(!soda_component_path.empty());
6016 CHECK(client->SetParameter(
6017 sandbox::policy::SandboxMac::kSandboxSodaComponentPath,
6018 soda_component_path.value()));
6019
6020 base::FilePath soda_language_pack_path =
6021 speech::GetSodaLanguagePacksDirectory();
6022 CHECK(!soda_language_pack_path.empty());
6023 CHECK(client->SetParameter(
6024 sandbox::policy::SandboxMac::kSandboxSodaLanguagePackPath,
6025 soda_language_pack_path.value()));
6026 return true;
6027 }
6028
6029 return false;
6030}
6031
6032#endif // defined(OS_MAC)
Koji Ishii3cbd93a2020-10-16 13:48:026033
6034void ChromeContentBrowserClient::GetHyphenationDictionary(
6035 base::OnceCallback<void(const base::FilePath&)> callback) {
6036#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
6037 component_updater::HyphenationComponentInstallerPolicy::
6038 GetHyphenationDictionary(std::move(callback));
6039#endif
6040}
Rakina Zata Amniba3eecb2020-11-02 10:12:286041
6042bool ChromeContentBrowserClient::HasErrorPage(int http_status_code) {
6043 // Use an internal error page, if we have one for the status code.
6044 return error_page::LocalizedError::HasStrings(
6045 error_page::Error::kHttpErrorDomain, http_status_code);
6046}
Yutaka Hirano93e924742020-11-11 10:40:136047
Ken Buchanan7d688352020-12-05 05:45:576048std::unique_ptr<content::IdentityRequestDialogController>
6049ChromeContentBrowserClient::CreateIdentityRequestDialogController() {
6050 return std::make_unique<IdentityDialogController>();
6051}
6052
Reid Kleckner4d3f21c2021-01-25 22:48:316053#if !defined(OS_ANDROID)
Yutaka Hirano93e924742020-11-11 10:40:136054void ChromeContentBrowserClient::OnKeepaliveTimerFired(
6055 std::unique_ptr<ScopedKeepAlive> keep_alive_handle) {
Yutaka Hirano311a7412021-01-06 06:17:356056 // TODO(crbug.com/1161996): Remove this entry once the investigation is done.
6057 VLOG(1) << "OnKeepaliveTimerFired";
Yutaka Hirano93e924742020-11-11 10:40:136058 DCHECK(base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive));
6059 const auto now = base::TimeTicks::Now();
Yutaka Hirano311a7412021-01-06 06:17:356060 const auto then = last_keepalive_request_time_ + GetKeepaliveTimerTimeout();
Yutaka Hirano93e924742020-11-11 10:40:136061 if (now < then) {
Yutaka Hirano311a7412021-01-06 06:17:356062 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6063 // done.
6064 VLOG(1) << "Extending keepalive timer";
Yutaka Hirano93e924742020-11-11 10:40:136065 keepalive_timer_.Start(
6066 FROM_HERE, then - now,
6067 base::BindOnce(&ChromeContentBrowserClient::OnKeepaliveTimerFired,
6068 weak_factory_.GetWeakPtr(),
6069 std::move(keep_alive_handle)));
6070 }
Yutaka Hirano93e924742020-11-11 10:40:136071}
Reid Kleckner4d3f21c2021-01-25 22:48:316072#endif