blob: 33914cd5b387bf8f4c9ec3b0cb2b92b04fc8a3dc [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"
Yann Dago3256b872021-01-13 18:48:0393#include "chrome/browser/policy/profile_policy_connector.h"
Evan Stade2f016c52021-01-11 20:43:3494#include "components/site_engagement/content/site_engagement_service.h"
Liquan (Max) Gud648f452020-12-18 05:28:4495#if !defined(OS_ANDROID)
96#include "chrome/browser/payments/payment_handler_navigation_throttle.h"
97#endif
Sigurdur Asgeirsson54b72702019-04-12 14:18:5498#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5199#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:56100#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:42101#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:11102#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:48103#include "chrome/browser/plugins/plugin_utils.h"
Hiroki Nakagawa3e4b5492020-11-03 01:41:04104#include "chrome/browser/prefetch/no_state_prefetch/chrome_prerender_contents_delegate.h"
105#include "chrome/browser/prefetch/no_state_prefetch/prerender_manager_factory.h"
Hiroki Nakagawa483686a92020-10-29 04:31:45106#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_features.h"
107#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service.h"
108#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service_factory.h"
109#include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_url_loader_interceptor.h"
Ryan Sturm8670b572020-10-21 18:45:30110#include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h"
111#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h"
112#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
Ryan Sturm6b2f6392020-12-09 21:46:00113#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader.h"
Ryan Sturm8670b572020-10-21 18:45:30114#include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader_interceptor.h"
Ryan Sturmcc5071be2019-02-16 02:15:19115#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54116#include "chrome/browser/previews/previews_service.h"
117#include "chrome/browser/previews/previews_service_factory.h"
118#include "chrome/browser/previews/previews_ui_tab_helper.h"
John Delaneyc2782792021-01-15 01:29:07119#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings.h"
120#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
[email protected]7e75e4a2013-05-17 17:20:03121#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14122#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32123#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49124#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06125#include "chrome/browser/profiles/renderer_updater.h"
126#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56127#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
128#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44129#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38130#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40131#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45132#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31133#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
134#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24135#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43136#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00137#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40138#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35139#include "chrome/browser/safe_browsing/ui_manager.h"
140#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58141#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43142#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44143#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20144#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35145#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40146#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23147#include "chrome/browser/signin/identity_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:02148#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Colin Blundell13e92ec2020-01-27 09:47:38149#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Chris Thompsone2e073d42020-07-23 12:33:45150#include "chrome/browser/ssl/sct_reporting_service.h"
151#include "chrome/browser/ssl/sct_reporting_service_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32152#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07153#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Mustafa Emre Acer06028d792021-01-05 19:48:51154#include "chrome/browser/ssl/typed_navigation_upgrade_throttle.h"
meacer4ef065e2015-01-09 03:21:35155#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45156#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52157#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19158#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44159#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Clark DuVall8a020d622020-06-04 00:45:50160#include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h"
Charles Harrison6dd11d282017-10-03 06:14:51161#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08162#include "chrome/browser/ui/browser_navigator.h"
163#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43164#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39165#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54166#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28167#include "chrome/browser/ui/login/login_tab_helper.h"
Jonathan Mengedoht42a19bb2020-07-28 14:10:16168#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56169#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25170#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44171#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58172#include "chrome/browser/ui/ui_features.h"
Ken Buchanan7d688352020-12-05 05:45:57173#include "chrome/browser/ui/webid/identity_dialog_controller.h"
[email protected]863f70a2012-01-27 02:05:50174#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01175#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45176#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53177#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25178#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59179#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23180#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22181#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01182#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48183#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51184#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14185#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22186#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30187#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02188#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50189#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34190#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37191#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12192#include "chrome/common/pref_names.h"
Mike Wittman67d63112020-09-19 00:33:46193#include "chrome/common/profiler/thread_profiler_configuration.h"
nigeltao7cd8d5582016-12-12 06:05:28194#include "chrome/common/renderer_configuration.mojom.h"
Ayu Ishiifbb1fad2020-06-22 20:15:07195#include "chrome/common/secure_origin_allowlist.h"
[email protected]c5dbef02011-05-13 05:06:09196#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47197#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37198#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18199#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30200#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12201#include "components/autofill/core/common/autofill_switches.h"
Clark DuVall8a020d622020-06-04 00:45:50202#include "components/blocked_content/popup_blocker.h"
Clark DuVallf5189252020-04-15 22:33:34203#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53204#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51205#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49206#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44207#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04208#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48209#include "components/cloud_devices/common/cloud_devices_switches.h"
Carlos Caballerob4283202020-08-10 14:40:46210#include "components/content_settings/browser/page_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16211#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09212#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16213#include "components/content_settings/core/browser/host_content_settings_map.h"
Titouan Rigoudy9c2c0142020-08-19 17:57:12214#include "components/content_settings/core/browser/private_network_settings.h"
mukai077089f2014-09-11 18:41:52215#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45216#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08217#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03218#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54219#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28220#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43221#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09222#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03223#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24224#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32225#include "components/embedder_support/switches.h"
Rakina Zata Amniba3eecb2020-11-02 10:12:28226#include "components/error_page/common/error.h"
blundella5e3240a2016-01-05 11:30:43227#include "components/error_page/common/error_page_switches.h"
Rakina Zata Amniba3eecb2020-11-02 10:12:28228#include "components/error_page/common/localized_error.h"
Ken Rockot4408a0f2020-07-27 19:40:54229#include "components/error_page/content/browser/net_error_auto_reloader.h"
khushalsagarc5447db22017-08-22 17:53:01230#include "components/feature_engagement/public/feature_constants.h"
231#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malekcdb5b522020-05-26 22:41:03232#include "components/google/core/common/google_switches.h"
Yutaka Hirano93e924742020-11-11 10:40:13233#include "components/keep_alive_registry/keep_alive_types.h"
234#include "components/keep_alive_registry/scoped_keep_alive.h"
Alexandre Frechette572755b2019-02-13 22:30:20235#include "components/language/core/browser/pref_names.h"
Evan Stadebbb9f5242020-09-25 17:26:46236#include "components/media_router/browser/presentation/presentation_service_delegate_impl.h"
237#include "components/media_router/browser/presentation/receiver_presentation_service_delegate_impl.h"
[email protected]8e885de2014-07-22 23:36:53238#include "components/metrics/client_info.h"
John Abd-El-Malekdc026012020-06-15 23:28:56239#include "components/metrics_services_manager/metrics_services_manager.h"
drogerc690e8802015-09-21 14:29:16240#include "components/net_log/chrome_net_log.h"
Hiroki Nakagawa76e0fe01b2020-11-06 04:32:45241#include "components/no_state_prefetch/browser/prerender_manager.h"
242#include "components/no_state_prefetch/common/prerender_final_status.h"
243#include "components/no_state_prefetch/common/prerender_types.mojom.h"
244#include "components/no_state_prefetch/common/prerender_url_loader_throttle.h"
245#include "components/no_state_prefetch/common/prerender_util.h"
Mustafa Emre Acer06028d792021-01-05 19:48:51246#include "components/omnibox/common/omnibox_features.h"
Tao Baib827b202019-09-19 21:22:12247#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
248#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06249#include "components/payments/content/payment_request_display_manager.h"
Chris Hamiltonab4722122020-05-13 18:01:28250#include "components/performance_manager/embedder/performance_manager_registry.h"
Clark DuValla11361ad32020-02-20 22:14:27251#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54252#include "components/permissions/quota_permission_context_impl.h"
Aaron Colwellb4226222020-07-25 16:11:36253#include "components/policy/content/policy_blocklist_navigation_throttle.h"
254#include "components/policy/content/policy_blocklist_service.h"
Chris Hamilton65c41312020-06-10 13:14:40255#include "components/policy/core/common/policy_pref_names.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18256#include "components/policy/core/common/policy_service.h"
257#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26258#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54259#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08260#include "components/prefs/pref_service.h"
261#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21262#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54263#include "components/previews/content/previews_decider_impl.h"
264#include "components/previews/content/previews_ui_service.h"
265#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54266#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45267#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43268#include "components/previews/core/previews_switches.h"
Nico Weberbc5b06f2019-07-26 14:00:13269#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47270#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
271#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
272#include "components/safe_browsing/core/browser/url_checker_delegate.h"
273#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
274#include "components/safe_browsing/core/db/database_manager.h"
275#include "components/safe_browsing/core/features.h"
276#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58277#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Carlos IL1a5edec2020-06-12 17:56:57278#include "components/security_interstitials/content/insecure_form_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14279#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49280#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48281#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49282#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23283#include "components/signin/public/identity_manager/identity_manager.h"
Clark DuVallaadc244c2020-06-06 03:47:14284#include "components/site_isolation/pref_names.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54285#include "components/site_isolation/preloaded_isolated_origins.h"
Clark DuVallaadc244c2020-06-06 03:47:14286#include "components/site_isolation/site_isolation_policy.h"
csharrisone985ebc2017-04-04 17:05:03287#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17288#include "components/translate/core/common/translate_switches.h"
Maks Orlovich5408ddfc2020-07-28 23:07:35289#include "components/ukm/content/source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21290#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28291#include "components/variations/variations_associated_data.h"
Ben Goldberger72533cd2020-07-21 16:11:38292#include "components/variations/variations_ids_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46293#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22294#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39295#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33296#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43297#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30298#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38299#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28300#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03301#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31302#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41303#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09304#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03305#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59306#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19307#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31308#include "content/public/browser/file_url_loader.h"
Olivier Yiptong935e6c42020-11-21 01:28:23309#include "content/public/browser/font_access_delegate.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35310#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47311#include "content/public/browser/navigation_handle.h"
312#include "content/public/browser/navigation_throttle.h"
Lukasz Anforowicz44a0f9e2020-09-30 15:05:38313#include "content/public/browser/non_network_url_loader_factory_base.h"
Jennifer Apacible4f854a82018-04-06 22:22:11314#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50315#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30316#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33317#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05318#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54319#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34320#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48321#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27322#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13323#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08324#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19325#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21326#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23327#include "content/public/browser/web_ui_url_loader_factory.h"
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:21328#include "content/public/common/bindings_policy.h"
[email protected]e0ada9c2012-03-20 03:54:43329#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18330#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56331#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40332#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02333#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18334#include "content/public/common/network_service_util.h"
Chris Mumfordbae8a742018-03-01 23:02:23335#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44336#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31337#include "content/public/common/user_agent.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56338#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43339#include "device/vr/buildflags/buildflags.h"
Karandeep Bhatiaae5d9f32020-07-17 02:52:34340#include "extensions/browser/process_map.h"
Scott Violetc8240b02018-03-08 22:03:59341#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48342#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30343#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28344#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18345#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04346#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31347#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44348#include "media/media_buildflags.h"
349#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12350#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42351#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52352#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08353#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53354#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51355#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58356#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23357#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46358#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57359#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48360#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14361#include "ppapi/buildflags/buildflags.h"
Scott Violet318a55f2018-03-30 19:08:19362#include "printing/buildflags/buildflags.h"
Guido Urdanetae02b5722020-07-22 05:58:21363#include "sandbox/policy/features.h"
Robert Sesek7d0b49b2020-07-08 18:31:27364#include "sandbox/policy/sandbox_type.h"
365#include "sandbox/policy/switches.h"
Yue Ru Sun03a6990a2020-10-24 18:04:31366#include "services/metrics/public/cpp/ukm_source_id.h"
Takashi Toyoshima128441462019-10-16 04:19:17367#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37368#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50369#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50370#include "services/network/public/cpp/resource_request.h"
Ken Rockotcebdf9c82019-05-28 20:33:03371#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06372#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02373#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02374#include "third_party/blink/public/common/features.h"
Minggang Wangb2f82902020-08-25 16:07:09375#include "third_party/blink/public/common/loader/referrer_utils.h"
Minggang Wangf6840ecf2019-07-29 05:15:02376#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:23377#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
Chris Hamilton65c41312020-06-10 13:14:40378#include "third_party/blink/public/common/switches.h"
Lily Chenc2c9e9f2019-12-05 19:55:31379#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17380#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Gyuyoung Kim1e9d3c32020-10-12 14:04:57381#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h"
Koji Ishii3cbd93a2020-10-16 13:48:02382#include "third_party/blink/public/public_buildflags.h"
Evan Liu7cdbf8872019-06-19 16:47:21383#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26384#include "third_party/widevine/cdm/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54385#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39386#include "ui/base/l10n/l10n_util.h"
Scott Violet5ae6c42e2020-10-28 02:47:37387#include "ui/base/page_transition_types.h"
[email protected]ac55e292011-06-24 05:16:08388#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35389#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56390#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21391#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49392#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57393#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45394#include "url/gurl.h"
395#include "url/origin.h"
Olya Kalitova78ae04932020-09-21 11:26:06396#include "url/third_party/mozilla/url_parse.h"
397#include "url/url_constants.h"
[email protected]d977f9c2011-03-14 16:10:26398
[email protected]b48c9182011-10-26 18:03:30399#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20400#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14401#include "base/win/win_util.h"
402#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38403#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36404#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18405#include "sandbox/win/src/sandbox_policy.h"
Avi Drissman2e458df2020-07-29 16:24:31406#elif defined(OS_MAC)
[email protected]199fc7a2011-09-28 22:45:38407#include "chrome/browser/chrome_browser_main_mac.h"
Evan Liu054dc082020-09-30 14:09:42408#include "components/soda/constants.h"
409#include "sandbox/mac/seatbelt_exec.h"
410#include "sandbox/policy/mac/sandbox_mac.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32411#elif BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhallda2659142020-05-14 06:04:37412#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42413#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30414#include "chrome/app/chrome_crash_reporter_client.h"
Aya ElAttareb5fee12020-05-05 08:56:05415#include "chrome/browser/browser_process.h"
Andreea Costinas81218bf2021-01-08 11:48:14416#include "chrome/browser/browser_process_platform_part.h"
hashimotoa53e7e82016-10-26 06:30:47417#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17418#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30419#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24420#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18421#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08422#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48423#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41424#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32425#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58426#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00427#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
428#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44429#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39430#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31431#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33432#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05433#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Andreea Costinas81218bf2021-01-08 11:48:14434#include "chrome/browser/chromeos/policy/system_proxy_manager.h"
Pavol Marko230ea2c92017-12-03 22:35:44435#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34436#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10437#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36438#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27439#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31440#include "chrome/browser/ui/browser_dialogs.h"
Jesse Schettlerb7047f32020-09-18 14:50:40441#include "chromeos/components/scanning/url_constants.h"
Steven Bennetts38e9bde22019-01-03 17:31:10442#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21443#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10444#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50445#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05446#include "components/policy/core/common/policy_pref_names.h"
447#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07448#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58449#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50450#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32451#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
[email protected]b48c9182011-10-26 18:03:30452#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09453#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35454#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23455#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45456#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47457#include "chrome/android/modules/extra_icu/provider/module_provider.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36458#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36459#include "chrome/browser/android/devtools_manager_delegate_android.h"
460#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
461#include "chrome/browser/android/service_tab_launcher.h"
462#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42463#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09464#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56465#include "chrome/browser/download/android/available_offline_content_provider.h"
466#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23467#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07468#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38469#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11470#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07471#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47472#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36473#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54474#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00475#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36476#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45477#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04478#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45479#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30480#elif defined(OS_POSIX)
481#include "chrome/browser/chrome_browser_main_posix.h"
482#endif
483
Yuta Hijikata235fc62b2020-12-08 03:48:32484#if !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51485#include "ui/accessibility/accessibility_features.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32486#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhalla9aafba42020-06-24 05:42:51487
tmartinofb341882017-02-10 19:36:53488#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40489#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36490#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54491#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59492#include "chrome/browser/media/unified_autoplay_config.h"
Zach Trudocc4aa4d2020-09-21 22:19:45493#include "chrome/browser/policy/dm_token_utils.h"
Marc Treib7895941d2017-11-28 12:37:02494#include "chrome/browser/search/instant_service.h"
495#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46496#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51497#include "chrome/browser/ui/browser.h"
498#include "chrome/browser/ui/browser_finder.h"
499#include "chrome/browser/ui/browser_list.h"
500#include "chrome/browser/ui/browser_window.h"
Conley Owensaafcf122018-02-26 18:53:51501#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39502#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
503#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43504#include "chrome/common/importer/profile_import.mojom.h"
Glen Robertson8a825ae4f2020-09-16 06:50:08505#include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897
Maggie Caia2f03f52019-04-02 02:13:28506#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36507
Yuta Hijikata235fc62b2020-12-08 03:48:32508// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
509// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:31510#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:32511 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52512#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
513#endif
514
Sean McAllister0d73ca3d2020-08-19 17:54:37515#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Rohit Rao92f84b6a2020-03-25 14:57:50516#include "components/crash/core/app/crash_switches.h"
517#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24518#endif
519
Avi Drissman2e458df2020-07-29 16:24:31520#if defined(OS_POSIX) && !defined(OS_MAC)
Joshua Perazaf890e4b2019-01-03 19:19:02521#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02522#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50523#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02524#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13525#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43526#endif
[email protected]b80f68432011-05-02 17:22:30527
Maggie Caia2f03f52019-04-02 02:13:28528// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
529// single navigation throttle to display the intent picker on all platforms.
530#if !defined(OS_ANDROID)
Yuta Hijikata235fc62b2020-12-08 03:48:32531#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Caia2f03f52019-04-02 02:13:28532#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51533#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28534#else
535#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
536#endif
537#endif
538
[email protected]e8b6ca02013-07-10 18:00:51539#if defined(TOOLKIT_VIEWS)
540#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
541#endif
542
Yuta Hijikata235fc62b2020-12-08 03:48:32543// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
544// of lacros-chrome is complete.
545#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
estaded3aa0e82016-02-17 22:55:21546#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51547#endif
548
Mohsen Izadif1958f22019-01-18 20:29:31549#if defined(USE_OZONE)
550#include "ui/ozone/public/ozone_platform.h"
551#endif
552
Maksim Sisov1686fc22020-06-17 07:59:20553#if defined(USE_X11) || defined(USE_OZONE)
554#include "chrome/browser/chrome_browser_main_extra_parts_ozone.h"
[email protected]e8b6ca02013-07-10 18:00:51555#endif
556
brettwab78fef2016-10-12 02:56:05557#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10558#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38559#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19560#endif
561
Nico Weberaf3b00b2017-09-11 17:58:17562#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55563#include "components/nacl/browser/nacl_browser.h"
564#include "components/nacl/browser/nacl_host_message_filter.h"
565#include "components/nacl/browser/nacl_process_host.h"
566#include "components/nacl/common/nacl_process_type.h"
567#include "components/nacl/common/nacl_switches.h"
568#endif
569
brettw00899e62016-11-12 02:10:17570#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05571#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20572#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27573#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23574#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32575#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51576#include "chrome/browser/extensions/user_script_listener.h"
thestig2dbee717e2014-09-05 14:54:28577#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49578#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46579#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39580#include "components/guest_view/browser/guest_view_base.h"
581#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25582#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31583#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35584#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32585#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12586#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57587#include "extensions/browser/extension_system.h"
Aaron Colwell8c430642020-08-04 01:55:20588#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48589#include "extensions/browser/guest_view/web_view/web_view_guest.h"
590#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
591#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31592#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27593#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28594#include "extensions/common/extension.h"
595#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13596#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28597#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33598#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28599#include "extensions/common/permissions/permissions_data.h"
600#include "extensions/common/permissions/socket_permission.h"
601#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34602#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25603
brettw4b461082016-11-19 18:55:16604#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55605#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39606#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55607#endif
608
bauerb8f9c37742017-03-30 15:04:12609#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
610#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
611#endif
612
Yuta Hijikata235fc62b2020-12-08 03:48:32613#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchuk762c40d2020-05-11 15:10:37614#include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06615#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
Scott Violet1644cf72020-06-24 04:51:55616#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Yuta Hijikata235fc62b2020-12-08 03:48:32617#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:06618
thakis678822e2017-04-20 17:20:34619#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38620#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09621#endif
622
Xiaohan Wanga4e41842018-06-26 18:45:10623#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49624#include "chrome/browser/media/output_protection_impl.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06625#if BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10626#include "third_party/widevine/cdm/widevine_cdm_common.h"
Jeffrey Kardatzke614424232020-12-12 00:54:06627#if defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)
628#include "chrome/browser/media/widevine_hardware_caps.h"
Xiaohan Wanga4e41842018-06-26 18:45:10629#endif
Jeffrey Kardatzke614424232020-12-12 00:54:06630#endif // BUILDFLAG(ENABLE_WIDEVINE)
631#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wanga4e41842018-06-26 18:45:10632
mmenkedb2637ff2017-03-30 23:59:42633#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
634#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
635#endif
636
Bettinafd0c1102020-08-06 00:23:43637#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Daniel Ruberya1611e32019-04-24 21:38:35638#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32639#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35640#endif
641
Glen Robertson8a825ae4f2020-09-16 06:50:08642#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
643#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897
644#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897
645#endif
646
Jian Lide7b43792018-06-01 23:22:13647#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54648#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13649#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
650#endif
651
Will Cassella40837ba2019-07-01 21:32:00652#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Glen Robertson8a825ae4f2020-09-16 06:50:08653#include "device/vr/public/mojom/isolated_xr_service.mojom.h" // nogncheck crbug.com/1125897
Bill Orreb429222018-08-08 21:14:43654#endif
655
John Lee0ee748bf2019-12-11 21:35:44656#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
657#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
658#endif
659
Roger Tawa03ffdbd2020-01-16 18:12:54660#if BUILDFLAG(FULL_SAFE_BROWSING)
Dominique Fauteux-Chapleau71912992020-10-22 18:15:37661#include "chrome/browser/enterprise/connectors/content_analysis_delegate.h"
Roger Tawa03ffdbd2020-01-16 18:12:54662#endif
663
Alexander Cooperc8448702020-03-14 01:39:56664#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23665#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56666#endif
667
Yuta Hijikata235fc62b2020-12-08 03:48:32668#if BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook70fee9862020-11-18 17:28:40669#include "chrome/browser/chrome_browser_main_parts_lacros.h"
Antonio Gomesaa2603362020-10-24 12:20:18670#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_lacros.h"
James Cook92730252020-07-22 01:57:26671#include "chromeos/lacros/lacros_chrome_service_impl.h"
James Cook247a8cb2020-12-22 23:09:51672#include "ui/base/ui_base_switches.h"
Hidehiko Abeeaffbbce2020-06-23 19:41:52673#endif
674
Koji Ishii3cbd93a2020-10-16 13:48:02675#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
676#include "chrome/browser/component_updater/hyphenation_component_installer.h"
677#endif
678
[email protected]c7abd422012-09-25 00:20:08679using base::FileDescriptor;
Gyuyoung Kimd6d4f992020-11-20 14:13:22680using blink::mojom::EffectiveConnectionType;
Gyuyoung Kim1ac4ca782020-09-11 03:32:51681using blink::web_pref::WebPreferences;
[email protected]631bb742011-11-02 11:29:39682using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31683using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13684using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59685using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00686using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02687using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11688using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33689using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13690using content::WebContents;
[email protected]593d2a72013-07-26 08:48:38691using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39692
[email protected]0daaebfe2014-03-15 00:09:05693#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20694using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05695#endif
696
brettw00899e62016-11-12 02:10:17697#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28698using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27699using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28700using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28701using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27702#endif
703
brettw4b461082016-11-19 18:55:16704#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55705using plugins::ChromeContentBrowserClientPluginsPart;
706#endif
707
[email protected]c5dbef02011-05-13 05:06:09708namespace {
709
Will Harris1b9b4152019-08-21 22:33:50710#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30711// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
712// running on Windows 10 1511 and above. See
713// https://blogs.windows.com/blog/tag/code-integrity-guard/.
714const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35715 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50716#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
717 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30718
Colin Blundell9ee731dd2020-01-23 10:42:38719// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
720// parameters.
721void HandleSSLErrorWrapper(
722 content::WebContents* web_contents,
723 int cert_error,
724 const net::SSLInfo& ssl_info,
725 const GURL& request_url,
726 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38727 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
728 Profile* profile =
729 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Scott Violet2fb481102020-07-27 00:23:54730 // Profile should always outlive a WebContents
731 DCHECK(profile);
Colin Blundell9ee731dd2020-01-23 10:42:38732
Colin Blundell27331f92020-02-05 21:13:01733 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51734
735#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
736 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
737#endif
738
Colin Blundell9ee731dd2020-01-23 10:42:38739 SSLErrorHandler::HandleSSLError(
740 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53741 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51742 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38743 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38744 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
745}
746
lazyboy5d5fede02016-03-10 04:10:14747enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53748 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14749 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53750
751 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14752 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53753
754 // An extension or app tried to load a resource of a different platform app in
755 // a tab.
756 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
757
758 // A non-app and non-extension page tried to load a platform app in a tab.
759 APP_LOADED_IN_TAB_SOURCE_OTHER,
760
lazyboy5d5fede02016-03-10 04:10:14761 APP_LOADED_IN_TAB_SOURCE_MAX
762};
763
Lei Zhang2cfceac2018-11-14 19:36:33764// Cached version of the locale so we can return the locale on the I/O
765// thread.
766std::string& GetIOThreadApplicationLocale() {
767 static base::NoDestructor<std::string> s;
768 return *s;
769}
770
[email protected]f8f93eb2012-09-25 03:06:24771// Returns a copy of the given url with its host set to given host and path set
772// to given path. Other parts of the url will be the same.
773GURL ReplaceURLHostAndPath(const GURL& url,
774 const std::string& host,
775 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05776 url::Replacements<char> replacements;
777 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
778 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24779 return url.ReplaceComponents(replacements);
780}
781
madfbd10852017-01-20 03:15:33782// Handles the rewriting of the new tab page URL based on group policy.
783bool HandleNewTabPageLocationOverride(
784 GURL* url,
785 content::BrowserContext* browser_context) {
786 if (!url->SchemeIs(content::kChromeUIScheme) ||
787 url->host() != chrome::kChromeUINewTabHost)
788 return false;
789
790 Profile* profile = Profile::FromBrowserContext(browser_context);
791 std::string ntp_location =
792 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
793 if (ntp_location.empty())
794 return false;
Olya Kalitova78ae04932020-09-21 11:26:06795 url::Component scheme;
796 if (!url::ExtractScheme(ntp_location.data(),
797 static_cast<int>(ntp_location.length()), &scheme)) {
798 ntp_location = base::StrCat(
799 {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location});
800 }
madfbd10852017-01-20 03:15:33801
802 *url = GURL(ntp_location);
803 return true;
804}
805
Becca Hughesfe8c32c2018-03-21 13:36:56806#if !defined(OS_ANDROID)
807// Check if the current url is whitelisted based on a list of whitelisted urls.
808bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57809 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56810 // Only check on HTTP and HTTPS pages.
811 if (!current_url.SchemeIsHTTPOrHTTPS())
812 return false;
813
814 for (auto const& value : whitelisted_urls) {
815 ContentSettingsPattern pattern =
816 ContentSettingsPattern::FromString(value.GetString());
817 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
818 continue;
819 if (pattern.Matches(current_url))
820 return true;
821 }
822
823 return false;
824}
825
826// Check if autoplay is allowed by policy configuration.
827bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
828 PrefService* prefs) {
829 DCHECK(prefs);
830
831 // Check if we have globally allowed autoplay by policy.
832 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
833 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
834 return true;
835 }
836
837 if (!contents)
838 return false;
839
840 // Check if the current URL matches a URL pattern on the whitelist.
841 const base::ListValue* autoplay_whitelist =
842 prefs->GetList(prefs::kAutoplayWhitelist);
843 return autoplay_whitelist &&
844 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
845 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
846}
847#endif
848
Joshua Perazaf890e4b2019-01-03 19:19:02849#if defined(OS_ANDROID)
850int GetCrashSignalFD(const base::CommandLine& command_line) {
851 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
852}
Avi Drissman2e458df2020-07-29 16:24:31853#elif defined(OS_POSIX) && !defined(OS_MAC)
[email protected]0b818f72013-10-22 00:11:03854breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
855 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02856 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52857 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02858 {
859 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31860 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03861 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50862 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02863 crash_handler->StartUploaderThread();
864 return crash_handler;
865 }
866}
867
avi3ef9ec9e2014-12-22 22:50:17868int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24869 if (crash_reporter::IsCrashpadEnabled()) {
870 int fd;
871 pid_t pid;
872 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
873 }
874
[email protected]9de4da52014-05-24 12:26:50875 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39876 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31877 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02878 if (!crash_handler)
879 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18880 return crash_handler->GetDeathSignalSocket();
881 }
882
883 std::string process_type =
884 command_line.GetSwitchValueASCII(switches::kProcessType);
885
[email protected]779dd282013-10-19 15:57:02886 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31887 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02888 if (!crash_handler)
889 crash_handler = CreateCrashHandlerHost(process_type);
890 return crash_handler->GetDeathSignalSocket();
891 }
[email protected]a1733df2012-06-22 11:24:18892
[email protected]779dd282013-10-19 15:57:02893 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31894 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02895 if (!crash_handler)
896 crash_handler = CreateCrashHandlerHost(process_type);
897 return crash_handler->GetDeathSignalSocket();
898 }
[email protected]a1733df2012-06-22 11:24:18899
[email protected]779dd282013-10-19 15:57:02900 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31901 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02902 if (!crash_handler)
903 crash_handler = CreateCrashHandlerHost(process_type);
904 return crash_handler->GetDeathSignalSocket();
905 }
[email protected]a1733df2012-06-22 11:24:18906
James Cook9207cc12017-10-19 17:08:39907 if (process_type == switches::kUtilityProcess) {
908 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
909 if (!crash_handler)
910 crash_handler = CreateCrashHandlerHost(process_type);
911 return crash_handler->GetDeathSignalSocket();
912 }
913
[email protected]a1733df2012-06-22 11:24:18914 return -1;
915}
Joshua Perazaf890e4b2019-01-03 19:19:02916#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18917
[email protected]eabbfb12013-04-05 23:28:35918void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52919 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33920 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35921}
922
estark3ba11132015-04-10 01:38:33923// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31924// SSLErrorHandler. Uses CertificateReportingService to send reports. The
925// service handles queueing and re-sending of failed reports. Each certificate
926// error creates a new instance of this class.
927class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33928 public:
meacerf43117a2016-12-27 21:02:31929 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12930 content::WebContents* web_contents)
931 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
932 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31933 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33934
935 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55936 void ReportInvalidCertificateChain(
937 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31938 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33939 }
940
941 private:
meacerf43117a2016-12-27 21:02:31942 CertificateReportingService* service_;
943
944 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33945};
946
brettw00899e62016-11-12 02:10:17947#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53948
949AppLoadedInTabSource ClassifyAppLoadedInTabSource(
950 const GURL& opener_url,
951 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58952 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
953 // The forbidden app URL was being opened by a non-extension page (e.g.
954 // http).
955 return APP_LOADED_IN_TAB_SOURCE_OTHER;
956 }
957
958 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53959 // The forbidden app URL was being opened by a different app or extension.
960 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
961 }
Lei Zhang7d0b0f42019-10-12 03:47:58962
963 // This platform app was trying to window.open() one of its own URLs.
964 if (opener_url ==
965 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
966 // Source was the background page.
967 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
968 }
969
970 // Source was a different page inside the app.
971 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53972}
[email protected]9c7656382014-08-08 21:02:30973
Charles Harrison34f67862017-08-22 01:04:17974// Returns true if there is is an extension matching |url| in
975// |opener_render_process_id| with APIPermission::kBackground.
976//
977// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
978// hosted app, even though normal extensions just use the host.
979bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35980 extensions::ProcessMap* process_map,
981 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17982 const GURL& url,
csharrison95f01e922017-04-24 18:52:35983 int opener_render_process_id) {
984 // Note: includes web URLs that are part of an extension's web extent.
985 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17986 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35987 return extension &&
988 extension->permissions_data()->HasAPIPermission(
989 APIPermission::kBackground) &&
990 process_map->Contains(extension->id(), opener_render_process_id);
991}
Kevin Marshall32f99d7e2017-07-11 23:17:46992
csharrison95f01e922017-04-24 18:52:35993#endif
994
Miyoung Shin6694b8e2020-06-18 01:38:17995mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler(
Alexander Cooperbc87af32020-07-15 15:59:45996 base::OnceCallback<content::WebContents*()> wc_getter) {
Miyoung Shin6694b8e2020-06-18 01:38:17997 mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler;
Mugdha Lakhani2c6b23af2020-07-31 14:55:57998 prerender::ChromePrerenderContentsDelegate::FromWebContents(
999 std::move(wc_getter).Run())
Darin Fishere41aab52020-01-29 18:31:231000 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
1001 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:121002}
1003
Julian Pastarmovb4773b82020-04-21 16:34:141004// Encapculates logic to determine if enterprise policies should be honored.
1005// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
1006// as a new central class to replace those checks is in the making.
1007bool ShouldHonorPolicies() {
1008#if defined(OS_WIN)
1009 bool is_enterprise_version =
1010 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
1011 return base::win::IsEnrolledToDomain() ||
1012 (base::win::IsDeviceRegisteredWithManagement() &&
1013 is_enterprise_version);
1014#else // defined(OS_WIN)
1015 // TODO(pastarmovj): Replace this with check for MacOS and the new management
1016 // service once it is ready.
1017 return true;
1018#endif // defined(OS_WIN)
1019}
1020
John Abd-El-Malek92bf3602019-07-31 02:25:481021void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:041022 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:481023 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451024 bool has_user_gesture,
1025 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:011026 // If there is no longer a WebContents, the request may have raced with tab
1027 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:041028 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:011029 if (!web_contents)
1030 return;
1031
1032 // Do not launch external requests attached to unswapped prerenders.
1033 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:571034 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
John Abd-El-Maleka67add82018-03-09 18:22:011035 if (prerender_contents) {
1036 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:011037 return;
1038 }
1039
Robbie McElrath1294d242019-05-31 20:46:221040 // Do not launch external requests for schemes that have a handler registered.
1041 ProtocolHandlerRegistry* protocol_handler_registry =
1042 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1043 web_contents->GetBrowserContext());
1044 if (protocol_handler_registry &&
1045 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1046 return;
1047
John Abd-El-Maleka67add82018-03-09 18:22:011048 bool is_whitelisted = false;
Aaron Colwellf94fd97a2020-07-21 19:37:081049 PolicyBlocklistService* service =
1050 PolicyBlocklistFactory::GetForBrowserContext(
Oleg Davydov5cfe7ab2019-02-01 12:27:191051 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:141052 if (ShouldHonorPolicies() && service) {
Aaron Colwellf94fd97a2020-07-21 19:37:081053 const policy::URLBlocklist::URLBlocklistState url_state =
1054 service->GetURLBlocklistState(url);
John Abd-El-Maleka67add82018-03-09 18:22:011055 is_whitelisted =
Aaron Colwellf94fd97a2020-07-21 19:37:081056 url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
John Abd-El-Maleka67add82018-03-09 18:22:011057 }
1058
1059 // If the URL is in whitelist, we launch it without asking the user and
1060 // without any additional security checks. Since the URL is whitelisted,
1061 // we assume it can be executed.
1062 if (is_whitelisted) {
1063 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1064 } else {
1065 ExternalProtocolHandler::LaunchUrl(
1066 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1067 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451068 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011069 }
1070}
1071
Yutaka Hirano968d6252018-12-04 05:09:311072std::string GetProduct() {
1073 return version_info::GetProductNameAndVersionForUserAgent();
1074}
1075
Lukasz Anforowicz60d1253d2019-05-08 16:31:371076void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1077 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1078 // For renderer and utility (e.g. NetworkService) processes the switch is the
1079 // only available source, so below the combined (pref/policy + cmdline)
1080 // allowlist of secure origins is injected into |cmdline| for these other
1081 // processes.
1082 std::vector<std::string> allowlist =
1083 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1084 if (!allowlist.empty()) {
1085 cmdline->AppendSwitchASCII(
1086 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1087 base::JoinString(allowlist, ","));
1088 }
1089}
1090
Will Harris1b9b4152019-08-21 22:33:501091#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301092// Returns the full path to |module_name|. Both dev builds (where |module_name|
1093// is in the current executable's directory) and proper installs (where
1094// |module_name| is in a versioned sub-directory of the current executable's
1095// directory) are supported. The identified file is not guaranteed to exist.
1096base::FilePath GetModulePath(base::StringPiece16 module_name) {
1097 base::FilePath exe_dir;
1098 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1099 DCHECK(has_path);
1100
1101 // Look for the module in a versioned sub-directory of the current
1102 // executable's directory and return the path if it can be read. This is the
1103 // expected location of modules for proper installs.
1104 const base::FilePath module_path =
1105 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1106 if (base::PathExists(module_path))
1107 return module_path;
1108
1109 // Otherwise, return the path to the module in the current executable's
1110 // directory. This is the expected location of modules for dev builds.
1111 return exe_dir.Append(module_name);
1112}
Will Harris1b9b4152019-08-21 22:33:501113#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1114 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301115
Lukasz Anforowicz7724d092019-10-03 23:50:211116void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281117 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1118 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211119 if (maybe_throttle)
1120 throttles->push_back(std::move(maybe_throttle));
1121}
1122
Chris Hamiltonab4722122020-05-13 18:01:281123void MaybeAddThrottles(
1124 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1125 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1126 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1127 std::make_move_iterator(additional.end()));
1128}
1129
Evan Stade1e71d6dd2019-10-29 03:04:491130// Returns whether |web_contents| is within a hosted app.
1131bool IsInHostedApp(WebContents* web_contents) {
1132#if BUILDFLAG(ENABLE_EXTENSIONS)
1133 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
Glen Robertson83263c72020-12-10 06:16:161134 return web_app::AppBrowserController::IsWebApp(browser);
Evan Stade1e71d6dd2019-10-29 03:04:491135#else
1136 return false;
1137#endif
1138}
1139
Lily Chenc2c9e9f2019-12-05 19:55:311140void MaybeRecordSameSiteCookieEngagementHistogram(
1141 content::RenderFrameHost* render_frame_host,
1142 blink::mojom::WebFeature feature) {
1143 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1144 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1145 return;
1146 }
1147
1148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1149 DCHECK(render_frame_host);
1150
1151 content::BrowserContext* browser_context =
1152 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1153 Profile* profile = Profile::FromBrowserContext(browser_context);
Evan Stade7a984802020-12-14 19:10:151154 auto* site_engagement_service =
1155 site_engagement::SiteEngagementService::Get(profile);
Lily Chenc2c9e9f2019-12-05 19:55:311156 if (!site_engagement_service)
1157 return;
1158
1159 blink::mojom::EngagementLevel engagement_level =
1160 site_engagement_service->GetEngagementLevel(
1161 render_frame_host->GetLastCommittedURL());
1162 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1163 UMA_HISTOGRAM_ENUMERATION(
1164 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1165 engagement_level);
1166 } else {
1167 UMA_HISTOGRAM_ENUMERATION(
1168 "Net.SameSiteBlockedCookieSiteEngagement."
1169 "CookieInsecureAndSameSiteNone",
1170 engagement_level);
1171 }
1172}
1173
Ken Rockot4408a0f2020-07-27 19:40:541174bool IsErrorPageAutoReloadEnabled() {
1175 const base::CommandLine& command_line =
1176 *base::CommandLine::ForCurrentProcess();
1177 if (command_line.HasSwitch(switches::kEnableAutomation))
1178 return false;
1179 if (command_line.HasSwitch(switches::kEnableAutoReload))
1180 return true;
1181 if (command_line.HasSwitch(switches::kDisableAutoReload))
1182 return false;
1183 return true;
1184}
1185
[email protected]9dbfff12011-07-01 19:37:071186} // namespace
[email protected]c5dbef02011-05-13 05:06:091187
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441188// Generate a pseudo-random permutation of the following brand/version pairs:
1189// 1. The base project (i.e. Chromium)
1190// 2. The browser brand, if available
1191// 3. A randomized string containing escaped characters to ensure proper
1192// header parsing, along with an arbitrarily low version to ensure proper
1193// version checking.
1194blink::UserAgentBrandList GenerateBrandVersionList(
1195 int seed,
1196 base::Optional<std::string> brand,
Aaron Tagliaboschia06275dc2020-11-17 17:55:041197 std::string major_version,
1198 base::Optional<std::string> maybe_greasey_brand) {
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441199 DCHECK_GE(seed, 0);
1200 const int npermutations = 6; // 3!
1201 int permutation = seed % npermutations;
1202
1203 // Pick a stable permutation seeded by major version number. any values here
1204 // and in order should be under three.
1205 const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
1206 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
Aaron Tagliaboschi8aeb0dc2020-11-16 17:28:241207 const std::vector<int> order = orders[permutation];
1208 DCHECK_EQ(6u, orders.size());
1209 DCHECK_EQ(3u, order.size());
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441210
Aaron Tagliaboschi023bf2912020-11-17 17:09:031211 // Previous values for indexes 0 and 1 were '\' and '"', temporarily removed
1212 // because of compat issues
1213 const std::vector<std::string> escaped_chars = {" ", " ", ";"};
Aaron Tagliaboschi8aeb0dc2020-11-16 17:28:241214 std::string greasey_brand =
1215 base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]],
1216 "A", escaped_chars[order[2]], "Brand"});
1217
Aaron Tagliaboschia06275dc2020-11-17 17:55:041218 blink::UserAgentBrandVersion greasey_bv = {
1219 maybe_greasey_brand.value_or(greasey_brand), "99"};
Aaron Tagliaboschi8aeb0dc2020-11-16 17:28:241220 blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version};
1221
1222 blink::UserAgentBrandList greased_brand_version_list(3);
1223
1224 if (brand) {
1225 blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version};
1226
1227 greased_brand_version_list[order[0]] = greasey_bv;
1228 greased_brand_version_list[order[1]] = chromium_bv;
1229 greased_brand_version_list[order[2]] = brand_bv;
1230 } else {
1231 greased_brand_version_list[seed % 2] = greasey_bv;
1232 greased_brand_version_list[(seed + 1) % 2] = chromium_bv;
1233
1234 // If left, the last element would make a blank "" at the end of the header.
1235 greased_brand_version_list.pop_back();
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441236 }
Aaron Tagliaboschi8aeb0dc2020-11-16 17:28:241237
1238 return greased_brand_version_list;
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441239}
1240
1241const blink::UserAgentBrandList& GetBrandVersionList() {
1242 static const base::NoDestructor<blink::UserAgentBrandList>
1243 greased_brand_version_list([] {
1244 int major_version_number;
1245 std::string major_version = version_info::GetMajorVersionNumber();
1246 base::StringToInt(major_version, &major_version_number);
1247 base::Optional<std::string> brand;
1248#if !BUILDFLAG(CHROMIUM_BRANDING)
1249 brand = version_info::GetProductName();
1250#endif
Aaron Tagliaboschia06275dc2020-11-17 17:55:041251 base::Optional<std::string> maybe_param_override =
1252 base::GetFieldTrialParamValueByFeature(features::kGreaseUACH,
1253 "brand_override");
1254 if (maybe_param_override->empty())
1255 maybe_param_override = base::nullopt;
1256
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441257 return GenerateBrandVersionList(major_version_number, brand,
Aaron Tagliaboschia06275dc2020-11-17 17:55:041258 major_version, maybe_param_override);
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441259 }());
1260 return *greased_brand_version_list;
1261}
1262
Yutaka Hirano968d6252018-12-04 05:09:311263std::string GetUserAgent() {
1264 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1265 if (command_line->HasSwitch(switches::kUserAgent)) {
1266 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1267 if (net::HttpUtil::IsValidHeaderValue(ua))
1268 return ua;
1269 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1270 }
1271
John Delaneyac24e572019-04-30 19:47:021272 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1273 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351274 command_line->HasSwitch(switches::kUseMobileUserAgent),
1275 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021276 }
1277
Yutaka Hirano968d6252018-12-04 05:09:311278 std::string product = GetProduct();
1279#if defined(OS_ANDROID)
1280 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1281 product += " Mobile";
1282#endif
1283 return content::BuildUserAgentFromProduct(product);
1284}
1285
Mike West6e4cbb32019-02-13 09:40:171286blink::UserAgentMetadata GetUserAgentMetadata() {
1287 blink::UserAgentMetadata metadata;
Aaron Tagliaboschi9f01b682020-05-05 21:03:171288
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441289 metadata.brand_version_list = GetBrandVersionList();
Mike Weste555be862019-02-20 16:17:301290 metadata.full_version = version_info::GetVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171291 metadata.platform = version_info::GetOSType();
Yoav Weiss4838f1b2020-04-30 21:37:001292 metadata.platform_version =
1293 content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude,
1294 content::IncludeAndroidModel::Exclude);
Aaron Tagliaboschi0585bc932020-05-08 20:03:171295 metadata.architecture = content::GetLowEntropyCpuArchitecture();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361296 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171297
Aaron Tagliaboschibe775e12019-12-09 19:33:041298 metadata.mobile = false;
1299#if defined(OS_ANDROID)
1300 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1301 switches::kUseMobileUserAgent);
1302#endif
1303
Mike West6e4cbb32019-02-13 09:40:171304 return metadata;
1305}
1306
Yutaka Hirano311a7412021-01-06 06:17:351307#if !defined(OS_ANDROID)
1308base::TimeDelta GetKeepaliveTimerTimeout() {
1309 constexpr base::TimeDelta kDefaultValue = base::TimeDelta::FromSeconds(1);
1310
1311 const int seconds = base::GetFieldTrialParamByFeatureAsInt(
1312 features::kShutdownSupportForKeepalive, "timeout", -1);
1313 if (seconds < 0 || seconds > 60) {
1314 return kDefaultValue;
1315 }
1316 return base::TimeDelta::FromSeconds(seconds);
1317}
1318#endif
1319
danakj5beedd02020-10-30 15:55:131320ChromeContentBrowserClient::ChromeContentBrowserClient() {
brettw4b461082016-11-19 18:55:161321#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551322 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401323#endif
[email protected]1deace22013-05-22 06:14:461324
Yuta Hijikata235fc62b2020-12-08 03:48:321325#if BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241326 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
Yuta Hijikata235fc62b2020-12-08 03:48:321327#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Ahmed Fakhryd70bf37b2018-04-04 17:07:241328
John Lee0ee748bf2019-12-11 21:35:441329#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1330 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1331#endif
1332
brettw00899e62016-11-12 02:10:171333#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131334 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271335#endif
bena06f7d62017-04-04 20:48:521336
Sigurdur Asgeirsson70696672019-02-08 16:14:511337 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401338}
1339
1340ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031341 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1342 delete extra_parts_[i];
1343 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401344}
1345
[email protected]bca18382012-06-25 19:15:231346// static
Chris Palmerac7d75642017-11-22 20:12:541347void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1348 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131349 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1350 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541351 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1352 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461353 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541354}
1355
1356// static
[email protected]37ca3fe02013-07-05 15:32:441357void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341358 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251359 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1360 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
Pavol Marko6adbea7f2018-02-20 16:35:281361 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1362 // user policy in addition to the same named ones in Local State (which are
1363 // used for mapping the command-line flags).
1364 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1365 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Clark DuVallaadc244c2020-06-06 03:47:141366 registry->RegisterListPref(
1367 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401368 registry->RegisterDictionaryPref(
1369 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041370 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101371#if !defined(OS_ANDROID)
1372 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561373 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101374#endif
[email protected]bca18382012-06-25 19:15:231375}
1376
[email protected]eabbfb12013-04-05 23:28:351377// static
1378void ChromeContentBrowserClient::SetApplicationLocale(
1379 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481380 // The common case is that this function is called early in Chrome startup
1381 // before any threads are created or registered. When there are no threads,
1382 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001383 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331384 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481385 return;
1386 }
1387
1388 // Otherwise we're being called to change the locale. In this case set it on
1389 // the IO thread.
thestig00844cea2015-09-08 21:44:521390 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351391
Gabriel Charettee7cdc5cd2020-05-27 23:35:051392 content::GetIOThreadTaskRunner({})->PostTask(
1393 FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351394}
1395
Patrick Monette61dfef92019-05-30 23:06:271396std::unique_ptr<content::BrowserMainParts>
1397ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311398 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271399 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301400 // Construct the Main browser parts based on the OS type.
1401#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051402 main_parts =
danakj5beedd02020-10-30 15:55:131403 std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_);
Avi Drissman2e458df2020-07-29 16:24:311404#elif defined(OS_MAC)
Patrick Monette61dfef92019-05-30 23:06:271405 main_parts =
danakj5beedd02020-10-30 15:55:131406 std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401407#elif BUILDFLAG(IS_CHROMEOS_ASH)
Patrick Monette61dfef92019-05-30 23:06:271408 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
danakj5beedd02020-10-30 15:55:131409 parameters, &startup_data_);
James Cook70fee9862020-11-18 17:28:401410#elif BUILDFLAG(IS_CHROMEOS_LACROS)
1411 main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(parameters,
1412 &startup_data_);
Yuta Hijikata235fc62b2020-12-08 03:48:321413#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
Patrick Monette61dfef92019-05-30 23:06:271414 main_parts =
danakj5beedd02020-10-30 15:55:131415 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_);
[email protected]6e677a342012-02-11 01:21:141416#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271417 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
danakj5beedd02020-10-30 15:55:131418 &startup_data_);
[email protected]b48c9182011-10-26 18:03:301419#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271420 main_parts =
danakj5beedd02020-10-30 15:55:131421 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_);
[email protected]f967b722011-09-07 00:58:041422#else
[email protected]b48c9182011-10-26 18:03:301423 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271424 main_parts =
danakj5beedd02020-10-30 15:55:131425 std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_);
[email protected]b48c9182011-10-26 18:03:301426#endif
1427
Xi Han9fd44002019-04-30 17:39:361428 bool add_profiles_extra_parts = true;
1429#if defined(OS_ANDROID)
danakj5beedd02020-10-30 15:55:131430 if (startup_data_.HasBuiltProfilePrefService())
Xi Han9fd44002019-04-30 17:39:361431 add_profiles_extra_parts = false;
1432#endif
1433 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271434 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031435
Xi Han9fd44002019-04-30 17:39:361436 // Construct additional browser parts. Stages are called in the order in
1437 // which they are added.
[email protected]c7480942011-11-08 19:18:271438#if defined(TOOLKIT_VIEWS)
Yuta Hijikata235fc62b2020-12-08 03:48:321439#if BUILDFLAG(IS_CHROMEOS_LACROS)
Antonio Gomesaa2603362020-10-24 12:20:181440 main_parts->AddParts(
1441 std::make_unique<ChromeBrowserMainExtraPartsViewsLacros>());
Yuta Hijikata235fc62b2020-12-08 03:48:321442// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
1443// of lacros-chrome is complete.
1444#elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
James Cook42e933062020-07-06 20:56:121445 main_parts->AddParts(
1446 std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>());
estaded3aa0e82016-02-17 22:55:211447#else
James Cook42e933062020-07-06 20:56:121448 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>());
James Cookf9d34d22017-10-04 16:39:351449#endif
1450#endif
1451
Yuta Hijikata235fc62b2020-12-08 03:48:321452#if BUILDFLAG(IS_CHROMEOS_ASH)
James Cookf9d34d22017-10-04 16:39:351453 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
James Cook42e933062020-07-06 20:56:121454 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>());
skycea631e2016-12-16 21:52:221455#endif
[email protected]dc04be7c2012-03-15 23:57:491456
Maksim Sisov1686fc22020-06-17 07:59:201457#if defined(USE_X11) || defined(USE_OZONE)
James Cook42e933062020-07-06 20:56:121458 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>());
[email protected]e050ef142012-03-21 01:04:241459#endif
1460
James Cook42e933062020-07-06 20:56:121461 main_parts->AddParts(
1462 std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>());
Etienne Bergeron05d62532017-10-13 18:24:001463
James Cook42e933062020-07-06 20:56:121464 main_parts->AddParts(
1465 std::make_unique<ChromeBrowserMainExtraPartsProfiling>());
Albert J. Wong59d85acb2017-08-10 00:50:571466
James Cook42e933062020-07-06 20:56:121467 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>());
Sebastien Marchand8c0088102019-10-11 16:47:561468
Patrick Monette61dfef92019-05-30 23:06:271469 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041470
Zhenyao Mo73144652020-04-06 18:55:051471 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1472 // GpuDataManager initialization could pick up about:flags settings.
James Cook42e933062020-07-06 20:56:121473 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>());
Zhenyao Mo73144652020-04-06 18:55:051474
[email protected]50462bf02011-11-21 19:13:311475 return main_parts;
[email protected]f967b722011-09-07 00:58:041476}
1477
michaeln96f887e22015-04-13 23:58:311478void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091479 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021480 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211481 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121482 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291483
Robert Sesek466e43e2019-08-19 22:02:021484 InitNetworkContextsParentDirectory();
1485
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291486 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1487 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311488}
1489
falkenb09d443f2016-04-07 12:36:121490bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1491 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1492}
1493
Gabriel Charettec8cca992017-08-10 18:21:491494void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1495 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1496}
1497
John Abd-El-Malek9d57f9c2019-02-20 18:50:041498bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361499 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041500}
1501
[email protected]e94bbcb2012-09-07 05:33:571502std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191503 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571504 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531505 std::string partition_id;
1506
1507 // The partition ID for webview guest processes is the string value of its
1508 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451509 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531510 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171511#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501512 // The partition ID for extensions with isolated storage is treated similarly
1513 // to the above.
Aaron Colwell8c430642020-08-04 01:55:201514 else if (extensions::util::IsExtensionSiteWithIsolatedStorage(
1515 site, browser_context))
blundellf650ea02016-02-08 11:50:501516 partition_id = site.spec();
1517#endif
[email protected]1bc28312012-11-08 08:31:531518
[email protected]056efdc2013-04-06 00:14:531519 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531520 return partition_id;
1521}
1522
1523bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1524 content::BrowserContext* browser_context,
1525 const std::string& partition_id) {
1526 // The default ID is empty and is always valid.
1527 if (partition_id.empty())
1528 return true;
1529
1530 return GURL(partition_id).is_valid();
1531}
1532
Bret Sepulveda56652152020-06-24 14:47:131533content::StoragePartitionConfig
1534ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
[email protected]1bc28312012-11-08 08:31:531535 content::BrowserContext* browser_context,
Bret Sepulveda56652152020-06-24 14:47:131536 const GURL& site) {
[email protected]14acc642012-11-17 12:20:101537 // Default to the browser-wide storage partition and override based on |site|
1538 // below.
Bret Sepulveda56652152020-06-24 14:47:131539 content::StoragePartitionConfig storage_partition_config =
1540 content::StoragePartitionConfig::CreateDefault();
[email protected]14acc642012-11-17 12:20:101541
brettw00899e62016-11-12 02:10:171542#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell0ee22132020-06-23 00:28:411543 if (extensions::WebViewGuest::GetGuestPartitionConfigForSite(
Bret Sepulveda56652152020-06-24 14:47:131544 site, &storage_partition_config)) {
1545 return storage_partition_config;
Aaron Colwell0ee22132020-06-23 00:28:411546 }
[email protected]3f24f97c2013-11-17 21:53:331547
Aaron Colwell8c430642020-08-04 01:55:201548 if (site.SchemeIs(extensions::kExtensionScheme)) {
1549 // The host in an extension site URL is the extension_id.
Aaron Colwell0ee22132020-06-23 00:28:411550 CHECK(site.has_host());
Aaron Colwell8c430642020-08-04 01:55:201551 return extensions::util::GetStoragePartitionConfigForExtensionId(
1552 site.host(), browser_context);
[email protected]1df3d972014-06-11 04:55:181553 }
1554#endif
Bret Sepulveda56652152020-06-24 14:47:131555
1556 return storage_partition_config;
[email protected]d7c7c98a2012-07-12 21:27:441557}
1558
[email protected]38b098f2012-03-14 21:11:571559content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441560ChromeContentBrowserClient::GetWebContentsViewDelegate(
1561 content::WebContents* web_contents) {
Chris Hamiltonc3d5c0d12020-06-01 19:30:051562 if (auto* registry =
1563 performance_manager::PerformanceManagerRegistry::GetInstance()) {
Chris Hamilton4269bab2020-06-04 20:03:211564 registry->MaybeCreatePageNodeForWebContents(web_contents);
Chris Hamiltonc3d5c0d12020-06-01 19:30:051565 }
cm.sanchi2db24a82017-11-16 07:22:101566 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321567}
1568
Bo Liu4ade6b1b22017-11-28 02:26:351569bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1570#if defined(OS_ANDROID)
1571 const base::android::ApplicationState app_state =
1572 base::android::ApplicationStatusListener::GetState();
1573 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1574 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1575 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1576#else
1577 return true;
1578#endif
1579}
1580
[email protected]6f2862742013-12-20 07:53:191581void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231582 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301583 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
Darin Fisher8c84328c2019-07-23 02:50:001584
Darin Fisher09aa7222019-08-29 09:27:361585 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001586 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021587
grunell086a4112017-03-02 09:23:041588 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1589 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021590 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121591 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021592 host->SetUserData(
1593 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091594 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021595 audio_debug_recordings_handler));
1596
Nico Weberaf3b00b2017-09-11 17:58:171597#if BUILDFLAG(ENABLE_NACL)
Julie Jeongeun Kimae46b4e2021-01-07 11:38:141598 host->AddFilter(new nacl::NaClHostMessageFilter(
1599 host->GetID(), profile->IsOffTheRecord(), profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351600#endif
jeremyim364ac1182015-03-03 18:49:431601
Xiaohan Wang9b34281b2017-09-08 23:48:331602#if defined(OS_ANDROID)
1603 // Data cannot be persisted if the profile is off the record.
1604 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061605 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071606
1607 // Register CrashMemoryMetricsCollector to report oom related metrics.
1608 host->SetUserData(
1609 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1610 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331611#endif
1612
Jun Caidb3f93cc2018-07-09 21:54:551613 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061614 RendererUpdaterFactory::GetForProfile(original_profile)
1615 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071616
[email protected]a48ab7112014-08-01 16:48:031617 for (size_t i = 0; i < extra_parts_.size(); ++i)
1618 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141619}
1620
[email protected]3d7474ff2011-07-27 17:47:371621GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571622 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301623 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371624 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521625 if (!profile)
1626 return url;
1627
Marc Treib7d467b792017-12-04 13:31:031628#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291629 // If the input |url| should be assigned to the Instant renderer, make its
1630 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311631 // This needs to happen even if |url| corresponds to an isolated origin; see
1632 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131633 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1634 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031635#endif
[email protected]b3cb3a32013-07-31 01:32:291636
brettw00899e62016-11-12 02:10:171637#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301638 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1639 url);
[email protected]d5a74be2014-08-08 01:01:271640#else
1641 return url;
1642#endif
[email protected]36fb2c7c2011-04-04 15:49:081643}
1644
Alexander Yashkin6aedc6e2018-08-15 08:58:451645bool ChromeContentBrowserClient::
1646 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1647 content::BrowserContext* browser_context,
1648 content::SiteInstance* candidate_site_instance,
1649 bool is_main_frame,
1650 const GURL& candidate_url,
1651 const GURL& destination_url) {
1652 DCHECK(browser_context);
1653 DCHECK(candidate_site_instance);
1654#if BUILDFLAG(ENABLE_EXTENSIONS)
1655 return ChromeContentBrowserClientExtensionsPart::
1656 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1657 browser_context, candidate_site_instance, is_main_frame,
1658 candidate_url, destination_url);
1659#else
1660 return true;
1661#endif
1662}
1663
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521664bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411665#if defined(OS_ANDROID)
1666 return true;
Yuta Hijikata235fc62b2020-12-08 03:48:321667#elif BUILDFLAG(IS_CHROMEOS_ASH)
Xiyuan Xiafc9f38132019-08-02 00:51:421668 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411669#else
1670 return false;
1671#endif // defined(OS_ANDROID)
1672}
1673
[email protected]056ad2a2011-07-12 02:13:551674bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441675 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591676 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521677 Profile* profile = Profile::FromBrowserContext(browser_context);
1678 if (!profile)
1679 return false;
1680
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301681 // NTP should use process-per-site. This is a performance optimization to
1682 // reduce process count associated with NTP tabs.
Tibor Goldschwendt52e168c2020-06-01 22:17:441683 if (site_url == GURL(chrome::kChromeUINewTabURL) ||
1684 site_url == GURL(chrome::kChromeUINewTabPageURL)) {
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301685 return true;
Tibor Goldschwendt52e168c2020-06-01 22:17:441686 }
Peter Boström8e9b1632019-08-22 23:12:471687
1688 // The web footer experiment should share its renderer to not effectively
1689 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591690 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471691 return true;
1692
Marc Treib7d467b792017-12-04 13:31:031693#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591694 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521695 return true;
Marc Treib7d467b792017-12-04 13:31:031696#endif
[email protected]c5dec6292013-01-25 04:54:521697
brettw00899e62016-11-12 02:10:171698#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301699 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591700 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301701 return true;
[email protected]d5a74be2014-08-08 01:01:271702#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301703
1704 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1705 // (rather than process-per-site).
1706 return false;
[email protected]056ad2a2011-07-12 02:13:551707}
1708
Lukasz Anforowicz32d27122018-04-09 21:48:331709bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1710 content::BrowserContext* browser_context,
1711 const GURL& site_url) {
1712 Profile* profile = Profile::FromBrowserContext(browser_context);
1713 if (!profile)
1714 return false;
1715
1716#if !defined(OS_ANDROID)
1717 // Instant renderers should not use a spare process, because they require
1718 // passing switches::kInstantProcess to the renderer process when it
1719 // launches. A spare process is launched earlier, before it is known which
1720 // navigation will use it, so it lacks this flag.
1721 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1722 return false;
1723#endif
1724
1725#if BUILDFLAG(ENABLE_EXTENSIONS)
1726 return ChromeContentBrowserClientExtensionsPart::
1727 ShouldUseSpareRenderProcessHost(profile, site_url);
1728#else
1729 return true;
1730#endif
1731}
1732
nickcc0d9142015-10-14 16:27:101733bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421734 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101735 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421736 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171737#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101738 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421739 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101740 return true;
1741 }
1742#endif
1743 return false;
1744}
1745
Aaron Colwell8812a972020-10-02 23:36:561746bool ChromeContentBrowserClient::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461747 content::BrowserContext* browser_context,
1748 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171749#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell8812a972020-10-02 23:36:561750 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461751 browser_context, effective_site_url)) {
1752 return false;
1753 }
1754#endif
1755 return true;
creise5d6d1732015-08-25 19:47:061756}
1757
Nasko Oskov39023672020-05-06 17:31:141758bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1759 base::StringPiece scheme) {
1760 // Note: This method can be called from multiple threads. It is not safe to
1761 // assume it runs only on the UI thread.
1762
1763 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371764 // locked to chrome-search: origin. Locking to chrome-search would kill
1765 // processes upon legitimate requests for cookies from the search engine's
1766 // domain.
Nasko Oskov39023672020-05-06 17:31:141767 if (scheme == chrome::kChromeSearchScheme)
1768 return false;
1769
1770 // All other WebUIs must be locked to origin.
1771 return true;
1772}
1773
Maks Orlovich0e23e312019-07-16 13:13:561774bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021775 base::StringPiece scheme,
1776 bool is_embedded_origin_secure) {
Lily Chen2387bd92020-06-02 21:15:271777 // This is needed to bypass the normal SameSite rules for any chrome:// page
1778 // embedding a secure origin, regardless of the registrable domains of any
1779 // intervening frames. For example, this is needed for browser UI to interact
1780 // with SameSite cookies on accounts.google.com, which are used for logging
1781 // into Cloud Print from chrome://print, for displaying a list of available
1782 // accounts on the NTP (chrome://new-tab-page), etc.
Lily Chen0db055b2019-11-15 20:29:021783 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1784 return true;
Maks Orlovich0e23e312019-07-16 13:13:561785#if BUILDFLAG(ENABLE_EXTENSIONS)
1786 return scheme == extensions::kExtensionScheme;
1787#else
1788 return false;
1789#endif
1790}
1791
Lily Chen0db055b2019-11-15 20:29:021792bool ChromeContentBrowserClient::
1793 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1794 base::StringPiece scheme,
1795 bool is_embedded_origin_secure) {
1796 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1797}
1798
Xiaohan Wang15a07af2020-05-28 23:24:551799// TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
1800// implementation. Find a general solution to avoid code duplication.
1801std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
1802 content::BrowserContext* browser_context,
1803 const GURL& site_url) {
1804 // By default, use the |site_url| spec as the display name.
1805 std::string name = site_url.spec();
1806
1807#if BUILDFLAG(ENABLE_EXTENSIONS)
1808 // If |site_url| wraps a chrome extension ID, we can display the extension
1809 // name instead, which is more human-readable.
1810 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
1811 const extensions::Extension* extension =
1812 extensions::ExtensionRegistry::Get(browser_context)
1813 ->enabled_extensions()
1814 .GetExtensionOrAppByURL(site_url);
1815 if (extension)
1816 name = extension->name();
1817 }
1818#endif // BUILDFLAG(ENABLE_EXTENSIONS)
1819
1820 return name;
1821}
1822
Lukasz Anforowicz7097890d2019-11-20 21:49:221823void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021824 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591825 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021826 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221827 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071828#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221829 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021830 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071831#endif
1832}
1833
[email protected]73b718f2014-01-27 02:59:461834// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1835// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411836void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1837 std::vector<std::string>* additional_schemes) {
1838 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241839 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351840 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061841}
1842
alexmos94875b3b2017-03-16 22:19:011843void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1844 std::vector<std::string>* additional_schemes) {
1845 GetAdditionalWebUISchemes(additional_schemes);
1846
1847#if BUILDFLAG(ENABLE_EXTENSIONS)
1848 additional_schemes->push_back(extensions::kExtensionScheme);
1849#endif
1850}
1851
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521852bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011853 return webui::LogWebUIUrl(web_ui_url);
1854}
1855
John Abd-El-Malek04bfa8532018-07-12 05:28:221856bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1857 const url::Origin& origin) {
1858 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1859 origin);
1860}
1861
[email protected]46fb9442011-12-09 17:57:471862bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1863 return ProfileIOData::IsHandledURL(url);
1864}
1865
Frédéric Wang1eabba72020-10-23 15:36:551866bool ChromeContentBrowserClient::HasCustomSchemeHandler(
1867 content::BrowserContext* browser_context,
1868 const std::string& scheme) {
1869 if (ProtocolHandlerRegistry* protocol_handler_registry =
1870 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1871 browser_context)) {
1872 return protocol_handler_registry->IsHandledProtocol(scheme);
1873 }
1874
1875 return false;
1876}
1877
[email protected]c4365fa42013-05-14 01:08:241878bool ChromeContentBrowserClient::CanCommitURL(
1879 content::RenderProcessHost* process_host,
1880 const GURL& url) {
brettw00899e62016-11-12 02:10:171881#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441882 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1883 url);
[email protected]d5a74be2014-08-08 01:01:271884#else
1885 return true;
1886#endif
[email protected]c4365fa42013-05-14 01:08:241887}
1888
rdevlin.cronina32a0902016-11-09 15:50:201889void ChromeContentBrowserClient::OverrideNavigationParams(
Scott Violet5ae6c42e2020-10-28 02:47:371890 content::WebContents* web_contents,
rdevlin.cronina32a0902016-11-09 15:50:201891 SiteInstance* site_instance,
1892 ui::PageTransition* transition,
1893 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581894 content::Referrer* referrer,
1895 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201896 DCHECK(transition);
1897 DCHECK(is_renderer_initiated);
1898 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471899 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1900 // use for making security decisions 99.44% of the time, for detecting the NTP
1901 // it is reliable and the correct way. See http://crbug.com/624410.
1902 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201903 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581904 // Clicks on tiles of the new tab page should be treated as if a user
1905 // clicked on a bookmark. This is consistent with native implementations
1906 // like Android's. This also helps ensure that security features (like
1907 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1908 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201909 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1910 *is_renderer_initiated = false;
1911 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581912 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421913 }
Scott Violet5ae6c42e2020-10-28 02:47:371914#if defined(OS_ANDROID)
1915 if (web_contents) {
1916 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
1917 if (tab && tab->should_add_api2_transition_to_future_navigations()) {
1918 *transition = ui::PageTransitionFromInt(*transition |
1919 ui::PAGE_TRANSITION_FROM_API_2);
1920 }
1921 }
1922#endif
mastiza77db6992016-06-30 09:48:421923}
1924
Charles Reis29e9dd12017-09-28 00:59:151925bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1926 const GURL& url,
1927 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471928 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1929 // use for making security decisions 99.44% of the time, for detecting the NTP
1930 // it is reliable and the correct way. See http://crbug.com/624410.
1931 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1932 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151933}
1934
[email protected]2a5221b2011-09-27 23:07:311935bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301936 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311937 const GURL& site_url) {
1938 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301939 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441940 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521941 // share any host.
1942 if (!profile)
1943 return true;
1944
Marc Treib7895941d2017-11-28 12:37:021945#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141946 // Instant URLs should only be in the instant process and instant process
1947 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521948 InstantService* instant_service =
1949 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141950 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441951 bool is_instant_process =
1952 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141953 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131954 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141955 if (is_instant_process || should_be_in_instant_process)
1956 return is_instant_process && should_be_in_instant_process;
1957 }
Marc Treib7895941d2017-11-28 12:37:021958#endif
[email protected]c5dec6292013-01-25 04:54:521959
brettw00899e62016-11-12 02:10:171960#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131961 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1962 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271963#else
1964 return true;
1965#endif
[email protected]2a5221b2011-09-27 23:07:311966}
1967
[email protected]28c5d0b72014-05-13 08:19:591968bool ChromeContentBrowserClient::MayReuseHost(
1969 content::RenderProcessHost* process_host) {
1970 // If there is currently a prerender in progress for the host provided,
1971 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041972 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591973 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371974 prerender::PrerenderManagerFactory::GetForBrowserContext(
1975 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591976 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491977 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591978 return false;
1979 }
1980
1981 return true;
1982}
1983
[email protected]76411f412012-02-22 18:56:061984bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441985 content::BrowserContext* browser_context,
1986 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061987 // It has to be a valid URL for us to check for an extension.
1988 if (!url.is_valid())
1989 return false;
1990
brettw00899e62016-11-12 02:10:171991#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061992 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131993 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441994 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271995#else
1996 return false;
1997#endif
[email protected]76411f412012-02-22 18:56:061998}
1999
Alex Moshchuk9c9e3882018-11-02 19:57:032000bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
2001 content::RenderFrameHost* main_frame) {
2002#if BUILDFLAG(ENABLE_EXTENSIONS)
2003 return ChromeContentBrowserClientExtensionsPart::
2004 ShouldSubframesTryToReuseExistingProcess(main_frame);
2005#else
2006 return true;
2007#endif
2008}
2009
[email protected]6f371442011-11-09 06:45:462010void ChromeContentBrowserClient::SiteInstanceGotProcess(
2011 SiteInstance* site_instance) {
2012 CHECK(site_instance->HasProcess());
2013
Aran Gilmanf010bdd2019-08-28 19:55:442014 Profile* profile =
2015 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:522016 if (!profile)
2017 return;
2018
Marc Treib7895941d2017-11-28 12:37:022019#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522020 // Remember the ID of the Instant process to signal the renderer process
2021 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:132022 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
2023 profile)) {
[email protected]c5dec6292013-01-25 04:54:522024 InstantService* instant_service =
2025 InstantServiceFactory::GetForProfile(profile);
2026 if (instant_service)
2027 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
2028 }
Marc Treib7895941d2017-11-28 12:37:022029#endif
[email protected]c5dec6292013-01-25 04:54:522030
[email protected]a48ab7112014-08-01 16:48:032031 for (size_t i = 0; i < extra_parts_.size(); ++i)
2032 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:462033}
2034
2035void ChromeContentBrowserClient::SiteInstanceDeleting(
2036 SiteInstance* site_instance) {
2037 if (!site_instance->HasProcess())
2038 return;
2039
[email protected]a48ab7112014-08-01 16:48:032040 for (size_t i = 0; i < extra_parts_.size(); ++i)
2041 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:462042}
2043
[email protected]453f5432013-11-26 19:43:002044bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:142045 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:562046 const GURL& current_effective_url,
2047 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:172048#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:132049 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:562050 ShouldSwapBrowsingInstancesForNavigation(
2051 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:272052#else
2053 return false;
2054#endif
[email protected]e3daf3c2011-10-05 21:17:082055}
2056
Nasko Oskovd83b5712018-05-04 04:50:572057bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
2058 // TODO(nasko): Consider supporting error page isolation in subframes if
2059 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:382060 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:572061}
2062
[email protected]3d831992013-07-04 01:13:292063bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
2064 return !url.SchemeIs(chrome::kChromeNativeScheme);
2065}
2066
Alex Moshchukd252c192017-07-17 22:03:482067std::vector<url::Origin>
2068ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
2069 std::vector<url::Origin> isolated_origin_list;
2070
Alex Moshchuk89352a72017-10-25 20:25:592071// Sign-in process isolation is not needed on Android, see
2072// https://crbug.com/739418.
2073#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:382074 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:122075 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:592076#endif
Alex Moshchukd252c192017-07-17 22:03:482077
Alex Moshchuk81d2a29e2019-07-16 01:14:382078#if BUILDFLAG(ENABLE_EXTENSIONS)
2079 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
2080 GetOriginsRequiringDedicatedProcess();
2081 std::move(std::begin(origins_from_extensions),
2082 std::end(origins_from_extensions),
2083 std::back_inserter(isolated_origin_list));
2084#endif
2085
Alex Moshchuk51e1428b2020-04-22 18:00:542086 // Include additional origins preloaded with specific browser configurations,
2087 // if any. For example, this is used on Google Chrome for Android to preload
2088 // a list of important sites to isolate.
2089 auto built_in_origins =
2090 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
2091 std::move(std::begin(built_in_origins), std::end(built_in_origins),
2092 std::back_inserter(isolated_origin_list));
2093
Alex Moshchukd252c192017-07-17 22:03:482094 return isolated_origin_list;
2095}
2096
Lukasz Anforowicz5e201abd2018-03-24 00:41:062097bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:342098 return base::FeatureList::IsEnabled(features::kSitePerProcess);
2099}
2100
2101bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Clark DuVallaadc244c2020-06-06 03:47:142102 return site_isolation::SiteIsolationPolicy::
2103 ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:062104}
2105
Alex Moshchuk082b5f82019-03-14 01:34:162106std::vector<std::string>
2107ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
Clark DuVallaadc244c2020-06-06 03:47:142108 if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
Alex Moshchuk082b5f82019-03-14 01:34:162109 return {"Isolate Password Sites"};
2110 else
2111 return {};
2112}
2113
Alex Moshchuke256d562019-04-26 21:43:572114void ChromeContentBrowserClient::PersistIsolatedOrigin(
2115 content::BrowserContext* context,
2116 const url::Origin& origin) {
2117 DCHECK(!context->IsOffTheRecord());
2118 Profile* profile = Profile::FromBrowserContext(context);
2119 ListPrefUpdate update(profile->GetPrefs(),
Clark DuVallaadc244c2020-06-06 03:47:142120 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Alex Moshchuke256d562019-04-26 21:43:572121 base::ListValue* list = update.Get();
2122 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:362123 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:122124 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:572125}
2126
Ken Rockot314714c2017-11-05 23:36:242127bool ChromeContentBrowserClient::IsFileAccessAllowed(
2128 const base::FilePath& path,
2129 const base::FilePath& absolute_path,
2130 const base::FilePath& profile_path) {
2131 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2132 profile_path);
2133}
2134
[email protected]d2e1a0a2014-06-16 15:49:372135namespace {
2136
bmcquade5d2d9cf32015-06-19 17:42:282137void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2138 const base::CommandLine& browser_command_line,
2139 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522140 // List of field trials that modify the blink-settings command line flag. No
2141 // two field trials in the list should specify the same keys, otherwise one
2142 // field trial may overwrite another. See Source/core/frame/Settings.in in
2143 // Blink for the list of valid keys.
2144 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162145 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2146 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2147 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2148 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522149 };
2150
2151 std::vector<std::string> blink_settings;
2152 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2153 // Each blink-settings field trial should include a forcing_flag group,
2154 // to make sure that clients that specify the blink-settings flag on the
2155 // command line are excluded from the experiment groups. To make
2156 // sure we assign clients that specify this flag to the forcing_flag
2157 // group, we must call GetVariationParams for each field trial first
2158 // (for example, before checking HasSwitch() and returning), since
2159 // GetVariationParams has the side-effect of assigning the client to
2160 // a field trial group.
2161 std::map<std::string, std::string> params;
2162 if (variations::GetVariationParams(field_trial_name, &params)) {
2163 for (const auto& param : params) {
2164 blink_settings.push_back(base::StringPrintf(
2165 "%s=%s", param.first.c_str(), param.second.c_str()));
2166 }
2167 }
2168 }
pmeenan9ac669682015-08-17 14:57:032169
bmcquade9dd54cc2015-06-22 16:56:522170 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282171 return;
2172 }
2173
Gyuyoung Kima252d4a2020-09-16 07:20:312174 if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) ||
2175 command_line->HasSwitch(blink::switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032176 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522177 // blink-settings flag into a group with no params, and we return
2178 // above if no params were specified, so it's an error if we reach
2179 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282180 LOG(WARNING) << "Received field trial params, "
2181 "but blink-settings switch already specified.";
2182 return;
2183 }
2184
Gyuyoung Kima252d4a2020-09-16 07:20:312185 command_line->AppendSwitchASCII(blink::switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262186 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282187}
2188
[email protected]d2e1a0a2014-06-16 15:49:372189} // namespace
2190
[email protected]b80f68432011-05-02 17:22:302191void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172192 base::CommandLine* command_line,
2193 int child_process_id) {
Avi Drissman2e458df2020-07-29 16:24:312194#if defined(OS_MAC)
dcheng4af48582016-04-19 00:29:352195 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062196 GoogleUpdateSettings::LoadMetricsClientInfo();
2197 if (client_info) {
2198 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2199 client_info->client_id);
2200 }
2201#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022202#if defined(OS_ANDROID)
2203 bool enable_crash_reporter = true;
2204#else
Joshua Perazace68e2f2019-09-23 18:44:242205 bool enable_crash_reporter = false;
2206 if (crash_reporter::IsCrashpadEnabled()) {
2207 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2208 enable_crash_reporter = true;
2209
2210 int fd;
2211 pid_t pid;
2212 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2213 command_line->AppendSwitchASCII(
2214 crash_reporter::switches::kCrashpadHandlerPid,
2215 base::NumberToString(pid));
2216 }
2217 } else {
2218 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2219 }
Joshua Perazaf890e4b2019-01-03 19:19:022220#endif
2221 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512222 std::string switch_value;
dcheng4af48582016-04-19 00:29:352223 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532224 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512225 if (client_info)
2226 switch_value = client_info->client_id;
2227 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252228 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302229 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512230 switch_value);
[email protected]b80f68432011-05-02 17:22:302231 }
Mark Mentovaic67fa64f2015-03-24 14:00:062232#endif
[email protected]b80f68432011-05-02 17:22:302233
[email protected]f1933792011-06-14 00:49:342234 if (logging::DialogsAreSuppressed())
2235 command_line->AppendSwitch(switches::kNoErrorDialogs);
2236
[email protected]b80f68432011-05-02 17:22:302237 std::string process_type =
2238 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172239 const base::CommandLine& browser_command_line =
2240 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322241
[email protected]7c9b6f92013-09-10 18:11:352242 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442243 switches::kUserAgent,
2244 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352245 };
2246 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372247 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322248
fqj15ff3f72015-10-09 19:20:022249 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432250 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312251 };
fqj15ff3f72015-10-09 19:20:022252 command_line->CopySwitchesFrom(browser_command_line,
2253 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372254 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312255
Yuta Hijikata235fc62b2020-12-08 03:48:322256#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]6bdc52272014-05-27 00:12:332257 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2258 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522259 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332260 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2261 homedir.value().c_str());
2262#endif
2263
[email protected]718eab62011-10-05 21:16:522264 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032265 content::RenderProcessHost* process =
2266 content::RenderProcessHost::FromID(child_process_id);
2267 Profile* profile =
2268 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442269 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032270 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442271 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2272 process, profile);
[email protected]a48ab7112014-08-01 16:48:032273 }
2274
Yuta Hijikata235fc62b2020-12-08 03:48:322275#if BUILDFLAG(IS_CHROMEOS_ASH)
Aran Gilmanf010bdd2019-08-28 19:55:442276 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2277 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302278 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442279 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2280 login_profile);
[email protected]b80f68432011-05-02 17:22:302281#endif
2282
Aran Gilmanf010bdd2019-08-28 19:55:442283 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222284 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372285 if (process) {
[email protected]a8d851f82011-12-21 00:32:372286 PrefService* prefs = profile->GetPrefs();
2287 // Currently this pref is only registered if applied via a policy.
2288 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2289 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2290 // Turn this policy into a command line switch.
2291 command_line->AppendSwitch(switches::kDisable3DAPIs);
2292 }
[email protected]718eab62011-10-05 21:16:522293
Bettinafd0c1102020-08-06 00:23:432294#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
2295 bool client_side_detection_enabled =
2296 safe_browsing::IsSafeBrowsingEnabled(*prefs) &&
Daniel Rubery33506f9f2020-10-07 00:28:132297 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2298 ::switches::kDisableClientSidePhishingDetection);
Bettinafd0c1102020-08-06 00:23:432299#if BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2300 client_side_detection_enabled &= base::FeatureList::IsEnabled(
2301 safe_browsing::kClientSideDetectionForAndroid);
2302#endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2303
[email protected]a8d851f82011-12-21 00:32:372304 // Disable client-side phishing detection in the renderer if it is
Bettinafd0c1102020-08-06 00:23:432305 // disabled in the Profile preferences, or by command line flag, or by not
2306 // being enabled on Android.
2307 if (!client_side_detection_enabled) {
[email protected]a8d851f82011-12-21 00:32:372308 command_line->AppendSwitch(
2309 switches::kDisableClientSidePhishingDetection);
2310 }
Bettinafd0c1102020-08-06 00:23:432311#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
[email protected]0045b0f42012-07-26 11:52:082312
vitalybukaa7ae5052014-09-26 04:11:132313 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2314 command_line->AppendSwitch(switches::kDisablePrintPreview);
2315
Marc Treib7895941d2017-11-28 12:37:022316#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522317 InstantService* instant_service =
2318 InstantServiceFactory::GetForProfile(profile);
2319 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542320 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522321 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542322 }
Marc Treib7895941d2017-11-28 12:37:022323#endif
fqjba8749c2015-10-29 15:33:072324
fqj38306f7b2015-11-02 16:59:062325 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542326 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432327 command_line->AppendSwitch(
2328 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542329 }
Daniel Vogelheim976f1c22017-11-22 16:26:032330
Lukasz Anforowicz60d1253d2019-05-08 16:31:372331 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2332
Katie Dillonc25ee5c92019-09-12 17:05:422333 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2334 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2335 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2336 }
Takashi Toyoshima128441462019-10-16 04:19:172337
Daniel Libbyc5bfd91f2020-03-07 03:44:102338 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2339 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2340 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2341 }
2342
Adrienne Walker297651292020-05-08 00:23:182343 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2344 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2345 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2346 }
Chris Hamilton65c41312020-06-10 13:14:402347
2348 // The IntensiveWakeUpThrottling feature is typically managed via a
2349 // base::Feature, but it has a managed policy override. The override is
2350 // communicated to blink via a custom command-line flag. See
2351 // PageSchedulerImpl for the other half of related logic.
2352 PrefService* local_state = g_browser_process->local_state();
2353 const PrefService::Preference* pref = local_state->FindPreference(
2354 policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled);
2355 if (pref && pref->IsManaged()) {
2356 command_line->AppendSwitchASCII(
2357 blink::switches::kIntensiveWakeUpThrottlingPolicy,
2358 pref->GetValue()->GetBool()
2359 ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable
2360 : blink::switches::
2361 kIntensiveWakeUpThrottlingPolicy_ForceDisable);
2362 }
Aaron Tagliaboschi8f3a28302020-06-24 03:08:262363
2364 // Same as above, but for the blink side of UserAgentClientHints
2365 if (!local_state->GetBoolean(
2366 policy::policy_prefs::kUserAgentClientHintsEnabled)) {
2367 command_line->AppendSwitch(
2368 blink::switches::kUserAgentClientHintDisable);
2369 }
Rakina Zata Amnic123bd22020-07-31 19:08:392370
Eric Lawrencea8a460c2020-11-06 21:10:422371 if (!local_state->GetBoolean(
2372 policy::policy_prefs::kTargetBlankImpliesNoOpener)) {
2373 command_line->AppendSwitch(
2374 switches::kDisableTargetBlankImpliesNoOpener);
2375 }
2376
Rakina Zata Amnic123bd22020-07-31 19:08:392377#if defined(OS_ANDROID)
2378 // Communicating to content/ for BackForwardCache.
2379 if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) &&
2380 !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) {
2381 command_line->AppendSwitch(switches::kDisableBackForwardCache);
2382 }
2383#endif // defined(OS_ANDROID)
[email protected]47c7ec82012-01-18 03:29:212384 }
[email protected]4287a3d2011-06-13 23:56:512385
Aran Gilmanf010bdd2019-08-28 19:55:442386 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2387 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282388
mdjonesa6b9e172016-09-23 16:24:302389#if defined(OS_ANDROID)
2390 // If the platform is Android, force the distillability service on.
2391 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2392#endif
2393
[email protected]47c7ec82012-01-18 03:29:212394 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512395 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192396 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412397 autofill::switches::kShowAutofillSignatures,
Yuta Hijikata235fc62b2020-12-08 03:48:322398#if BUILDFLAG(IS_CHROMEOS_ASH)
Chris Mumford6b1696b2019-01-25 02:54:302399 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2400#endif
brettw00899e62016-11-12 02:10:172401#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512402 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272403 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172404 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512405 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272406 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172407 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]5adb7742020-06-30 14:28:122408 extensions::switches::kAllowlistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282409#endif
estark4b003b332015-02-14 01:07:052410 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512411 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482412 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512413 switches::kCloudPrintXmppEndpoint,
dslomova893e972014-12-05 09:39:572414 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462415 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302416 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512417 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172418#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242419 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482420 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552421#endif
[email protected]ce304ce2013-02-22 21:54:452422 switches::kEnableNetBenchmarking,
Yuta Hijikata235fc62b2020-12-08 03:48:322423#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchukce6f8802020-01-30 09:30:342424 switches::kForceAppMode,
2425#endif
Nico Weberaf3b00b2017-09-11 17:58:172426#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592427 switches::kForcePNaClSubzero,
2428#endif
Marc Treibad33cf942017-08-24 11:19:002429 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032430 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512431 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102432 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322433 embedder_support::kOriginTrialDisabledFeatures,
2434 embedder_support::kOriginTrialDisabledTokens,
2435 embedder_support::kOriginTrialPublicKey,
wychene55687342015-11-13 20:17:032436 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092437 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512438 };
2439
2440 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372441 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172442 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172443#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382444 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442445 extensions::switches::kAllowHTTPBackgroundPage,
2446 extensions::switches::kEnableExperimentalExtensionApis,
2447 extensions::switches::kExtensionsOnChromeURLs,
[email protected]5adb7742020-06-30 14:28:122448 extensions::switches::kAllowlistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382449 };
2450
2451 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372452 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282453#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372454 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Ken Rockot4e805fd2020-10-01 03:07:392455 } else if (process_type == switches::kZygoteProcess) {
Yutaka Hirano93e924742020-11-11 10:40:132456 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
Nico Weberaf3b00b2017-09-11 17:58:172457#if BUILDFLAG(ENABLE_NACL)
Yutaka Hirano93e924742020-11-11 10:40:132458 static const char* const kSwitchNames[] = {
2459 switches::kEnableNaClDebug,
2460 switches::kEnableNaClNonSfiMode,
2461 switches::kForcePNaClSubzero,
2462 switches::kNaClDangerousNoSandboxNonSfi,
2463 };
[email protected]4287a3d2011-06-13 23:56:512464
Yutaka Hirano93e924742020-11-11 10:40:132465 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2466 base::size(kSwitchNames));
Bill Budge431f0b32020-10-27 21:31:382467#endif
James Cook247a8cb2020-12-22 23:09:512468#if BUILDFLAG(IS_CHROMEOS_LACROS)
2469 // Ensure zygote loads the resource bundle for the right locale.
2470 static const char* const kMoreSwitchNames[] = {switches::kLang};
2471 command_line->CopySwitchesFrom(browser_command_line, kMoreSwitchNames,
2472 base::size(kMoreSwitchNames));
2473#endif
[email protected]d56ecf922012-02-15 16:03:112474 } else if (process_type == switches::kGpuProcess) {
Corentin Walleze660b152020-07-15 16:07:542475 // If --ignore-gpu-blocklist is passed in, don't send in crash reports
[email protected]d56ecf922012-02-15 16:03:112476 // because GPU is expected to be unreliable.
Corentin Wallez49c0110d2020-11-17 10:15:162477 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) &&
[email protected]d56ecf922012-02-15 16:03:112478 !command_line->HasSwitch(switches::kDisableBreakpad))
2479 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302480 }
[email protected]6f08af82011-09-15 01:19:032481
Yuta Hijikata235fc62b2020-12-08 03:48:322482#if BUILDFLAG(IS_CHROMEOS_ASH)
Joshua Peraza30d8fc72019-08-19 17:24:302483 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112484 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292485 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112486 };
2487 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2488 base::size(kSwitchNames));
2489 }
2490#endif
2491
Mike Wittman67d63112020-09-19 00:33:462492 ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Mike Wittman0d21648f2020-09-30 19:05:082493 command_line);
Andrew Comminos66057672019-05-01 00:03:342494
Sean McAllister0d73ca3d2020-08-19 17:54:372495#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Andrew Comminos66057672019-05-01 00:03:342496 // Processes may only query perf_event_open with the BPF sandbox disabled.
2497 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
Robert Sesek7d0b49b2020-07-08 18:31:272498 command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
Andrew Comminos66057672019-05-01 00:03:342499 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2500 }
2501#endif
[email protected]b80f68432011-05-02 17:22:302502}
2503
Olivier Yiptong0daa93f2019-08-22 19:40:082504std::string
2505ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2506 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2507}
2508
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:592509download::QuarantineConnectionCallback
2510ChromeContentBrowserClient::GetQuarantineConnectionCallback() {
2511 return base::BindRepeating(
2512 &ChromeDownloadManagerDelegate::ConnectToQuarantineService);
2513}
2514
[email protected]b80f68432011-05-02 17:22:302515std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432516 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332517 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302518 return g_browser_process->GetApplicationLocale();
2519}
2520
[email protected]597a867b2011-11-18 18:31:202521std::string ChromeContentBrowserClient::GetAcceptLangs(
2522 content::BrowserContext* context) {
2523 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202524 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082525}
2526
Dana Fried34d580002019-04-24 20:05:482527gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492528 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482529 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082530}
2531
bengre8a146f2016-03-10 01:20:222532bool ChromeContentBrowserClient::IsDataSaverEnabled(
2533 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382534 if (!browser_context || browser_context->IsOffTheRecord())
2535 return false;
2536
Robert Ogdenc995d4fe2019-03-25 19:18:372537 Profile* profile = Profile::FromBrowserContext(browser_context);
2538 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412539 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2540 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222541}
2542
Kenichi Ishibashi46329872018-07-17 09:43:402543void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2544 content::BrowserContext* browser_context,
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:232545 blink::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402546 DCHECK(browser_context);
2547 DCHECK(out_prefs);
2548 renderer_preferences_util::UpdateFromSystemSettings(
2549 out_prefs, Profile::FromBrowserContext(browser_context));
2550}
2551
Clark DuVall5690e742019-07-17 18:26:172552bool ChromeContentBrowserClient::AllowAppCache(
2553 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172554 const GURL& site_for_cookies,
2555 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172556 content::BrowserContext* context) {
2557 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2558 return CookieSettingsFactory::GetForProfile(
2559 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172560 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172561}
2562
Alexander Timin17edc742020-04-23 18:22:182563content::AllowServiceWorkerResult
John Abd-El-Malek70810942020-10-27 05:14:382564ChromeContentBrowserClient::AllowServiceWorker(
Matt Falkenhagen7b509e52019-08-15 23:11:412565 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542566 const GURL& site_for_cookies,
2567 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412568 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182569 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412570 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542571 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412572
2573#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022574 // Check if this is an extension-related service worker, and, if so, if it's
2575 // allowed (this can return false if, e.g., the extension is disabled).
2576 // If it's not allowed, return immediately. We deliberately do *not* report
Carlos Caballerob4283202020-08-10 14:40:462577 // to the PageSpecificContentSettings, since the service worker is blocked
Matt Falkenhagena59e1cce2019-08-22 23:45:022578 // because of the extension, rather than because of the user's content
2579 // settings.
John Abd-El-Malek70810942020-10-27 05:14:382580 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
Matt Falkenhagena59e1cce2019-08-22 23:45:022581 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182582 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022583 }
Matt Falkenhagen7b509e52019-08-15 23:11:412584#endif
2585
2586 Profile* profile = Profile::FromBrowserContext(context);
2587
2588 // Check if JavaScript is allowed.
2589 content_settings::SettingInfo info;
2590 std::unique_ptr<base::Value> value =
2591 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452592 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Illia Klimov48f643c2020-11-05 20:06:142593 &info);
Matt Falkenhagen7b509e52019-08-15 23:11:412594 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2595 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2596
2597 // Check if cookies are allowed.
2598 bool allow_cookies =
2599 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542600 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412601
Alexander Timin17edc742020-04-23 18:22:182602 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2603 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412604}
2605
Jochen Eisinger0ff7645c2017-11-28 08:11:262606bool ChromeContentBrowserClient::AllowSharedWorker(
2607 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542608 const GURL& site_for_cookies,
2609 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262610 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372611 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262612 content::BrowserContext* context,
2613 int render_process_id,
2614 int render_frame_id) {
2615 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2616
2617 // Check if cookies are allowed.
2618 bool allow =
2619 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542620 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2621 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262622
Carlos Caballerob4283202020-08-10 14:40:462623 content_settings::PageSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372624 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2625 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262626 return allow;
2627}
2628
Patrick Monette6cb099a2019-09-18 19:31:272629bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2630 const std::string& scheme) {
2631#if BUILDFLAG(ENABLE_EXTENSIONS)
2632 // Extensions are allowed to start cross-origin shared workers.
2633 if (scheme == extensions::kExtensionScheme)
2634 return true;
2635#endif
2636
2637 return false;
2638}
2639
Clark DuVallab63d142019-07-23 04:24:362640bool ChromeContentBrowserClient::AllowSignedExchange(
2641 content::BrowserContext* browser_context) {
2642 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2643 Profile* profile = Profile::FromBrowserContext(browser_context);
2644 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2645}
2646
[email protected]f917df22014-07-10 07:45:492647void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352648 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572649 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172650 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572651 base::OnceCallback<void(bool)> callback) {
2652 Profile* profile = Profile::FromBrowserContext(browser_context);
2653 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172654 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352655
brettw00899e62016-11-12 02:10:172656#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572657 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492658#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572659 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492660#endif
2661}
2662
brettw00899e62016-11-12 02:10:172663#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492664void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2665 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172666 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572667 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492668 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572669 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492670 std::map<int, int> process_map;
2671 std::map<int, int>::const_iterator it;
2672 bool has_web_view_guest = false;
2673 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172674 for (const auto& it : render_frames) {
2675 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492676 continue;
2677
Lukasz Anforowicz09060bdf72018-08-23 15:53:172678 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492679
Lukasz Anforowicz09060bdf72018-08-23 15:53:172680 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492681 has_web_view_guest = true;
2682 }
2683 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572684 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492685 return;
2686 }
[email protected]dffb9fc2014-07-16 04:14:022687 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492688 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492689
[email protected]140d6cd92014-08-12 18:26:462690 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572691 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2692 web_view_permission_helper->RequestFileSystemPermission(
2693 url, allow,
2694 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2695 weak_factory_.GetWeakPtr(), url, render_frames,
2696 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492697}
2698#endif
2699
2700void ChromeContentBrowserClient::FileSystemAccessed(
2701 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172702 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572703 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492704 bool allow) {
[email protected]62151052012-02-01 18:40:482705 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172706 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462707 content_settings::PageSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572708 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352709 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572710 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352711}
2712
[email protected]7c5ff9a2012-03-02 07:42:492713bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2714 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572715 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172716 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572717 Profile* profile = Profile::FromBrowserContext(browser_context);
2718 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2719
Christian Dullweber77740152020-05-12 09:54:172720 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492721
2722 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172723 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462724 content_settings::PageSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572725 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492726 }
2727
2728 return allow;
2729}
2730
Ben Kelly6b2e61c2019-03-14 16:06:292731bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2732 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572733 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292734 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572735 Profile* profile = Profile::FromBrowserContext(browser_context);
2736 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172737 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292738
2739 // Record access to CacheStorage for potential display in UI.
2740 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462741 content_settings::PageSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572742 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292743 }
2744
2745 return allow;
2746}
2747
Joshua Bell1ebc8df2019-11-06 00:27:582748bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2749 const GURL& url,
2750 content::BrowserContext* browser_context,
2751 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2752 Profile* profile = Profile::FromBrowserContext(browser_context);
2753 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172754 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582755}
2756
jyasskinc993ce8d2016-03-31 00:38:342757ChromeContentBrowserClient::AllowWebBluetoothResult
2758ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452759 content::BrowserContext* browser_context,
2760 const url::Origin& requesting_origin,
2761 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342762 // TODO(crbug.com/598890): Don't disable if
2763 // base::CommandLine::ForCurrentProcess()->
2764 // HasSwitch(switches::kEnableWebBluetooth) is true.
2765 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272766 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342767 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272768 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342769 // The kill switch is enabled for this permission. Block requests.
2770 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2771 }
2772
jyasskin98bdd3992016-02-26 20:25:452773 const HostContentSettingsMap* const content_settings =
2774 HostContentSettingsMapFactory::GetForProfile(
2775 Profile::FromBrowserContext(browser_context));
2776
csharrisonaec2c542016-10-12 19:40:362777 if (content_settings->GetContentSetting(
2778 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:142779 ContentSettingsType::BLUETOOTH_GUARD) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342780 return AllowWebBluetoothResult::BLOCK_POLICY;
2781 }
2782 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452783}
2784
beaufort.francois01135bf2016-11-23 14:37:362785std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2786 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2787 "blocklist_additions");
scheib74250322016-04-07 03:32:212788}
2789
John Delaneyc2782792021-01-15 01:29:072790bool ChromeContentBrowserClient::IsConversionMeasurementAllowed(
Charlie Harrison071ac922020-06-25 19:11:222791 content::BrowserContext* browser_context) {
Charlie Harrison071ac922020-06-25 19:11:222792 Profile* profile = Profile::FromBrowserContext(browser_context);
John Delaneyc2782792021-01-15 01:29:072793 PrivacySandboxSettings* privacy_sandbox_settings =
2794 PrivacySandboxSettingsFactory::GetForProfile(profile);
2795
2796 return privacy_sandbox_settings &&
2797 privacy_sandbox_settings->IsPrivacySandboxAllowed();
2798}
2799
2800bool ChromeContentBrowserClient::IsConversionMeasurementOperationAllowed(
2801 content::BrowserContext* browser_context,
2802 ConversionMeasurementOperation operation,
2803 const url::Origin* impression_origin,
2804 const url::Origin* conversion_origin,
2805 const url::Origin* reporting_origin) {
2806 Profile* profile = Profile::FromBrowserContext(browser_context);
2807
2808 PrivacySandboxSettings* privacy_sandbox_settings =
2809 PrivacySandboxSettingsFactory::GetForProfile(profile);
2810 if (!privacy_sandbox_settings)
2811 return false;
2812
2813 switch (operation) {
2814 case ConversionMeasurementOperation::kImpression:
2815 DCHECK(impression_origin);
2816 DCHECK(reporting_origin);
2817 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2818 *impression_origin, *reporting_origin);
2819 case ConversionMeasurementOperation::kConversion:
2820 DCHECK(conversion_origin);
2821 DCHECK(reporting_origin);
2822 return privacy_sandbox_settings->IsConversionMeasurementAllowed(
2823 *conversion_origin, *reporting_origin);
2824 case ConversionMeasurementOperation::kReport:
2825 DCHECK(impression_origin);
2826 DCHECK(conversion_origin);
2827 DCHECK(reporting_origin);
2828 return privacy_sandbox_settings->ShouldSendConversionReport(
2829 *impression_origin, *conversion_origin, *reporting_origin);
2830 }
Charlie Harrison071ac922020-06-25 19:11:222831}
2832
Yuta Hijikata235fc62b2020-12-08 03:48:322833#if BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522834void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072835 content::BrowserContext* browser_context) {
2836 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2837 if (user_manager) {
2838 const user_manager::User* user =
2839 chromeos::ProfileHelper::Get()->GetUserByProfile(
2840 Profile::FromBrowserContext(browser_context));
2841 if (user && !user->username_hash().empty()) {
2842 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
Andreea Costinase1dd9e3a2020-09-22 11:43:352843 user->GetAccountId().GetUserEmail());
John Abd-El-Malek35bfaa52019-08-20 16:22:072844 }
2845 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332846}
2847#endif
2848
Reilly Grant19aaccd2018-07-16 22:06:372849scoped_refptr<network::SharedURLLoaderFactory>
2850ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2852 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2853
2854 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372855 return nullptr;
2856
Min Qinda0d55b2018-10-12 18:30:052857 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372858 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042859}
2860
Sean Gilhulyda1ee4b2018-11-13 21:56:092861network::mojom::NetworkContext*
2862ChromeContentBrowserClient::GetSystemNetworkContext() {
2863 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2864 DCHECK(g_browser_process->system_network_context_manager());
2865 return g_browser_process->system_network_context_manager()->GetContext();
2866}
2867
Andrew Moylan17329fc2017-09-25 07:43:302868std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2869 return google_apis::GetAPIKey();
2870}
2871
Ke He21ee87f2018-05-30 02:35:322872#if defined(OS_ANDROID)
2873bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2874 // Indicate that Chrome uses the GMS core location provider.
2875 return true;
2876}
2877#endif
2878
Yeolf3dc22ca2019-04-18 17:25:322879scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412880ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542881 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412882}
2883
Mythri Alle0b8de0d2018-10-22 11:06:222884content::GeneratedCodeCacheSettings
2885ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2886 content::BrowserContext* context) {
2887 base::FilePath cache_path;
2888 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2889 // If we pass 0 for size, disk_cache will pick a default size using the
2890 // heuristics based on available disk size. These are implemented in
2891 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162892 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132893 DCHECK(g_browser_process);
2894 PrefService* local_state = g_browser_process->local_state();
2895 if (local_state) {
2896 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2897 base::FilePath disk_cache_dir =
2898 local_state->GetFilePath(prefs::kDiskCacheDir);
2899 if (!disk_cache_dir.empty())
2900 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2901 }
Mythri Ab2486572019-06-13 14:48:162902 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222903}
2904
[email protected]848dd042011-06-04 18:24:032905void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262906 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172907 int cert_error,
2908 const net::SSLInfo& ssl_info,
2909 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232910 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222911 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262912 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262913 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232914 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142915 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022916 // have a context for making the right decision, so block the
2917 // request hard, without an info bar to allow showing the insecure
2918 // content.
estark719dde52016-08-09 03:14:272919 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262920 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022921 return;
2922 }
2923
[email protected]f9034cf2011-07-21 12:43:412924 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572925 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:572926 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572927 if (prerender_contents) {
2928 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272929 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262930 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272931 }
[email protected]09667f02014-01-06 15:37:572932 return;
[email protected]f9034cf2011-07-21 12:43:412933 }
2934
Erik Staaba65a6032019-11-27 22:23:262935 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282936 return;
[email protected]848dd042011-06-04 18:24:032937}
2938
Katie D1882617e2020-05-06 20:06:012939#if !defined(OS_ANDROID)
2940bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2941 const GURL main_page_url) {
2942 // Desktop Reader Mode pages should never load resources with certificate
2943 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2944 // on Android: the desktop version has its own security indicator and
2945 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2946 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2947 // pages).
2948 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2949}
2950#endif
2951
Alexander Hendrichbcf2616e2018-05-18 08:21:102952namespace {
2953
Pavol Markob211ab22019-01-23 20:03:042954certificate_matching::CertificatePrincipalPattern
2955ParseCertificatePrincipalPattern(const base::Value* pattern) {
2956 return certificate_matching::CertificatePrincipalPattern::
2957 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2958}
2959
Alexander Hendrichbcf2616e2018-05-18 08:21:102960// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452961// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102962// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2963std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2964 Profile* profile,
2965 const GURL& requesting_url,
2966 net::ClientCertIdentityList& client_certs) {
2967 HostContentSettingsMap* host_content_settings_map =
2968 HostContentSettingsMapFactory::GetForProfile(profile);
2969 std::unique_ptr<base::Value> setting =
2970 host_content_settings_map->GetWebsiteSetting(
2971 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142972 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102973
Pavol Markob211ab22019-01-23 20:03:042974 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102975 return nullptr;
2976
Alexander Hendrichbcf2616e2018-05-18 08:21:102977 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042978 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2979 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102980 // |setting_dict| has the wrong format (e.g. single filter instead of a
2981 // list of filters). This content setting is only provided by
2982 // the |PolicyProvider|, which should always set it to a valid format.
2983 // Therefore, delete the invalid value.
2984 host_content_settings_map->SetWebsiteSettingDefaultScope(
2985 requesting_url, requesting_url,
Illia Klimov48f643c2020-11-05 20:06:142986 ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr);
Pavol Markob211ab22019-01-23 20:03:042987 return nullptr;
2988 }
2989
2990 for (const base::Value& filter : filters->GetList()) {
2991 DCHECK(filter.is_dict());
2992
2993 auto issuer_pattern = ParseCertificatePrincipalPattern(
2994 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2995 auto subject_pattern = ParseCertificatePrincipalPattern(
2996 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2997 // Use the first certificate that is matched by the filter.
2998 for (auto& client_cert : client_certs) {
2999 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
3000 subject_pattern.Matches(client_cert->certificate()->subject())) {
3001 return std::move(client_cert);
3002 }
3003 }
Alexander Hendrichbcf2616e2018-05-18 08:21:103004 }
3005
3006 return nullptr;
3007}
3008
Prashant Nevase788dcee2020-10-30 19:00:173009#if !defined(OS_ANDROID)
3010blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
3011 ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
3012 switch (native_theme_scheme) {
3013 case ui::NativeTheme::PreferredColorScheme::kDark:
3014 return blink::mojom::PreferredColorScheme::kDark;
3015 case ui::NativeTheme::PreferredColorScheme::kLight:
3016 return blink::mojom::PreferredColorScheme::kLight;
3017 }
3018
3019 NOTREACHED();
3020}
3021#endif // !defined(OS_ANDROID)
3022
3023// Returns true if preferred color scheme is modified based on at least one of
3024// the following -
3025// |url| - Last committed url.
3026// |web_contents| - For Android based on IsNightModeEnabled().
3027// |native_theme| - For other platforms based on native theme scheme.
3028bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
3029 const GURL& url,
3030 WebContents* web_contents,
3031 const ui::NativeTheme* native_theme) {
3032 auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
3033
3034#if defined(OS_ANDROID)
3035 auto* delegate = TabAndroid::FromWebContents(web_contents)
3036 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3037 web_contents->GetDelegate())
3038 : nullptr;
3039 if (delegate) {
3040 web_prefs->preferred_color_scheme =
3041 delegate->IsNightModeEnabled()
3042 ? blink::mojom::PreferredColorScheme::kDark
3043 : blink::mojom::PreferredColorScheme::kLight;
3044 }
3045#else
3046 // Update based on native theme scheme.
3047 web_prefs->preferred_color_scheme =
3048 ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
3049#endif // defined(OS_ANDROID)
3050
Alex Ilin85e8fd92020-12-01 14:07:183051 bool force_light = false;
Prashant Nevase788dcee2020-10-30 19:00:173052 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3053 // disabled; some of the UI is not yet correctly themed.
3054 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3055 // Update based on last committed url.
Alex Ilin85e8fd92020-12-01 14:07:183056 force_light |= url.SchemeIs(content::kChromeUIScheme);
Prashant Nevase788dcee2020-10-30 19:00:173057#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Ilin85e8fd92020-12-01 14:07:183058 force_light |= url.SchemeIs(extensions::kExtensionScheme) &&
3059 url.host_piece() == extension_misc::kPdfExtensionId;
Prashant Nevase788dcee2020-10-30 19:00:173060#endif
Alex Ilin85e8fd92020-12-01 14:07:183061 }
3062
3063 // Reauth WebUI doesn't support dark mode yet because it shares the dialog
3064 // with GAIA web contents that is not correctly themed.
3065 force_light |= url.SchemeIs(content::kChromeUIScheme) &&
3066 url.host_piece() == chrome::kChromeUISigninReauthHost;
3067
3068 if (force_light) {
3069 web_prefs->preferred_color_scheme =
3070 blink::mojom::PreferredColorScheme::kLight;
Prashant Nevase788dcee2020-10-30 19:00:173071 }
3072
3073 return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
3074}
3075
Alexander Hendrichbcf2616e2018-05-18 08:21:103076} // namespace
3077
Daniel McArdle85735f52019-06-25 03:27:063078base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:193079 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:403080 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:083081 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:353082 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:023083 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:573084 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:023085 if (prerender_contents) {
3086 prerender_contents->Destroy(
3087 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:063088 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:453089 }
3090
[email protected]791879c2013-12-17 07:22:413091 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
3092 DCHECK(requesting_url.is_valid())
3093 << "Invalid URL string: https://"
3094 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:453095
Pavol Marko230ea2c92017-12-03 22:35:443096 bool may_show_cert_selection = true;
3097
davidben3b8455ae72015-03-11 19:42:193098 Profile* profile =
3099 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Yuta Hijikata235fc62b2020-12-08 03:48:323100#if BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443101 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:253102 // On the sign-in profile, never show certificate selection to the user. A
3103 // client certificate is an identifier that can be stable for a long time,
3104 // so only the administrator is allowed to decide which endpoints should see
3105 // it.
3106 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:443107
3108 content::StoragePartition* storage_partition =
3109 content::BrowserContext::GetStoragePartition(
3110 profile, web_contents->GetSiteInstance());
3111 chromeos::login::SigninPartitionManager* signin_partition_manager =
3112 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
3113 profile);
3114
3115 // On the sign-in profile, only allow client certs in the context of the
3116 // sign-in frame.
3117 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
3118 storage_partition)) {
3119 LOG(WARNING)
3120 << "Client cert requested in sign-in profile in wrong context.";
3121 // Continue without client certificate. We do this to mimic the case of no
3122 // client certificate being present in the profile's certificate store.
3123 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063124 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443125 }
3126 VLOG(1) << "Client cert requested in sign-in profile.";
3127 }
Yuta Hijikata235fc62b2020-12-08 03:48:323128#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Pavol Marko230ea2c92017-12-03 22:35:443129
Alexander Hendrichbcf2616e2018-05-18 08:21:103130 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
3131 AutoSelectCertificate(profile, requesting_url, client_certs);
3132 if (auto_selected_identity) {
3133 // The callback will own |auto_selected_identity| and |delegate|, keeping
3134 // them alive until after ContinueWithCertificate is called.
3135 scoped_refptr<net::X509Certificate> cert =
3136 auto_selected_identity->certificate();
3137 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
3138 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:583139 base::BindOnce(
3140 &content::ClientCertificateDelegate::ContinueWithCertificate,
3141 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:323142 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:063143 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:453144 }
3145
Pavol Marko230ea2c92017-12-03 22:35:443146 if (!may_show_cert_selection) {
3147 LOG(WARNING) << "No client cert matched by policy and user selection is "
3148 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:323149 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:443150 // Continue without client certificate. We do this to mimic the case of no
3151 // client certificate being present in the profile's certificate store.
3152 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063153 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443154 }
3155
Daniel McArdle85735f52019-06-25 03:27:063156 return chrome::ShowSSLClientCertificateSelector(
3157 web_contents, cert_request_info, std::move(client_certs),
3158 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:453159}
3160
[email protected]dc73a7b2012-03-25 15:27:183161content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:563162 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:183163}
3164
Adrienne Walker80d95f02020-02-07 22:37:043165content::FeatureObserverClient*
3166ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:243167 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:043168 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:053169}
3170
peterc26c6c62014-12-10 14:13:593171content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:023172ChromeContentBrowserClient::GetPlatformNotificationService(
3173 content::BrowserContext* browser_context) {
3174 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3175 Profile* profile = Profile::FromBrowserContext(browser_context);
3176 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:043177}
3178
[email protected]9f3fba52011-06-08 20:37:193179bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:353180 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:353181 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:573182 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:353183 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:033184 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233185 const GURL& target_url,
3186 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213187 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233188 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483189 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233190 bool user_gesture,
3191 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013192 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353193 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3194 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013195
csharrison95f01e922017-04-24 18:52:353196 content::WebContents* web_contents =
3197 content::WebContents::FromRenderFrameHost(opener);
3198 Profile* profile =
3199 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3200 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013201 *no_javascript_access = false;
3202
[email protected]9f3fba52011-06-08 20:37:193203 // If the opener is trying to create a background window but doesn't have
3204 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033205 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173206#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353207 auto* process_map = extensions::ProcessMap::Get(profile);
3208 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173209 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3210 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013211 return false;
3212 }
3213
[email protected]7b54ca02012-03-02 18:06:533214 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3215 // return a recently installed Extension even if this CanCreateWindow call
3216 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013217 // because the permission check above would have caused an early return
3218 // already. We must use the full URL to find hosted apps, though, and not
3219 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553220 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353221 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293222 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013223 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023224#endif
[email protected]190e5e22013-07-27 05:59:233225
3226 return true;
[email protected]9f3fba52011-06-08 20:37:193227 }
[email protected]056efdc2013-04-06 00:14:533228
brettw00899e62016-11-12 02:10:173229#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463230 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353231 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233232 return true;
lazyboy04b75d32016-02-25 03:12:183233 }
3234
nick0fbc3922016-12-16 20:52:073235 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353236 // Intentionally duplicating |registry| code from above because we want to
3237 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3238 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183239 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353240 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143241 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533242 UMA_HISTOGRAM_ENUMERATION(
3243 "Extensions.AppLoadedInTab",
3244 ClassifyAppLoadedInTabSource(opener_url, extension),
3245 APP_LOADED_IN_TAB_SOURCE_MAX);
3246
3247 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163248 return false;
lazyboy5d5fede02016-03-10 04:10:143249 }
lazyboy04b75d32016-02-25 03:12:183250 }
[email protected]5940b0d2014-07-01 00:18:263251#endif
[email protected]190e5e22013-07-27 05:59:233252
Mugdha Lakhani2c6b23af2020-07-31 14:55:573253 DCHECK(!prerender::ChromePrerenderContentsDelegate::FromWebContents(
3254 web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023255
Aaron Colwell9dab1652019-12-09 18:29:493256 BlockedWindowParams blocked_params(
3257 target_url, source_origin, opener->GetSiteInstance(), referrer,
3258 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133259 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Clark DuVall8a020d622020-06-04 00:45:503260 return blocked_content::MaybeBlockPopup(
3261 web_contents, &opener_top_level_frame_url,
3262 std::make_unique<ChromePopupNavigationDelegate>(
3263 std::move(nav_params)),
3264 nullptr /*=open_url_params*/, blocked_params.features(),
3265 HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr;
[email protected]9f3fba52011-06-08 20:37:193266}
3267
[email protected]c52b2892012-03-07 11:01:023268content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443269ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003270 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513271}
3272
Yuta Hijikata235fc62b2020-12-08 03:48:323273#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D840d9532018-11-27 06:20:483274content::TtsControllerDelegate*
3275ChromeContentBrowserClient::GetTtsControllerDelegate() {
Scott Violet1644cf72020-06-24 04:51:553276 return TtsControllerDelegateImpl::GetInstance();
3277}
3278#endif
3279
3280content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
Katie D840d9532018-11-27 06:20:483281#if !defined(OS_ANDROID)
Scott Violete217e5e2020-06-22 19:18:223282 content::TtsController::GetInstance()->SetTtsEngineDelegate(
3283 TtsExtensionEngine::GetInstance());
Katie D840d9532018-11-27 06:20:483284#endif
Yuta Hijikata235fc62b2020-12-08 03:48:323285#if BUILDFLAG(IS_CHROMEOS_ASH)
Katie D4713ee42018-11-30 01:48:273286 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273287#else
3288 return nullptr;
3289#endif
3290}
3291
[email protected]64d69de42012-02-06 00:19:543292void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443293 RenderViewHost* rvh,
3294 WebPreferences* web_prefs) {
3295 Profile* profile =
3296 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063297 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063298
aelias0df335a2017-03-02 23:43:513299// Fill font preferences. These are not registered on Android
3300// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453301#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193302 FontFamilyCache::FillFontFamilyMap(profile,
3303 prefs::kWebKitStandardFontFamilyMap,
3304 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443305 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193306 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443307 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193308 &web_prefs->serif_font_family_map);
3309 FontFamilyCache::FillFontFamilyMap(profile,
3310 prefs::kWebKitSansSerifFontFamilyMap,
3311 &web_prefs->sans_serif_font_family_map);
3312 FontFamilyCache::FillFontFamilyMap(profile,
3313 prefs::kWebKitCursiveFontFamilyMap,
3314 &web_prefs->cursive_font_family_map);
3315 FontFamilyCache::FillFontFamilyMap(profile,
3316 prefs::kWebKitFantasyFontFamilyMap,
3317 &web_prefs->fantasy_font_family_map);
3318 FontFamilyCache::FillFontFamilyMap(profile,
3319 prefs::kWebKitPictographFontFamilyMap,
3320 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063321
[email protected]64d69de42012-02-06 00:19:543322 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403323 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543324 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403325 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543326 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403327 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543328 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403329 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513330#endif
[email protected]f3986f82012-01-03 20:00:063331
[email protected]ddf72142012-05-22 04:52:403332 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063333
[email protected]64d69de42012-02-06 00:19:543334 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063335 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213336 web_prefs->javascript_can_access_clipboard =
3337 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543338 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063339
[email protected]ddf72142012-05-22 04:52:403340 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543341 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573342
Avi Drissman1aa6cb92019-01-23 15:58:383343 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543344 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573345
[email protected]ddf72142012-05-22 04:52:403346 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543347 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543348 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403349 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063350
Zhenyao Moa3fda9972017-09-16 01:34:403351 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3352 web_prefs->webgl1_enabled = false;
3353 web_prefs->webgl2_enabled = false;
3354 }
[email protected]f3986f82012-01-03 20:00:063355
[email protected]64d69de42012-02-06 00:19:543356 web_prefs->allow_running_insecure_content =
3357 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323358#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053359 web_prefs->font_scale_factor =
3360 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323361 web_prefs->force_enable_zoom =
3362 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493363#endif
Becky Zhoubbfbde32019-02-20 17:07:593364 web_prefs->force_dark_mode_enabled =
3365 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393366
Yuta Hijikata235fc62b2020-12-08 03:48:323367#if BUILDFLAG(IS_CHROMEOS_ASH)
Alice Boxhallda2659142020-05-14 06:04:373368 web_prefs->always_show_focus =
3369 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
Alice Boxhalla9aafba42020-06-24 05:42:513370#else
3371 if (features::IsAccessibilityFocusHighlightEnabled()) {
3372 web_prefs->always_show_focus =
3373 prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled);
3374 }
Alice Boxhallda2659142020-05-14 06:04:373375#endif
3376
[email protected]af4256d52013-06-04 20:39:073377#if defined(OS_ANDROID)
3378 web_prefs->password_echo_enabled =
3379 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3380#else
[email protected]9d06d88d2012-02-23 22:37:083381 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073382#endif
3383
[email protected]64d69de42012-02-06 00:19:543384 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063385 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543386 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063387 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3388
brettw00899e62016-11-12 02:10:173389#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053390 std::string image_animation_policy =
3391 prefs->GetString(prefs::kAnimationPolicy);
Gyuyoung Kim3b4703d2020-09-18 00:25:493392 if (image_animation_policy == kAnimationPolicyOnce) {
je_julie.kim7fbb5a1a2015-02-09 17:26:053393 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573394 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
Gyuyoung Kim3b4703d2020-09-18 00:25:493395 } else if (image_animation_policy == kAnimationPolicyNone) {
Gyuyoung Kim1ac4ca782020-09-11 03:32:513396 web_prefs->animation_policy =
Gyuyoung Kim1e9d3c32020-10-12 14:04:573397 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
Gyuyoung Kim3b4703d2020-09-18 00:25:493398 } else {
Gyuyoung Kim1e9d3c32020-10-12 14:04:573399 web_prefs->animation_policy =
3400 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
Gyuyoung Kim3b4703d2020-09-18 00:25:493401 }
je_julie.kim7fbb5a1a2015-02-09 17:26:053402#endif
3403
[email protected]f3986f82012-01-03 20:00:063404 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153405 web_prefs->default_encoding =
3406 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543407 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403408 prefs->ClearPref(prefs::kDefaultCharset);
3409 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063410 }
[email protected]64d69de42012-02-06 00:19:543411 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063412
mkwst05544102015-01-10 20:26:163413 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3414 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073415 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163416 web_prefs->strict_mixed_content_checking = true;
3417 web_prefs->strict_powerful_feature_restrictions = true;
3418 }
3419
Robert Ogdencf2872d2019-03-19 18:59:373420 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213421
Tarun Bansal333819e2018-05-15 16:38:423422 web_prefs->data_saver_holdback_web_api_enabled =
3423 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3424 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423425
Jinsuk Kima3d393ce2019-05-27 00:57:423426 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133427 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533428#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423429 auto* delegate = TabAndroid::FromWebContents(contents)
3430 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3431 contents->GetDelegate())
3432 : nullptr;
3433 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133434 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423435 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133436
Mounir Lamouri9c99a1602018-07-05 15:01:443437 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423438 delegate->IsPictureInPictureEnabled();
zqzhang183dc822017-02-15 17:04:113439 }
Ian Vollick6243dfe02018-03-08 01:08:533440#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533441
Mounir Lamouri6926107f2019-01-31 18:17:433442 // web_app_scope value is platform specific.
3443#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423444 if (delegate)
3445 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433446#elif BUILDFLAG(ENABLE_EXTENSIONS)
3447 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253448 web_prefs->web_app_scope = GURL();
3449 // Set |web_app_scope| based on the app associated with the app window if
3450 // any. Note that the app associated with the window never changes, even
3451 // if the app navigates off scope. This is not a problem because we still
3452 // want to use the scope of the app associated with the window, not the
3453 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433454 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233455 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593456 browser->app_controller()->HasAppId()) {
3457 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3458 const web_app::AppRegistrar& registrar =
3459 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3460 if (registrar.IsLocallyInstalled(app_id))
3461 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433462 }
Mounir Lamouri6926107f2019-01-31 18:17:433463 }
3464#endif
3465
Ian Vollick6243dfe02018-03-08 01:08:533466 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113467 }
zqzhang93e959d12017-03-16 13:10:203468
rajendrant0521cee2019-07-29 06:09:263469 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3470 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003471
Scott Little878f7d6702018-05-31 22:09:063472 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3473 const char* param_name =
3474 web_prefs->data_saver_enabled
3475 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3476 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3477 "saver_enabled";
3478
3479 base::StringPairs pairs;
3480 base::SplitStringIntoKeyValuePairs(
3481 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3482 param_name),
3483 ':', ',', &pairs);
3484
3485 for (const auto& pair : pairs) {
3486 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3487 net::GetEffectiveConnectionTypeForName(pair.first);
3488 int value = 0;
3489 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223490 web_prefs->lazy_frame_loading_distance_thresholds_px[static_cast<
3491 EffectiveConnectionType>(effective_connection_type.value())] =
3492 value;
Scott Little878f7d6702018-05-31 22:09:063493 }
3494 }
3495 }
3496
rajendrantd8026342018-08-29 08:08:393497 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3498 const char* param_name =
3499 web_prefs->data_saver_enabled
3500 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3501 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3502 "saver_enabled";
3503
3504 base::StringPairs pairs;
3505 base::SplitStringIntoKeyValuePairs(
3506 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3507 param_name),
3508 ':', ',', &pairs);
3509
3510 for (const auto& pair : pairs) {
3511 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3512 net::GetEffectiveConnectionTypeForName(pair.first);
3513 int value = 0;
3514 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223515 web_prefs->lazy_image_loading_distance_thresholds_px[static_cast<
3516 EffectiveConnectionType>(effective_connection_type.value())] =
3517 value;
rajendrantd8026342018-08-29 08:08:393518 }
3519 }
rajendrant3daeae292019-09-20 07:57:543520
3521 pairs.clear();
3522 base::SplitStringIntoKeyValuePairs(
3523 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3524 "lazy_image_first_k_fully_load"),
3525 ':', ',', &pairs);
3526
3527 for (const auto& pair : pairs) {
3528 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3529 net::GetEffectiveConnectionTypeForName(pair.first);
3530 int value = 0;
3531 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
Gyuyoung Kimd6d4f992020-11-20 14:13:223532 web_prefs->lazy_image_first_k_fully_load[static_cast<
3533 EffectiveConnectionType>(effective_connection_type.value())] =
rajendrant3daeae292019-09-20 07:57:543534 value;
3535 }
3536 }
rajendrantd8026342018-08-29 08:08:393537 }
3538
Tarun Bansald10f17a02018-09-13 00:23:173539 if (base::FeatureList::IsEnabled(
3540 features::kNetworkQualityEstimatorWebHoldback)) {
3541 std::string effective_connection_type_param =
3542 base::GetFieldTrialParamValueByFeature(
3543 features::kNetworkQualityEstimatorWebHoldback,
3544 "web_effective_connection_type_override");
3545
3546 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3547 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3548 DCHECK(effective_connection_type_param.empty() ||
3549 effective_connection_type);
3550 if (effective_connection_type) {
3551 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3552 effective_connection_type.value());
3553 web_prefs->network_quality_estimator_web_holdback =
Gyuyoung Kimd6d4f992020-11-20 14:13:223554 static_cast<EffectiveConnectionType>(
3555 effective_connection_type.value());
Tarun Bansald10f17a02018-09-13 00:23:173556 }
3557 }
3558
François Beaufort4f8107d2018-03-05 12:12:103559#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563560 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593561 // If autoplay is allowed by policy then force the no user gesture required
3562 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103563 web_prefs->autoplay_policy =
Gyuyoung Kimf6c02a262020-10-13 01:36:133564 blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553565 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593566 web_prefs->autoplay_policy ==
Gyuyoung Kimf6c02a262020-10-13 01:36:133567 blink::mojom::AutoplayPolicy::
Gyuyoung Kim1ac4ca782020-09-11 03:32:513568 kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553569 // If the autoplay disable settings feature is enabled and the autoplay
3570 // policy is set to using the unified policy then set the default autoplay
3571 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593572 web_prefs->autoplay_policy =
3573 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
Gyuyoung Kimf6c02a262020-10-13 01:36:133574 ? blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired
3575 : blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103576 }
3577#endif // !defined(OS_ANDROID)
3578
Prashant Nevase788dcee2020-10-30 19:00:173579 switch (GetWebTheme()->GetPreferredContrast()) {
Alison Maher3b11e942020-10-27 17:17:503580 case ui::NativeTheme::PreferredContrast::kNoPreference:
3581 web_prefs->preferred_contrast =
3582 blink::mojom::PreferredContrast::kNoPreference;
3583 break;
3584 case ui::NativeTheme::PreferredContrast::kMore:
3585 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kMore;
3586 break;
3587 case ui::NativeTheme::PreferredContrast::kLess:
3588 web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kLess;
3589 break;
3590 }
3591
Prashant Nevase788dcee2020-10-30 19:00:173592 UpdatePreferredColorScheme(web_prefs, rvh->GetSiteInstance()->GetSiteURL(),
3593 contents, GetWebTheme());
Elly Fong-Jonesf92897392019-01-24 16:05:493594
Rakina Zata Amni347b70902020-07-22 10:49:043595 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Alison Maher7f366dc62020-03-03 19:46:003596
Abigail Kleina81f2e22020-05-04 14:32:413597 base::Optional<ui::CaptionStyle> style =
3598 captions::GetCaptionStyleFromUserSettings(prefs,
3599 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213600 if (style) {
3601 web_prefs->text_track_background_color = style->background_color;
3602 web_prefs->text_track_text_color = style->text_color;
3603 web_prefs->text_track_text_size = style->text_size;
3604 web_prefs->text_track_text_shadow = style->text_shadow;
3605 web_prefs->text_track_font_family = style->font_family;
3606 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563607 web_prefs->text_track_window_color = style->window_color;
3608 web_prefs->text_track_window_padding = style->window_padding;
3609 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213610 }
Elly Fong-Jonesf92897392019-01-24 16:05:493611
[email protected]a48ab7112014-08-01 16:48:033612 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503613 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363614}
3615
Rakina Zata Amni347b70902020-07-22 10:49:043616bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation(
3617 WebContents* web_contents,
3618 WebPreferences* prefs) {
Prashant Nevase788dcee2020-10-30 19:00:173619 return UpdatePreferredColorScheme(prefs, web_contents->GetLastCommittedURL(),
3620 web_contents, GetWebTheme());
Rakina Zata Amni347b70902020-07-22 10:49:043621}
3622
[email protected]b8148ac2011-07-13 22:03:253623void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3624 BrowserURLHandler* handler) {
Nicolas Ouellet-Payeur5e6d2102020-08-21 16:28:413625 // The group policy NTP URL handler must be registered before the other NTP
3626 // URL handlers below. Also register it before the "parts" handlers, so the
3627 // NTP policy takes precedence over extensions that override the NTP.
3628 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3629 BrowserURLHandler::null_handler());
3630
[email protected]a48ab7112014-08-01 16:48:033631 for (size_t i = 0; i < extra_parts_.size(); ++i)
3632 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253633
Lukasz Anforowicz7b078792020-10-20 17:04:313634 // Handler to rewrite chrome://about and chrome://sync URLs.
3635 handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
[email protected]b8148ac2011-07-13 22:03:253636 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033637
zpengdb4a58e2017-01-10 17:40:323638#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033639 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353640 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033641 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453642#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033643 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133644 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3645 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453646#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033647
[email protected]b8148ac2011-07-13 22:03:253648 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313649 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3650 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253651}
3652
[email protected]650b2d52013-02-10 03:41:453653base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493654 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323655}
3656
[email protected]c9b6eb62011-10-18 20:49:393657std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3658 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3659}
3660
Dominik Röttsches47347832019-03-12 17:45:013661base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3662 base::FilePath user_data_dir;
3663 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3664 DCHECK(!user_data_dir.empty());
3665 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3666}
3667
jmadill57b52d42015-08-21 18:16:133668base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3669 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523670 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133671 DCHECK(!user_data_dir.empty());
3672 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3673}
3674
Khushal7ca0b782018-07-20 05:53:273675base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3676 base::FilePath user_data_dir;
3677 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3678 DCHECK(!user_data_dir.empty());
3679 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3680}
3681
[email protected]b7631cc2012-09-15 05:08:383682void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3683 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163684#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553685 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543686#endif
[email protected]b7631cc2012-09-15 05:08:383687}
3688
[email protected]0c7193742012-11-07 19:05:033689content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443690ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173691#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553692 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033693 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443694 nacl::NaClProcessHost* host =
3695 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3696 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033697 // Found the plugin.
3698 return host->browser_ppapi_host();
3699 }
3700 ++iter;
3701 }
[email protected]a56f8322014-07-16 21:13:553702#endif
Aran Gilmanf010bdd2019-08-28 19:55:443703 return nullptr;
[email protected]0c7193742012-11-07 19:05:033704}
3705
[email protected]38cd8f7f2012-06-15 22:06:073706bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583707 content::BrowserContext* browser_context,
3708 const GURL& url,
[email protected]dda54822013-06-15 01:26:393709 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123710 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163711#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553712 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193713 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403714#else
[email protected]a658d452012-03-02 12:45:293715 return false;
[email protected]93f72062013-05-29 20:29:403716#endif
[email protected]e461da2f2012-02-16 19:06:403717}
3718
adrian.belgund54465ba2016-05-18 10:03:583719bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3720 content::BrowserContext* browser_context,
3721 const GURL& url) {
brettw4b461082016-11-19 18:55:163722#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583723 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3724 browser_context, url);
3725#else
3726 return false;
3727#endif
3728}
3729
adrian.belgun5b341c72016-06-22 22:24:083730std::unique_ptr<content::VpnServiceProxy>
3731ChromeContentBrowserClient::GetVpnServiceProxy(
3732 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173733#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083734 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3735 browser_context);
3736#else
3737 return nullptr;
3738#endif
3739}
3740
Brett Wilson804e83c2017-08-18 22:57:333741std::unique_ptr<ui::SelectFilePolicy>
3742ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3743 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433744}
3745
[email protected]7d9424702013-04-14 13:14:163746void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3747 std::vector<std::string>* additional_allowed_schemes) {
3748 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3749 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483750 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293751 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033752 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3753 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3754 additional_allowed_schemes);
3755 }
[email protected]7d9424702013-04-14 13:14:163756}
3757
Ayu Ishiifbb1fad2020-06-22 20:15:073758void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist(
falkenad185092016-06-16 06:10:023759 std::set<std::string>* schemes) {
Ayu Ishiifbb1fad2020-06-22 20:15:073760 *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023761}
3762
[email protected]c79859b82014-03-20 22:43:553763void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313764 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033765 for (size_t i = 0; i < extra_parts_.size(); ++i)
3766 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553767}
3768
[email protected]f19bbf62013-07-09 01:22:323769void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313770 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533771 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003772 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3773 additional_backends) {
Yuta Hijikata235fc62b2020-12-08 03:48:323774#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]cd501a72014-08-22 19:58:313775 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313776 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313777 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093778 auto backend = std::make_unique<chromeos::FileSystemBackend>(
David Black8f8c1eb2020-12-09 04:02:233779 Profile::FromBrowserContext(browser_context),
Jeremy Romanec48d7a2018-03-01 17:35:093780 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3781 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473782 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093783 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3784 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053785 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3786 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343787 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3788 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473789 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323790 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313791 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003792 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313793#endif
[email protected]445b7db2013-08-02 04:58:273794
[email protected]a48ab7112014-08-01 16:48:033795 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3796 extra_parts_[i]->GetAdditionalFileSystemBackends(
3797 browser_context, storage_partition_path, additional_backends);
3798 }
[email protected]02250952013-04-24 23:52:533799}
3800
Avi Drissman2e458df2020-07-29 16:24:313801#if defined(OS_POSIX) && !defined(OS_MAC)
[email protected]a1733df2012-06-22 11:24:183802void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173803 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383804 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203805 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123806#if defined(OS_ANDROID)
3807 base::MemoryMappedFile::Region region;
3808 int fd = ui::GetMainAndroidPackFd(&region);
3809 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003810
Samuel Huang31eadf082019-08-28 19:50:433811 // For Android: Native resources for DFMs should only be used by the browser
3812 // process. Their file descriptors and memory mapped file regions are not
3813 // passed to child processes.
3814
jcivellie6f550742017-01-06 19:29:123815 fd = ui::GetCommonResourcesPackFd(&region);
3816 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393817
jcivellie6f550742017-01-06 19:29:123818 fd = ui::GetLocalePackFd(&region);
3819 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383820
zpeng368afac82017-07-17 18:47:453821 // Optional secondary locale .pak file.
3822 fd = ui::GetSecondaryLocalePackFd(&region);
3823 if (fd != -1) {
3824 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3825 }
3826
[email protected]09560f7f2014-06-10 18:40:283827 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523828 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283829 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023830#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383831 int crash_signal_fd = GetCrashSignalFD(command_line);
3832 if (crash_signal_fd >= 0) {
Ken Rockot69fbb962020-09-21 22:22:033833 mappings->Share(kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383834 }
jcivellie6f550742017-01-06 19:29:123835}
Avi Drissman2e458df2020-07-29 16:24:313836#endif // defined(OS_POSIX) && !defined(OS_MAC)
[email protected]b80f68432011-05-02 17:22:303837
[email protected]4a65826d2011-08-25 16:04:013838#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033839base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Robert Sesek7d0b49b2020-07-08 18:31:273840 sandbox::policy::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033841 // TODO(wfh): Add support for more process types here. crbug.com/499523
3842 switch (sandbox_type) {
Robert Sesek7d0b49b2020-07-08 18:31:273843 case sandbox::policy::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363844 return base::string16(install_static::GetSandboxSidPrefix()) +
3845 L"129201922";
Robert Sesek7d0b49b2020-07-08 18:31:273846 case sandbox::policy::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033847 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273848 case sandbox::policy::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033849 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273850 case sandbox::policy::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363851 return base::string16(install_static::GetSandboxSidPrefix()) +
3852 L"129201925";
Robert Sesek7d0b49b2020-07-08 18:31:273853 case sandbox::policy::SandboxType::kNoSandbox:
3854 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3855 case sandbox::policy::SandboxType::kXrCompositing:
3856 case sandbox::policy::SandboxType::kNetwork:
3857 case sandbox::policy::SandboxType::kCdm:
3858 case sandbox::policy::SandboxType::kPrintCompositor:
3859 case sandbox::policy::SandboxType::kAudio:
3860 case sandbox::policy::SandboxType::kSpeechRecognition:
3861 case sandbox::policy::SandboxType::kProxyResolver:
3862 case sandbox::policy::SandboxType::kPdfConversion:
3863 case sandbox::policy::SandboxType::kSharingService:
3864 case sandbox::policy::SandboxType::kVideoCapture:
3865 case sandbox::policy::SandboxType::kIconReader:
Frank Li49bb6912020-09-30 18:05:523866 case sandbox::policy::SandboxType::kMediaFoundationCdm:
Alex Gough9ab468a6c32019-12-10 19:10:223867 // Should never reach here.
3868 CHECK(0);
wfh182da09c2015-06-24 19:23:033869 return base::string16();
wfh182da09c2015-06-24 19:23:033870 }
wfh182da09c2015-06-24 19:23:033871}
3872
Will Harris956e0ca2019-08-23 20:47:393873bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3874 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503875// Does not work under component build because all the component DLLs would need
3876// to be manually added and maintained. Does not work under ASAN build because
3877// ASAN has not yet fully initialized its instrumentation by the time the CIG
3878// intercepts run.
3879#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393880 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3881 return true;
Will Harrisc196ed942019-08-03 03:45:303882 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3883 return true;
3884
3885 // Only enable signing mitigation if launching from chrome.exe.
3886 base::FilePath exe_path;
3887 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3888 return true;
3889 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3890 return true;
3891
3892 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3893 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093894 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303895 if (result != sandbox::SBOX_ALL_OK)
3896 return false;
3897
Nico Weberc36b0152020-04-18 03:12:463898 // Allow loading Chrome's DLLs.
3899 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303900 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3901 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3902 GetModulePath(dll).value().c_str());
3903 if (result != sandbox::SBOX_ALL_OK)
3904 return false;
3905 }
Will Harris1b9b4152019-08-21 22:33:503906#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303907
3908 return true;
[email protected]34f48682013-03-20 00:30:183909}
Will Harris956e0ca2019-08-23 20:47:393910
3911bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3912 PrefService* local_state = g_browser_process->local_state();
3913 if (local_state &&
3914 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3915 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3916 return false;
3917 return true;
3918}
3919
wfhc91e9672016-01-27 00:14:203920#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013921
Lingqi Chi775e60752020-12-14 06:31:163922void ChromeContentBrowserClient::RegisterMojoBinderPoliciesForPrerendering(
3923 content::MojoBinderPolicyMap& policy_map) {
3924 // Changes to `policy_map` should be made in
3925 // RegisterChromeMojoBinderPoliciesForPrerendering() which requires security
3926 // review.
3927 RegisterChromeMojoBinderPoliciesForPrerendering(policy_map);
3928}
3929
peterbbcccc12015-02-11 22:23:333930void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373931 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333932 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293933 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083934 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373935
3936 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083937
zpengdb4a58e2017-01-10 17:40:323938#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223939 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293940 std::move(callback));
jam1c5a91492016-02-24 20:47:533941#else
cm.sanchi2522bc92017-12-04 08:04:133942 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3943 params.url, params.transition);
3944 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083945
3946 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293947 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333948#endif
mlamourieb40d552015-02-05 00:57:083949}
3950
zhaobinf3704f82017-01-12 07:19:363951content::ControllerPresentationServiceDelegate*
3952ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3953 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463954 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093955 return media_router::PresentationServiceDelegateImpl::
3956 GetOrCreateForWebContents(web_contents);
3957 }
haibinlu9e605a92015-06-06 03:45:093958 return nullptr;
3959}
3960
zhaobinf3704f82017-01-12 07:19:363961content::ReceiverPresentationServiceDelegate*
3962ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3963 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363964 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3965 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3966 // created for offscreen presentations. The WebContents must belong to
3967 // an incognito profile.
3968 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3969 FromWebContents(web_contents)) {
3970 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3971 return impl;
3972 }
3973 }
zhaobinf3704f82017-01-12 07:19:363974 return nullptr;
3975}
3976
avid6d88b912017-01-13 00:16:003977std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473978ChromeContentBrowserClient::CreateThrottlesForNavigation(
3979 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003980 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273981
bmcquadeb4556552017-03-24 22:24:373982 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3983 // that may delay or cancel navigations, so only NavigationThrottles that
3984 // don't delay or cancel navigations (e.g. throttles that are only observing
3985 // callbacks without affecting navigation behavior) should be added before
3986 // MetricsNavigationThrottle.
3987 if (handle->IsInMainFrame()) {
3988 throttles.push_back(
3989 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3990 }
3991
Yuta Hijikata235fc62b2020-12-08 03:48:323992#if BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063993 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283994 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3995 &throttles);
Yuta Hijikata235fc62b2020-12-08 03:48:323996#endif // BUILDFLAG(IS_CHROMEOS_ASH)
yilkal240b4f22019-11-27 19:09:063997
mmenkedb2637ff2017-03-30 23:59:423998#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213999 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284000 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
4001 &throttles);
mmenkedb2637ff2017-03-30 23:59:424002#endif
4003
clamy40c9e142015-09-29 11:18:474004#if defined(OS_ANDROID)
4005 // TODO(davidben): This is insufficient to integrate with prerender properly.
4006 // https://crbug.com/370595
4007 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:574008 prerender::ChromePrerenderContentsDelegate::FromWebContents(
4009 handle->GetWebContents());
clamy40c9e142015-09-29 11:18:474010 if (!prerender_contents && handle->IsInMainFrame()) {
4011 throttles.push_back(
4012 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304013 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474014 }
Min Qin0ab0e162017-11-14 21:57:194015 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:044016
4017#if BUILDFLAG(DFMIFY_DEV_UI)
4018 // If the DevUI DFM is already installed, then this is a no-op, except for the
4019 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:284020 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
4021 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:044022#endif // BUILDFLAG(DFMIFY_DEV_UI)
4023
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574024#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474025 if (handle->IsInMainFrame()) {
4026 // Redirect some navigations to apps that have registered matching URL
4027 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:284028 MaybeAddThrottle(
4029 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
4030 &throttles);
clamy40c9e142015-09-29 11:18:474031 }
4032#endif
clamy49678312015-10-22 21:59:004033
Yuta Hijikata235fc62b2020-12-08 03:48:324034#if BUILDFLAG(IS_CHROMEOS_ASH)
clamy49678312015-10-22 21:59:004035 // Check if we need to add merge session throttle. This throttle will postpone
4036 // loading of main frames.
4037 if (handle->IsInMainFrame()) {
4038 // Add interstitial page while merge session process (cookie reconstruction
4039 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4040 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024041 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4042 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004043 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4044 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4045 }
Maggie Caia2f03f52019-04-02 02:13:284046 }
4047#endif
djacobo21e56e02016-07-02 01:14:314048
Maggie Caia2f03f52019-04-02 02:13:284049#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:104050 auto url_to_apps_throttle =
Yuta Hijikata235fc62b2020-12-08 03:48:324051#if BUILDFLAG(IS_CHROMEOS_ASH)
Maggie Caic08b7d42020-05-05 03:51:104052 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
4053 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
4054 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284055#else
Maggie Caic08b7d42020-05-05 03:51:104056 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:284057#endif
Maggie Caic08b7d42020-05-05 03:51:104058 if (url_to_apps_throttle)
4059 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004060#endif
4061
brettw00899e62016-11-12 02:10:174062#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004063 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094064 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514065
Chris Hamiltonab4722122020-05-13 18:01:284066 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
4067 ->GetUserScriptListener()
4068 ->CreateNavigationThrottle(handle),
4069 &throttles);
naskob9164c42016-06-07 01:21:354070#endif
4071
bauerb8f9c37742017-03-30 15:04:124072#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:214073 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284074 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
4075 &throttles);
bauerb8f9c37742017-03-30 15:04:124076#endif
4077
csharrisone985ebc2017-04-04 17:05:034078 content::WebContents* web_contents = handle->GetWebContents();
Colin Blundell0ec5d642020-10-06 17:29:524079 if (auto* throttle_manager =
4080 subresource_filter::ContentSubresourceFilterThrottleManager::
4081 FromWebContents(web_contents)) {
4082 throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles);
csharrisone985ebc2017-04-04 17:05:034083 }
4084
zhenw6edd49c2017-07-12 05:49:454085#if !defined(OS_ANDROID)
4086 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4087 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:284088 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
4089 MaybeCreateThrottleFor(handle),
4090 &throttles);
zhenw6edd49c2017-07-12 05:49:454091#endif
4092
Bettinafd0c1102020-08-06 00:23:434093#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Chris Hamiltonab4722122020-05-13 18:01:284094 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
4095 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:094096#endif
4097
Lukasz Anforowicz7724d092019-10-03 23:50:214098 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284099 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
4100 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:274101
Chris Hamiltonab4722122020-05-13 18:01:284102 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
4103 &throttles);
Amber Won6b5edc752017-08-17 19:23:544104
Chris Hamiltonab4722122020-05-13 18:01:284105 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:514106
Jonathan Mengedoht42a19bb2020-07-28 14:10:164107 MaybeAddThrottle(
4108 WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
4109 &throttles);
4110
Yann Dago3256b872021-01-13 18:48:034111 policy::PolicyService* policy_service = nullptr;
4112 Profile* profile = Profile::FromBrowserContext(
4113 handle->GetWebContents()->GetBrowserContext());
4114 if (profile && profile->GetProfilePolicyConnector())
4115 policy_service = profile->GetProfilePolicyConnector()->policy_service();
4116
Aaron Colwellf94fd97a2020-07-21 19:37:084117 throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
Yann Dago3256b872021-01-13 18:48:034118 handle, handle->GetWebContents()->GetBrowserContext(), policy_service));
Doug Turner9dcaf5962017-12-21 04:38:534119
Colin Blundelleaa7377bf2020-01-22 08:49:104120 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
4121 // the relevant extension API whenever an SSL interstitial is shown.
4122 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
4123 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:284124 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4125 handle,
4126 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Mustafa Emre Acer06028d792021-01-05 19:48:514127 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp),
4128 base::BindOnce(
4129 &TypedNavigationUpgradeThrottle::
4130 ShouldIgnoreInterstitialBecauseNavigationDefaultedToHttps)));
Lucas Garron94b16052017-11-11 01:58:124131
Emily Starkd6896cd32019-08-21 04:55:544132 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4133
Mustafa Emre Acer06028d792021-01-05 19:48:514134 if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) {
4135 MaybeAddThrottle(
4136 TypedNavigationUpgradeThrottle::MaybeCreateThrottleFor(handle),
4137 &throttles);
4138 }
4139
Dmitry Gozman57b92ce2017-12-28 22:24:544140#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284141 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4142 &throttles);
4143
4144 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4145 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544146#endif
4147
Carlos IL800e3502020-04-30 16:35:594148 throttles.push_back(
4149 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034150
Mustafa Emre Acer97be4752020-05-13 01:24:434151 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4152 throttles.push_back(
4153 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4154 handle));
4155 }
4156
Yuta Hijikata235fc62b2020-12-08 03:48:324157// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
4158// of lacros-chrome is complete.
Avi Drissman2e458df2020-07-29 16:24:314159#if defined(OS_WIN) || defined(OS_MAC) || \
Yuta Hijikata235fc62b2020-12-08 03:48:324160 (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
Chris Hamiltonab4722122020-05-13 18:01:284161 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4162 MaybeCreateThrottleFor(handle),
4163 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134164#endif
4165
Yuta Hijikata235fc62b2020-12-08 03:48:324166#if BUILDFLAG(IS_CHROMEOS_ASH)
Anatoliy Potapchuk762c40d2020-05-11 15:10:374167 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284168 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
4169 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374170#endif
4171
Chris Hamiltonab4722122020-05-13 18:01:284172 auto* performance_manager_registry =
4173 performance_manager::PerformanceManagerRegistry::GetInstance();
4174 if (performance_manager_registry) {
4175 MaybeAddThrottles(
4176 performance_manager_registry->CreateThrottlesForNavigation(handle),
4177 &throttles);
4178 }
4179
Carlos IL06e6c8c2020-07-28 00:25:194180 if (profile && profile->GetPrefs()) {
4181 MaybeAddThrottle(
4182 security_interstitials::InsecureFormNavigationThrottle::
4183 MaybeCreateNavigationThrottle(
4184 handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
4185 profile->GetPrefs()),
4186 &throttles);
4187 }
Carlos IL1a5edec2020-06-12 17:56:574188
Ken Rockot4408a0f2020-07-27 19:40:544189 if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) {
4190 MaybeAddThrottle(
4191 error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle),
4192 &throttles);
4193 }
4194
Liquan (Max) Gud648f452020-12-18 05:28:444195#if !defined(OS_ANDROID)
4196 MaybeAddThrottle(
4197 payments::PaymentHandlerNavigationThrottle::MaybeCreateThrottleFor(
4198 handle),
4199 &throttles);
4200#endif
4201
dchenge73d8520c2015-12-27 01:19:094202 return throttles;
clamy40c9e142015-09-29 11:18:474203}
4204
clamy1e5574e2016-09-29 16:48:444205std::unique_ptr<content::NavigationUIData>
4206ChromeContentBrowserClient::GetNavigationUIData(
4207 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094208 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444209}
4210
Xiaohan Wanga4e41842018-06-26 18:45:104211void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4212 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104213 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124214 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Jeffrey Kardatzke614424232020-12-12 00:54:064215#if (defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)) && \
4216 BUILDFLAG(ENABLE_LIBRARY_CDMS) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104217 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334218 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104219 }
4220#endif
4221}
4222
[email protected]487974a2014-06-13 16:49:014223content::DevToolsManagerDelegate*
4224ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354225#if defined(OS_ANDROID)
4226 return new DevToolsManagerDelegateAndroid();
4227#else
[email protected]487974a2014-06-13 16:49:014228 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354229#endif
[email protected]487974a2014-06-13 16:49:014230}
4231
Rayan Kanso411e84e2019-02-13 15:27:404232void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4233 content::BrowserContext* browser_context,
4234 int service,
4235 base::Time expiration_time) {
4236 Profile* profile = Profile::FromBrowserContext(browser_context);
4237 DCHECK(profile);
4238
4239 auto* pref_service = profile->GetPrefs();
4240 DCHECK(pref_service);
4241
4242 DictionaryPrefUpdate pref_update(
4243 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4244 base::DictionaryValue* exp_dict = pref_update.Get();
4245
4246 // Convert |expiration_time| to minutes since that is the most granular
4247 // option that returns an int. base::Value does not accept int64.
4248 int expiration_time_minutes =
4249 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4250 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4251}
4252
4253base::flat_map<int, base::Time>
4254ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4255 content::BrowserContext* browser_context) {
4256 Profile* profile = Profile::FromBrowserContext(browser_context);
4257 DCHECK(profile);
4258
4259 auto* pref_service = profile->GetPrefs();
4260 DCHECK(pref_service);
4261
4262 auto* expiration_dict = pref_service->GetDictionary(
4263 prefs::kDevToolsBackgroundServicesExpirationDict);
4264 DCHECK(expiration_dict);
4265
4266 base::flat_map<int, base::Time> expiration_times;
4267 for (const auto& it : *expiration_dict) {
4268 // key.
4269 int service = 0;
4270 bool did_convert = base::StringToInt(it.first, &service);
4271 DCHECK(did_convert);
4272
4273 // value.
4274 DCHECK(it.second->is_int());
4275 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4276 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4277
4278 expiration_times[service] = expiration_time;
4279 }
4280
4281 return expiration_times;
4282}
4283
oysteinec563c582015-02-13 19:19:524284content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524285 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524286}
4287
[email protected]a6868c22013-10-09 02:50:294288bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4289 content::BrowserContext* browser_context,
4290 const GURL& url) {
brettw4b461082016-11-19 18:55:164291#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554292 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194293 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294294#else
4295 return false;
4296#endif
4297}
4298
[email protected]aec5ed52014-06-20 07:51:424299bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4300 content::BrowserContext* browser_context,
4301 const GURL& url) {
brettw4b461082016-11-19 18:55:164302#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554303 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194304 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064305#else
4306 return false;
4307#endif
4308}
4309
mlamourif8c23a2002015-01-27 13:10:104310void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014311 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434312 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524313 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104314
4315 WebContents* web_contents =
4316 WebContents::FromRenderFrameHost(render_frame_host);
4317 DCHECK(web_contents);
4318
mlamourif8c23a2002015-01-27 13:10:104319 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374320 prerender::PrerenderManagerFactory::GetForBrowserContext(
4321 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104322 if (prerender_manager &&
Hiroki Nakagawaee49bcd2020-09-09 23:09:084323 prerender_manager->IsWebContentsPrerendering(web_contents)) {
Collin Baker98457b52019-11-06 21:34:294324 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104325 }
4326}
4327
Robert Sesek466e43e2019-08-19 22:02:024328void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4329 base::FilePath user_data_dir;
4330 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4331 DCHECK(!user_data_dir.empty());
4332 network_contexts_parent_directory_.push_back(user_data_dir);
4333
4334 base::FilePath cache_dir;
4335 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4336 DCHECK(!cache_dir.empty());
4337 // On some platforms, the cache is a child of the user_data_dir so only
4338 // return the one path.
4339 if (!user_data_dir.IsParent(cache_dir))
4340 network_contexts_parent_directory_.push_back(cache_dir);
4341
4342 // If the cache location has been overridden by a switch or preference,
4343 // include that as well.
4344 if (auto* local_state = g_browser_process->local_state()) {
4345 base::FilePath pref_cache_dir =
4346 local_state->GetFilePath(prefs::kDiskCacheDir);
4347 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4348 network_contexts_parent_directory_.push_back(pref_cache_dir);
4349 }
4350}
4351
[email protected]30335fdf02014-02-26 19:51:274352void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174353 base::CommandLine* to_command_line,
4354 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544355 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274356#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544357 const version_info::Channel kMaxDisableEncryptionChannel =
4358 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274359#else
sdefresne6e883e42015-07-30 08:05:544360 const version_info::Channel kMaxDisableEncryptionChannel =
4361 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274362#endif
4363 if (channel <= kMaxDisableEncryptionChannel) {
4364 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444365 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274366 };
Avi Drissmand251e912018-12-26 15:46:374367 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4368 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274369 }
4370}
bashi933629552016-10-13 23:32:404371
miu54dca6c2016-11-17 10:59:384372#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4373void ChromeContentBrowserClient::CreateMediaRemoter(
4374 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504375 mojo::PendingRemote<media::mojom::RemotingSource> source,
4376 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384377 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504378 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384379}
4380#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464381
Michael Giuffrida6802ffe2017-09-29 03:40:254382base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4383 const base::CommandLine& command_line) {
4384 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164385}
4386
John Abd-El-Malek8efa11f2019-01-06 00:51:534387namespace {
4388// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024389class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534390 public:
4391 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174392 ProtocolHandlerRegistry* protocol_handler_registry)
Matt Falkenhagen7811fd42020-06-24 22:42:414393 : protocol_handler_registry_(protocol_handler_registry) {
4394 DCHECK(protocol_handler_registry);
4395 }
John Abd-El-Malek8efa11f2019-01-06 00:51:534396 ~ProtocolHandlerThrottle() override = default;
4397
4398 void WillStartRequest(network::ResourceRequest* request,
4399 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294400 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534401 }
4402
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584403 void WillRedirectRequest(
4404 net::RedirectInfo* redirect_info,
4405 const network::mojom::URLResponseHead& response_head,
4406 bool* defer,
4407 std::vector<std::string>* to_be_removed_headers,
4408 net::HttpRequestHeaders* modified_headers,
4409 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294410 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534411 }
4412
4413 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294414 void TranslateUrl(GURL* url) {
4415 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4416 return;
4417 GURL translated_url = protocol_handler_registry_->Translate(*url);
4418 if (!translated_url.is_empty())
4419 *url = translated_url;
4420 }
4421
Clark DuValla411bda2019-08-02 03:09:174422 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534423};
4424} // namespace
4425
Minggang Wangf6840ecf2019-07-29 05:15:024426std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194427ChromeContentBrowserClient::CreateURLLoaderThrottles(
4428 const network::ResourceRequest& request,
4429 content::BrowserContext* browser_context,
4430 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4431 content::NavigationUIData* navigation_ui_data,
4432 int frame_tree_node_id) {
4433 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4434
Minggang Wangf6840ecf2019-07-29 05:15:024435 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194436
Matt Falkenhagen7811fd42020-06-24 22:42:414437 DCHECK(browser_context);
Clark DuVallfffa41e2019-06-25 20:27:194438 Profile* profile = Profile::FromBrowserContext(browser_context);
Matt Falkenhagen7811fd42020-06-24 22:42:414439 DCHECK(profile);
Clark DuVallfffa41e2019-06-25 20:27:194440
4441 ChromeNavigationUIData* chrome_navigation_ui_data =
4442 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4443
Bettinafd0c1102020-08-06 00:23:434444#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Clark DuVall5497288d2019-07-17 00:17:564445 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4446 request.url, *profile->GetPrefs());
4447 if (!matches_enterprise_whitelist) {
Xinghui Luf45d7ef72020-06-09 02:16:384448#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494449 auto* connectors_service =
4450 enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
4451 browser_context);
4452 bool has_valid_dm_token =
4453 connectors_service &&
4454 connectors_service->GetDMTokenForRealTimeUrlCheck().has_value();
4455 bool is_enterprise_lookup_enabled =
Xinghui Lucf23c902020-06-10 17:38:254456 safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494457 profile->GetPrefs(), has_valid_dm_token, profile->IsOffTheRecord());
Xinghui Lucf23c902020-06-10 17:38:254458#else
Dominique Fauteux-Chapleau5fd6beb2021-01-13 18:46:494459 bool is_enterprise_lookup_enabled = false;
Xinghui Luf45d7ef72020-06-09 02:16:384460#endif
Xinghui Lucf23c902020-06-10 17:38:254461 bool is_consumer_lookup_enabled =
Xinghui Luf45d7ef72020-06-09 02:16:384462 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
4463 profile->GetPrefs(), profile->IsOffTheRecord(),
Xinghui Lucf23c902020-06-10 17:38:254464 g_browser_process->variations_service());
4465
4466 // |url_lookup_service| is used when real time url check is enabled.
4467 safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service =
4468 GetUrlLookupService(browser_context, is_enterprise_lookup_enabled,
4469 is_consumer_lookup_enabled);
Clark DuVall5497288d2019-07-17 00:17:564470 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4471 base::BindOnce(
4472 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534473 base::Unretained(this),
Xinghui Lucf23c902020-06-10 17:38:254474 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
4475 // Should check for enterprise when safe browsing is disabled.
4476 /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled),
Xinghui Lua142c102020-03-02 20:50:084477 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584478 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564479 }
Nico Weberbc5b06f2019-07-26 14:00:134480#endif
Clark DuVall5497288d2019-07-17 00:17:564481
dalykba7bbfc2019-12-18 19:59:214482#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4483 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014484 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4485 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214486#endif
4487
Clark DuVallfffa41e2019-06-25 20:27:194488 if (chrome_navigation_ui_data &&
Miyoung Shinf53c2e792020-06-19 03:20:254489 chrome_navigation_ui_data->prerender_mode() !=
4490 prerender::mojom::PrerenderMode::kNoPrerender) {
Clark DuVallfffa41e2019-06-25 20:27:194491 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
Clark DuVallfffa41e2019-06-25 20:27:194492 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234493 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194494 }
4495
John Abd-El-Malek4f380d92020-02-19 16:43:364496#if defined(OS_ANDROID)
4497 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234498 bool night_mode_enabled = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374499 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4500 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364501 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4502 if (web_contents) {
4503 auto* client_data_header_observer =
4504 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4505 web_contents);
4506 if (client_data_header_observer)
4507 client_data_header = client_data_header_observer->header();
Brandon Wylie21a88ac92020-05-15 02:49:234508
Brandon Wylief6bfdab2020-08-12 21:49:364509 auto* delegate =
4510 TabAndroid::FromWebContents(web_contents)
4511 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4512 web_contents->GetDelegate())
4513 : nullptr;
4514 if (delegate)
4515 night_mode_enabled = delegate->IsNightModeEnabled();
Brandon Wylie21a88ac92020-05-15 02:49:234516 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374517 }
John Abd-El-Malek4f380d92020-02-19 16:43:364518#endif
4519
Clark DuVallfffa41e2019-06-25 20:27:194520 chrome::mojom::DynamicParams dynamic_params = {
4521 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4522 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274523 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4524 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364525#if defined(OS_ANDROID)
Brandon Wylie21a88ac92020-05-15 02:49:234526 client_data_header, night_mode_enabled,
John Abd-El-Malek4f380d92020-02-19 16:43:364527#endif
Alex Clarke3ebd9772020-02-28 10:50:274528 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194529
Matt Falkenhagen7811fd42020-06-24 22:42:414530 {
4531 auto* factory =
4532 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context);
4533 // null in unit tests.
4534 if (factory)
4535 result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory));
4536 }
Clark DuVall8512cee62019-06-26 01:14:214537
Clark DuVall39c2cfc2019-06-25 21:49:284538#if BUILDFLAG(ENABLE_PLUGINS)
4539 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464540 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284541#endif
4542
Robbie McElrath127ad2b2019-07-22 22:38:114543 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404544 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584545 auto signin_throttle =
4546 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114547 if (signin_throttle)
4548 result.push_back(std::move(signin_throttle));
4549
Clark DuVallfffa41e2019-06-25 20:27:194550 return result;
4551}
4552
Ken Rockot6414c4d92017-11-08 19:58:324553void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464554 int frame_tree_node_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314555 ukm::SourceIdObj ukm_source_id,
Ken Rockot6414c4d92017-11-08 19:58:324556 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324557#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
John Abd-El-Malekea006302018-05-10 05:50:464558 content::WebContents* web_contents =
4559 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414560#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174561 factories->emplace(
Ken Rockot6414c4d92017-11-08 19:58:324562 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574563 extensions::CreateExtensionNavigationURLLoaderFactory(
Maks Orlovich5408ddfc2020-07-28 23:07:354564 web_contents->GetBrowserContext(), ukm_source_id,
John Abd-El-Malekea006302018-05-10 05:50:464565 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414566#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Yuta Hijikata235fc62b2020-12-08 03:48:324567#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414568 Profile* profile =
4569 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354570 factories->emplace(content::kExternalFileScheme,
4571 chromeos::ExternalFileURLLoaderFactory::Create(
4572 profile, content::ChildProcessHost::kInvalidUniqueID));
Yuta Hijikata235fc62b2020-12-08 03:48:324573#endif // BUILDFLAG(IS_CHROMEOS_ASH)
4574#endif // BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH)
Ken Rockot6414c4d92017-11-08 19:58:324575}
4576
Ting Shao2dc60582019-07-15 04:43:364577void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344578 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4579 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174580 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawa1efa31d2019-10-01 22:36:344581 DCHECK(browser_context);
4582 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174583
4584#if BUILDFLAG(ENABLE_EXTENSIONS)
Hiroki Nakagawa1efa31d2019-10-01 22:36:344585 factories->emplace(
4586 extensions::kExtensionScheme,
4587 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4588 browser_context));
4589#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4590}
4591
4592void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364593 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4594 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174595 NonNetworkURLLoaderFactoryMap* factories) {
Ting Shao2dc60582019-07-15 04:43:364596 DCHECK(browser_context);
4597 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174598
4599#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364600 factories->emplace(
4601 extensions::kExtensionScheme,
4602 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4603 browser_context));
4604#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364605}
4606
Jay Civelli2578ebe2018-06-05 18:44:314607namespace {
4608
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384609// The SpecialAccessFileURLLoaderFactory provided to the extension background
4610// pages. Checks with the ChildProcessSecurityPolicy to validate the file
4611// access.
4612class SpecialAccessFileURLLoaderFactory
4613 : public content::NonNetworkURLLoaderFactoryBase {
Jay Civelli2578ebe2018-06-05 18:44:314614 public:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384615 // Returns mojo::PendingRemote to a newly constructed
4616 // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
4617 // delete itself once there are no more receivers (including the receiver
4618 // associated with the returned mojo::PendingRemote and the receivers bound by
4619 // the Clone method).
4620 static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
4621 int child_id) {
4622 mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
4623
4624 // The SpecialAccessFileURLLoaderFactory will delete itself when there are
4625 // no more receivers - see the NonNetworkURLLoaderFactoryBase::OnDisconnect
4626 // method.
4627 new SpecialAccessFileURLLoaderFactory(
4628 child_id, pending_remote.InitWithNewPipeAndPassReceiver());
4629
4630 return pending_remote;
4631 }
Jay Civelli2578ebe2018-06-05 18:44:314632
4633 private:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384634 explicit SpecialAccessFileURLLoaderFactory(
4635 int child_id,
4636 mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
4637 : content::NonNetworkURLLoaderFactoryBase(std::move(factory_receiver)),
4638 child_id_(child_id) {}
4639
Jay Civelli2578ebe2018-06-05 18:44:314640 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274641 void CreateLoaderAndStart(
4642 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4643 int32_t routing_id,
4644 int32_t request_id,
4645 uint32_t options,
4646 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304647 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274648 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4649 override {
Jay Civelli2578ebe2018-06-05 18:44:314650 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4651 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304652 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4653 ->OnComplete(
4654 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314655 return;
4656 }
Yutaka Hiranodf83dca42020-01-07 06:24:554657 content::CreateFileURLLoaderBypassingSecurityChecks(
4658 request, std::move(loader), std::move(client),
4659 /*observer=*/nullptr,
4660 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314661 }
4662
Jay Civelli2578ebe2018-06-05 18:44:314663 int child_id_;
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384664 DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory);
Jay Civelli2578ebe2018-06-05 18:44:314665};
4666
Yuta Hijikata235fc62b2020-12-08 03:48:324667#if BUILDFLAG(IS_CHROMEOS_ASH)
Aya ElAttareb5fee12020-05-05 08:56:054668bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4669 PrefService* const local_state = g_browser_process->local_state();
4670 if (!local_state) // Sometimes it's not available in tests.
4671 return false;
4672
4673 const base::ListValue* disabled_system_features_pref =
4674 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4675 if (!disabled_system_features_pref)
4676 return false;
4677
4678 const auto disabled_system_features =
4679 disabled_system_features_pref->GetList();
4680 return base::Contains(disabled_system_features, base::Value(system_feature));
4681}
4682
4683bool IsSystemFeatureURLDisabled(const GURL& url) {
4684 if (!url.SchemeIs(content::kChromeUIScheme))
4685 return false;
4686
4687 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4688 // installation complete successfully.
4689 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4690 url.path() != "/pwa.html" &&
Anqing Zhaod99eda172020-11-30 13:49:494691 IsSystemFeatureDisabled(policy::SystemFeature::kOsSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054692 return true;
4693 }
4694
4695 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494696 IsSystemFeatureDisabled(policy::SystemFeature::kBrowserSettings)) {
Aya ElAttareb5fee12020-05-05 08:56:054697 return true;
4698 }
4699
Jesse Schettlerb7047f32020-09-18 14:50:404700 if (url.DomainIs(chromeos::kChromeUIScanningAppHost) &&
Anqing Zhaod99eda172020-11-30 13:49:494701 IsSystemFeatureDisabled(policy::SystemFeature::kScanning)) {
Jesse Schettlerb7047f32020-09-18 14:50:404702 return true;
4703 }
4704
Aya ElAttareb5fee12020-05-05 08:56:054705 return false;
4706}
4707#endif
Jay Civelli2578ebe2018-06-05 18:44:314708} // namespace
4709
Ken Rockot6414c4d92017-11-08 19:58:324710void ChromeContentBrowserClient::
4711 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464712 int render_process_id,
4713 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324714 NonNetworkURLLoaderFactoryMap* factories) {
Yuta Hijikata235fc62b2020-12-08 03:48:324715#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414716 content::RenderFrameHost* frame_host =
4717 RenderFrameHost::FromID(render_process_id, render_frame_id);
4718 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
Yuta Hijikata235fc62b2020-12-08 03:48:324719#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS)
Robbie McElrath6a45ea62018-12-05 06:53:414720
Yuta Hijikata235fc62b2020-12-08 03:48:324721#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414722 if (web_contents) {
4723 Profile* profile =
4724 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354725 factories->emplace(content::kExternalFileScheme,
4726 chromeos::ExternalFileURLLoaderFactory::Create(
4727 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414728 }
Yuta Hijikata235fc62b2020-12-08 03:48:324729#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath6a45ea62018-12-05 06:53:414730
Ken Rockot6414c4d92017-11-08 19:58:324731#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174732 factories->emplace(extensions::kExtensionScheme,
4733 extensions::CreateExtensionURLLoaderFactory(
4734 render_process_id, render_frame_id));
Chris Mumfordbae8a742018-03-01 23:02:234735
4736 // This logic should match
4737 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314738 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234739 return;
Jay Civellic9bbf72d2018-03-24 01:58:314740
4741 Profile* profile =
4742 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4743 InstantService* instant_service =
4744 InstantServiceFactory::GetForProfile(profile);
4745 // The test below matches what's done by ShouldServiceRequestIOThread in
4746 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464747 if (instant_service->IsInstantProcess(render_process_id)) {
Lukasz Anforowicz7f695532020-09-15 16:05:224748 factories->emplace(
Jay Civellic9bbf72d2018-03-24 01:58:314749 chrome::kChromeSearchScheme,
Lukasz Anforowicz7f695532020-09-15 16:05:224750 content::CreateWebUIURLLoaderFactory(
Jay Civellic9bbf72d2018-03-24 01:58:314751 frame_host, chrome::kChromeSearchScheme,
4752 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234753 }
Jay Civellic9bbf72d2018-03-24 01:58:314754
Chris Mumfordbae8a742018-03-01 23:02:234755 extensions::ChromeExtensionWebContentsObserver* web_observer =
4756 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4757 web_contents);
4758
Karan Bhatia91928572018-03-06 01:18:074759 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4760 // to the |web_contents|.
4761 if (!web_observer)
4762 return;
4763
Chris Mumfordbae8a742018-03-01 23:02:234764 const Extension* extension =
4765 web_observer->GetExtensionFromFrame(frame_host, false);
4766 if (!extension)
4767 return;
4768
Sam McNally7414eeb72018-09-03 04:05:304769 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234770 // Support for chrome:// scheme if appropriate.
4771 if ((extension->is_extension() || extension->is_platform_app()) &&
4772 Manifest::IsComponentLocation(extension->location())) {
4773 // Components of chrome that are implemented as extensions or platform apps
4774 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304775 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4776 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4777 }
4778 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4779 (extension->is_platform_app() &&
4780 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234781 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024782 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4783 // URLs. Hosted apps are not allowed because they are served via web servers
4784 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304785 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4786 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024787 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304788 }
4789 if (!allowed_webui_hosts.empty()) {
Lukasz Anforowicz7f695532020-09-15 16:05:224790 factories->emplace(content::kChromeUIScheme,
4791 content::CreateWebUIURLLoaderFactory(
4792 frame_host, content::kChromeUIScheme,
4793 std::move(allowed_webui_hosts)));
Chris Mumfordbae8a742018-03-01 23:02:234794 }
Jay Civelli2578ebe2018-06-05 18:44:314795
4796 // Extension with a background page get file access that gets approval from
4797 // ChildProcessSecurityPolicy.
4798 extensions::ExtensionHost* host =
4799 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4800 ->GetBackgroundHostForExtension(extension->id());
4801 if (host) {
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384802 factories->emplace(
Lukasz Anforowiczb7d8b542020-09-03 19:50:344803 url::kFileScheme,
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384804 SpecialAccessFileURLLoaderFactory::Create(render_process_id));
Jay Civelli2578ebe2018-06-05 18:44:314805 }
Chris Mumfordbae8a742018-03-01 23:02:234806#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324807}
4808
Ken Rockota0dfaca12018-02-15 07:26:254809bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214810 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254811 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384812 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444813 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264814 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004815 base::Optional<int64_t> navigation_id,
Yue Ru Sun03a6990a2020-10-24 18:04:314816 ukm::SourceIdObj ukm_source_id,
Dominic Farolino1be897a2019-07-20 08:11:424817 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184818 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4819 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334820 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084821 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334822 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014823 bool use_proxy = false;
4824
Ken Rockota0dfaca12018-02-15 07:26:254825#if BUILDFLAG(ENABLE_EXTENSIONS)
4826 auto* web_request_api =
4827 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214828 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254829
4830 // NOTE: Some unit test environments do not initialize
4831 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014832 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124833 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384834 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004835 browser_context, frame, render_process_id, type,
Maks Orlovichf334d642020-09-21 22:19:594836 std::move(navigation_id), ukm_source_id, factory_receiver,
4837 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124838 if (bypass_redirect_checks)
4839 *bypass_redirect_checks = use_proxy_for_web_request;
4840 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014841 }
Ken Rockota0dfaca12018-02-15 07:26:254842#endif
Reilly Grant24bf8332018-08-27 21:55:014843
Reilly Grantcc22e602018-09-07 15:25:204844 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444845 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4846 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014847
Hiroki Nakagawa483686a92020-10-29 04:31:454848 auto* prefetch_proxy_service = PrefetchProxyServiceFactory::GetForProfile(
4849 Profile::FromBrowserContext(browser_context));
Robert Ogden31b234712020-06-04 22:51:214850 // |frame| is null when |type| is service worker.
Hiroki Nakagawa483686a92020-10-29 04:31:454851 if (frame && prefetch_proxy_service) {
4852 use_proxy |= prefetch_proxy_service->MaybeProxyURLLoaderFactory(
Robert Ogden8c53bc52020-06-19 21:24:184853 frame, render_process_id, type, factory_receiver);
Robert Ogden31b234712020-06-04 22:51:214854 }
4855
dalyk0018c16f2020-01-08 20:20:084856#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4857 if (disable_secure_dns) {
4858 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4859 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014860 web_contents &&
4861 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4862 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084863 ->is_captive_portal_window();
4864 }
4865#endif
4866
Reilly Grant24bf8332018-08-27 21:55:014867 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254868}
4869
Jian Lide7b43792018-06-01 23:22:134870std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4871ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4872 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144873 int frame_tree_node_id,
4874 const scoped_refptr<network::SharedURLLoaderFactory>&
4875 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134876 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4877 interceptors;
4878#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234879 interceptors.push_back(
4880 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4881 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134882#endif
Ryan Sturmaf523742019-01-16 00:15:454883
Robert Ogden6946ad42020-01-13 18:01:304884 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
Hiroki Nakagawa483686a92020-10-29 04:31:454885 interceptors.push_back(std::make_unique<PrefetchProxyURLLoaderInterceptor>(
4886 frame_tree_node_id));
Robert Ogden6946ad42020-01-13 18:01:304887 }
4888
Ryan Sturm8670b572020-10-21 18:45:304889 if (SearchPrefetchServiceIsEnabled()) {
4890 interceptors.push_back(std::make_unique<SearchPrefetchURLLoaderInterceptor>(
4891 frame_tree_node_id));
4892 }
4893
Jian Lide7b43792018-06-01 23:22:134894 return interceptors;
4895}
4896
Ryan Sturm6b2f6392020-12-09 21:46:004897content::ContentBrowserClient::URLLoaderRequestHandler
4898ChromeContentBrowserClient::
4899 CreateURLLoaderHandlerForServiceWorkerNavigationPreload(
4900 int frame_tree_node_id,
4901 const network::ResourceRequest& resource_request) {
4902 content::ContentBrowserClient::URLLoaderRequestHandler callback;
4903
4904 // If search prefetch is disabled, nothing needs to be handled.
4905 if (!SearchPrefetchServiceIsEnabled()) {
4906 return callback;
4907 }
4908
4909 std::unique_ptr<SearchPrefetchURLLoader> loader =
4910 SearchPrefetchURLLoaderInterceptor::MaybeCreateLoaderForRequest(
4911 resource_request, frame_tree_node_id);
4912 if (!loader) {
4913 return callback;
4914 }
4915
4916 auto* raw_loader = loader.get();
4917
4918 // Hand ownership of the loader to the callback, when it runs, mojo will
4919 // manage it. If the callback is deleted, the loader will be deleted.
4920 callback = raw_loader->ServingResponseHandler(std::move(loader));
4921 return callback;
4922}
4923
Yutaka Hirano8e0b4d432019-07-04 07:12:384924bool ChromeContentBrowserClient::WillInterceptWebSocket(
4925 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334926#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384927 if (!frame) {
4928 return false;
4929 }
4930 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334931 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4932 frame->GetProcess()->GetBrowserContext());
4933
4934 // NOTE: Some unit test environments do not initialize
4935 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4936 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384937 return false;
Yutaka Hirano36c94952018-05-30 21:33:334938
Yutaka Hirano8e0b4d432019-07-04 07:12:384939 return web_request_api->MayHaveProxies();
4940#else
4941 return false;
4942#endif
4943}
4944
4945void ChromeContentBrowserClient::CreateWebSocket(
4946 content::RenderFrameHost* frame,
4947 WebSocketFactory factory,
4948 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394949 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384950 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404951 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4952 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384953#if BUILDFLAG(ENABLE_EXTENSIONS)
4954 if (!frame) {
4955 return;
4956 }
4957 auto* web_request_api =
4958 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4959 frame->GetProcess()->GetBrowserContext());
4960
4961 DCHECK(web_request_api);
4962 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394963 site_for_cookies.RepresentativeUrl(),
4964 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334965#endif
4966}
4967
Maks Orlovich710d5e32019-07-09 20:16:454968bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464969 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454970 content::BrowserContext* browser_context,
Shuran Huang92b415d72021-01-12 20:48:154971 const net::IsolationInfo& isolation_info,
Maks Orlovich710d5e32019-07-09 20:16:454972 bool is_service_worker,
4973 int process_id,
4974 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034975 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454976 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4977#if BUILDFLAG(ENABLE_EXTENSIONS)
Shuran Huang92b415d72021-01-12 20:48:154978 DCHECK(isolation_info.frame_origin());
4979 if (isolation_info.frame_origin()->scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464980 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454981 extensions::ChromeExtensionCookies::Get(browser_context)
Shuran Huang92b415d72021-01-12 20:48:154982 ->CreateRestrictedCookieManager(isolation_info, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454983 return true;
4984 }
4985#endif
4986 return false;
4987}
4988
Matt Menkeae4fdb12018-06-02 06:32:544989void ChromeContentBrowserClient::OnNetworkServiceCreated(
4990 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534991 PrefService* local_state;
4992 if (g_browser_process) {
4993 DCHECK(g_browser_process->local_state());
4994 local_state = g_browser_process->local_state();
4995 } else {
danakj5beedd02020-10-30 15:55:134996 DCHECK(startup_data_.chrome_feature_list_creator()->local_state());
4997 local_state = startup_data_.chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534998 }
4999
5000 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
5001 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
5002
Henrique Nakashimaa3b1c5d2019-07-03 19:25:495003 // Create SystemNetworkContextManager if it has not been created yet. We need
5004 // to set up global NetworkService state before anything else uses it and this
5005 // is the first opportunity to initialize SystemNetworkContextManager with the
5006 // NetworkService.
5007 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:535008 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:075009
Min Qin8caab1d2018-10-03 17:28:135010 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:545011 network_service);
5012}
5013
Matthew Denton8888ae52020-05-14 08:20:025014void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:255015 content::BrowserContext* context,
5016 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:025017 const base::FilePath& relative_partition_path,
5018 network::mojom::NetworkContextParams* network_context_params,
5019 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
Glen Robertsoncbb40ac2020-11-23 04:04:045020 ProfileNetworkContextService* service =
5021 ProfileNetworkContextServiceFactory::GetForContext(context);
5022 if (service) {
5023 service->ConfigureNetworkContextParams(in_memory, relative_partition_path,
5024 network_context_params,
5025 cert_verifier_creation_params);
5026 } else {
5027 // Set default params.
5028 network_context_params->user_agent = GetUserAgent();
5029 network_context_params->accept_language = GetApplicationLocale();
5030 }
Ken Rockota0dfaca12018-02-15 07:26:255031}
5032
Robert Sesek34f68f312019-01-14 20:25:115033std::vector<base::FilePath>
5034ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:025035 DCHECK(!network_contexts_parent_directory_.empty());
5036 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:115037}
5038
John Abd-El-Malekc240cfc42020-07-08 12:22:445039base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() {
5040 auto platform_dict = net_log::GetPlatformConstantsForNetLog(
5041 base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
5042 chrome::GetChannelName());
5043 if (platform_dict)
5044 return std::move(*platform_dict);
5045 else
5046 return base::DictionaryValue();
5047}
5048
Min Qin75ed6df2017-12-01 20:39:155049bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135050 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155051#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5052 // It is OK to load the saved offline copy, in MHTML format.
5053 ChromeNavigationUIData* chrome_navigation_ui_data =
5054 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5055 if (!chrome_navigation_ui_data)
5056 return false;
5057 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5058 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5059 return offline_page_data && offline_page_data->is_offline_page();
5060#else
5061 return false;
5062#endif
5063}
5064
Min Qin30a78a12017-12-06 01:29:135065bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5066 const GURL& url,
5067 const std::string& mime_type) {
5068#if BUILDFLAG(ENABLE_EXTENSIONS)
5069 // Special-case user scripts to get downloaded instead of viewed.
5070 return extensions::UserScript::IsURLUserScript(url, mime_type);
5071#else
5072 return false;
5073#endif
5074}
5075
Donna Wu838ac362018-08-10 10:36:335076void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345077 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:045078 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:465079 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:345080 return;
5081
[email protected]95ebe7c2020-04-08 19:12:455082 CHECK(render_frame_host);
5083 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
5084 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:345085}
5086
Ovidio Henriquez3d729f62020-02-07 00:43:295087content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
5088 if (!bluetooth_delegate_)
5089 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
5090 return bluetooth_delegate_.get();
5091}
5092
Reilly Grant0d282322019-01-29 02:42:585093#if !defined(OS_ANDROID)
Anatoliy Potapchuk096e4d0a2020-12-01 16:49:215094void ChromeContentBrowserClient::CreateDeviceInfoService(
5095 content::RenderFrameHost* render_frame_host,
5096 mojo::PendingReceiver<blink::mojom::DeviceAPIService> receiver) {
5097 DCHECK(render_frame_host);
5098 DeviceServiceImpl::Create(render_frame_host, std::move(receiver));
5099}
5100
Reilly Grant0d282322019-01-29 02:42:585101content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5102 if (!serial_delegate_)
5103 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5104 return serial_delegate_.get();
5105}
Matt Reynolds93616f9b2019-06-07 01:28:525106
5107content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5108 if (!hid_delegate_)
5109 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5110 return hid_delegate_.get();
5111}
Reilly Grant0d282322019-01-29 02:42:585112
Olivier Yiptong935e6c42020-11-21 01:28:235113content::FontAccessDelegate*
5114ChromeContentBrowserClient::GetFontAccessDelegate() {
5115 if (!font_access_delegate_)
5116 font_access_delegate_ = std::make_unique<ChromeFontAccessDelegate>();
5117 return static_cast<content::FontAccessDelegate*>(font_access_delegate_.get());
5118}
5119
Balazs Engedya7ff70982018-06-04 18:14:475120std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5121ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:335122 content::RenderFrameHost* render_frame_host) {
5123 return AuthenticatorRequestScheduler::CreateRequestDelegate(
5124 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:475125}
Nina Satragno8c832df2019-07-29 15:59:395126#endif
Balazs Engedya7ff70982018-06-04 18:14:475127
Jun Cai9409ded2018-01-30 00:19:465128std::unique_ptr<net::ClientCertStore>
5129ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:105130 content::BrowserContext* browser_context) {
5131 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:465132 ->CreateClientCertStore();
5133}
5134
David Benjamineced01fc2019-02-27 18:29:025135std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395136ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585137 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025138 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035139 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245140 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395141 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035142 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395143 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565144 LoginAuthRequiredCallback auth_required_callback) {
Andreea Costinas81218bf2021-01-08 11:48:145145#if BUILDFLAG(IS_CHROMEOS_ASH)
5146 policy::SystemProxyManager* system_proxy_manager =
5147 g_browser_process->platform_part()
5148 ->browser_policy_connector_chromeos()
5149 ->GetSystemProxyManager();
5150 // For Managed Guest Session and Kiosk devices, the credentials configured
5151 // via the policy SystemProxySettings may be used for proxy authentication.
5152 // Note: |system_proxy_manager| may be missing in tests.
5153 if (system_proxy_manager && system_proxy_manager->CanUsePolicyCredentials(
5154 auth_info, first_auth_attempt)) {
5155 return system_proxy_manager->CreateLoginDelegate(
5156 std::move(auth_required_callback));
5157 }
5158#endif // BUILDFLAG(IS_CHROMEOS_ASH)
5159
Emily Stark63c884f2020-05-12 03:55:285160 // For subresources, create a LoginHandler directly, which may show a login
5161 // prompt to the user. Main frame resources go through LoginTabHelper, which
5162 // manages a more complicated flow to avoid confusion about which website is
5163 // showing the prompt.
5164 if (is_request_for_main_frame) {
5165 LoginTabHelper::CreateForWebContents(web_contents);
5166 return LoginTabHelper::FromWebContents(web_contents)
5167 ->CreateAndStartMainFrameLoginDelegate(
5168 auth_info, web_contents, request_id, url, response_headers,
5169 std::move(auth_required_callback));
5170 }
5171 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
5172 auth_info, web_contents, std::move(auth_required_callback));
5173 login_handler->StartSubresource(request_id, url, response_headers);
5174 return login_handler;
Jun Caibc561f412018-02-28 18:41:395175}
5176
John Abd-El-Maleka67add82018-03-09 18:22:015177bool ChromeContentBrowserClient::HandleExternalProtocol(
5178 const GURL& url,
danakjf4b9e942019-11-29 15:43:045179 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015180 int child_id,
5181 content::NavigationUIData* navigation_data,
5182 bool is_main_frame,
5183 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455184 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:455185 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:105186 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015187#if BUILDFLAG(ENABLE_EXTENSIONS)
5188 // External protocols are disabled for guests. An exception is made for the
5189 // "mailto" protocol, so that pages that utilize it work properly in a
5190 // WebView.
5191 ChromeNavigationUIData* chrome_data =
5192 static_cast<ChromeNavigationUIData*>(navigation_data);
5193 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5194 (chrome_data &&
5195 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5196 !url.SchemeIs(url::kMailToScheme)) {
5197 return false;
5198 }
5199#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5200
5201#if defined(OS_ANDROID)
5202 // Main frame external protocols are handled by
5203 // InterceptNavigationResourceThrottle.
5204 if (is_main_frame)
5205 return false;
5206#endif // defined(ANDROID)
5207
Gabriel Charettee7cdc5cd2020-05-27 23:35:055208 content::GetUIThreadTaskRunner({})->PostTask(
5209 FROM_HERE,
danakjf4b9e942019-11-29 15:43:045210 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
5211 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:015212 return true;
5213}
5214
Jennifer Apacible4f854a82018-04-06 22:22:115215std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285216ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5217 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115218 // Note: content::OverlayWindow::Create() is defined by platform-specific
5219 // implementation in chrome/browser/ui/views. This layering hack, which goes
5220 // through //content and ContentBrowserClient, allows us to work around the
5221 // dependency constraints that disallow directly calling
5222 // chrome/browser/ui/views code either from here or from other code in
5223 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285224 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115225}
5226
Kunihiko Sakamoto19aa7082019-02-25 03:14:435227void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565228 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115229 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565230 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435231 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5232 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565233}
5234
dbeam25472e0c2017-06-23 19:02:315235// Static; handles rewriting Web UI URLs.
5236bool ChromeContentBrowserClient::HandleWebUI(
5237 GURL* url,
5238 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:395239 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315240 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395241 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315242 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5243 chrome::kChromeUIHelpHost);
5244 return true; // Return true to update the displayed URL.
5245 }
5246
sauskib5f82762020-07-21 17:13:225247 // Replace deprecated cookie settings URL with the current version.
5248 if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) {
5249 *url = GURL(chrome::kChromeUICookieSettingsURL);
5250 return true;
5251 }
5252
Hector Carmona566a20b2019-09-13 22:44:425253#if defined(OS_WIN)
5254 // TODO(crbug.com/1003960): Remove when issue is resolved.
5255 if (url->SchemeIs(content::kChromeUIScheme) &&
5256 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5257 url::Replacements<char> replacements;
5258 replacements.SetHost(
5259 chrome::kChromeUIWelcomeHost,
5260 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5261 *url = url->ReplaceComponents(replacements);
5262 return true;
5263 }
5264#endif // defined(OS_WIN)
5265
dbeam25472e0c2017-06-23 19:02:315266 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5267 browser_context, *url)) {
5268 return false;
5269 }
5270
Yuta Hijikata235fc62b2020-12-08 03:48:325271#if BUILDFLAG(IS_CHROMEOS_ASH)
dbeam25472e0c2017-06-23 19:02:315272 // Special case : in ChromeOS in Guest mode bookmarks and history are
5273 // disabled for security reasons. New tab page explains the reasons, so
5274 // we redirect user to new tab page.
5275 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5276 if (url->SchemeIs(content::kChromeUIScheme) &&
5277 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5278 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5279 // Rewrite with new tab URL
5280 *url = GURL(chrome::kChromeUINewTabURL);
5281 }
5282 }
Aya ElAttareb5fee12020-05-05 08:56:055283
5284 if (IsSystemFeatureURLDisabled(*url)) {
5285 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
5286 return true;
5287 }
5288
dbeam25472e0c2017-06-23 19:02:315289#endif
5290
5291 return true;
5292}
5293
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065294bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5295 content::BrowserContext* browser_context,
5296 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325297 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065298#if defined(OS_ANDROID)
5299 return false;
5300#else
5301 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5302 ->GetForBrowserContext(browser_context)
5303 ->ShowPaymentHandlerWindow(url, std::move(callback));
5304 return true;
5305#endif
5306}
5307
Dan Beam141c48932019-08-22 02:29:395308// static
dbeam25472e0c2017-06-23 19:02:315309bool ChromeContentBrowserClient::HandleWebUIReverse(
5310 GURL* url,
5311 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425312#if defined(OS_WIN)
5313 // TODO(crbug.com/1003960): Remove when issue is resolved.
5314 // No need to actually reverse-rewrite the URL, but return true to update the
5315 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5316 if (url->SchemeIs(content::kChromeUIScheme) &&
5317 url->host() == chrome::kChromeUIWelcomeHost) {
5318 return true;
5319 }
5320#endif // defined(OS_WIN)
5321
dbeam25472e0c2017-06-23 19:02:315322 // No need to actually reverse-rewrite the URL, but return true to update the
5323 // displayed URL when rewriting chrome://help to chrome://settings/help.
5324 return url->SchemeIs(content::kChromeUIScheme) &&
5325 url->host() == chrome::kChromeUISettingsHost;
5326}
5327
Alison Maher7f366dc62020-03-03 19:46:005328const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585329 return ui::NativeTheme::GetInstanceForWeb();
5330}
5331
Clark DuVall5497288d2019-07-17 00:17:565332scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505333ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Xinghui Lucf23c902020-06-10 17:38:255334 bool safe_browsing_enabled_for_profile,
5335 bool should_check_on_sb_disabled) {
Yuzhu Shen44094e22017-07-18 22:52:355336 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5337
Xinghui Lucf23c902020-06-10 17:38:255338 // Should not bypass safe browsing check if the check is for enterprise
5339 // lookup.
5340 if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled)
Yuzhu Shencb3011f62018-02-08 02:51:505341 return nullptr;
5342
Yuzhu Shen44094e22017-07-18 22:52:355343 // |safe_browsing_service_| may be unavailable in tests.
5344 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5345 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435346 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355347 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435348 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355349 }
5350
Clark DuVall5497288d2019-07-17 00:17:565351 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355352}
Daniel Vogelheim6008f572018-09-24 14:35:145353
Xinghui Lucf23c902020-06-10 17:38:255354safe_browsing::RealTimeUrlLookupServiceBase*
5355ChromeContentBrowserClient::GetUrlLookupService(
5356 content::BrowserContext* browser_context,
5357 bool is_enterprise_lookup_enabled,
5358 bool is_consumer_lookup_enabled) {
5359 // |safe_browsing_service_| may be unavailable in tests.
5360 if (!safe_browsing_service_) {
5361 return nullptr;
5362 }
5363
5364 Profile* profile = Profile::FromBrowserContext(browser_context);
5365
5366#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
5367 if (is_enterprise_lookup_enabled) {
5368 return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory::
5369 GetForProfile(profile);
5370 }
5371#endif
5372
5373 if (is_consumer_lookup_enabled) {
5374 return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
5375 profile);
5376 }
5377 return nullptr;
5378}
5379
Daniel Vogelheim6008f572018-09-24 14:35:145380base::Optional<std::string>
5381ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595382 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185383 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595384 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5385 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145386}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525387
Takashi Toyoshima5af383aa2019-07-22 15:24:225388bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525389 // We require --user-data-dir flag too so that no dangerous changes are made
5390 // in the user's regular profile.
5391 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5392 switches::kUserDataDir);
5393}
rajendrantfeea8592018-10-19 18:26:065394
5395void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5396 int32_t network_traffic_annotation_id_hash,
5397 int64_t recv_bytes,
5398 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035399 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5400 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5401 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5402 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065403 }
5404}
Ryan Sturmaa05092f2018-10-21 03:56:545405
Ken Rockot4e284d32020-03-06 06:26:495406base::FilePath
5407ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
Ken Rockota22aaa572020-10-14 18:46:145408 if (!g_browser_process || !g_browser_process->profile_manager())
5409 return base::FilePath();
Ken Rockot4e284d32020-03-06 06:26:495410 return g_browser_process->profile_manager()->user_data_dir();
5411}
5412
Guido Urdanetae02b5722020-07-22 05:58:215413bool ChromeContentBrowserClient::ShouldSandboxAudioService() {
5414 return IsAudioServiceSandboxEnabled();
5415}
5416
Hiroki Nakagawa41366152020-07-27 18:31:405417blink::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5418 blink::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395419 content::NavigationHandle* navigation_handle,
5420 const GURL& current_navigation_url) {
Sophie Changc4ddda6772020-07-15 15:08:325421 return DetermineAllowedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135422 initial_state, navigation_handle, current_navigation_url);
Robert Ogden30bbc9d2019-04-30 20:15:135423}
5424
Hiroki Nakagawa41366152020-07-27 18:31:405425blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135426ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405427 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135428 content::NavigationHandle* navigation_handle,
5429 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545430 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295431 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215432
Ryan Sturmaa05092f2018-10-21 03:56:545433 // If this is not a main frame, return the initial state. If there are no
5434 // previews in the state, return the state as is.
5435 if (!navigation_handle->IsInMainFrame() ||
5436 navigation_handle->IsSameDocument()) {
5437 return initial_state;
5438 }
5439
Robert Ogdena994eb42019-02-14 19:15:085440 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405441 return blink::PreviewsTypes::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085442
Doug Arnettb3b99bc2019-08-09 16:55:565443 // Check if initial state specifies no previews should be considered.
Hiroki Nakagawa41366152020-07-27 18:31:405444 if (initial_state == blink::PreviewsTypes::PREVIEWS_OFF)
Doug Arnettb3b99bc2019-08-09 16:55:565445 return initial_state;
5446
Robert Ogdena994eb42019-02-14 19:15:085447 // Do not allow previews on POST navigations since the primary opt-out
5448 // mechanism is to reload the page. Because POST navigations are not
5449 // idempotent, we do not want to show a preview on a POST navigation where
5450 // opting out would cause another navigation, i.e.: a reload.
5451 if (navigation_handle->IsPost())
Hiroki Nakagawa41366152020-07-27 18:31:405452 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395453
5454 content::WebContents* web_contents = navigation_handle->GetWebContents();
5455 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5456
Ryan Sturmda2a0e02018-10-25 01:52:215457 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545458
5459 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5460 Profile::FromBrowserContext(browser_context));
5461 auto* data_reduction_proxy_settings =
5462 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5463 browser_context);
5464 // If the profile does not support previews or Data Saver, do not turn on
5465 // Previews.
5466 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355467 !data_reduction_proxy_settings) {
Hiroki Nakagawa41366152020-07-27 18:31:405468 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545469 }
5470
5471 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215472 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545473 // If this tab does not have a PreviewsUITabHelper, no preview should be
5474 // served.
5475 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405476 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545477
5478 DCHECK(!browser_context->IsOffTheRecord());
5479
5480 // Other previews objects should all exist and be initialized if we have made
5481 // it past earlier checks.
5482 previews::PreviewsDeciderImpl* previews_decider_impl =
5483 previews_service->previews_ui_service()->previews_decider_impl();
5484 DCHECK(previews_decider_impl);
5485
Ryan Sturm647d1d92018-11-07 15:41:395486 // Start with an unspecified state.
Hiroki Nakagawa41366152020-07-27 18:31:405487 blink::PreviewsState previews_state =
5488 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturmaa05092f2018-10-21 03:56:545489
Ryan Sturm647d1d92018-11-07 15:41:395490 previews::PreviewsUserData* previews_data =
5491 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5492
5493 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315494 // previews) and cannot re-evaluate PreviewsState once previews triggering
5495 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375496 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315497 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395498 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375499 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395500 } else {
5501 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5502 navigation_handle, previews_decider_impl->GeneratePageId());
5503 }
5504
5505 DCHECK(previews_data);
5506
Sophie Changa71fa5d2019-11-19 23:53:515507 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545508 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315509 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355510 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5511 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545512
Hiroki Nakagawa41366152020-07-27 18:31:405513 if (previews_state & blink::PreviewsTypes::PREVIEWS_OFF) {
5514 previews_data->set_allowed_previews_state(
5515 blink::PreviewsTypes::PREVIEWS_OFF);
5516 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545517 }
5518
Hiroki Nakagawa41366152020-07-27 18:31:405519 if (previews_state & blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM) {
5520 previews_data->set_allowed_previews_state(
5521 blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM);
5522 return blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM;
Ryan Sturmaa05092f2018-10-21 03:56:545523 }
5524
5525 // At this point, if no Preview is allowed, don't allow previews.
Hiroki Nakagawa41366152020-07-27 18:31:405526 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
5527 previews_data->set_allowed_previews_state(
5528 blink::PreviewsTypes::PREVIEWS_OFF);
5529 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395530 }
5531
Hiroki Nakagawa41366152020-07-27 18:31:405532 blink::PreviewsState embedder_state =
5533 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturm647d1d92018-11-07 15:41:395534 if (delegate) {
5535 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5536 }
Ryan Sturmaa05092f2018-10-21 03:56:545537
5538 // If the allowed previews are limited by the embedder, ensure previews honors
5539 // those limits.
Hiroki Nakagawa41366152020-07-27 18:31:405540 if (embedder_state != blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
Ryan Sturm647d1d92018-11-07 15:41:395541 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545542 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
Hiroki Nakagawa41366152020-07-27 18:31:405543 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED)
5544 previews_state = blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545545 }
Ryan Sturm647d1d92018-11-07 15:41:395546 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545547 return previews_state;
5548}
5549
5550// static
Hiroki Nakagawa41366152020-07-27 18:31:405551blink::PreviewsState
Ryan Sturmaa05092f2018-10-21 03:56:545552ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5553 const GURL& url,
5554 data_reduction_proxy::DataReductionProxyData* drp_data,
5555 previews::PreviewsUserData* previews_user_data,
5556 const previews::PreviewsDecider* previews_decider,
Hiroki Nakagawa41366152020-07-27 18:31:405557 blink::PreviewsState initial_state,
Ryan Sturm737bd1d2019-02-28 01:38:055558 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545559 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5560 if (!previews::HasEnabledPreviews(initial_state))
Hiroki Nakagawa41366152020-07-27 18:31:405561 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545562
Ryan Sturmaa05092f2018-10-21 03:56:545563 // Check the various other client previews types.
5564 return previews::DetermineCommittedClientPreviewsState(
Sophie Changc4ddda6772020-07-15 15:08:325565 previews_user_data, url, initial_state, previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055566 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545567}
5568
Hiroki Nakagawa41366152020-07-27 18:31:405569blink::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5570 blink::PreviewsState initial_state,
Ryan Sturmaa05092f2018-10-21 03:56:545571 content::NavigationHandle* navigation_handle,
5572 const net::HttpResponseHeaders* response_headers) {
Hiroki Nakagawa41366152020-07-27 18:31:405573 blink::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135574 initial_state, navigation_handle, response_headers);
5575
5576 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5577}
5578
Hiroki Nakagawa41366152020-07-27 18:31:405579blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135580ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405581 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135582 content::NavigationHandle* navigation_handle,
5583 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545584 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arthursonzogni90bb0922020-05-28 09:22:235585 DCHECK(!navigation_handle->HasCommitted());
5586
Ryan Sturmaa05092f2018-10-21 03:56:545587 // Only support HTTP and HTTPS.
arthursonzogni90bb0922020-05-28 09:22:235588 if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405589 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545590
5591 // If this is not a main frame, return the initial state. If there are no
5592 // previews in the state, return the state as is.
5593 if (!previews::HasEnabledPreviews(initial_state) ||
5594 !navigation_handle->IsInMainFrame() ||
5595 navigation_handle->IsSameDocument()) {
5596 return initial_state;
5597 }
5598
5599 // WebContents that don't have a PreviewsUITabHelper are not supported.
5600 PreviewsUITabHelper* ui_tab_helper =
5601 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5602 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405603 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545604
5605 // If we did not previously create a PreviewsUserData, do not go any further.
5606 previews::PreviewsUserData* previews_user_data =
5607 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5608 if (!previews_user_data)
Hiroki Nakagawa41366152020-07-27 18:31:405609 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545610
5611 PreviewsService* previews_service =
5612 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5613 navigation_handle->GetWebContents()->GetBrowserContext()));
5614
5615 if (!previews_service || !previews_service->previews_ui_service())
Hiroki Nakagawa41366152020-07-27 18:31:405616 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545617
Ryan Sturmaa05092f2018-10-21 03:56:545618 // Annotate request if no-transform directive found in response headers.
5619 if (response_headers &&
5620 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265621 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545622 }
5623
5624 previews::PreviewsDeciderImpl* previews_decider_impl =
5625 previews_service->previews_ui_service()->previews_decider_impl();
5626 DCHECK(previews_decider_impl);
5627
Clark DuVall9c5a72cc2018-10-25 01:29:215628 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5629 auto* settings =
5630 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5631 navigation_handle->GetWebContents()->GetBrowserContext());
5632 if (settings) {
5633 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5634 // does not yet have all the response information.
5635 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5636 response_headers);
5637 }
Ryan Sturmaa05092f2018-10-21 03:56:545638
5639 // Determine effective PreviewsState for this committed main frame response.
Hiroki Nakagawa41366152020-07-27 18:31:405640 blink::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215641 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055642 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545643
5644 // Double check that we never serve a preview when we have a
5645 // cache-control:no-transform directive.
5646 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5647 !previews::HasEnabledPreviews(committed_state));
5648
Robert Ogdended292c6f2019-05-03 22:44:515649 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545650 previews_user_data->set_committed_previews_state(committed_state);
5651
5652 previews::PreviewsType committed_type =
5653 previews::GetMainFramePreviewsType(committed_state);
5654
5655 // Capture committed previews type, if any, in PreviewsUserData.
5656 // Note: this is for the subset of previews types that are decided upon
5657 // navigation commit. Previews types that are determined prior to
5658 // navigation (such as for offline pages or for redirecting to another
5659 // url), are not set here.
5660 previews_user_data->SetCommittedPreviewsType(committed_type);
5661
5662 // Log the commit decision.
5663 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5664 previews_decider_impl->LogPreviewDecisionMade(
5665 (previews_user_data->cache_control_no_transform_directive()
5666 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5667 : previews::PreviewsEligibilityReason::COMMITTED),
5668 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055669 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055670 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545671
5672 return committed_state;
5673}
Charlie Harrison650e11422018-12-04 00:37:265674
5675void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5676 content::RenderFrameHost* render_frame_host,
5677 blink::mojom::WebFeature feature) {
5678 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5679 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5680 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5681 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315682
5683 // For the SameSite-by-default-cookies related features, log
5684 // the site engagement score for the site whose cookie was blocked. This is to
5685 // gauge the user impact of the cookies being blocked.
5686 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265687}
Yutaka Hirano968d6252018-12-04 05:09:315688
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525689std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315690 return ::GetProduct();
5691}
5692
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525693std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315694 return ::GetUserAgent();
5695}
Sam McNallyd54e23f92019-01-16 04:42:395696
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525697blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175698 return ::GetUserAgentMetadata();
5699}
5700
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525701base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275702 // This icon is available on Android, but adds 19KiB to the APK. Since it
5703 // isn't used on Android we exclude it to avoid bloat.
5704#if !defined(OS_ANDROID)
5705 return base::Optional<gfx::ImageSkia>(
5706 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5707 IDR_PRODUCT_LOGO_256));
5708#else
5709 return base::nullopt;
5710#endif
5711}
5712
Sam McNallyd54e23f92019-01-16 04:42:395713bool ChromeContentBrowserClient::IsBuiltinComponent(
5714 content::BrowserContext* browser_context,
5715 const url::Origin& origin) {
5716#if BUILDFLAG(ENABLE_EXTENSIONS)
5717 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5718 browser_context, origin);
5719#else
5720 return false;
5721#endif
5722}
Oleg Davydov2cc0167b2019-02-05 14:32:485723
Aaron Colwelle1908d982020-06-26 22:08:155724bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:485725 const GURL& url,
5726 content::BrowserContext* context) {
Aaron Colwellf94fd97a2020-07-21 19:37:085727 PolicyBlocklistService* service =
5728 PolicyBlocklistFactory::GetForBrowserContext(context);
Oleg Davydov2cc0167b2019-02-05 14:32:485729
Aaron Colwellf94fd97a2020-07-21 19:37:085730 using URLBlocklistState = policy::URLBlocklist::URLBlocklistState;
5731 URLBlocklistState blocklist_state = service->GetURLBlocklistState(url);
5732 return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST;
Oleg Davydov2cc0167b2019-02-05 14:32:485733}
Dominic Mazzoni21fb0282019-02-13 18:32:475734
5735ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5736 content::BrowserContext* browser_context) {
5737 Profile* profile = Profile::FromBrowserContext(browser_context);
5738 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5739}
Eric Karld6cd75b2019-03-14 22:01:365740
5741#if defined(OS_ANDROID)
5742content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525743ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335744 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425745 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365746 return WideColorGamutHeuristic::kUseDisplay;
5747 }
Khushal1fc0da52019-10-09 00:38:565748
5749 if (display::Display::HasForceDisplayColorProfile() &&
5750 display::Display::GetForcedDisplayColorProfile() ==
5751 gfx::ColorSpace::CreateDisplayP3D65()) {
5752 return WideColorGamutHeuristic::kUseDisplay;
5753 }
5754
Eric Karld6cd75b2019-03-14 22:01:365755 return WideColorGamutHeuristic::kNone;
5756}
5757#endif
Ehsan Karamad91413d72019-03-22 16:37:485758
5759base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435760ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465761 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485762 base::flat_set<std::string> mime_types;
5763#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465764 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485765 for (const auto& pair : map)
5766 mime_types.insert(pair.first);
5767#endif
5768 return mime_types;
5769}
Yao Xiaod06607b2019-05-02 23:16:365770
5771void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
Alex Turner5d3dd2572020-12-16 18:08:055772 content::WebContents* web_contents,
5773 content::RenderFrameHost* frame_host,
Yao Xiaod06607b2019-05-02 23:16:365774 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525775 content::NavigationDownloadPolicy* download_policy) {
Colin Blundell0ec5d642020-10-06 17:29:525776 const auto* throttle_manager = subresource_filter::
5777 ContentSubresourceFilterThrottleManager::FromWebContents(web_contents);
5778 if (throttle_manager && throttle_manager->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045779 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365780 if (!user_gesture) {
5781 if (base::FeatureList::IsEnabled(
5782 blink::features::
5783 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5784 download_policy->SetDisallowed(
5785 content::NavigationDownloadType::kAdFrameNoGesture);
5786 } else {
5787 download_policy->SetAllowed(
5788 content::NavigationDownloadType::kAdFrameNoGesture);
5789 }
Yao Xiaod06607b2019-05-02 23:16:365790 }
5791 }
5792}
Jun Cai732a05e32019-05-29 19:34:195793
Yao Xiaoebed8c12020-09-26 07:51:205794std::string ChromeContentBrowserClient::GetInterestCohortForJsApi(
Yao Xiaoc5436ad2021-01-12 00:22:305795 content::WebContents* web_contents,
Yao Xiao1e28cd42020-12-22 19:31:215796 const GURL& url,
5797 const base::Optional<url::Origin>& top_frame_origin) {
Yao Xiaoc5436ad2021-01-12 00:22:305798 federated_learning::FlocEligibilityObserver::GetOrCreateForCurrentDocument(
5799 web_contents->GetMainFrame())
5800 ->OnInterestCohortApiUsed();
5801
Yao Xiaoebed8c12020-09-26 07:51:205802 federated_learning::FlocIdProvider* floc_id_provider =
5803 federated_learning::FlocIdProviderFactory::GetForProfile(
Yao Xiaoc5436ad2021-01-12 00:22:305804 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
Yao Xiaoebed8c12020-09-26 07:51:205805
5806 if (!floc_id_provider)
5807 return std::string();
5808
Yao Xiao1e28cd42020-12-22 19:31:215809 return floc_id_provider->GetInterestCohortForJsApi(url, top_frame_origin);
Yao Xiaoebed8c12020-09-26 07:51:205810}
5811
Jun Cai732a05e32019-05-29 19:34:195812bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5813 content::BrowserContext* browser_context,
5814 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525815 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195816 const HostContentSettingsMap* const content_settings =
5817 HostContentSettingsMapFactory::GetForProfile(
5818 Profile::FromBrowserContext(browser_context));
5819
5820 if (content_settings->GetContentSetting(
5821 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145822 ContentSettingsType::BLUETOOTH_SCANNING) == CONTENT_SETTING_BLOCK) {
Jun Cai732a05e32019-05-29 19:34:195823 return true;
5824 }
5825
5826 return false;
5827}
5828
5829void ChromeContentBrowserClient::BlockBluetoothScanning(
5830 content::BrowserContext* browser_context,
5831 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525832 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195833 HostContentSettingsMap* const content_settings =
5834 HostContentSettingsMapFactory::GetForProfile(
5835 Profile::FromBrowserContext(browser_context));
5836
5837 content_settings->SetContentSettingDefaultScope(
5838 requesting_origin.GetURL(), embedding_origin.GetURL(),
Illia Klimov48f643c2020-11-05 20:06:145839 ContentSettingsType::BLUETOOTH_SCANNING, CONTENT_SETTING_BLOCK);
Jun Cai732a05e32019-05-29 19:34:195840}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475841
Clark DuVall1635a6b02020-11-06 18:53:515842bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile(
5843 std::string* split_name) {
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475844#if defined(OS_ANDROID)
Clark DuVall1635a6b02020-11-06 18:53:515845 *split_name = "extra_icu";
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475846 return extra_icu::ModuleProvider::IsModuleInstalled();
5847#endif
5848 return false;
5849}
Guido Urdaneta4030d6a32019-10-17 09:38:165850
5851bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5852 content::BrowserContext* browser_context,
5853 const GURL& url,
5854 const GURL& site_for_cookies,
5855 const base::Optional<url::Origin>& top_frame_origin) {
5856 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5857 return CookieSettingsFactory::GetForProfile(
5858 Profile::FromBrowserContext(browser_context))
5859 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5860}
Sam Goto5cf068e82019-11-04 23:08:445861
5862#if !defined(OS_ANDROID)
5863void ChromeContentBrowserClient::FetchRemoteSms(
5864 content::BrowserContext* browser_context,
5865 const url::Origin& origin,
5866 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5867 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5868}
5869#endif
Roger Tawa03ffdbd2020-01-16 18:12:545870
5871void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5872 content::WebContents* web_contents,
5873 const GURL& url,
5874 const ui::ClipboardFormatType& data_type,
5875 const std::string& data,
5876 IsClipboardPasteAllowedCallback callback) {
5877#if BUILDFLAG(FULL_SAFE_BROWSING)
5878 // Safe browsing does not support images, so accept without checking.
5879 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5880 // types when it is implemented.
Darwin Huang0024dbf2020-08-04 00:53:555881 if (data_type == ui::ClipboardFormatType::GetBitmapType()) {
Roger Tawa03ffdbd2020-01-16 18:12:545882 std::move(callback).Run(ClipboardPasteAllowed(true));
5883 return;
5884 }
5885
5886 Profile* profile =
5887 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375888 enterprise_connectors::ContentAnalysisDelegate::Data dialog_data;
5889 if (enterprise_connectors::ContentAnalysisDelegate::IsEnabled(
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265890 profile, url, &dialog_data,
5891 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545892 dialog_data.text.push_back(base::UTF8ToUTF16(data));
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375893 enterprise_connectors::ContentAnalysisDelegate::CreateForWebContents(
Roger Tawa03ffdbd2020-01-16 18:12:545894 web_contents, std::move(dialog_data),
5895 base::BindOnce(
5896 [](IsClipboardPasteAllowedCallback callback,
Dominique Fauteux-Chapleau71912992020-10-22 18:15:375897 const enterprise_connectors::ContentAnalysisDelegate::Data& data,
5898 const enterprise_connectors::ContentAnalysisDelegate::Result&
Roger Tawa03ffdbd2020-01-16 18:12:545899 result) {
5900 std::move(callback).Run(
5901 ClipboardPasteAllowed(result.text_results[0]));
5902 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245903 std::move(callback)),
5904 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545905 } else {
5906 std::move(callback).Run(ClipboardPasteAllowed(true));
5907 }
5908#else
5909 std::move(callback).Run(ClipboardPasteAllowed(true));
5910#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5911}
Lukasz Anforowicz4600ea32020-01-18 02:37:485912
5913#if BUILDFLAG(ENABLE_PLUGINS)
5914bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5915 const url::Origin& embedder_origin,
5916 const content::PepperPluginInfo& plugin_info) {
5917#if BUILDFLAG(ENABLE_PDF)
5918 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5919#if BUILDFLAG(ENABLE_EXTENSIONS)
5920 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5921 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5922 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5923 return true;
5924 }
5925#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5926
5927 // Allow embedding the internal PDF plugin in chrome://print.
5928 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5929 return true;
5930
5931 // Only allow the PDF plugin in the known, trustworthy origins that are
5932 // allowlisted above. See also https://crbug.com/520422 and
5933 // https://crbug.com/1027173.
5934 return false;
5935 }
5936#endif // BUILDFLAG(ENABLE_PDF)
5937
5938 return true;
5939}
5940#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565941
5942#if BUILDFLAG(ENABLE_VR)
5943content::XrIntegrationClient*
5944ChromeContentBrowserClient::GetXrIntegrationClient() {
5945 if (!xr_integration_client_)
5946 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
Peter Kasting796cde22020-11-18 21:06:535947 base::PassKey<ChromeContentBrowserClient>());
Alexander Cooperc8448702020-03-14 01:39:565948 return xr_integration_client_.get();
5949}
5950#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185951
5952bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5953 content::BrowserContext* browser_context) {
5954 auto* profile = Profile::FromBrowserContext(browser_context);
5955 auto* prefs = profile->GetPrefs();
5956
5957 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5958 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5959 return false;
5960 }
5961 if (base::FeatureList::IsEnabled(
5962 blink::features::kAppCacheRequireOriginTrial)) {
5963 return true;
5964 }
5965
5966 return false;
5967}
Yutaka Hirano3e613662020-06-02 02:59:345968
Hidehiko Abeeaffbbce2020-06-23 19:41:525969void ChromeContentBrowserClient::BindBrowserControlInterface(
Hidehiko Abe23e45e82020-08-25 08:41:485970 mojo::ScopedMessagePipeHandle pipe) {
Yuta Hijikata235fc62b2020-12-08 03:48:325971#if BUILDFLAG(IS_CHROMEOS_LACROS)
Hidehiko Abe23e45e82020-08-25 08:41:485972 chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(
5973 mojo::PendingReceiver<crosapi::mojom::LacrosChromeService>(
5974 std::move(pipe)));
Hidehiko Abeeaffbbce2020-06-23 19:41:525975#endif
5976}
5977
Yutaka Hirano3e613662020-06-02 02:59:345978bool ChromeContentBrowserClient::
5979 ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) {
5980#if BUILDFLAG(ENABLE_EXTENSIONS)
5981 return url.SchemeIs(extensions::kExtensionScheme);
5982#else
5983 return false;
5984#endif
5985}
John Abd-El-Malekdc026012020-06-15 23:28:565986
Titouan Rigoudycfc73552020-08-21 14:18:305987bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125988 content::BrowserContext* browser_context,
5989 const GURL& url) {
Titouan Rigoudycfc73552020-08-21 14:18:305990 return content_settings::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125991 HostContentSettingsMapFactory::GetForProfile(browser_context), url);
5992}
5993
John Abd-El-Malekdc026012020-06-15 23:28:565994ukm::UkmService* ChromeContentBrowserClient::GetUkmService() {
5995 return g_browser_process->GetMetricsServicesManager()->GetUkmService();
5996}
Evan Liu054dc082020-09-30 14:09:425997
Yutaka Hirano93e924742020-11-11 10:40:135998void ChromeContentBrowserClient::OnKeepaliveRequestStarted() {
5999#if !defined(OS_ANDROID)
6000 if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) {
Yutaka Hirano311a7412021-01-06 06:17:356001 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6002 // done.
6003 VLOG(1) << "OnKeepaliveRequestStarted: " << num_keepalive_requests_
6004 << " ==> " << num_keepalive_requests_ + 1;
Yutaka Hirano93e924742020-11-11 10:40:136005 ++num_keepalive_requests_;
6006
6007 DCHECK_GT(num_keepalive_requests_, 0u);
6008 last_keepalive_request_time_ = base::TimeTicks::Now();
6009 if (!keepalive_timer_.IsRunning()) {
Yutaka Hirano311a7412021-01-06 06:17:356010 const auto timeout = GetKeepaliveTimerTimeout();
6011 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6012 // done.
6013 VLOG(1) << "Starting a keepalive timer(" << timeout.InSecondsF()
6014 << " seconds)";
Yutaka Hirano93e924742020-11-11 10:40:136015 keepalive_timer_.Start(
Yutaka Hirano311a7412021-01-06 06:17:356016 FROM_HERE, timeout,
Yutaka Hirano93e924742020-11-11 10:40:136017 base::BindOnce(
6018 &ChromeContentBrowserClient::OnKeepaliveTimerFired,
6019 weak_factory_.GetWeakPtr(),
6020 std::make_unique<ScopedKeepAlive>(
6021 KeepAliveOrigin::BROWSER, KeepAliveRestartOption::DISABLED)));
6022 }
6023 }
6024#endif // !defined(OS_ANDROID)
6025}
6026
6027void ChromeContentBrowserClient::OnKeepaliveRequestFinished() {
6028#if !defined(OS_ANDROID)
6029 if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) {
6030 DCHECK_GT(num_keepalive_requests_, 0u);
Yutaka Hirano311a7412021-01-06 06:17:356031 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6032 // done.
6033 VLOG(1) << "OnKeepaliveRequestFinished: " << num_keepalive_requests_
6034 << " ==> " << num_keepalive_requests_ - 1;
Yutaka Hirano93e924742020-11-11 10:40:136035 --num_keepalive_requests_;
6036 if (num_keepalive_requests_ == 0) {
Yutaka Hirano311a7412021-01-06 06:17:356037 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6038 // done.
6039 VLOG(1) << "Stopping the keepalive timer";
Yutaka Hirano93e924742020-11-11 10:40:136040 keepalive_timer_.Stop();
6041 // This deletes the keep alive handle attached to the timer function and
6042 // unblock the shutdown sequence.
6043 }
6044 }
6045#endif // !defined(OS_ANDROID)
6046}
6047
Evan Liu054dc082020-09-30 14:09:426048#if defined(OS_MAC)
6049bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters(
6050 sandbox::policy::SandboxType sandbox_type,
6051 sandbox::SeatbeltExecClient* client) {
6052 if (sandbox_type == sandbox::policy::SandboxType::kSpeechRecognition) {
6053 base::FilePath soda_component_path = speech::GetSodaDirectory();
6054 CHECK(!soda_component_path.empty());
6055 CHECK(client->SetParameter(
6056 sandbox::policy::SandboxMac::kSandboxSodaComponentPath,
6057 soda_component_path.value()));
6058
6059 base::FilePath soda_language_pack_path =
6060 speech::GetSodaLanguagePacksDirectory();
6061 CHECK(!soda_language_pack_path.empty());
6062 CHECK(client->SetParameter(
6063 sandbox::policy::SandboxMac::kSandboxSodaLanguagePackPath,
6064 soda_language_pack_path.value()));
6065 return true;
6066 }
6067
6068 return false;
6069}
6070
6071#endif // defined(OS_MAC)
Koji Ishii3cbd93a2020-10-16 13:48:026072
6073void ChromeContentBrowserClient::GetHyphenationDictionary(
6074 base::OnceCallback<void(const base::FilePath&)> callback) {
6075#if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID)
6076 component_updater::HyphenationComponentInstallerPolicy::
6077 GetHyphenationDictionary(std::move(callback));
6078#endif
6079}
Rakina Zata Amniba3eecb2020-11-02 10:12:286080
6081bool ChromeContentBrowserClient::HasErrorPage(int http_status_code) {
6082 // Use an internal error page, if we have one for the status code.
6083 return error_page::LocalizedError::HasStrings(
6084 error_page::Error::kHttpErrorDomain, http_status_code);
6085}
Yutaka Hirano93e924742020-11-11 10:40:136086
Ken Buchanan7d688352020-12-05 05:45:576087std::unique_ptr<content::IdentityRequestDialogController>
6088ChromeContentBrowserClient::CreateIdentityRequestDialogController() {
6089 return std::make_unique<IdentityDialogController>();
6090}
6091
Yutaka Hirano93e924742020-11-11 10:40:136092void ChromeContentBrowserClient::OnKeepaliveTimerFired(
6093 std::unique_ptr<ScopedKeepAlive> keep_alive_handle) {
6094#if !defined(OS_ANDROID)
Yutaka Hirano311a7412021-01-06 06:17:356095 // TODO(crbug.com/1161996): Remove this entry once the investigation is done.
6096 VLOG(1) << "OnKeepaliveTimerFired";
Yutaka Hirano93e924742020-11-11 10:40:136097 DCHECK(base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive));
6098 const auto now = base::TimeTicks::Now();
Yutaka Hirano311a7412021-01-06 06:17:356099 const auto then = last_keepalive_request_time_ + GetKeepaliveTimerTimeout();
Yutaka Hirano93e924742020-11-11 10:40:136100 if (now < then) {
Yutaka Hirano311a7412021-01-06 06:17:356101 // TODO(crbug.com/1161996): Remove this entry once the investigation is
6102 // done.
6103 VLOG(1) << "Extending keepalive timer";
Yutaka Hirano93e924742020-11-11 10:40:136104 keepalive_timer_.Start(
6105 FROM_HERE, then - now,
6106 base::BindOnce(&ChromeContentBrowserClient::OnKeepaliveTimerFired,
6107 weak_factory_.GetWeakPtr(),
6108 std::move(keep_alive_handle)));
6109 }
6110#endif
6111}