blob: d127251641622ddd528bca9deffee10c26c64044 [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"
estark3ba11132015-04-10 01:38:3315#include "base/bind_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"
Will Harrisc196ed942019-08-03 03:45:3018#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2419#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0020#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1521#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5822#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2523#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1424#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3325#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3926#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0227#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3728#include "base/stl_util.h"
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"
[email protected]b80f68432011-05-02 17:22:3046#include "chrome/browser/browser_process.h"
msramek1c2b3ca2017-03-14 17:57:5647#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5148#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
[email protected]d5a74be2014-08-08 01:01:2749#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0950#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0851#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2252#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
53#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3054#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
55#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0656#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0857#include "chrome/browser/defaults.h"
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:5958#include "chrome/browser/download/chrome_download_manager_delegate.h"
[email protected]b1d97272013-08-17 13:38:4959#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3160#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4561#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0162#include "chrome/browser/external_protocol/external_protocol_handler.h"
Yao Xiaoebed8c12020-09-26 07:51:2063#include "chrome/browser/federated_learning/floc_id_provider.h"
64#include "chrome/browser/federated_learning/floc_id_provider_factory.h"
[email protected]354de9e2014-08-07 03:27:1965#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5366#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5267#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1068#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2769#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2770#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
Guido Urdanetae02b5722020-07-22 05:58:2171#include "chrome/browser/media/audio_service_util.h"
thakis678822e2017-04-20 17:20:3472#include "chrome/browser/media/router/media_router_feature.h"
Patrik Höglundb564859b2018-05-17 11:17:1673#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3674#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3675#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5676#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0477#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0578#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0779#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2380#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1081#include "chrome/browser/net/profile_network_context_service.h"
82#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5483#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0284#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5985#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5686#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0687#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5488#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5189#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5690#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4291#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1192#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4893#include "chrome/browser/plugins/plugin_utils.h"
Mugdha Lakhani2c6b23af2020-07-31 14:55:5794#include "chrome/browser/prerender/chrome_prerender_contents_delegate.h"
Robert Ogdenea4ea7392020-01-25 01:44:5395#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden31b234712020-06-04 22:51:2196#include "chrome/browser/prerender/isolated/isolated_prerender_service.h"
97#include "chrome/browser/prerender/isolated/isolated_prerender_service_factory.h"
Robert Ogden6946ad42020-01-13 18:01:3098#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]3085c502011-10-05 17:50:5099#include "chrome/browser/prerender/prerender_manager_factory.h"
Ryan Sturmcc5071be2019-02-16 02:15:19100#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54101#include "chrome/browser/previews/previews_service.h"
102#include "chrome/browser/previews/previews_service_factory.h"
103#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03104#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14105#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32106#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49107#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06108#include "chrome/browser/profiles/renderer_updater.h"
109#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56110#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
111#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44112#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38113#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40114#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45115#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31116#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
117#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24118#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43119#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00120#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40121#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35122#include "chrome/browser/safe_browsing/ui_manager.h"
123#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58124#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43125#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44126#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20127#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35128#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40129#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23130#include "chrome/browser/signin/identity_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:02131#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Colin Blundell13e92ec2020-01-27 09:47:38132#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Chris Thompsone2e073d42020-07-23 12:33:45133#include "chrome/browser/ssl/sct_reporting_service.h"
134#include "chrome/browser/ssl/sct_reporting_service_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32135#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07136#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35137#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45138#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52139#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19140#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44141#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Clark DuVall8a020d622020-06-04 00:45:50142#include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h"
Charles Harrison6dd11d282017-10-03 06:14:51143#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08144#include "chrome/browser/ui/browser_navigator.h"
145#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43146#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39147#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54148#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28149#include "chrome/browser/ui/login/login_tab_helper.h"
Jonathan Mengedoht42a19bb2020-07-28 14:10:16150#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56151#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25152#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44153#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58154#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50155#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01156#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45157#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53158#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25159#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59160#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23161#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22162#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01163#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48164#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51165#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14166#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22167#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30168#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02169#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50170#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34171#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37172#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12173#include "chrome/common/pref_names.h"
Mike Wittman67d63112020-09-19 00:33:46174#include "chrome/common/profiler/thread_profiler_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38175#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28176#include "chrome/common/renderer_configuration.mojom.h"
Ayu Ishiifbb1fad2020-06-22 20:15:07177#include "chrome/common/secure_origin_allowlist.h"
[email protected]c5dbef02011-05-13 05:06:09178#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47179#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37180#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18181#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30182#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12183#include "components/autofill/core/common/autofill_switches.h"
Clark DuVall8a020d622020-06-04 00:45:50184#include "components/blocked_content/popup_blocker.h"
Clark DuVallf5189252020-04-15 22:33:34185#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53186#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51187#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49188#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44189#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04190#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48191#include "components/cloud_devices/common/cloud_devices_switches.h"
Carlos Caballerob4283202020-08-10 14:40:46192#include "components/content_settings/browser/page_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16193#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09194#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16195#include "components/content_settings/core/browser/host_content_settings_map.h"
Titouan Rigoudy9c2c0142020-08-19 17:57:12196#include "components/content_settings/core/browser/private_network_settings.h"
mukai077089f2014-09-11 18:41:52197#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45198#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08199#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03200#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54201#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28202#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43203#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09204#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03205#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24206#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32207#include "components/embedder_support/switches.h"
blundella5e3240a2016-01-05 11:30:43208#include "components/error_page/common/error_page_switches.h"
Ken Rockot4408a0f2020-07-27 19:40:54209#include "components/error_page/content/browser/net_error_auto_reloader.h"
khushalsagarc5447db22017-08-22 17:53:01210#include "components/feature_engagement/public/feature_constants.h"
211#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malekcdb5b522020-05-26 22:41:03212#include "components/google/core/common/google_switches.h"
Alexandre Frechette572755b2019-02-13 22:30:20213#include "components/language/core/browser/pref_names.h"
Evan Stadebbb9f5242020-09-25 17:26:46214#include "components/media_router/browser/presentation/presentation_service_delegate_impl.h"
215#include "components/media_router/browser/presentation/receiver_presentation_service_delegate_impl.h"
[email protected]8e885de2014-07-22 23:36:53216#include "components/metrics/client_info.h"
John Abd-El-Malekdc026012020-06-15 23:28:56217#include "components/metrics_services_manager/metrics_services_manager.h"
drogerc690e8802015-09-21 14:29:16218#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12219#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
220#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06221#include "components/payments/content/payment_request_display_manager.h"
Chris Hamiltonab4722122020-05-13 18:01:28222#include "components/performance_manager/embedder/performance_manager_registry.h"
Clark DuValla11361ad32020-02-20 22:14:27223#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54224#include "components/permissions/quota_permission_context_impl.h"
Aaron Colwellb4226222020-07-25 16:11:36225#include "components/policy/content/policy_blocklist_navigation_throttle.h"
226#include "components/policy/content/policy_blocklist_service.h"
Chris Hamilton65c41312020-06-10 13:14:40227#include "components/policy/core/common/policy_pref_names.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18228#include "components/policy/core/common/policy_service.h"
229#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26230#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54231#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08232#include "components/prefs/pref_service.h"
233#include "components/prefs/scoped_user_pref_update.h"
Mugdha Lakhani827a5f42020-07-21 12:35:22234#include "components/prerender//common/prerender_url_loader_throttle.h"
Mugdha Lakhani3cff5332020-08-05 07:31:20235#include "components/prerender/browser/prerender_manager.h"
Mugdha Lakhani8ff91c82020-06-08 18:17:33236#include "components/prerender/common/prerender_final_status.h"
Miyoung Shinf53c2e792020-06-19 03:20:25237#include "components/prerender/common/prerender_types.mojom.h"
Mugdha Lakhanifdb9f662020-07-20 15:36:12238#include "components/prerender/common/prerender_util.h"
Sophie Changff1fc382019-08-21 16:30:21239#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54240#include "components/previews/content/previews_decider_impl.h"
241#include "components/previews/content/previews_ui_service.h"
242#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54243#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45244#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43245#include "components/previews/core/previews_switches.h"
Nico Weberbc5b06f2019-07-26 14:00:13246#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47247#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
248#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
249#include "components/safe_browsing/core/browser/url_checker_delegate.h"
250#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
251#include "components/safe_browsing/core/db/database_manager.h"
252#include "components/safe_browsing/core/features.h"
253#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58254#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Carlos IL1a5edec2020-06-12 17:56:57255#include "components/security_interstitials/content/insecure_form_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14256#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49257#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48258#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49259#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23260#include "components/signin/public/identity_manager/identity_manager.h"
Clark DuVallaadc244c2020-06-06 03:47:14261#include "components/site_isolation/pref_names.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54262#include "components/site_isolation/preloaded_isolated_origins.h"
Clark DuVallaadc244c2020-06-06 03:47:14263#include "components/site_isolation/site_isolation_policy.h"
csharrisone985ebc2017-04-04 17:05:03264#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17265#include "components/translate/core/common/translate_switches.h"
Maks Orlovich5408ddfc2020-07-28 23:07:35266#include "components/ukm/content/source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21267#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28268#include "components/variations/variations_associated_data.h"
Ben Goldberger72533cd2020-07-21 16:11:38269#include "components/variations/variations_ids_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46270#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22271#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39272#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33273#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43274#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30275#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38276#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28277#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03278#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31279#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41280#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09281#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03282#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59283#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19284#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31285#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35286#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47287#include "content/public/browser/navigation_handle.h"
288#include "content/public/browser/navigation_throttle.h"
Lukasz Anforowicz44a0f9e2020-09-30 15:05:38289#include "content/public/browser/non_network_url_loader_factory_base.h"
Jennifer Apacible4f854a82018-04-06 22:22:11290#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50291#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30292#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33293#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05294#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54295#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34296#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48297#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27298#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13299#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08300#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19301#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21302#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23303#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43304#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18305#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56306#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40307#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02308#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18309#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57310#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23311#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44312#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31313#include "content/public/common/user_agent.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56314#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43315#include "device/vr/buildflags/buildflags.h"
Karandeep Bhatiaae5d9f32020-07-17 02:52:34316#include "extensions/browser/process_map.h"
Scott Violetc8240b02018-03-08 22:03:59317#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48318#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30319#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28320#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18321#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04322#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31323#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44324#include "media/media_buildflags.h"
325#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12326#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42327#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52328#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08329#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53330#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51331#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58332#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23333#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46334#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57335#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48336#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14337#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38338#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19339#include "printing/buildflags/buildflags.h"
Guido Urdanetae02b5722020-07-22 05:58:21340#include "sandbox/policy/features.h"
Robert Sesek7d0b49b2020-07-08 18:31:27341#include "sandbox/policy/sandbox_type.h"
342#include "sandbox/policy/switches.h"
Takashi Toyoshima128441462019-10-16 04:19:17343#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37344#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50345#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50346#include "services/network/public/cpp/resource_request.h"
Ken Rockotcebdf9c82019-05-28 20:33:03347#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06348#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02349#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02350#include "third_party/blink/public/common/features.h"
Minggang Wangb2f82902020-08-25 16:07:09351#include "third_party/blink/public/common/loader/referrer_utils.h"
Minggang Wangf6840ecf2019-07-29 05:15:02352#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Chris Hamilton65c41312020-06-10 13:14:40353#include "third_party/blink/public/common/switches.h"
Gyuyoung Kim78c5cf52020-09-21 14:24:01354#include "third_party/blink/public/common/web_preferences/autoplay_policy.h"
Gyuyoung Kim3b4703d2020-09-18 00:25:49355#include "third_party/blink/public/common/web_preferences/image_animation_policy.h"
Leon Hanc819dc62019-01-28 04:30:19356#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31357#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17358#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21359#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26360#include "third_party/widevine/cdm/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54361#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39362#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08363#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35364#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56365#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21366#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49367#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57368#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45369#include "url/gurl.h"
370#include "url/origin.h"
Olya Kalitova78ae04932020-09-21 11:26:06371#include "url/third_party/mozilla/url_parse.h"
372#include "url/url_constants.h"
[email protected]d977f9c2011-03-14 16:10:26373
[email protected]b48c9182011-10-26 18:03:30374#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20375#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14376#include "base/win/win_util.h"
377#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38378#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36379#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18380#include "sandbox/win/src/sandbox_policy.h"
Avi Drissman2e458df2020-07-29 16:24:31381#elif defined(OS_MAC)
Avi Drissmana2969a552019-10-30 15:32:25382#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38383#include "chrome/browser/chrome_browser_main_mac.h"
Evan Liu054dc082020-09-30 14:09:42384#include "components/soda/constants.h"
385#include "sandbox/mac/seatbelt_exec.h"
386#include "sandbox/policy/mac/sandbox_mac.h"
[email protected]b48c9182011-10-26 18:03:30387#elif defined(OS_CHROMEOS)
Alice Boxhallda2659142020-05-14 06:04:37388#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42389#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30390#include "chrome/app/chrome_crash_reporter_client.h"
Aya ElAttareb5fee12020-05-05 08:56:05391#include "chrome/browser/browser_process.h"
hashimotoa53e7e82016-10-26 06:30:47392#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17393#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30394#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24395#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18396#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08397#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48398#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41399#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32400#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58401#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00402#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
403#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44404#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39405#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31406#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33407#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05408#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Pavol Marko230ea2c92017-12-03 22:35:44409#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34410#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10411#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36412#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27413#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31414#include "chrome/browser/ui/browser_dialogs.h"
Jesse Schettlerb7047f32020-09-18 14:50:40415#include "chromeos/components/scanning/url_constants.h"
Steven Bennetts38e9bde22019-01-03 17:31:10416#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21417#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10418#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50419#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05420#include "components/policy/core/common/policy_pref_names.h"
421#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07422#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58423#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50424#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26425#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30426#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09427#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35428#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23429#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45430#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47431#include "chrome/android/modules/extra_icu/provider/module_provider.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36432#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36433#include "chrome/browser/android/devtools_manager_delegate_android.h"
434#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
435#include "chrome/browser/android/service_tab_launcher.h"
436#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42437#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09438#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56439#include "chrome/browser/download/android/available_offline_content_provider.h"
440#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23441#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07442#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38443#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11444#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07445#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47446#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36447#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54448#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00449#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36450#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45451#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04452#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45453#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30454#elif defined(OS_POSIX)
455#include "chrome/browser/chrome_browser_main_posix.h"
456#endif
457
Alice Boxhalla9aafba42020-06-24 05:42:51458#if !defined(OS_CHROMEOS)
459#include "ui/accessibility/accessibility_features.h"
460#endif // !defined(OS_CHROMEOS)
461
tmartinofb341882017-02-10 19:36:53462#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40463#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36464#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54465#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59466#include "chrome/browser/media/unified_autoplay_config.h"
Zach Trudocc4aa4d2020-09-21 22:19:45467#include "chrome/browser/policy/dm_token_utils.h"
Marc Treib7895941d2017-11-28 12:37:02468#include "chrome/browser/search/instant_service.h"
469#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46470#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51471#include "chrome/browser/ui/browser.h"
472#include "chrome/browser/ui/browser_finder.h"
473#include "chrome/browser/ui/browser_list.h"
474#include "chrome/browser/ui/browser_window.h"
Conley Owensaafcf122018-02-26 18:53:51475#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39476#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
477#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43478#include "chrome/common/importer/profile_import.mojom.h"
Glen Robertson8a825ae4f2020-09-16 06:50:08479#include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897
Maggie Caia2f03f52019-04-02 02:13:28480#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36481
Avi Drissman2e458df2020-07-29 16:24:31482#if defined(OS_WIN) || defined(OS_MAC) || \
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33483 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52484#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
485#endif
486
Sean McAllister0d73ca3d2020-08-19 17:54:37487#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Rohit Rao92f84b6a2020-03-25 14:57:50488#include "components/crash/core/app/crash_switches.h"
489#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24490#endif
491
Avi Drissman2e458df2020-07-29 16:24:31492#if defined(OS_POSIX) && !defined(OS_MAC)
Joshua Perazaf890e4b2019-01-03 19:19:02493#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02494#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50495#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02496#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13497#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43498#endif
[email protected]b80f68432011-05-02 17:22:30499
Maggie Caia2f03f52019-04-02 02:13:28500// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
501// single navigation throttle to display the intent picker on all platforms.
502#if !defined(OS_ANDROID)
503#if defined(OS_CHROMEOS)
504#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51505#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28506#else
507#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
508#endif
509#endif
510
[email protected]e8b6ca02013-07-10 18:00:51511#if defined(TOOLKIT_VIEWS)
512#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
513#endif
514
estaded3aa0e82016-02-17 22:55:21515#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
516#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51517#endif
518
Mohsen Izadif1958f22019-01-18 20:29:31519#if defined(USE_OZONE)
520#include "ui/ozone/public/ozone_platform.h"
521#endif
522
Maksim Sisov1686fc22020-06-17 07:59:20523#if defined(USE_X11) || defined(USE_OZONE)
524#include "chrome/browser/chrome_browser_main_extra_parts_ozone.h"
[email protected]e8b6ca02013-07-10 18:00:51525#endif
526
brettwab78fef2016-10-12 02:56:05527#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10528#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38529#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19530#endif
531
Nico Weberaf3b00b2017-09-11 17:58:17532#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55533#include "components/nacl/browser/nacl_browser.h"
534#include "components/nacl/browser/nacl_host_message_filter.h"
535#include "components/nacl/browser/nacl_process_host.h"
536#include "components/nacl/common/nacl_process_type.h"
537#include "components/nacl/common/nacl_switches.h"
538#endif
539
brettw00899e62016-11-12 02:10:17540#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05541#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20542#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27543#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23544#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32545#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51546#include "chrome/browser/extensions/user_script_listener.h"
thestig2dbee717e2014-09-05 14:54:28547#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49548#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46549#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39550#include "components/guest_view/browser/guest_view_base.h"
551#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25552#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31553#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35554#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32555#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12556#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57557#include "extensions/browser/extension_system.h"
Aaron Colwell8c430642020-08-04 01:55:20558#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48559#include "extensions/browser/guest_view/web_view/web_view_guest.h"
560#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
561#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31562#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27563#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28564#include "extensions/common/extension.h"
565#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13566#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28567#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33568#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28569#include "extensions/common/permissions/permissions_data.h"
570#include "extensions/common/permissions/socket_permission.h"
571#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34572#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25573
brettw4b461082016-11-19 18:55:16574#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55575#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27576#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39577#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55578#endif
579
bauerb8f9c37742017-03-30 15:04:12580#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
581#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
582#endif
583
yilkal240b4f22019-11-27 19:09:06584#if defined(OS_CHROMEOS)
Anatoliy Potapchuk762c40d2020-05-11 15:10:37585#include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06586#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
Scott Violet1644cf72020-06-24 04:51:55587#include "chrome/browser/speech/tts_controller_delegate_impl.h"
yilkal240b4f22019-11-27 19:09:06588#endif // defined(OS_CHROMEOS)
589
thakis678822e2017-04-20 17:20:34590#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38591#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09592#endif
593
weilifabbf7572017-05-22 19:05:16594#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21595#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16596#endif
Lei Zhanga2fa14c2018-05-15 00:05:21597
Xiaohan Wanga4e41842018-06-26 18:45:10598#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49599#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26600#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10601#include "chrome/browser/media/widevine_hardware_caps_win.h"
602#include "third_party/widevine/cdm/widevine_cdm_common.h"
603#endif
604#endif
605
mmenkedb2637ff2017-03-30 23:59:42606#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
607#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
608#endif
609
Bettinafd0c1102020-08-06 00:23:43610#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Daniel Ruberya1611e32019-04-24 21:38:35611#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32612#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35613#endif
614
Glen Robertson8a825ae4f2020-09-16 06:50:08615#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
616#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897
617#include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897
618#endif
619
Jian Lide7b43792018-06-01 23:22:13620#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54621#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13622#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
623#endif
624
Will Cassella40837ba2019-07-01 21:32:00625#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Glen Robertson8a825ae4f2020-09-16 06:50:08626#include "device/vr/public/mojom/isolated_xr_service.mojom.h" // nogncheck crbug.com/1125897
Bill Orreb429222018-08-08 21:14:43627#endif
628
John Lee0ee748bf2019-12-11 21:35:44629#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
630#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
631#endif
632
Roger Tawa03ffdbd2020-01-16 18:12:54633#if BUILDFLAG(FULL_SAFE_BROWSING)
634#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
635#endif
636
Alexander Cooperc8448702020-03-14 01:39:56637#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23638#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56639#endif
640
James Cook26d27122020-06-26 19:57:07641#if BUILDFLAG(IS_LACROS)
James Cook92730252020-07-22 01:57:26642#include "chromeos/lacros/lacros_chrome_service_impl.h"
Hidehiko Abeeaffbbce2020-06-23 19:41:52643#endif
644
[email protected]c7abd422012-09-25 00:20:08645using base::FileDescriptor;
Gyuyoung Kim1ac4ca782020-09-11 03:32:51646using blink::web_pref::WebPreferences;
[email protected]631bb742011-11-02 11:29:39647using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31648using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13649using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59650using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00651using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02652using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11653using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33654using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13655using content::WebContents;
[email protected]593d2a72013-07-26 08:48:38656using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39657
[email protected]0daaebfe2014-03-15 00:09:05658#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20659using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05660#endif
661
brettw00899e62016-11-12 02:10:17662#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28663using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27664using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28665using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28666using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27667#endif
668
brettw4b461082016-11-19 18:55:16669#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55670using plugins::ChromeContentBrowserClientPluginsPart;
671#endif
672
[email protected]c5dbef02011-05-13 05:06:09673namespace {
674
Will Harris1b9b4152019-08-21 22:33:50675#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30676// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
677// running on Windows 10 1511 and above. See
678// https://blogs.windows.com/blog/tag/code-integrity-guard/.
679const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35680 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50681#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
682 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30683
Colin Blundell9ee731dd2020-01-23 10:42:38684// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
685// parameters.
686void HandleSSLErrorWrapper(
687 content::WebContents* web_contents,
688 int cert_error,
689 const net::SSLInfo& ssl_info,
690 const GURL& request_url,
691 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38692 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
693 Profile* profile =
694 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Scott Violet2fb481102020-07-27 00:23:54695 // Profile should always outlive a WebContents
696 DCHECK(profile);
Colin Blundell9ee731dd2020-01-23 10:42:38697
Colin Blundell27331f92020-02-05 21:13:01698 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51699
700#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
701 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
702#endif
703
Colin Blundell9ee731dd2020-01-23 10:42:38704 SSLErrorHandler::HandleSSLError(
705 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53706 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51707 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38708 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38709 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
710}
711
lazyboy5d5fede02016-03-10 04:10:14712enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53713 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14714 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53715
716 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14717 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53718
719 // An extension or app tried to load a resource of a different platform app in
720 // a tab.
721 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
722
723 // A non-app and non-extension page tried to load a platform app in a tab.
724 APP_LOADED_IN_TAB_SOURCE_OTHER,
725
lazyboy5d5fede02016-03-10 04:10:14726 APP_LOADED_IN_TAB_SOURCE_MAX
727};
728
Lei Zhang2cfceac2018-11-14 19:36:33729// Cached version of the locale so we can return the locale on the I/O
730// thread.
731std::string& GetIOThreadApplicationLocale() {
732 static base::NoDestructor<std::string> s;
733 return *s;
734}
735
[email protected]f8f93eb2012-09-25 03:06:24736// Returns a copy of the given url with its host set to given host and path set
737// to given path. Other parts of the url will be the same.
738GURL ReplaceURLHostAndPath(const GURL& url,
739 const std::string& host,
740 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05741 url::Replacements<char> replacements;
742 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
743 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24744 return url.ReplaceComponents(replacements);
745}
746
madfbd10852017-01-20 03:15:33747// Handles the rewriting of the new tab page URL based on group policy.
748bool HandleNewTabPageLocationOverride(
749 GURL* url,
750 content::BrowserContext* browser_context) {
751 if (!url->SchemeIs(content::kChromeUIScheme) ||
752 url->host() != chrome::kChromeUINewTabHost)
753 return false;
754
755 Profile* profile = Profile::FromBrowserContext(browser_context);
756 std::string ntp_location =
757 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
758 if (ntp_location.empty())
759 return false;
Olya Kalitova78ae04932020-09-21 11:26:06760 url::Component scheme;
761 if (!url::ExtractScheme(ntp_location.data(),
762 static_cast<int>(ntp_location.length()), &scheme)) {
763 ntp_location = base::StrCat(
764 {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location});
765 }
madfbd10852017-01-20 03:15:33766
767 *url = GURL(ntp_location);
768 return true;
769}
770
Becca Hughesfe8c32c2018-03-21 13:36:56771#if !defined(OS_ANDROID)
772// Check if the current url is whitelisted based on a list of whitelisted urls.
773bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57774 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56775 // Only check on HTTP and HTTPS pages.
776 if (!current_url.SchemeIsHTTPOrHTTPS())
777 return false;
778
779 for (auto const& value : whitelisted_urls) {
780 ContentSettingsPattern pattern =
781 ContentSettingsPattern::FromString(value.GetString());
782 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
783 continue;
784 if (pattern.Matches(current_url))
785 return true;
786 }
787
788 return false;
789}
790
791// Check if autoplay is allowed by policy configuration.
792bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
793 PrefService* prefs) {
794 DCHECK(prefs);
795
796 // Check if we have globally allowed autoplay by policy.
797 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
798 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
799 return true;
800 }
801
802 if (!contents)
803 return false;
804
805 // Check if the current URL matches a URL pattern on the whitelist.
806 const base::ListValue* autoplay_whitelist =
807 prefs->GetList(prefs::kAutoplayWhitelist);
808 return autoplay_whitelist &&
809 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
810 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
811}
812#endif
813
Joshua Perazaf890e4b2019-01-03 19:19:02814#if defined(OS_ANDROID)
815int GetCrashSignalFD(const base::CommandLine& command_line) {
816 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
817}
Avi Drissman2e458df2020-07-29 16:24:31818#elif defined(OS_POSIX) && !defined(OS_MAC)
[email protected]0b818f72013-10-22 00:11:03819breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
820 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02821 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52822 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02823 {
824 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31825 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03826 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50827 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02828 crash_handler->StartUploaderThread();
829 return crash_handler;
830 }
831}
832
avi3ef9ec9e2014-12-22 22:50:17833int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24834 if (crash_reporter::IsCrashpadEnabled()) {
835 int fd;
836 pid_t pid;
837 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
838 }
839
[email protected]9de4da52014-05-24 12:26:50840 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39841 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31842 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02843 if (!crash_handler)
844 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18845 return crash_handler->GetDeathSignalSocket();
846 }
847
848 std::string process_type =
849 command_line.GetSwitchValueASCII(switches::kProcessType);
850
[email protected]779dd282013-10-19 15:57:02851 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31852 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02853 if (!crash_handler)
854 crash_handler = CreateCrashHandlerHost(process_type);
855 return crash_handler->GetDeathSignalSocket();
856 }
[email protected]a1733df2012-06-22 11:24:18857
[email protected]779dd282013-10-19 15:57:02858 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31859 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02860 if (!crash_handler)
861 crash_handler = CreateCrashHandlerHost(process_type);
862 return crash_handler->GetDeathSignalSocket();
863 }
[email protected]a1733df2012-06-22 11:24:18864
[email protected]779dd282013-10-19 15:57:02865 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31866 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02867 if (!crash_handler)
868 crash_handler = CreateCrashHandlerHost(process_type);
869 return crash_handler->GetDeathSignalSocket();
870 }
[email protected]a1733df2012-06-22 11:24:18871
James Cook9207cc12017-10-19 17:08:39872 if (process_type == switches::kUtilityProcess) {
873 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
874 if (!crash_handler)
875 crash_handler = CreateCrashHandlerHost(process_type);
876 return crash_handler->GetDeathSignalSocket();
877 }
878
[email protected]a1733df2012-06-22 11:24:18879 return -1;
880}
Joshua Perazaf890e4b2019-01-03 19:19:02881#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18882
[email protected]eabbfb12013-04-05 23:28:35883void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52884 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33885 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35886}
887
estark3ba11132015-04-10 01:38:33888// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31889// SSLErrorHandler. Uses CertificateReportingService to send reports. The
890// service handles queueing and re-sending of failed reports. Each certificate
891// error creates a new instance of this class.
892class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33893 public:
meacerf43117a2016-12-27 21:02:31894 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12895 content::WebContents* web_contents)
896 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
897 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31898 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33899
900 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55901 void ReportInvalidCertificateChain(
902 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31903 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33904 }
905
906 private:
meacerf43117a2016-12-27 21:02:31907 CertificateReportingService* service_;
908
909 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33910};
911
brettw00899e62016-11-12 02:10:17912#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53913
914AppLoadedInTabSource ClassifyAppLoadedInTabSource(
915 const GURL& opener_url,
916 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58917 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
918 // The forbidden app URL was being opened by a non-extension page (e.g.
919 // http).
920 return APP_LOADED_IN_TAB_SOURCE_OTHER;
921 }
922
923 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53924 // The forbidden app URL was being opened by a different app or extension.
925 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
926 }
Lei Zhang7d0b0f42019-10-12 03:47:58927
928 // This platform app was trying to window.open() one of its own URLs.
929 if (opener_url ==
930 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
931 // Source was the background page.
932 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
933 }
934
935 // Source was a different page inside the app.
936 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53937}
[email protected]9c7656382014-08-08 21:02:30938
Charles Harrison34f67862017-08-22 01:04:17939// Returns true if there is is an extension matching |url| in
940// |opener_render_process_id| with APIPermission::kBackground.
941//
942// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
943// hosted app, even though normal extensions just use the host.
944bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35945 extensions::ProcessMap* process_map,
946 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17947 const GURL& url,
csharrison95f01e922017-04-24 18:52:35948 int opener_render_process_id) {
949 // Note: includes web URLs that are part of an extension's web extent.
950 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17951 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35952 return extension &&
953 extension->permissions_data()->HasAPIPermission(
954 APIPermission::kBackground) &&
955 process_map->Contains(extension->id(), opener_render_process_id);
956}
Kevin Marshall32f99d7e2017-07-11 23:17:46957
csharrison95f01e922017-04-24 18:52:35958#endif
959
Miyoung Shin6694b8e2020-06-18 01:38:17960mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler(
Alexander Cooperbc87af32020-07-15 15:59:45961 base::OnceCallback<content::WebContents*()> wc_getter) {
Miyoung Shin6694b8e2020-06-18 01:38:17962 mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler;
Mugdha Lakhani2c6b23af2020-07-31 14:55:57963 prerender::ChromePrerenderContentsDelegate::FromWebContents(
964 std::move(wc_getter).Run())
Darin Fishere41aab52020-01-29 18:31:23965 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
966 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12967}
968
Julian Pastarmovb4773b82020-04-21 16:34:14969// Encapculates logic to determine if enterprise policies should be honored.
970// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
971// as a new central class to replace those checks is in the making.
972bool ShouldHonorPolicies() {
973#if defined(OS_WIN)
974 bool is_enterprise_version =
975 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
976 return base::win::IsEnrolledToDomain() ||
977 (base::win::IsDeviceRegisteredWithManagement() &&
978 is_enterprise_version);
979#else // defined(OS_WIN)
980 // TODO(pastarmovj): Replace this with check for MacOS and the new management
981 // service once it is ready.
982 return true;
983#endif // defined(OS_WIN)
984}
985
John Abd-El-Malek92bf3602019-07-31 02:25:48986void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04987 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48988 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45989 bool has_user_gesture,
990 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01991 // If there is no longer a WebContents, the request may have raced with tab
992 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04993 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01994 if (!web_contents)
995 return;
996
997 // Do not launch external requests attached to unswapped prerenders.
998 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:57999 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
John Abd-El-Maleka67add82018-03-09 18:22:011000 if (prerender_contents) {
1001 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:011002 return;
1003 }
1004
Robbie McElrath1294d242019-05-31 20:46:221005 // Do not launch external requests for schemes that have a handler registered.
1006 ProtocolHandlerRegistry* protocol_handler_registry =
1007 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1008 web_contents->GetBrowserContext());
1009 if (protocol_handler_registry &&
1010 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1011 return;
1012
John Abd-El-Maleka67add82018-03-09 18:22:011013 bool is_whitelisted = false;
Aaron Colwellf94fd97a2020-07-21 19:37:081014 PolicyBlocklistService* service =
1015 PolicyBlocklistFactory::GetForBrowserContext(
Oleg Davydov5cfe7ab2019-02-01 12:27:191016 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:141017 if (ShouldHonorPolicies() && service) {
Aaron Colwellf94fd97a2020-07-21 19:37:081018 const policy::URLBlocklist::URLBlocklistState url_state =
1019 service->GetURLBlocklistState(url);
John Abd-El-Maleka67add82018-03-09 18:22:011020 is_whitelisted =
Aaron Colwellf94fd97a2020-07-21 19:37:081021 url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
John Abd-El-Maleka67add82018-03-09 18:22:011022 }
1023
1024 // If the URL is in whitelist, we launch it without asking the user and
1025 // without any additional security checks. Since the URL is whitelisted,
1026 // we assume it can be executed.
1027 if (is_whitelisted) {
1028 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1029 } else {
1030 ExternalProtocolHandler::LaunchUrl(
1031 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1032 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451033 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011034 }
1035}
1036
Yutaka Hirano968d6252018-12-04 05:09:311037std::string GetProduct() {
1038 return version_info::GetProductNameAndVersionForUserAgent();
1039}
1040
Lukasz Anforowicz60d1253d2019-05-08 16:31:371041void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1042 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1043 // For renderer and utility (e.g. NetworkService) processes the switch is the
1044 // only available source, so below the combined (pref/policy + cmdline)
1045 // allowlist of secure origins is injected into |cmdline| for these other
1046 // processes.
1047 std::vector<std::string> allowlist =
1048 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1049 if (!allowlist.empty()) {
1050 cmdline->AppendSwitchASCII(
1051 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1052 base::JoinString(allowlist, ","));
1053 }
1054}
1055
Will Harris1b9b4152019-08-21 22:33:501056#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301057// Returns the full path to |module_name|. Both dev builds (where |module_name|
1058// is in the current executable's directory) and proper installs (where
1059// |module_name| is in a versioned sub-directory of the current executable's
1060// directory) are supported. The identified file is not guaranteed to exist.
1061base::FilePath GetModulePath(base::StringPiece16 module_name) {
1062 base::FilePath exe_dir;
1063 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1064 DCHECK(has_path);
1065
1066 // Look for the module in a versioned sub-directory of the current
1067 // executable's directory and return the path if it can be read. This is the
1068 // expected location of modules for proper installs.
1069 const base::FilePath module_path =
1070 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1071 if (base::PathExists(module_path))
1072 return module_path;
1073
1074 // Otherwise, return the path to the module in the current executable's
1075 // directory. This is the expected location of modules for dev builds.
1076 return exe_dir.Append(module_name);
1077}
Will Harris1b9b4152019-08-21 22:33:501078#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1079 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301080
Lukasz Anforowicz7724d092019-10-03 23:50:211081void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281082 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1083 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211084 if (maybe_throttle)
1085 throttles->push_back(std::move(maybe_throttle));
1086}
1087
Chris Hamiltonab4722122020-05-13 18:01:281088void MaybeAddThrottles(
1089 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1090 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1091 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1092 std::make_move_iterator(additional.end()));
1093}
1094
Evan Stade1e71d6dd2019-10-29 03:04:491095// Returns whether |web_contents| is within a hosted app.
1096bool IsInHostedApp(WebContents* web_contents) {
1097#if BUILDFLAG(ENABLE_EXTENSIONS)
1098 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1099 return (browser &&
1100 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1101#else
1102 return false;
1103#endif
1104}
1105
Lily Chenc2c9e9f2019-12-05 19:55:311106void MaybeRecordSameSiteCookieEngagementHistogram(
1107 content::RenderFrameHost* render_frame_host,
1108 blink::mojom::WebFeature feature) {
1109 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1110 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1111 return;
1112 }
1113
1114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1115 DCHECK(render_frame_host);
1116
1117 content::BrowserContext* browser_context =
1118 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1119 Profile* profile = Profile::FromBrowserContext(browser_context);
1120 SiteEngagementService* site_engagement_service =
1121 SiteEngagementService::Get(profile);
1122 if (!site_engagement_service)
1123 return;
1124
1125 blink::mojom::EngagementLevel engagement_level =
1126 site_engagement_service->GetEngagementLevel(
1127 render_frame_host->GetLastCommittedURL());
1128 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1129 UMA_HISTOGRAM_ENUMERATION(
1130 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1131 engagement_level);
1132 } else {
1133 UMA_HISTOGRAM_ENUMERATION(
1134 "Net.SameSiteBlockedCookieSiteEngagement."
1135 "CookieInsecureAndSameSiteNone",
1136 engagement_level);
1137 }
1138}
1139
Ken Rockot4408a0f2020-07-27 19:40:541140bool IsErrorPageAutoReloadEnabled() {
1141 const base::CommandLine& command_line =
1142 *base::CommandLine::ForCurrentProcess();
1143 if (command_line.HasSwitch(switches::kEnableAutomation))
1144 return false;
1145 if (command_line.HasSwitch(switches::kEnableAutoReload))
1146 return true;
1147 if (command_line.HasSwitch(switches::kDisableAutoReload))
1148 return false;
1149 return true;
1150}
1151
[email protected]9dbfff12011-07-01 19:37:071152} // namespace
[email protected]c5dbef02011-05-13 05:06:091153
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441154// Generate a pseudo-random permutation of the following brand/version pairs:
1155// 1. The base project (i.e. Chromium)
1156// 2. The browser brand, if available
1157// 3. A randomized string containing escaped characters to ensure proper
1158// header parsing, along with an arbitrarily low version to ensure proper
1159// version checking.
1160blink::UserAgentBrandList GenerateBrandVersionList(
1161 int seed,
1162 base::Optional<std::string> brand,
1163 std::string major_version) {
1164 DCHECK_GE(seed, 0);
1165 const int npermutations = 6; // 3!
1166 int permutation = seed % npermutations;
1167
1168 // Pick a stable permutation seeded by major version number. any values here
1169 // and in order should be under three.
1170 const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
1171 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
1172 const std::vector<int> order = orders[permutation];
1173 DCHECK_EQ(6u, orders.size());
1174 DCHECK_EQ(3u, order.size());
1175
1176 const std::vector<std::string> escaped_chars = {"\\", "\"", ";"};
1177 std::string greasey_brand =
1178 base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]],
1179 "A", escaped_chars[order[2]], "Brand"});
1180
1181 blink::UserAgentBrandVersion greasey_bv = {greasey_brand, "99"};
1182 blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version};
1183
1184 blink::UserAgentBrandList greased_brand_version_list(3);
1185
1186 if (brand) {
1187 blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version};
1188
1189 greased_brand_version_list[order[0]] = greasey_bv;
1190 greased_brand_version_list[order[1]] = chromium_bv;
1191 greased_brand_version_list[order[2]] = brand_bv;
1192 } else {
1193 greased_brand_version_list[seed % 2] = greasey_bv;
1194 greased_brand_version_list[(seed + 1) % 2] = chromium_bv;
1195
1196 // If left, the last element would make a blank "" at the end of the header.
1197 greased_brand_version_list.pop_back();
1198 }
1199
1200 return greased_brand_version_list;
1201}
1202
1203const blink::UserAgentBrandList& GetBrandVersionList() {
1204 static const base::NoDestructor<blink::UserAgentBrandList>
1205 greased_brand_version_list([] {
1206 int major_version_number;
1207 std::string major_version = version_info::GetMajorVersionNumber();
1208 base::StringToInt(major_version, &major_version_number);
1209 base::Optional<std::string> brand;
1210#if !BUILDFLAG(CHROMIUM_BRANDING)
1211 brand = version_info::GetProductName();
1212#endif
1213 return GenerateBrandVersionList(major_version_number, brand,
1214 major_version);
1215 }());
1216 return *greased_brand_version_list;
1217}
1218
Yutaka Hirano968d6252018-12-04 05:09:311219std::string GetUserAgent() {
1220 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1221 if (command_line->HasSwitch(switches::kUserAgent)) {
1222 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1223 if (net::HttpUtil::IsValidHeaderValue(ua))
1224 return ua;
1225 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1226 }
1227
John Delaneyac24e572019-04-30 19:47:021228 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1229 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351230 command_line->HasSwitch(switches::kUseMobileUserAgent),
1231 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021232 }
1233
Yutaka Hirano968d6252018-12-04 05:09:311234 std::string product = GetProduct();
1235#if defined(OS_ANDROID)
1236 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1237 product += " Mobile";
1238#endif
1239 return content::BuildUserAgentFromProduct(product);
1240}
1241
Mike West6e4cbb32019-02-13 09:40:171242blink::UserAgentMetadata GetUserAgentMetadata() {
1243 blink::UserAgentMetadata metadata;
Aaron Tagliaboschi9f01b682020-05-05 21:03:171244
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441245 metadata.brand_version_list = GetBrandVersionList();
Mike Weste555be862019-02-20 16:17:301246 metadata.full_version = version_info::GetVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171247 metadata.platform = version_info::GetOSType();
Yoav Weiss4838f1b2020-04-30 21:37:001248 metadata.platform_version =
1249 content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude,
1250 content::IncludeAndroidModel::Exclude);
Aaron Tagliaboschi0585bc932020-05-08 20:03:171251 metadata.architecture = content::GetLowEntropyCpuArchitecture();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361252 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171253
Aaron Tagliaboschibe775e12019-12-09 19:33:041254 metadata.mobile = false;
1255#if defined(OS_ANDROID)
1256 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1257 switches::kUseMobileUserAgent);
1258#endif
1259
Mike West6e4cbb32019-02-13 09:40:171260 return metadata;
1261}
1262
Ran Jia96d43d42018-05-02 17:14:531263ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051264 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311265 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161266#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551267 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401268#endif
[email protected]1deace22013-05-22 06:14:461269
Ahmed Fakhryd70bf37b2018-04-04 17:07:241270#if defined(OS_CHROMEOS)
1271 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1272#endif // defined(OS_CHROMEOS)
1273
John Lee0ee748bf2019-12-11 21:35:441274#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1275 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1276#endif
1277
brettw00899e62016-11-12 02:10:171278#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131279 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271280#endif
bena06f7d62017-04-04 20:48:521281
Sigurdur Asgeirsson70696672019-02-08 16:14:511282 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401283}
1284
1285ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031286 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1287 delete extra_parts_[i];
1288 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401289}
1290
[email protected]bca18382012-06-25 19:15:231291// static
Chris Palmerac7d75642017-11-22 20:12:541292void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1293 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131294 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1295 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541296 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1297 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461298 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541299}
1300
1301// static
[email protected]37ca3fe02013-07-05 15:32:441302void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341303 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251304 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1305 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
Pavol Marko6adbea7f2018-02-20 16:35:281306 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1307 // user policy in addition to the same named ones in Local State (which are
1308 // used for mapping the command-line flags).
1309 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1310 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Clark DuVallaadc244c2020-06-06 03:47:141311 registry->RegisterListPref(
1312 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401313 registry->RegisterDictionaryPref(
1314 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041315 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101316#if !defined(OS_ANDROID)
1317 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561318 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101319#endif
[email protected]bca18382012-06-25 19:15:231320}
1321
[email protected]eabbfb12013-04-05 23:28:351322// static
1323void ChromeContentBrowserClient::SetApplicationLocale(
1324 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481325 // The common case is that this function is called early in Chrome startup
1326 // before any threads are created or registered. When there are no threads,
1327 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001328 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331329 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481330 return;
1331 }
1332
1333 // Otherwise we're being called to change the locale. In this case set it on
1334 // the IO thread.
thestig00844cea2015-09-08 21:44:521335 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351336
Gabriel Charettee7cdc5cd2020-05-27 23:35:051337 content::GetIOThreadTaskRunner({})->PostTask(
1338 FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351339}
1340
Patrick Monette61dfef92019-05-30 23:06:271341std::unique_ptr<content::BrowserMainParts>
1342ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311343 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271344 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301345 // Construct the Main browser parts based on the OS type.
1346#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051347 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271348 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
Avi Drissman2e458df2020-07-29 16:24:311349#elif defined(OS_MAC)
Patrick Monette61dfef92019-05-30 23:06:271350 main_parts =
1351 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1352#elif defined(OS_CHROMEOS)
1353 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1354 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261355#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271356 main_parts =
1357 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141358#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271359 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1360 startup_data_);
[email protected]b48c9182011-10-26 18:03:301361#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271362 main_parts =
1363 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041364#else
[email protected]b48c9182011-10-26 18:03:301365 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271366 main_parts =
1367 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301368#endif
1369
Xi Han9fd44002019-04-30 17:39:361370 bool add_profiles_extra_parts = true;
1371#if defined(OS_ANDROID)
1372 if (startup_data_->HasBuiltProfilePrefService())
1373 add_profiles_extra_parts = false;
1374#endif
1375 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271376 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031377
Xi Han9fd44002019-04-30 17:39:361378 // Construct additional browser parts. Stages are called in the order in
1379 // which they are added.
[email protected]c7480942011-11-08 19:18:271380#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221381#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
James Cook42e933062020-07-06 20:56:121382 main_parts->AddParts(
1383 std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>());
estaded3aa0e82016-02-17 22:55:211384#else
James Cook42e933062020-07-06 20:56:121385 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>());
James Cookf9d34d22017-10-04 16:39:351386#endif
1387#endif
1388
1389#if defined(OS_CHROMEOS)
1390 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
James Cook42e933062020-07-06 20:56:121391 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>());
skycea631e2016-12-16 21:52:221392#endif
[email protected]dc04be7c2012-03-15 23:57:491393
Maksim Sisov1686fc22020-06-17 07:59:201394#if defined(USE_X11) || defined(USE_OZONE)
James Cook42e933062020-07-06 20:56:121395 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>());
[email protected]e050ef142012-03-21 01:04:241396#endif
1397
James Cook42e933062020-07-06 20:56:121398 main_parts->AddParts(
1399 std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>());
Etienne Bergeron05d62532017-10-13 18:24:001400
James Cook42e933062020-07-06 20:56:121401 main_parts->AddParts(
1402 std::make_unique<ChromeBrowserMainExtraPartsProfiling>());
Albert J. Wong59d85acb2017-08-10 00:50:571403
James Cook42e933062020-07-06 20:56:121404 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>());
Sebastien Marchand8c0088102019-10-11 16:47:561405
Patrick Monette61dfef92019-05-30 23:06:271406 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041407
Zhenyao Mo73144652020-04-06 18:55:051408 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1409 // GpuDataManager initialization could pick up about:flags settings.
James Cook42e933062020-07-06 20:56:121410 main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>());
Zhenyao Mo73144652020-04-06 18:55:051411
[email protected]50462bf02011-11-21 19:13:311412 return main_parts;
[email protected]f967b722011-09-07 00:58:041413}
1414
michaeln96f887e22015-04-13 23:58:311415void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091416 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021417 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211418 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121419 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291420
Robert Sesek466e43e2019-08-19 22:02:021421 InitNetworkContextsParentDirectory();
1422
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291423 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1424 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311425}
1426
falkenb09d443f2016-04-07 12:36:121427bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1428 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1429}
1430
Gabriel Charettec8cca992017-08-10 18:21:491431void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1432 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1433}
1434
John Abd-El-Malek9d57f9c2019-02-20 18:50:041435bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361436 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041437}
1438
[email protected]e94bbcb2012-09-07 05:33:571439std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191440 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571441 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531442 std::string partition_id;
1443
1444 // The partition ID for webview guest processes is the string value of its
1445 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451446 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531447 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171448#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501449 // The partition ID for extensions with isolated storage is treated similarly
1450 // to the above.
Aaron Colwell8c430642020-08-04 01:55:201451 else if (extensions::util::IsExtensionSiteWithIsolatedStorage(
1452 site, browser_context))
blundellf650ea02016-02-08 11:50:501453 partition_id = site.spec();
1454#endif
[email protected]1bc28312012-11-08 08:31:531455
[email protected]056efdc2013-04-06 00:14:531456 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531457 return partition_id;
1458}
1459
1460bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1461 content::BrowserContext* browser_context,
1462 const std::string& partition_id) {
1463 // The default ID is empty and is always valid.
1464 if (partition_id.empty())
1465 return true;
1466
1467 return GURL(partition_id).is_valid();
1468}
1469
Bret Sepulveda56652152020-06-24 14:47:131470content::StoragePartitionConfig
1471ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
[email protected]1bc28312012-11-08 08:31:531472 content::BrowserContext* browser_context,
Bret Sepulveda56652152020-06-24 14:47:131473 const GURL& site) {
[email protected]14acc642012-11-17 12:20:101474 // Default to the browser-wide storage partition and override based on |site|
1475 // below.
Bret Sepulveda56652152020-06-24 14:47:131476 content::StoragePartitionConfig storage_partition_config =
1477 content::StoragePartitionConfig::CreateDefault();
[email protected]14acc642012-11-17 12:20:101478
brettw00899e62016-11-12 02:10:171479#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell0ee22132020-06-23 00:28:411480 if (extensions::WebViewGuest::GetGuestPartitionConfigForSite(
Bret Sepulveda56652152020-06-24 14:47:131481 site, &storage_partition_config)) {
1482 return storage_partition_config;
Aaron Colwell0ee22132020-06-23 00:28:411483 }
[email protected]3f24f97c2013-11-17 21:53:331484
Aaron Colwell8c430642020-08-04 01:55:201485 if (site.SchemeIs(extensions::kExtensionScheme)) {
1486 // The host in an extension site URL is the extension_id.
Aaron Colwell0ee22132020-06-23 00:28:411487 CHECK(site.has_host());
Aaron Colwell8c430642020-08-04 01:55:201488 return extensions::util::GetStoragePartitionConfigForExtensionId(
1489 site.host(), browser_context);
[email protected]1df3d972014-06-11 04:55:181490 }
1491#endif
Bret Sepulveda56652152020-06-24 14:47:131492
1493 return storage_partition_config;
[email protected]d7c7c98a2012-07-12 21:27:441494}
1495
[email protected]38b098f2012-03-14 21:11:571496content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441497ChromeContentBrowserClient::GetWebContentsViewDelegate(
1498 content::WebContents* web_contents) {
Chris Hamiltonc3d5c0d12020-06-01 19:30:051499 if (auto* registry =
1500 performance_manager::PerformanceManagerRegistry::GetInstance()) {
Chris Hamilton4269bab2020-06-04 20:03:211501 registry->MaybeCreatePageNodeForWebContents(web_contents);
Chris Hamiltonc3d5c0d12020-06-01 19:30:051502 }
cm.sanchi2db24a82017-11-16 07:22:101503 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321504}
1505
Bo Liu4ade6b1b22017-11-28 02:26:351506bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1507#if defined(OS_ANDROID)
1508 const base::android::ApplicationState app_state =
1509 base::android::ApplicationStatusListener::GetState();
1510 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1511 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1512 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1513#else
1514 return true;
1515#endif
1516}
1517
[email protected]6f2862742013-12-20 07:53:191518void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231519 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301520 int id = host->GetID();
1521 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
Brett Wilson65f951c2016-11-03 22:06:121522#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401523 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031524#endif
Darin Fisher8c84328c2019-07-23 02:50:001525
Darin Fisher09aa7222019-08-29 09:27:361526 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001527 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021528
grunell086a4112017-03-02 09:23:041529 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1530 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021531 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121532 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021533 host->SetUserData(
1534 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091535 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021536 audio_debug_recordings_handler));
1537
Nico Weberaf3b00b2017-09-11 17:58:171538#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031539 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1540 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351541#endif
jeremyim364ac1182015-03-03 18:49:431542
Xiaohan Wang9b34281b2017-09-08 23:48:331543#if defined(OS_ANDROID)
1544 // Data cannot be persisted if the profile is off the record.
1545 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061546 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071547
1548 // Register CrashMemoryMetricsCollector to report oom related metrics.
1549 host->SetUserData(
1550 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1551 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331552#endif
1553
Jun Caidb3f93cc2018-07-09 21:54:551554 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061555 RendererUpdaterFactory::GetForProfile(original_profile)
1556 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071557
[email protected]a48ab7112014-08-01 16:48:031558 for (size_t i = 0; i < extra_parts_.size(); ++i)
1559 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141560}
1561
[email protected]3d7474ff2011-07-27 17:47:371562GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571563 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301564 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371565 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521566 if (!profile)
1567 return url;
1568
Marc Treib7d467b792017-12-04 13:31:031569#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291570 // If the input |url| should be assigned to the Instant renderer, make its
1571 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311572 // This needs to happen even if |url| corresponds to an isolated origin; see
1573 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131574 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1575 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031576#endif
[email protected]b3cb3a32013-07-31 01:32:291577
brettw00899e62016-11-12 02:10:171578#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301579 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1580 url);
[email protected]d5a74be2014-08-08 01:01:271581#else
1582 return url;
1583#endif
[email protected]36fb2c7c2011-04-04 15:49:081584}
1585
Alexander Yashkin6aedc6e2018-08-15 08:58:451586bool ChromeContentBrowserClient::
1587 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1588 content::BrowserContext* browser_context,
1589 content::SiteInstance* candidate_site_instance,
1590 bool is_main_frame,
1591 const GURL& candidate_url,
1592 const GURL& destination_url) {
1593 DCHECK(browser_context);
1594 DCHECK(candidate_site_instance);
1595#if BUILDFLAG(ENABLE_EXTENSIONS)
1596 return ChromeContentBrowserClientExtensionsPart::
1597 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1598 browser_context, candidate_site_instance, is_main_frame,
1599 candidate_url, destination_url);
1600#else
1601 return true;
1602#endif
1603}
1604
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521605bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411606#if defined(OS_ANDROID)
1607 return true;
1608#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421609 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411610#else
1611 return false;
1612#endif // defined(OS_ANDROID)
1613}
1614
[email protected]056ad2a2011-07-12 02:13:551615bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441616 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591617 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521618 Profile* profile = Profile::FromBrowserContext(browser_context);
1619 if (!profile)
1620 return false;
1621
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301622 // NTP should use process-per-site. This is a performance optimization to
1623 // reduce process count associated with NTP tabs.
Tibor Goldschwendt52e168c2020-06-01 22:17:441624 if (site_url == GURL(chrome::kChromeUINewTabURL) ||
1625 site_url == GURL(chrome::kChromeUINewTabPageURL)) {
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301626 return true;
Tibor Goldschwendt52e168c2020-06-01 22:17:441627 }
Peter Boström8e9b1632019-08-22 23:12:471628
1629 // The web footer experiment should share its renderer to not effectively
1630 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591631 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471632 return true;
1633
Marc Treib7d467b792017-12-04 13:31:031634#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591635 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521636 return true;
Marc Treib7d467b792017-12-04 13:31:031637#endif
[email protected]c5dec6292013-01-25 04:54:521638
brettw00899e62016-11-12 02:10:171639#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301640 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591641 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301642 return true;
[email protected]d5a74be2014-08-08 01:01:271643#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301644
1645 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1646 // (rather than process-per-site).
1647 return false;
[email protected]056ad2a2011-07-12 02:13:551648}
1649
Lukasz Anforowicz32d27122018-04-09 21:48:331650bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1651 content::BrowserContext* browser_context,
1652 const GURL& site_url) {
1653 Profile* profile = Profile::FromBrowserContext(browser_context);
1654 if (!profile)
1655 return false;
1656
1657#if !defined(OS_ANDROID)
1658 // Instant renderers should not use a spare process, because they require
1659 // passing switches::kInstantProcess to the renderer process when it
1660 // launches. A spare process is launched earlier, before it is known which
1661 // navigation will use it, so it lacks this flag.
1662 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1663 return false;
1664#endif
1665
1666#if BUILDFLAG(ENABLE_EXTENSIONS)
1667 return ChromeContentBrowserClientExtensionsPart::
1668 ShouldUseSpareRenderProcessHost(profile, site_url);
1669#else
1670 return true;
1671#endif
1672}
1673
nickcc0d9142015-10-14 16:27:101674bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421675 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101676 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421677 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171678#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101679 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421680 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101681 return true;
1682 }
1683#endif
1684 return false;
1685}
1686
Aaron Colwell8812a972020-10-02 23:36:561687bool ChromeContentBrowserClient::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461688 content::BrowserContext* browser_context,
1689 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171690#if BUILDFLAG(ENABLE_EXTENSIONS)
Aaron Colwell8812a972020-10-02 23:36:561691 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcessToSite(
nick7d0984c2015-08-29 00:13:461692 browser_context, effective_site_url)) {
1693 return false;
1694 }
1695#endif
1696 return true;
creise5d6d1732015-08-25 19:47:061697}
1698
Nasko Oskov39023672020-05-06 17:31:141699bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1700 base::StringPiece scheme) {
1701 // Note: This method can be called from multiple threads. It is not safe to
1702 // assume it runs only on the UI thread.
1703
1704 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371705 // locked to chrome-search: origin. Locking to chrome-search would kill
1706 // processes upon legitimate requests for cookies from the search engine's
1707 // domain.
Nasko Oskov39023672020-05-06 17:31:141708 if (scheme == chrome::kChromeSearchScheme)
1709 return false;
1710
1711 // All other WebUIs must be locked to origin.
1712 return true;
1713}
1714
Maks Orlovich0e23e312019-07-16 13:13:561715bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021716 base::StringPiece scheme,
1717 bool is_embedded_origin_secure) {
Lily Chen2387bd92020-06-02 21:15:271718 // This is needed to bypass the normal SameSite rules for any chrome:// page
1719 // embedding a secure origin, regardless of the registrable domains of any
1720 // intervening frames. For example, this is needed for browser UI to interact
1721 // with SameSite cookies on accounts.google.com, which are used for logging
1722 // into Cloud Print from chrome://print, for displaying a list of available
1723 // accounts on the NTP (chrome://new-tab-page), etc.
Lily Chen0db055b2019-11-15 20:29:021724 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1725 return true;
Maks Orlovich0e23e312019-07-16 13:13:561726#if BUILDFLAG(ENABLE_EXTENSIONS)
1727 return scheme == extensions::kExtensionScheme;
1728#else
1729 return false;
1730#endif
1731}
1732
Lily Chen0db055b2019-11-15 20:29:021733bool ChromeContentBrowserClient::
1734 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1735 base::StringPiece scheme,
1736 bool is_embedded_origin_secure) {
1737 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1738}
1739
Xiaohan Wang15a07af2020-05-28 23:24:551740// TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
1741// implementation. Find a general solution to avoid code duplication.
1742std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
1743 content::BrowserContext* browser_context,
1744 const GURL& site_url) {
1745 // By default, use the |site_url| spec as the display name.
1746 std::string name = site_url.spec();
1747
1748#if BUILDFLAG(ENABLE_EXTENSIONS)
1749 // If |site_url| wraps a chrome extension ID, we can display the extension
1750 // name instead, which is more human-readable.
1751 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
1752 const extensions::Extension* extension =
1753 extensions::ExtensionRegistry::Get(browser_context)
1754 ->enabled_extensions()
1755 .GetExtensionOrAppByURL(site_url);
1756 if (extension)
1757 name = extension->name();
1758 }
1759#endif // BUILDFLAG(ENABLE_EXTENSIONS)
1760
1761 return name;
1762}
1763
Lukasz Anforowicz7097890d2019-11-20 21:49:221764void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021765 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591766 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021767 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221768 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071769#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221770 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021771 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071772#endif
1773}
1774
[email protected]73b718f2014-01-27 02:59:461775// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1776// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411777void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1778 std::vector<std::string>* additional_schemes) {
1779 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241780 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351781 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061782}
1783
alexmos94875b3b2017-03-16 22:19:011784void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1785 std::vector<std::string>* additional_schemes) {
1786 GetAdditionalWebUISchemes(additional_schemes);
1787
1788#if BUILDFLAG(ENABLE_EXTENSIONS)
1789 additional_schemes->push_back(extensions::kExtensionScheme);
1790#endif
1791}
1792
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521793bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011794 return webui::LogWebUIUrl(web_ui_url);
1795}
1796
John Abd-El-Malek04bfa8532018-07-12 05:28:221797bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1798 const url::Origin& origin) {
1799 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1800 origin);
1801}
1802
[email protected]46fb9442011-12-09 17:57:471803bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1804 return ProfileIOData::IsHandledURL(url);
1805}
1806
[email protected]c4365fa42013-05-14 01:08:241807bool ChromeContentBrowserClient::CanCommitURL(
1808 content::RenderProcessHost* process_host,
1809 const GURL& url) {
brettw00899e62016-11-12 02:10:171810#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441811 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1812 url);
[email protected]d5a74be2014-08-08 01:01:271813#else
1814 return true;
1815#endif
[email protected]c4365fa42013-05-14 01:08:241816}
1817
rdevlin.cronina32a0902016-11-09 15:50:201818void ChromeContentBrowserClient::OverrideNavigationParams(
1819 SiteInstance* site_instance,
1820 ui::PageTransition* transition,
1821 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581822 content::Referrer* referrer,
1823 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201824 DCHECK(transition);
1825 DCHECK(is_renderer_initiated);
1826 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471827 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1828 // use for making security decisions 99.44% of the time, for detecting the NTP
1829 // it is reliable and the correct way. See http://crbug.com/624410.
1830 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201831 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581832 // Clicks on tiles of the new tab page should be treated as if a user
1833 // clicked on a bookmark. This is consistent with native implementations
1834 // like Android's. This also helps ensure that security features (like
1835 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1836 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201837 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1838 *is_renderer_initiated = false;
1839 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581840 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421841 }
1842}
1843
Charles Reis29e9dd12017-09-28 00:59:151844bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1845 const GURL& url,
1846 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471847 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1848 // use for making security decisions 99.44% of the time, for detecting the NTP
1849 // it is reliable and the correct way. See http://crbug.com/624410.
1850 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1851 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151852}
1853
[email protected]2a5221b2011-09-27 23:07:311854bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301855 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311856 const GURL& site_url) {
1857 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301858 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441859 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521860 // share any host.
1861 if (!profile)
1862 return true;
1863
Marc Treib7895941d2017-11-28 12:37:021864#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141865 // Instant URLs should only be in the instant process and instant process
1866 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521867 InstantService* instant_service =
1868 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141869 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441870 bool is_instant_process =
1871 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141872 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131873 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141874 if (is_instant_process || should_be_in_instant_process)
1875 return is_instant_process && should_be_in_instant_process;
1876 }
Marc Treib7895941d2017-11-28 12:37:021877#endif
[email protected]c5dec6292013-01-25 04:54:521878
brettw00899e62016-11-12 02:10:171879#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131880 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1881 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271882#else
1883 return true;
1884#endif
[email protected]2a5221b2011-09-27 23:07:311885}
1886
[email protected]28c5d0b72014-05-13 08:19:591887bool ChromeContentBrowserClient::MayReuseHost(
1888 content::RenderProcessHost* process_host) {
1889 // If there is currently a prerender in progress for the host provided,
1890 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041891 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591892 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371893 prerender::PrerenderManagerFactory::GetForBrowserContext(
1894 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591895 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491896 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591897 return false;
1898 }
1899
1900 return true;
1901}
1902
[email protected]76411f412012-02-22 18:56:061903bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441904 content::BrowserContext* browser_context,
1905 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061906 // It has to be a valid URL for us to check for an extension.
1907 if (!url.is_valid())
1908 return false;
1909
brettw00899e62016-11-12 02:10:171910#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061911 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131912 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441913 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271914#else
1915 return false;
1916#endif
[email protected]76411f412012-02-22 18:56:061917}
1918
Alex Moshchuk9c9e3882018-11-02 19:57:031919bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1920 content::RenderFrameHost* main_frame) {
1921#if BUILDFLAG(ENABLE_EXTENSIONS)
1922 return ChromeContentBrowserClientExtensionsPart::
1923 ShouldSubframesTryToReuseExistingProcess(main_frame);
1924#else
1925 return true;
1926#endif
1927}
1928
[email protected]6f371442011-11-09 06:45:461929void ChromeContentBrowserClient::SiteInstanceGotProcess(
1930 SiteInstance* site_instance) {
1931 CHECK(site_instance->HasProcess());
1932
Aran Gilmanf010bdd2019-08-28 19:55:441933 Profile* profile =
1934 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521935 if (!profile)
1936 return;
1937
Marc Treib7895941d2017-11-28 12:37:021938#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521939 // Remember the ID of the Instant process to signal the renderer process
1940 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131941 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1942 profile)) {
[email protected]c5dec6292013-01-25 04:54:521943 InstantService* instant_service =
1944 InstantServiceFactory::GetForProfile(profile);
1945 if (instant_service)
1946 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1947 }
Marc Treib7895941d2017-11-28 12:37:021948#endif
[email protected]c5dec6292013-01-25 04:54:521949
[email protected]a48ab7112014-08-01 16:48:031950 for (size_t i = 0; i < extra_parts_.size(); ++i)
1951 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461952}
1953
1954void ChromeContentBrowserClient::SiteInstanceDeleting(
1955 SiteInstance* site_instance) {
1956 if (!site_instance->HasProcess())
1957 return;
1958
[email protected]a48ab7112014-08-01 16:48:031959 for (size_t i = 0; i < extra_parts_.size(); ++i)
1960 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461961}
1962
[email protected]453f5432013-11-26 19:43:001963bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141964 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561965 const GURL& current_effective_url,
1966 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171967#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131968 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561969 ShouldSwapBrowsingInstancesForNavigation(
1970 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271971#else
1972 return false;
1973#endif
[email protected]e3daf3c2011-10-05 21:17:081974}
1975
Nasko Oskovd83b5712018-05-04 04:50:571976bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1977 // TODO(nasko): Consider supporting error page isolation in subframes if
1978 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381979 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571980}
1981
[email protected]3d831992013-07-04 01:13:291982bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1983 return !url.SchemeIs(chrome::kChromeNativeScheme);
1984}
1985
Alex Moshchukd252c192017-07-17 22:03:481986std::vector<url::Origin>
1987ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1988 std::vector<url::Origin> isolated_origin_list;
1989
Alex Moshchuk89352a72017-10-25 20:25:591990// Sign-in process isolation is not needed on Android, see
1991// https://crbug.com/739418.
1992#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381993 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121994 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591995#endif
Alex Moshchukd252c192017-07-17 22:03:481996
Alex Moshchuk81d2a29e2019-07-16 01:14:381997#if BUILDFLAG(ENABLE_EXTENSIONS)
1998 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1999 GetOriginsRequiringDedicatedProcess();
2000 std::move(std::begin(origins_from_extensions),
2001 std::end(origins_from_extensions),
2002 std::back_inserter(isolated_origin_list));
2003#endif
2004
Alex Moshchuk51e1428b2020-04-22 18:00:542005 // Include additional origins preloaded with specific browser configurations,
2006 // if any. For example, this is used on Google Chrome for Android to preload
2007 // a list of important sites to isolate.
2008 auto built_in_origins =
2009 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
2010 std::move(std::begin(built_in_origins), std::end(built_in_origins),
2011 std::back_inserter(isolated_origin_list));
2012
Alex Moshchukd252c192017-07-17 22:03:482013 return isolated_origin_list;
2014}
2015
Lukasz Anforowicz5e201abd2018-03-24 00:41:062016bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:342017 return base::FeatureList::IsEnabled(features::kSitePerProcess);
2018}
2019
2020bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Clark DuVallaadc244c2020-06-06 03:47:142021 return site_isolation::SiteIsolationPolicy::
2022 ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:062023}
2024
Alex Moshchuk082b5f82019-03-14 01:34:162025std::vector<std::string>
2026ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
Clark DuVallaadc244c2020-06-06 03:47:142027 if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
Alex Moshchuk082b5f82019-03-14 01:34:162028 return {"Isolate Password Sites"};
2029 else
2030 return {};
2031}
2032
Alex Moshchuke256d562019-04-26 21:43:572033void ChromeContentBrowserClient::PersistIsolatedOrigin(
2034 content::BrowserContext* context,
2035 const url::Origin& origin) {
2036 DCHECK(!context->IsOffTheRecord());
2037 Profile* profile = Profile::FromBrowserContext(context);
2038 ListPrefUpdate update(profile->GetPrefs(),
Clark DuVallaadc244c2020-06-06 03:47:142039 site_isolation::prefs::kUserTriggeredIsolatedOrigins);
Alex Moshchuke256d562019-04-26 21:43:572040 base::ListValue* list = update.Get();
2041 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:362042 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:122043 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:572044}
2045
Ken Rockot314714c2017-11-05 23:36:242046bool ChromeContentBrowserClient::IsFileAccessAllowed(
2047 const base::FilePath& path,
2048 const base::FilePath& absolute_path,
2049 const base::FilePath& profile_path) {
2050 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2051 profile_path);
2052}
2053
[email protected]d2e1a0a2014-06-16 15:49:372054namespace {
2055
bmcquade5d2d9cf32015-06-19 17:42:282056void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2057 const base::CommandLine& browser_command_line,
2058 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522059 // List of field trials that modify the blink-settings command line flag. No
2060 // two field trials in the list should specify the same keys, otherwise one
2061 // field trial may overwrite another. See Source/core/frame/Settings.in in
2062 // Blink for the list of valid keys.
2063 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162064 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2065 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2066 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2067 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522068 };
2069
2070 std::vector<std::string> blink_settings;
2071 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2072 // Each blink-settings field trial should include a forcing_flag group,
2073 // to make sure that clients that specify the blink-settings flag on the
2074 // command line are excluded from the experiment groups. To make
2075 // sure we assign clients that specify this flag to the forcing_flag
2076 // group, we must call GetVariationParams for each field trial first
2077 // (for example, before checking HasSwitch() and returning), since
2078 // GetVariationParams has the side-effect of assigning the client to
2079 // a field trial group.
2080 std::map<std::string, std::string> params;
2081 if (variations::GetVariationParams(field_trial_name, &params)) {
2082 for (const auto& param : params) {
2083 blink_settings.push_back(base::StringPrintf(
2084 "%s=%s", param.first.c_str(), param.second.c_str()));
2085 }
2086 }
2087 }
pmeenan9ac669682015-08-17 14:57:032088
bmcquade9dd54cc2015-06-22 16:56:522089 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282090 return;
2091 }
2092
Gyuyoung Kima252d4a2020-09-16 07:20:312093 if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) ||
2094 command_line->HasSwitch(blink::switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032095 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522096 // blink-settings flag into a group with no params, and we return
2097 // above if no params were specified, so it's an error if we reach
2098 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282099 LOG(WARNING) << "Received field trial params, "
2100 "but blink-settings switch already specified.";
2101 return;
2102 }
2103
Gyuyoung Kima252d4a2020-09-16 07:20:312104 command_line->AppendSwitchASCII(blink::switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262105 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282106}
2107
[email protected]d2e1a0a2014-06-16 15:49:372108} // namespace
2109
[email protected]b80f68432011-05-02 17:22:302110void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172111 base::CommandLine* command_line,
2112 int child_process_id) {
Avi Drissman2e458df2020-07-29 16:24:312113#if defined(OS_MAC)
dcheng4af48582016-04-19 00:29:352114 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062115 GoogleUpdateSettings::LoadMetricsClientInfo();
2116 if (client_info) {
2117 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2118 client_info->client_id);
2119 }
2120#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022121#if defined(OS_ANDROID)
2122 bool enable_crash_reporter = true;
2123#else
Joshua Perazace68e2f2019-09-23 18:44:242124 bool enable_crash_reporter = false;
2125 if (crash_reporter::IsCrashpadEnabled()) {
2126 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2127 enable_crash_reporter = true;
2128
2129 int fd;
2130 pid_t pid;
2131 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2132 command_line->AppendSwitchASCII(
2133 crash_reporter::switches::kCrashpadHandlerPid,
2134 base::NumberToString(pid));
2135 }
2136 } else {
2137 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2138 }
Joshua Perazaf890e4b2019-01-03 19:19:022139#endif
2140 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512141 std::string switch_value;
dcheng4af48582016-04-19 00:29:352142 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532143 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512144 if (client_info)
2145 switch_value = client_info->client_id;
2146 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252147 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302148 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512149 switch_value);
[email protected]b80f68432011-05-02 17:22:302150 }
Mark Mentovaic67fa64f2015-03-24 14:00:062151#endif
[email protected]b80f68432011-05-02 17:22:302152
[email protected]f1933792011-06-14 00:49:342153 if (logging::DialogsAreSuppressed())
2154 command_line->AppendSwitch(switches::kNoErrorDialogs);
2155
[email protected]b80f68432011-05-02 17:22:302156 std::string process_type =
2157 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172158 const base::CommandLine& browser_command_line =
2159 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322160
[email protected]7c9b6f92013-09-10 18:11:352161 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442162 switches::kUserAgent,
2163 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352164 };
2165 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372166 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322167
fqj15ff3f72015-10-09 19:20:022168 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432169 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312170 };
fqj15ff3f72015-10-09 19:20:022171 command_line->CopySwitchesFrom(browser_command_line,
2172 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372173 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312174
Minggang Wangb2f82902020-08-25 16:07:092175 if (blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy())
Minggang Wang1daff4ec2020-08-13 05:06:172176 command_line->AppendSwitch(
2177 blink::switches::kForceLegacyDefaultReferrerPolicy);
David Van Cleve3df6abb2019-11-26 17:52:512178
fqj15ff3f72015-10-09 19:20:022179#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332180 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2181 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522182 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332183 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2184 homedir.value().c_str());
2185#endif
2186
[email protected]718eab62011-10-05 21:16:522187 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032188 content::RenderProcessHost* process =
2189 content::RenderProcessHost::FromID(child_process_id);
2190 Profile* profile =
2191 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442192 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032193 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442194 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2195 process, profile);
[email protected]a48ab7112014-08-01 16:48:032196 }
2197
[email protected]b80f68432011-05-02 17:22:302198#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442199 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2200 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302201 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442202 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2203 login_profile);
[email protected]b80f68432011-05-02 17:22:302204#endif
2205
Aran Gilmanf010bdd2019-08-28 19:55:442206 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222207 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372208 if (process) {
[email protected]a8d851f82011-12-21 00:32:372209 PrefService* prefs = profile->GetPrefs();
2210 // Currently this pref is only registered if applied via a policy.
2211 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2212 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2213 // Turn this policy into a command line switch.
2214 command_line->AppendSwitch(switches::kDisable3DAPIs);
2215 }
[email protected]718eab62011-10-05 21:16:522216
Bettinafd0c1102020-08-06 00:23:432217#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
2218 bool client_side_detection_enabled =
2219 safe_browsing::IsSafeBrowsingEnabled(*prefs) &&
Daniel Rubery33506f9f2020-10-07 00:28:132220 !base::CommandLine::ForCurrentProcess()->HasSwitch(
2221 ::switches::kDisableClientSidePhishingDetection);
Bettinafd0c1102020-08-06 00:23:432222#if BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2223 client_side_detection_enabled &= base::FeatureList::IsEnabled(
2224 safe_browsing::kClientSideDetectionForAndroid);
2225#endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
2226
[email protected]a8d851f82011-12-21 00:32:372227 // Disable client-side phishing detection in the renderer if it is
Bettinafd0c1102020-08-06 00:23:432228 // disabled in the Profile preferences, or by command line flag, or by not
2229 // being enabled on Android.
2230 if (!client_side_detection_enabled) {
[email protected]a8d851f82011-12-21 00:32:372231 command_line->AppendSwitch(
2232 switches::kDisableClientSidePhishingDetection);
2233 }
Bettinafd0c1102020-08-06 00:23:432234#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
[email protected]0045b0f42012-07-26 11:52:082235
vitalybukaa7ae5052014-09-26 04:11:132236 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2237 command_line->AppendSwitch(switches::kDisablePrintPreview);
2238
Marc Treib7895941d2017-11-28 12:37:022239#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522240 InstantService* instant_service =
2241 InstantServiceFactory::GetForProfile(profile);
2242 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542243 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522244 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542245 }
Marc Treib7895941d2017-11-28 12:37:022246#endif
fqjba8749c2015-10-29 15:33:072247
fqj38306f7b2015-11-02 16:59:062248 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542249 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432250 command_line->AppendSwitch(
2251 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542252 }
Daniel Vogelheim976f1c22017-11-22 16:26:032253
Lukasz Anforowicz60d1253d2019-05-08 16:31:372254 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2255
Amr Aboelkherb04cbf32019-04-29 15:17:102256 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2257 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292258 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102259 }
Katie Dillonc25ee5c92019-09-12 17:05:422260
2261 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2262 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2263 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2264 }
Takashi Toyoshima128441462019-10-16 04:19:172265
Daniel Libbyc5bfd91f2020-03-07 03:44:102266 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2267 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2268 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2269 }
2270
Adrienne Walker297651292020-05-08 00:23:182271 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2272 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2273 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2274 }
Chris Hamilton65c41312020-06-10 13:14:402275
2276 // The IntensiveWakeUpThrottling feature is typically managed via a
2277 // base::Feature, but it has a managed policy override. The override is
2278 // communicated to blink via a custom command-line flag. See
2279 // PageSchedulerImpl for the other half of related logic.
2280 PrefService* local_state = g_browser_process->local_state();
2281 const PrefService::Preference* pref = local_state->FindPreference(
2282 policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled);
2283 if (pref && pref->IsManaged()) {
2284 command_line->AppendSwitchASCII(
2285 blink::switches::kIntensiveWakeUpThrottlingPolicy,
2286 pref->GetValue()->GetBool()
2287 ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable
2288 : blink::switches::
2289 kIntensiveWakeUpThrottlingPolicy_ForceDisable);
2290 }
Aaron Tagliaboschi8f3a28302020-06-24 03:08:262291
2292 // Same as above, but for the blink side of UserAgentClientHints
2293 if (!local_state->GetBoolean(
2294 policy::policy_prefs::kUserAgentClientHintsEnabled)) {
2295 command_line->AppendSwitch(
2296 blink::switches::kUserAgentClientHintDisable);
2297 }
Rakina Zata Amnic123bd22020-07-31 19:08:392298
2299#if defined(OS_ANDROID)
2300 // Communicating to content/ for BackForwardCache.
2301 if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) &&
2302 !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) {
2303 command_line->AppendSwitch(switches::kDisableBackForwardCache);
2304 }
2305#endif // defined(OS_ANDROID)
[email protected]47c7ec82012-01-18 03:29:212306 }
[email protected]4287a3d2011-06-13 23:56:512307
Aran Gilmanf010bdd2019-08-28 19:55:442308 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2309 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282310
mdjonesa6b9e172016-09-23 16:24:302311#if defined(OS_ANDROID)
2312 // If the platform is Android, force the distillability service on.
2313 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2314#endif
2315
[email protected]47c7ec82012-01-18 03:29:212316 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512317 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192318 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412319 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302320#if defined(OS_CHROMEOS)
2321 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2322#endif
brettw00899e62016-11-12 02:10:172323#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512324 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272325 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172326 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512327 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272328 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172329 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]5adb7742020-06-30 14:28:122330 extensions::switches::kAllowlistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282331#endif
estark4b003b332015-02-14 01:07:052332 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512333 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482334 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512335 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502336 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572337 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462338 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302339 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512340 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172341#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242342 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482343 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552344#endif
[email protected]ce304ce2013-02-22 21:54:452345 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342346#if defined(OS_CHROMEOS)
2347 switches::kForceAppMode,
2348#endif
Nico Weberaf3b00b2017-09-11 17:58:172349#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592350 switches::kForcePNaClSubzero,
2351#endif
Marc Treibad33cf942017-08-24 11:19:002352 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032353 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512354 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102355 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322356 embedder_support::kOriginTrialDisabledFeatures,
2357 embedder_support::kOriginTrialDisabledTokens,
2358 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512359 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512360 switches::kPpapiFlashPath,
2361 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032362 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092363 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512364 };
2365
2366 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372367 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172368 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172369#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382370 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442371 extensions::switches::kAllowHTTPBackgroundPage,
2372 extensions::switches::kEnableExperimentalExtensionApis,
2373 extensions::switches::kExtensionsOnChromeURLs,
[email protected]5adb7742020-06-30 14:28:122374 extensions::switches::kAllowlistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382375 };
2376
2377 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372378 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282379#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372380 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Ken Rockot4e805fd2020-10-01 03:07:392381 } else if (process_type == switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512382 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512383 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502384 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172385#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242386 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582387 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592388 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412389 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552390#endif
[email protected]4287a3d2011-06-13 23:56:512391 switches::kPpapiFlashPath,
2392 switches::kPpapiFlashVersion,
2393 };
2394
2395 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372396 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112397 } else if (process_type == switches::kGpuProcess) {
Corentin Walleze660b152020-07-15 16:07:542398 // If --ignore-gpu-blocklist is passed in, don't send in crash reports
[email protected]d56ecf922012-02-15 16:03:112399 // because GPU is expected to be unreliable.
Corentin Walleze660b152020-07-15 16:07:542400 if ((browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) ||
2401 browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) &&
[email protected]d56ecf922012-02-15 16:03:112402 !command_line->HasSwitch(switches::kDisableBreakpad))
2403 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302404 }
[email protected]6f08af82011-09-15 01:19:032405
Ian Barkley-Yeung550aae052019-07-11 00:11:112406#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302407 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112408 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292409 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112410 };
2411 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2412 base::size(kSwitchNames));
2413 }
2414#endif
2415
Mike Wittman67d63112020-09-19 00:33:462416 ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Mike Wittman0d21648f2020-09-30 19:05:082417 command_line);
Andrew Comminos66057672019-05-01 00:03:342418
Sean McAllister0d73ca3d2020-08-19 17:54:372419#if defined(OS_LINUX) || defined(OS_CHROMEOS)
Andrew Comminos66057672019-05-01 00:03:342420 // Processes may only query perf_event_open with the BPF sandbox disabled.
2421 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
Robert Sesek7d0b49b2020-07-08 18:31:272422 command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
Andrew Comminos66057672019-05-01 00:03:342423 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2424 }
2425#endif
[email protected]b80f68432011-05-02 17:22:302426}
2427
Olivier Yiptong0daa93f2019-08-22 19:40:082428std::string
2429ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2430 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2431}
2432
Marijn Kruisselbrinkefe0bef62020-07-21 22:44:592433download::QuarantineConnectionCallback
2434ChromeContentBrowserClient::GetQuarantineConnectionCallback() {
2435 return base::BindRepeating(
2436 &ChromeDownloadManagerDelegate::ConnectToQuarantineService);
2437}
2438
[email protected]b80f68432011-05-02 17:22:302439std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432440 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332441 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302442 return g_browser_process->GetApplicationLocale();
2443}
2444
[email protected]597a867b2011-11-18 18:31:202445std::string ChromeContentBrowserClient::GetAcceptLangs(
2446 content::BrowserContext* context) {
2447 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202448 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082449}
2450
Dana Fried34d580002019-04-24 20:05:482451gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492452 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482453 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082454}
2455
bengre8a146f2016-03-10 01:20:222456bool ChromeContentBrowserClient::IsDataSaverEnabled(
2457 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382458 if (!browser_context || browser_context->IsOffTheRecord())
2459 return false;
2460
Robert Ogdenc995d4fe2019-03-25 19:18:372461 Profile* profile = Profile::FromBrowserContext(browser_context);
2462 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412463 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2464 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222465}
2466
Kenichi Ishibashi46329872018-07-17 09:43:402467void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2468 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192469 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402470 DCHECK(browser_context);
2471 DCHECK(out_prefs);
2472 renderer_preferences_util::UpdateFromSystemSettings(
2473 out_prefs, Profile::FromBrowserContext(browser_context));
2474}
2475
Clark DuVall5690e742019-07-17 18:26:172476bool ChromeContentBrowserClient::AllowAppCache(
2477 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172478 const GURL& site_for_cookies,
2479 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172480 content::BrowserContext* context) {
2481 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2482 return CookieSettingsFactory::GetForProfile(
2483 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172484 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172485}
2486
Alexander Timin17edc742020-04-23 18:22:182487content::AllowServiceWorkerResult
2488ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072489 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542490 const GURL& site_for_cookies,
2491 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362492 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182493 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522494 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542495 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452496
brettw00899e62016-11-12 02:10:172497#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452498 // Check if this is an extension-related service worker, and, if so, if it's
2499 // allowed (this can return false if, e.g., the extension is disabled).
2500 // If it's not allowed, return immediately. We deliberately do *not* report
Carlos Caballerob4283202020-08-10 14:40:462501 // to the PageSpecificContentSettings, since the service worker is blocked
rdevlin.croninf5863da2015-09-10 19:21:452502 // because of the extension, rather than because of the user's content
2503 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022504 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362505 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182506 return content::AllowServiceWorkerResult::No();
rdevlin.croninf5863da2015-09-10 19:21:452507 }
2508#endif
2509
falken3dbc36e2014-10-10 16:48:072510 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202511
shimazuce8af88122016-10-06 23:49:212512 // Check if JavaScript is allowed.
2513 content_settings::SettingInfo info;
2514 std::unique_ptr<base::Value> value =
2515 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452516 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212517 std::string(), &info);
2518 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2519 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2520
2521 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542522 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2523 scope, site_for_cookies, top_frame_origin);
Alexander Timin17edc742020-04-23 18:22:182524
2525 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2526 !allow_cookies);
falken3dbc36e2014-10-10 16:48:072527}
2528
Alexander Timin17edc742020-04-23 18:22:182529content::AllowServiceWorkerResult
2530ChromeContentBrowserClient::AllowServiceWorkerOnUI(
Matt Falkenhagen7b509e52019-08-15 23:11:412531 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542532 const GURL& site_for_cookies,
2533 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412534 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182535 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412536 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542537 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412538
2539#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022540 // Check if this is an extension-related service worker, and, if so, if it's
2541 // allowed (this can return false if, e.g., the extension is disabled).
2542 // If it's not allowed, return immediately. We deliberately do *not* report
Carlos Caballerob4283202020-08-10 14:40:462543 // to the PageSpecificContentSettings, since the service worker is blocked
Matt Falkenhagena59e1cce2019-08-22 23:45:022544 // because of the extension, rather than because of the user's content
2545 // settings.
2546 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2547 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182548 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022549 }
Matt Falkenhagen7b509e52019-08-15 23:11:412550#endif
2551
2552 Profile* profile = Profile::FromBrowserContext(context);
2553
2554 // Check if JavaScript is allowed.
2555 content_settings::SettingInfo info;
2556 std::unique_ptr<base::Value> value =
2557 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452558 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412559 std::string(), &info);
2560 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2561 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2562
2563 // Check if cookies are allowed.
2564 bool allow_cookies =
2565 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542566 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412567
Alexander Timin17edc742020-04-23 18:22:182568 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2569 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412570}
2571
Jochen Eisinger0ff7645c2017-11-28 08:11:262572bool ChromeContentBrowserClient::AllowSharedWorker(
2573 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542574 const GURL& site_for_cookies,
2575 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262576 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372577 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262578 content::BrowserContext* context,
2579 int render_process_id,
2580 int render_frame_id) {
2581 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2582
2583 // Check if cookies are allowed.
2584 bool allow =
2585 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542586 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2587 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262588
Carlos Caballerob4283202020-08-10 14:40:462589 content_settings::PageSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372590 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2591 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262592 return allow;
2593}
2594
Patrick Monette6cb099a2019-09-18 19:31:272595bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2596 const std::string& scheme) {
2597#if BUILDFLAG(ENABLE_EXTENSIONS)
2598 // Extensions are allowed to start cross-origin shared workers.
2599 if (scheme == extensions::kExtensionScheme)
2600 return true;
2601#endif
2602
2603 return false;
2604}
2605
Clark DuVallab63d142019-07-23 04:24:362606bool ChromeContentBrowserClient::AllowSignedExchange(
2607 content::BrowserContext* browser_context) {
2608 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2609 Profile* profile = Profile::FromBrowserContext(browser_context);
2610 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2611}
2612
[email protected]f917df22014-07-10 07:45:492613void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352614 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572615 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172616 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572617 base::OnceCallback<void(bool)> callback) {
2618 Profile* profile = Profile::FromBrowserContext(browser_context);
2619 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172620 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352621
brettw00899e62016-11-12 02:10:172622#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572623 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492624#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572625 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492626#endif
2627}
2628
brettw00899e62016-11-12 02:10:172629#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492630void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2631 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172632 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572633 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492634 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572635 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492636 std::map<int, int> process_map;
2637 std::map<int, int>::const_iterator it;
2638 bool has_web_view_guest = false;
2639 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172640 for (const auto& it : render_frames) {
2641 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492642 continue;
2643
Lukasz Anforowicz09060bdf72018-08-23 15:53:172644 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492645
Lukasz Anforowicz09060bdf72018-08-23 15:53:172646 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492647 has_web_view_guest = true;
2648 }
2649 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572650 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492651 return;
2652 }
[email protected]dffb9fc2014-07-16 04:14:022653 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492654 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492655
[email protected]140d6cd92014-08-12 18:26:462656 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572657 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2658 web_view_permission_helper->RequestFileSystemPermission(
2659 url, allow,
2660 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2661 weak_factory_.GetWeakPtr(), url, render_frames,
2662 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492663}
2664#endif
2665
2666void ChromeContentBrowserClient::FileSystemAccessed(
2667 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172668 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572669 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492670 bool allow) {
[email protected]62151052012-02-01 18:40:482671 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172672 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462673 content_settings::PageSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572674 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352675 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572676 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352677}
2678
[email protected]7c5ff9a2012-03-02 07:42:492679bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2680 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572681 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172682 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572683 Profile* profile = Profile::FromBrowserContext(browser_context);
2684 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2685
Christian Dullweber77740152020-05-12 09:54:172686 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492687
2688 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172689 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462690 content_settings::PageSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572691 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492692 }
2693
2694 return allow;
2695}
2696
Ben Kelly6b2e61c2019-03-14 16:06:292697bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2698 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572699 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292700 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572701 Profile* profile = Profile::FromBrowserContext(browser_context);
2702 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172703 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292704
2705 // Record access to CacheStorage for potential display in UI.
2706 for (const auto& it : render_frames) {
Carlos Caballerob4283202020-08-10 14:40:462707 content_settings::PageSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572708 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292709 }
2710
2711 return allow;
2712}
2713
Joshua Bell1ebc8df2019-11-06 00:27:582714bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2715 const GURL& url,
2716 content::BrowserContext* browser_context,
2717 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2718 Profile* profile = Profile::FromBrowserContext(browser_context);
2719 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172720 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582721}
2722
jyasskinc993ce8d2016-03-31 00:38:342723ChromeContentBrowserClient::AllowWebBluetoothResult
2724ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452725 content::BrowserContext* browser_context,
2726 const url::Origin& requesting_origin,
2727 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342728 // TODO(crbug.com/598890): Don't disable if
2729 // base::CommandLine::ForCurrentProcess()->
2730 // HasSwitch(switches::kEnableWebBluetooth) is true.
2731 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272732 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342733 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272734 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342735 // The kill switch is enabled for this permission. Block requests.
2736 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2737 }
2738
jyasskin98bdd3992016-02-26 20:25:452739 const HostContentSettingsMap* const content_settings =
2740 HostContentSettingsMapFactory::GetForProfile(
2741 Profile::FromBrowserContext(browser_context));
2742
csharrisonaec2c542016-10-12 19:40:362743 if (content_settings->GetContentSetting(
2744 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452745 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362746 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342747 return AllowWebBluetoothResult::BLOCK_POLICY;
2748 }
2749 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452750}
2751
beaufort.francois01135bf2016-11-23 14:37:362752std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2753 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2754 "blocklist_additions");
scheib74250322016-04-07 03:32:212755}
2756
Charlie Harrison071ac922020-06-25 19:11:222757bool ChromeContentBrowserClient::AllowConversionMeasurement(
2758 content::BrowserContext* browser_context) {
2759 // For now, disable conversion measurement if third party cookie blocking is
2760 // enabled.
2761 // TODO(crbug.com/1058018): Add dedicated UI to this feature.
2762 Profile* profile = Profile::FromBrowserContext(browser_context);
2763 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2764 return !cookie_settings->ShouldBlockThirdPartyCookies();
2765}
2766
John Abd-El-Malek21bca7c2018-10-26 22:13:332767#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522768void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072769 content::BrowserContext* browser_context) {
2770 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2771 if (user_manager) {
2772 const user_manager::User* user =
2773 chromeos::ProfileHelper::Get()->GetUserByProfile(
2774 Profile::FromBrowserContext(browser_context));
2775 if (user && !user->username_hash().empty()) {
2776 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
Andreea Costinase1dd9e3a2020-09-22 11:43:352777 user->GetAccountId().GetUserEmail());
John Abd-El-Malek35bfaa52019-08-20 16:22:072778 }
2779 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332780}
2781#endif
2782
Reilly Grant19aaccd2018-07-16 22:06:372783scoped_refptr<network::SharedURLLoaderFactory>
2784ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2786 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2787
2788 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372789 return nullptr;
2790
Min Qinda0d55b2018-10-12 18:30:052791 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372792 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042793}
2794
Sean Gilhulyda1ee4b2018-11-13 21:56:092795network::mojom::NetworkContext*
2796ChromeContentBrowserClient::GetSystemNetworkContext() {
2797 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2798 DCHECK(g_browser_process->system_network_context_manager());
2799 return g_browser_process->system_network_context_manager()->GetContext();
2800}
2801
Andrew Moylan17329fc2017-09-25 07:43:302802std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2803 return google_apis::GetAPIKey();
2804}
2805
Ke He21ee87f2018-05-30 02:35:322806#if defined(OS_ANDROID)
2807bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2808 // Indicate that Chrome uses the GMS core location provider.
2809 return true;
2810}
2811#endif
2812
Yeolf3dc22ca2019-04-18 17:25:322813scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412814ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542815 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412816}
2817
Mythri Alle0b8de0d2018-10-22 11:06:222818content::GeneratedCodeCacheSettings
2819ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2820 content::BrowserContext* context) {
2821 base::FilePath cache_path;
2822 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2823 // If we pass 0 for size, disk_cache will pick a default size using the
2824 // heuristics based on available disk size. These are implemented in
2825 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162826 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132827 DCHECK(g_browser_process);
2828 PrefService* local_state = g_browser_process->local_state();
2829 if (local_state) {
2830 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2831 base::FilePath disk_cache_dir =
2832 local_state->GetFilePath(prefs::kDiskCacheDir);
2833 if (!disk_cache_dir.empty())
2834 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2835 }
Mythri Ab2486572019-06-13 14:48:162836 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222837}
2838
[email protected]848dd042011-06-04 18:24:032839void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262840 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172841 int cert_error,
2842 const net::SSLInfo& ssl_info,
2843 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232844 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222845 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262846 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262847 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232848 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142849 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022850 // have a context for making the right decision, so block the
2851 // request hard, without an info bar to allow showing the insecure
2852 // content.
estark719dde52016-08-09 03:14:272853 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262854 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022855 return;
2856 }
2857
[email protected]f9034cf2011-07-21 12:43:412858 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572859 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:572860 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572861 if (prerender_contents) {
2862 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272863 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262864 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272865 }
[email protected]09667f02014-01-06 15:37:572866 return;
[email protected]f9034cf2011-07-21 12:43:412867 }
2868
Erik Staaba65a6032019-11-27 22:23:262869 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282870 return;
[email protected]848dd042011-06-04 18:24:032871}
2872
Katie D1882617e2020-05-06 20:06:012873#if !defined(OS_ANDROID)
2874bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2875 const GURL main_page_url) {
2876 // Desktop Reader Mode pages should never load resources with certificate
2877 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2878 // on Android: the desktop version has its own security indicator and
2879 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2880 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2881 // pages).
2882 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2883}
2884#endif
2885
Alexander Hendrichbcf2616e2018-05-18 08:21:102886namespace {
2887
Pavol Markob211ab22019-01-23 20:03:042888certificate_matching::CertificatePrincipalPattern
2889ParseCertificatePrincipalPattern(const base::Value* pattern) {
2890 return certificate_matching::CertificatePrincipalPattern::
2891 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2892}
2893
Alexander Hendrichbcf2616e2018-05-18 08:21:102894// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452895// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102896// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2897std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2898 Profile* profile,
2899 const GURL& requesting_url,
2900 net::ClientCertIdentityList& client_certs) {
2901 HostContentSettingsMap* host_content_settings_map =
2902 HostContentSettingsMapFactory::GetForProfile(profile);
2903 std::unique_ptr<base::Value> setting =
2904 host_content_settings_map->GetWebsiteSetting(
2905 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452906 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102907
Pavol Markob211ab22019-01-23 20:03:042908 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102909 return nullptr;
2910
Alexander Hendrichbcf2616e2018-05-18 08:21:102911 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042912 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2913 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102914 // |setting_dict| has the wrong format (e.g. single filter instead of a
2915 // list of filters). This content setting is only provided by
2916 // the |PolicyProvider|, which should always set it to a valid format.
2917 // Therefore, delete the invalid value.
2918 host_content_settings_map->SetWebsiteSettingDefaultScope(
2919 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452920 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042921 return nullptr;
2922 }
2923
2924 for (const base::Value& filter : filters->GetList()) {
2925 DCHECK(filter.is_dict());
2926
2927 auto issuer_pattern = ParseCertificatePrincipalPattern(
2928 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2929 auto subject_pattern = ParseCertificatePrincipalPattern(
2930 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2931 // Use the first certificate that is matched by the filter.
2932 for (auto& client_cert : client_certs) {
2933 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2934 subject_pattern.Matches(client_cert->certificate()->subject())) {
2935 return std::move(client_cert);
2936 }
2937 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102938 }
2939
2940 return nullptr;
2941}
2942
2943} // namespace
2944
Daniel McArdle85735f52019-06-25 03:27:062945base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192946 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402947 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082948 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352949 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022950 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:572951 prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022952 if (prerender_contents) {
2953 prerender_contents->Destroy(
2954 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062955 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452956 }
2957
[email protected]791879c2013-12-17 07:22:412958 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2959 DCHECK(requesting_url.is_valid())
2960 << "Invalid URL string: https://"
2961 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452962
Pavol Marko230ea2c92017-12-03 22:35:442963 bool may_show_cert_selection = true;
2964
davidben3b8455ae72015-03-11 19:42:192965 Profile* profile =
2966 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442967#if defined(OS_CHROMEOS)
2968 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252969 // On the sign-in profile, never show certificate selection to the user. A
2970 // client certificate is an identifier that can be stable for a long time,
2971 // so only the administrator is allowed to decide which endpoints should see
2972 // it.
2973 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442974
2975 content::StoragePartition* storage_partition =
2976 content::BrowserContext::GetStoragePartition(
2977 profile, web_contents->GetSiteInstance());
2978 chromeos::login::SigninPartitionManager* signin_partition_manager =
2979 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2980 profile);
2981
2982 // On the sign-in profile, only allow client certs in the context of the
2983 // sign-in frame.
2984 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2985 storage_partition)) {
2986 LOG(WARNING)
2987 << "Client cert requested in sign-in profile in wrong context.";
2988 // Continue without client certificate. We do this to mimic the case of no
2989 // client certificate being present in the profile's certificate store.
2990 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062991 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442992 }
2993 VLOG(1) << "Client cert requested in sign-in profile.";
2994 }
2995#endif // defined(OS_CHROMEOS)
2996
Alexander Hendrichbcf2616e2018-05-18 08:21:102997 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2998 AutoSelectCertificate(profile, requesting_url, client_certs);
2999 if (auto_selected_identity) {
3000 // The callback will own |auto_selected_identity| and |delegate|, keeping
3001 // them alive until after ContinueWithCertificate is called.
3002 scoped_refptr<net::X509Certificate> cert =
3003 auto_selected_identity->certificate();
3004 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
3005 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:583006 base::BindOnce(
3007 &content::ClientCertificateDelegate::ContinueWithCertificate,
3008 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:323009 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:063010 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:453011 }
3012
Pavol Marko230ea2c92017-12-03 22:35:443013 if (!may_show_cert_selection) {
3014 LOG(WARNING) << "No client cert matched by policy and user selection is "
3015 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:323016 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:443017 // Continue without client certificate. We do this to mimic the case of no
3018 // client certificate being present in the profile's certificate store.
3019 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:063020 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:443021 }
3022
Daniel McArdle85735f52019-06-25 03:27:063023 return chrome::ShowSSLClientCertificateSelector(
3024 web_contents, cert_request_info, std::move(client_certs),
3025 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:453026}
3027
[email protected]dc73a7b2012-03-25 15:27:183028content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:563029 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:183030}
3031
Adrienne Walker80d95f02020-02-07 22:37:043032content::FeatureObserverClient*
3033ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:243034 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:043035 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:053036}
3037
peterc26c6c62014-12-10 14:13:593038content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:023039ChromeContentBrowserClient::GetPlatformNotificationService(
3040 content::BrowserContext* browser_context) {
3041 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3042 Profile* profile = Profile::FromBrowserContext(browser_context);
3043 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:043044}
3045
[email protected]9f3fba52011-06-08 20:37:193046bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:353047 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:353048 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:573049 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:353050 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:033051 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233052 const GURL& target_url,
3053 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213054 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233055 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483056 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233057 bool user_gesture,
3058 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013059 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353060 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3061 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013062
csharrison95f01e922017-04-24 18:52:353063 content::WebContents* web_contents =
3064 content::WebContents::FromRenderFrameHost(opener);
3065 Profile* profile =
3066 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3067 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013068 *no_javascript_access = false;
3069
[email protected]9f3fba52011-06-08 20:37:193070 // If the opener is trying to create a background window but doesn't have
3071 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033072 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173073#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353074 auto* process_map = extensions::ProcessMap::Get(profile);
3075 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173076 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3077 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013078 return false;
3079 }
3080
[email protected]7b54ca02012-03-02 18:06:533081 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3082 // return a recently installed Extension even if this CanCreateWindow call
3083 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013084 // because the permission check above would have caused an early return
3085 // already. We must use the full URL to find hosted apps, though, and not
3086 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553087 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353088 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293089 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013090 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023091#endif
[email protected]190e5e22013-07-27 05:59:233092
3093 return true;
[email protected]9f3fba52011-06-08 20:37:193094 }
[email protected]056efdc2013-04-06 00:14:533095
brettw00899e62016-11-12 02:10:173096#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463097 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353098 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233099 return true;
lazyboy04b75d32016-02-25 03:12:183100 }
3101
nick0fbc3922016-12-16 20:52:073102 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353103 // Intentionally duplicating |registry| code from above because we want to
3104 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3105 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183106 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353107 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143108 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533109 UMA_HISTOGRAM_ENUMERATION(
3110 "Extensions.AppLoadedInTab",
3111 ClassifyAppLoadedInTabSource(opener_url, extension),
3112 APP_LOADED_IN_TAB_SOURCE_MAX);
3113
3114 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163115 return false;
lazyboy5d5fede02016-03-10 04:10:143116 }
lazyboy04b75d32016-02-25 03:12:183117 }
[email protected]5940b0d2014-07-01 00:18:263118#endif
[email protected]190e5e22013-07-27 05:59:233119
Charles Harrisonaf2acd02017-08-18 22:46:023120#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:233121 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:353122 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:583123 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
3124 content_settings, opener_top_level_frame_url, target_url,
3125 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353126 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3127 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583128 return false;
3129 }
3130#endif
3131
Mugdha Lakhani2c6b23af2020-07-31 14:55:573132 DCHECK(!prerender::ChromePrerenderContentsDelegate::FromWebContents(
3133 web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023134
Aaron Colwell9dab1652019-12-09 18:29:493135 BlockedWindowParams blocked_params(
3136 target_url, source_origin, opener->GetSiteInstance(), referrer,
3137 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133138 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Clark DuVall8a020d622020-06-04 00:45:503139 return blocked_content::MaybeBlockPopup(
3140 web_contents, &opener_top_level_frame_url,
3141 std::make_unique<ChromePopupNavigationDelegate>(
3142 std::move(nav_params)),
3143 nullptr /*=open_url_params*/, blocked_params.features(),
3144 HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr;
[email protected]9f3fba52011-06-08 20:37:193145}
3146
[email protected]c52b2892012-03-07 11:01:023147content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443148ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003149 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513150}
3151
Scott Violet1644cf72020-06-24 04:51:553152#if defined(OS_CHROMEOS)
Katie D840d9532018-11-27 06:20:483153content::TtsControllerDelegate*
3154ChromeContentBrowserClient::GetTtsControllerDelegate() {
Scott Violet1644cf72020-06-24 04:51:553155 return TtsControllerDelegateImpl::GetInstance();
3156}
3157#endif
3158
3159content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
Katie D840d9532018-11-27 06:20:483160#if !defined(OS_ANDROID)
Scott Violete217e5e2020-06-22 19:18:223161 content::TtsController::GetInstance()->SetTtsEngineDelegate(
3162 TtsExtensionEngine::GetInstance());
Katie D840d9532018-11-27 06:20:483163#endif
Katie D4713ee42018-11-30 01:48:273164#ifdef OS_CHROMEOS
3165 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273166#else
3167 return nullptr;
3168#endif
3169}
3170
Rakina Zata Amni347b70902020-07-22 10:49:043171bool UpdatePreferredColorSchemesBasedOnURLIfNeeded(WebPreferences* web_prefs,
3172 const GURL& url) {
3173 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3174 // disabled; some of the UI is not yet correctly themed.
3175 if (base::FeatureList::IsEnabled(features::kWebUIDarkMode))
3176 return false;
3177 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3178#if BUILDFLAG(ENABLE_EXTENSIONS)
3179 if (!force_light) {
3180 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3181 url.host_piece() == extension_misc::kPdfExtensionId;
3182 }
3183#endif
3184 auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
3185 if (force_light)
3186 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3187 return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
3188}
3189
[email protected]64d69de42012-02-06 00:19:543190void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443191 RenderViewHost* rvh,
3192 WebPreferences* web_prefs) {
3193 Profile* profile =
3194 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063195 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063196
aelias0df335a2017-03-02 23:43:513197// Fill font preferences. These are not registered on Android
3198// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453199#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193200 FontFamilyCache::FillFontFamilyMap(profile,
3201 prefs::kWebKitStandardFontFamilyMap,
3202 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443203 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193204 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443205 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193206 &web_prefs->serif_font_family_map);
3207 FontFamilyCache::FillFontFamilyMap(profile,
3208 prefs::kWebKitSansSerifFontFamilyMap,
3209 &web_prefs->sans_serif_font_family_map);
3210 FontFamilyCache::FillFontFamilyMap(profile,
3211 prefs::kWebKitCursiveFontFamilyMap,
3212 &web_prefs->cursive_font_family_map);
3213 FontFamilyCache::FillFontFamilyMap(profile,
3214 prefs::kWebKitFantasyFontFamilyMap,
3215 &web_prefs->fantasy_font_family_map);
3216 FontFamilyCache::FillFontFamilyMap(profile,
3217 prefs::kWebKitPictographFontFamilyMap,
3218 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063219
[email protected]64d69de42012-02-06 00:19:543220 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403221 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543222 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403223 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543224 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403225 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543226 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403227 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513228#endif
[email protected]f3986f82012-01-03 20:00:063229
[email protected]ddf72142012-05-22 04:52:403230 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063231
[email protected]64d69de42012-02-06 00:19:543232 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063233 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213234 web_prefs->javascript_can_access_clipboard =
3235 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543236 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063237
[email protected]ddf72142012-05-22 04:52:403238 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543239 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573240
Avi Drissman1aa6cb92019-01-23 15:58:383241 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543242 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573243
[email protected]ddf72142012-05-22 04:52:403244 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543245 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543246 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403247 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063248
Zhenyao Moa3fda9972017-09-16 01:34:403249 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3250 web_prefs->webgl1_enabled = false;
3251 web_prefs->webgl2_enabled = false;
3252 }
[email protected]f3986f82012-01-03 20:00:063253
[email protected]64d69de42012-02-06 00:19:543254 web_prefs->allow_running_insecure_content =
3255 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323256#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053257 web_prefs->font_scale_factor =
3258 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323259 web_prefs->force_enable_zoom =
3260 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493261#endif
Becky Zhoubbfbde32019-02-20 17:07:593262 web_prefs->force_dark_mode_enabled =
3263 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393264
Alice Boxhallda2659142020-05-14 06:04:373265#if defined(OS_CHROMEOS)
3266 web_prefs->always_show_focus =
3267 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
Alice Boxhalla9aafba42020-06-24 05:42:513268#else
3269 if (features::IsAccessibilityFocusHighlightEnabled()) {
3270 web_prefs->always_show_focus =
3271 prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled);
3272 }
Alice Boxhallda2659142020-05-14 06:04:373273#endif
3274
[email protected]af4256d52013-06-04 20:39:073275#if defined(OS_ANDROID)
3276 web_prefs->password_echo_enabled =
3277 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3278#else
[email protected]9d06d88d2012-02-23 22:37:083279 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073280#endif
3281
[email protected]64d69de42012-02-06 00:19:543282 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063283 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543284 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063285 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3286
brettw00899e62016-11-12 02:10:173287#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053288 std::string image_animation_policy =
3289 prefs->GetString(prefs::kAnimationPolicy);
Gyuyoung Kim3b4703d2020-09-18 00:25:493290 if (image_animation_policy == kAnimationPolicyOnce) {
je_julie.kim7fbb5a1a2015-02-09 17:26:053291 web_prefs->animation_policy =
Gyuyoung Kim3b4703d2020-09-18 00:25:493292 blink::web_pref::kImageAnimationPolicyAnimateOnce;
3293 } else if (image_animation_policy == kAnimationPolicyNone) {
Gyuyoung Kim1ac4ca782020-09-11 03:32:513294 web_prefs->animation_policy =
Gyuyoung Kim3b4703d2020-09-18 00:25:493295 blink::web_pref::kImageAnimationPolicyNoAnimation;
3296 } else {
3297 web_prefs->animation_policy = blink::web_pref::kImageAnimationPolicyAllowed;
3298 }
je_julie.kim7fbb5a1a2015-02-09 17:26:053299#endif
3300
[email protected]f3986f82012-01-03 20:00:063301 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153302 web_prefs->default_encoding =
3303 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543304 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403305 prefs->ClearPref(prefs::kDefaultCharset);
3306 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063307 }
[email protected]64d69de42012-02-06 00:19:543308 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063309
mkwst05544102015-01-10 20:26:163310 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3311 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073312 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163313 web_prefs->strict_mixed_content_checking = true;
3314 web_prefs->strict_powerful_feature_restrictions = true;
3315 }
3316
Robert Ogdencf2872d2019-03-19 18:59:373317 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213318
Tarun Bansal333819e2018-05-15 16:38:423319 web_prefs->data_saver_holdback_web_api_enabled =
3320 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3321 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423322
Jinsuk Kima3d393ce2019-05-27 00:57:423323 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133324 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533325#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423326 auto* delegate = TabAndroid::FromWebContents(contents)
3327 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3328 contents->GetDelegate())
3329 : nullptr;
3330 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133331 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423332 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133333
Mounir Lamouri9c99a1602018-07-05 15:01:443334 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423335 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383336
Alison Maher7f366dc62020-03-03 19:46:003337 web_prefs->preferred_color_scheme =
3338 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3339 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113340 }
Ian Vollick6243dfe02018-03-08 01:08:533341#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533342
Mounir Lamouri6926107f2019-01-31 18:17:433343 // web_app_scope value is platform specific.
3344#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423345 if (delegate)
3346 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433347#elif BUILDFLAG(ENABLE_EXTENSIONS)
3348 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253349 web_prefs->web_app_scope = GURL();
3350 // Set |web_app_scope| based on the app associated with the app window if
3351 // any. Note that the app associated with the window never changes, even
3352 // if the app navigates off scope. This is not a problem because we still
3353 // want to use the scope of the app associated with the window, not the
3354 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433355 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233356 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593357 browser->app_controller()->HasAppId()) {
3358 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3359 const web_app::AppRegistrar& registrar =
3360 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3361 if (registrar.IsLocallyInstalled(app_id))
3362 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433363 }
Mounir Lamouri6926107f2019-01-31 18:17:433364 }
3365#endif
3366
Ian Vollick6243dfe02018-03-08 01:08:533367 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113368 }
zqzhang93e959d12017-03-16 13:10:203369
rajendrant0521cee2019-07-29 06:09:263370 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3371 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003372
Scott Little878f7d6702018-05-31 22:09:063373 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3374 const char* param_name =
3375 web_prefs->data_saver_enabled
3376 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3377 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3378 "saver_enabled";
3379
3380 base::StringPairs pairs;
3381 base::SplitStringIntoKeyValuePairs(
3382 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3383 param_name),
3384 ':', ',', &pairs);
3385
3386 for (const auto& pair : pairs) {
3387 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3388 net::GetEffectiveConnectionTypeForName(pair.first);
3389 int value = 0;
3390 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3391 web_prefs->lazy_frame_loading_distance_thresholds_px
3392 [effective_connection_type.value()] = value;
3393 }
3394 }
3395 }
3396
rajendrantd8026342018-08-29 08:08:393397 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3398 const char* param_name =
3399 web_prefs->data_saver_enabled
3400 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3401 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3402 "saver_enabled";
3403
3404 base::StringPairs pairs;
3405 base::SplitStringIntoKeyValuePairs(
3406 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3407 param_name),
3408 ':', ',', &pairs);
3409
3410 for (const auto& pair : pairs) {
3411 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3412 net::GetEffectiveConnectionTypeForName(pair.first);
3413 int value = 0;
3414 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3415 web_prefs->lazy_image_loading_distance_thresholds_px
3416 [effective_connection_type.value()] = value;
3417 }
3418 }
rajendrant3daeae292019-09-20 07:57:543419
3420 pairs.clear();
3421 base::SplitStringIntoKeyValuePairs(
3422 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3423 "lazy_image_first_k_fully_load"),
3424 ':', ',', &pairs);
3425
3426 for (const auto& pair : pairs) {
3427 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3428 net::GetEffectiveConnectionTypeForName(pair.first);
3429 int value = 0;
3430 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3431 web_prefs
3432 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3433 value;
3434 }
3435 }
rajendrantd8026342018-08-29 08:08:393436 }
3437
Tarun Bansald10f17a02018-09-13 00:23:173438 if (base::FeatureList::IsEnabled(
3439 features::kNetworkQualityEstimatorWebHoldback)) {
3440 std::string effective_connection_type_param =
3441 base::GetFieldTrialParamValueByFeature(
3442 features::kNetworkQualityEstimatorWebHoldback,
3443 "web_effective_connection_type_override");
3444
3445 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3446 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3447 DCHECK(effective_connection_type_param.empty() ||
3448 effective_connection_type);
3449 if (effective_connection_type) {
3450 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3451 effective_connection_type.value());
3452 web_prefs->network_quality_estimator_web_holdback =
3453 effective_connection_type.value();
3454 }
3455 }
3456
François Beaufort4f8107d2018-03-05 12:12:103457#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563458 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593459 // If autoplay is allowed by policy then force the no user gesture required
3460 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103461 web_prefs->autoplay_policy =
Gyuyoung Kim1ac4ca782020-09-11 03:32:513462 blink::web_pref::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553463 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593464 web_prefs->autoplay_policy ==
Gyuyoung Kim1ac4ca782020-09-11 03:32:513465 blink::web_pref::AutoplayPolicy::
3466 kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553467 // If the autoplay disable settings feature is enabled and the autoplay
3468 // policy is set to using the unified policy then set the default autoplay
3469 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593470 web_prefs->autoplay_policy =
3471 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
Gyuyoung Kim1ac4ca782020-09-11 03:32:513472 ? blink::web_pref::AutoplayPolicy::kDocumentUserActivationRequired
3473 : blink::web_pref::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103474 }
Alison Maher7f366dc62020-03-03 19:46:003475
Abigail Kleina81f2e22020-05-04 14:32:413476 auto* native_theme = GetWebTheme();
Alison Maher7f366dc62020-03-03 19:46:003477 switch (native_theme->GetPreferredColorScheme()) {
3478 case ui::NativeTheme::PreferredColorScheme::kDark:
3479 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3480 break;
3481 case ui::NativeTheme::PreferredColorScheme::kLight:
3482 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3483 break;
Alison Maher7f366dc62020-03-03 19:46:003484 }
François Beaufort4f8107d2018-03-05 12:12:103485#endif // !defined(OS_ANDROID)
3486
Rakina Zata Amni347b70902020-07-22 10:49:043487 UpdatePreferredColorSchemesBasedOnURLIfNeeded(
3488 web_prefs, rvh->GetSiteInstance()->GetSiteURL());
Elly Fong-Jonesf92897392019-01-24 16:05:493489
Rakina Zata Amni347b70902020-07-22 10:49:043490 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Alison Maher7f366dc62020-03-03 19:46:003491
Abigail Kleina81f2e22020-05-04 14:32:413492 base::Optional<ui::CaptionStyle> style =
3493 captions::GetCaptionStyleFromUserSettings(prefs,
3494 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213495 if (style) {
3496 web_prefs->text_track_background_color = style->background_color;
3497 web_prefs->text_track_text_color = style->text_color;
3498 web_prefs->text_track_text_size = style->text_size;
3499 web_prefs->text_track_text_shadow = style->text_shadow;
3500 web_prefs->text_track_font_family = style->font_family;
3501 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563502 web_prefs->text_track_window_color = style->window_color;
3503 web_prefs->text_track_window_padding = style->window_padding;
3504 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213505 }
Elly Fong-Jonesf92897392019-01-24 16:05:493506
[email protected]a48ab7112014-08-01 16:48:033507 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503508 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363509}
3510
Rakina Zata Amni347b70902020-07-22 10:49:043511bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation(
3512 WebContents* web_contents,
3513 WebPreferences* prefs) {
3514 return UpdatePreferredColorSchemesBasedOnURLIfNeeded(
3515 prefs, web_contents->GetLastCommittedURL());
3516}
3517
[email protected]b8148ac2011-07-13 22:03:253518void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3519 BrowserURLHandler* handler) {
Nicolas Ouellet-Payeur5e6d2102020-08-21 16:28:413520 // The group policy NTP URL handler must be registered before the other NTP
3521 // URL handlers below. Also register it before the "parts" handlers, so the
3522 // NTP policy takes precedence over extensions that override the NTP.
3523 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3524 BrowserURLHandler::null_handler());
3525
[email protected]a48ab7112014-08-01 16:48:033526 for (size_t i = 0; i < extra_parts_.size(); ++i)
3527 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253528
[email protected]b3adbd02011-11-30 22:23:273529 // about: handler. Must come before chrome: handler, since it will
3530 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053531 // actually handle them. Also relies on a preliminary fixup phase.
3532 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253533 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3534 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033535
zpengdb4a58e2017-01-10 17:40:323536#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033537 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353538 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033539 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453540#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033541 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133542 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3543 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453544#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033545
[email protected]b8148ac2011-07-13 22:03:253546 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313547 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3548 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253549}
3550
[email protected]650b2d52013-02-10 03:41:453551base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493552 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323553}
3554
[email protected]c9b6eb62011-10-18 20:49:393555std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3556 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3557}
3558
Dominik Röttsches47347832019-03-12 17:45:013559base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3560 base::FilePath user_data_dir;
3561 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3562 DCHECK(!user_data_dir.empty());
3563 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3564}
3565
jmadill57b52d42015-08-21 18:16:133566base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3567 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523568 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133569 DCHECK(!user_data_dir.empty());
3570 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3571}
3572
Khushal7ca0b782018-07-20 05:53:273573base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3574 base::FilePath user_data_dir;
3575 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3576 DCHECK(!user_data_dir.empty());
3577 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3578}
3579
[email protected]b7631cc2012-09-15 05:08:383580void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3581 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163582#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553583 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543584#endif
[email protected]b7631cc2012-09-15 05:08:383585}
3586
[email protected]0c7193742012-11-07 19:05:033587content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443588ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173589#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553590 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033591 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443592 nacl::NaClProcessHost* host =
3593 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3594 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033595 // Found the plugin.
3596 return host->browser_ppapi_host();
3597 }
3598 ++iter;
3599 }
[email protected]a56f8322014-07-16 21:13:553600#endif
Aran Gilmanf010bdd2019-08-28 19:55:443601 return nullptr;
[email protected]0c7193742012-11-07 19:05:033602}
3603
[email protected]38cd8f7f2012-06-15 22:06:073604bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583605 content::BrowserContext* browser_context,
3606 const GURL& url,
[email protected]dda54822013-06-15 01:26:393607 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123608 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163609#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553610 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193611 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403612#else
[email protected]a658d452012-03-02 12:45:293613 return false;
[email protected]93f72062013-05-29 20:29:403614#endif
[email protected]e461da2f2012-02-16 19:06:403615}
3616
adrian.belgund54465ba2016-05-18 10:03:583617bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3618 content::BrowserContext* browser_context,
3619 const GURL& url) {
brettw4b461082016-11-19 18:55:163620#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583621 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3622 browser_context, url);
3623#else
3624 return false;
3625#endif
3626}
3627
adrian.belgun5b341c72016-06-22 22:24:083628std::unique_ptr<content::VpnServiceProxy>
3629ChromeContentBrowserClient::GetVpnServiceProxy(
3630 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173631#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083632 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3633 browser_context);
3634#else
3635 return nullptr;
3636#endif
3637}
3638
Brett Wilson804e83c2017-08-18 22:57:333639std::unique_ptr<ui::SelectFilePolicy>
3640ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3641 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433642}
3643
[email protected]7d9424702013-04-14 13:14:163644void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3645 std::vector<std::string>* additional_allowed_schemes) {
3646 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3647 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483648 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293649 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033650 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3651 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3652 additional_allowed_schemes);
3653 }
[email protected]7d9424702013-04-14 13:14:163654}
3655
Ayu Ishiifbb1fad2020-06-22 20:15:073656void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist(
falkenad185092016-06-16 06:10:023657 std::set<std::string>* schemes) {
Ayu Ishiifbb1fad2020-06-22 20:15:073658 *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023659}
3660
[email protected]c79859b82014-03-20 22:43:553661void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313662 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033663 for (size_t i = 0; i < extra_parts_.size(); ++i)
3664 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553665}
3666
[email protected]f19bbf62013-07-09 01:22:323667void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313668 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533669 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003670 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3671 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313672#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313673 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313674 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313675 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093676 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093677 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3678 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473679 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093680 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3681 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053682 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3683 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343684 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3685 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473686 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323687 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313688 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003689 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313690#endif
[email protected]445b7db2013-08-02 04:58:273691
[email protected]a48ab7112014-08-01 16:48:033692 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3693 extra_parts_[i]->GetAdditionalFileSystemBackends(
3694 browser_context, storage_partition_path, additional_backends);
3695 }
[email protected]02250952013-04-24 23:52:533696}
3697
Avi Drissman2e458df2020-07-29 16:24:313698#if defined(OS_POSIX) && !defined(OS_MAC)
[email protected]a1733df2012-06-22 11:24:183699void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173700 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383701 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203702 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123703#if defined(OS_ANDROID)
3704 base::MemoryMappedFile::Region region;
3705 int fd = ui::GetMainAndroidPackFd(&region);
3706 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003707
Samuel Huang31eadf082019-08-28 19:50:433708 // For Android: Native resources for DFMs should only be used by the browser
3709 // process. Their file descriptors and memory mapped file regions are not
3710 // passed to child processes.
3711
jcivellie6f550742017-01-06 19:29:123712 fd = ui::GetCommonResourcesPackFd(&region);
3713 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393714
jcivellie6f550742017-01-06 19:29:123715 fd = ui::GetLocalePackFd(&region);
3716 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383717
zpeng368afac82017-07-17 18:47:453718 // Optional secondary locale .pak file.
3719 fd = ui::GetSecondaryLocalePackFd(&region);
3720 if (fd != -1) {
3721 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3722 }
3723
[email protected]09560f7f2014-06-10 18:40:283724 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523725 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283726 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023727#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383728 int crash_signal_fd = GetCrashSignalFD(command_line);
3729 if (crash_signal_fd >= 0) {
Ken Rockot69fbb962020-09-21 22:22:033730 mappings->Share(kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383731 }
jcivellie6f550742017-01-06 19:29:123732}
Avi Drissman2e458df2020-07-29 16:24:313733#endif // defined(OS_POSIX) && !defined(OS_MAC)
[email protected]b80f68432011-05-02 17:22:303734
[email protected]4a65826d2011-08-25 16:04:013735#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033736base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Robert Sesek7d0b49b2020-07-08 18:31:273737 sandbox::policy::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033738 // TODO(wfh): Add support for more process types here. crbug.com/499523
3739 switch (sandbox_type) {
Robert Sesek7d0b49b2020-07-08 18:31:273740 case sandbox::policy::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363741 return base::string16(install_static::GetSandboxSidPrefix()) +
3742 L"129201922";
Robert Sesek7d0b49b2020-07-08 18:31:273743 case sandbox::policy::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033744 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273745 case sandbox::policy::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033746 return base::string16();
Robert Sesek7d0b49b2020-07-08 18:31:273747 case sandbox::policy::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363748 return base::string16(install_static::GetSandboxSidPrefix()) +
3749 L"129201925";
Robert Sesek7d0b49b2020-07-08 18:31:273750 case sandbox::policy::SandboxType::kNoSandbox:
3751 case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges:
3752 case sandbox::policy::SandboxType::kXrCompositing:
3753 case sandbox::policy::SandboxType::kNetwork:
3754 case sandbox::policy::SandboxType::kCdm:
3755 case sandbox::policy::SandboxType::kPrintCompositor:
3756 case sandbox::policy::SandboxType::kAudio:
3757 case sandbox::policy::SandboxType::kSpeechRecognition:
3758 case sandbox::policy::SandboxType::kProxyResolver:
3759 case sandbox::policy::SandboxType::kPdfConversion:
3760 case sandbox::policy::SandboxType::kSharingService:
3761 case sandbox::policy::SandboxType::kVideoCapture:
3762 case sandbox::policy::SandboxType::kIconReader:
Frank Li49bb6912020-09-30 18:05:523763 case sandbox::policy::SandboxType::kMediaFoundationCdm:
Alex Gough9ab468a6c32019-12-10 19:10:223764 // Should never reach here.
3765 CHECK(0);
wfh182da09c2015-06-24 19:23:033766 return base::string16();
wfh182da09c2015-06-24 19:23:033767 }
wfh182da09c2015-06-24 19:23:033768}
3769
Will Harris956e0ca2019-08-23 20:47:393770bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3771 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503772// Does not work under component build because all the component DLLs would need
3773// to be manually added and maintained. Does not work under ASAN build because
3774// ASAN has not yet fully initialized its instrumentation by the time the CIG
3775// intercepts run.
3776#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393777 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3778 return true;
Will Harrisc196ed942019-08-03 03:45:303779 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3780 return true;
3781
3782 // Only enable signing mitigation if launching from chrome.exe.
3783 base::FilePath exe_path;
3784 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3785 return true;
3786 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3787 return true;
3788
3789 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3790 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093791 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303792 if (result != sandbox::SBOX_ALL_OK)
3793 return false;
3794
Nico Weberc36b0152020-04-18 03:12:463795 // Allow loading Chrome's DLLs.
3796 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303797 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3798 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3799 GetModulePath(dll).value().c_str());
3800 if (result != sandbox::SBOX_ALL_OK)
3801 return false;
3802 }
Will Harris1b9b4152019-08-21 22:33:503803#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303804
3805 return true;
[email protected]34f48682013-03-20 00:30:183806}
Will Harris956e0ca2019-08-23 20:47:393807
3808bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3809 PrefService* local_state = g_browser_process->local_state();
3810 if (local_state &&
3811 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3812 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3813 return false;
3814 return true;
3815}
3816
wfhc91e9672016-01-27 00:14:203817#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013818
Armando Miraglia3a7be232019-11-08 00:33:323819
Ken Rockotfa5d57112019-05-29 20:57:143820void ChromeContentBrowserClient::WillStartServiceManager() {
Avi Drissman2e458df2020-07-29 16:24:313821#if defined(OS_WIN) || defined(OS_MAC) || \
Guido Urdanetad06ae842019-10-10 20:04:123822 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053823 if (startup_data_) {
3824 auto* chrome_feature_list_creator =
3825 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183826 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123827 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053828 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183829 ->GetPolicyService()
3830 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123831 std::string()));
Guido Urdanetae02b5722020-07-22 05:58:213832 const base::Value* audio_sandbox_enabled_policy_value =
3833 policies.GetValue(policy::key::kAudioSandboxEnabled);
3834 if (audio_sandbox_enabled_policy_value) {
3835 bool force_enable_audio_sandbox;
3836 audio_sandbox_enabled_policy_value->GetAsBoolean(
3837 &force_enable_audio_sandbox);
3838 SetForceAudioServiceSandboxed(force_enable_audio_sandbox);
3839 }
John Abd-El-Malek27b3ebd22019-02-12 18:59:183840 }
3841#endif
xhwang5e630462015-10-30 03:18:483842}
3843
peterbbcccc12015-02-11 22:23:333844void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373845 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333846 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293847 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083848 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373849
3850 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083851
zpengdb4a58e2017-01-10 17:40:323852#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223853 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293854 std::move(callback));
jam1c5a91492016-02-24 20:47:533855#else
cm.sanchi2522bc92017-12-04 08:04:133856 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3857 params.url, params.transition);
3858 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083859
3860 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293861 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333862#endif
mlamourieb40d552015-02-05 00:57:083863}
3864
zhaobinf3704f82017-01-12 07:19:363865content::ControllerPresentationServiceDelegate*
3866ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3867 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463868 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093869 return media_router::PresentationServiceDelegateImpl::
3870 GetOrCreateForWebContents(web_contents);
3871 }
haibinlu9e605a92015-06-06 03:45:093872 return nullptr;
3873}
3874
zhaobinf3704f82017-01-12 07:19:363875content::ReceiverPresentationServiceDelegate*
3876ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3877 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363878 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3879 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3880 // created for offscreen presentations. The WebContents must belong to
3881 // an incognito profile.
3882 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3883 FromWebContents(web_contents)) {
3884 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3885 return impl;
3886 }
3887 }
zhaobinf3704f82017-01-12 07:19:363888 return nullptr;
3889}
3890
avid6d88b912017-01-13 00:16:003891std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473892ChromeContentBrowserClient::CreateThrottlesForNavigation(
3893 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003894 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273895
bmcquadeb4556552017-03-24 22:24:373896 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3897 // that may delay or cancel navigations, so only NavigationThrottles that
3898 // don't delay or cancel navigations (e.g. throttles that are only observing
3899 // callbacks without affecting navigation behavior) should be added before
3900 // MetricsNavigationThrottle.
3901 if (handle->IsInMainFrame()) {
3902 throttles.push_back(
3903 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3904 }
3905
brettw4b461082016-11-19 18:55:163906#if BUILDFLAG(ENABLE_PLUGINS)
Chris Hamiltonab4722122020-05-13 18:01:283907 MaybeAddThrottle(FlashDownloadInterception::MaybeCreateThrottleFor(handle),
3908 &throttles);
trizzofo8ddaeb72016-09-01 23:18:273909#endif
3910
yilkal240b4f22019-11-27 19:09:063911#if defined(OS_CHROMEOS)
3912 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283913 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3914 &throttles);
yilkal240b4f22019-11-27 19:09:063915#endif // defined(OS_CHROMEOS)
3916
mmenkedb2637ff2017-03-30 23:59:423917#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213918 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283919 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
3920 &throttles);
mmenkedb2637ff2017-03-30 23:59:423921#endif
3922
clamy40c9e142015-09-29 11:18:473923#if defined(OS_ANDROID)
3924 // TODO(davidben): This is insufficient to integrate with prerender properly.
3925 // https://crbug.com/370595
3926 prerender::PrerenderContents* prerender_contents =
Mugdha Lakhani2c6b23af2020-07-31 14:55:573927 prerender::ChromePrerenderContentsDelegate::FromWebContents(
3928 handle->GetWebContents());
clamy40c9e142015-09-29 11:18:473929 if (!prerender_contents && handle->IsInMainFrame()) {
3930 throttles.push_back(
3931 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303932 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473933 }
Min Qin0ab0e162017-11-14 21:57:193934 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043935
3936#if BUILDFLAG(DFMIFY_DEV_UI)
3937 // If the DevUI DFM is already installed, then this is a no-op, except for the
3938 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:283939 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
3940 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:043941#endif // BUILDFLAG(DFMIFY_DEV_UI)
3942
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573943#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473944 if (handle->IsInMainFrame()) {
3945 // Redirect some navigations to apps that have registered matching URL
3946 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:283947 MaybeAddThrottle(
3948 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
3949 &throttles);
clamy40c9e142015-09-29 11:18:473950 }
3951#endif
clamy49678312015-10-22 21:59:003952
3953#if defined(OS_CHROMEOS)
3954 // Check if we need to add merge session throttle. This throttle will postpone
3955 // loading of main frames.
3956 if (handle->IsInMainFrame()) {
3957 // Add interstitial page while merge session process (cookie reconstruction
3958 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3959 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023960 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3961 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003962 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3963 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3964 }
Maggie Caia2f03f52019-04-02 02:13:283965 }
3966#endif
djacobo21e56e02016-07-02 01:14:313967
Maggie Caia2f03f52019-04-02 02:13:283968#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:103969 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283970#if defined(OS_CHROMEOS)
Maggie Caic08b7d42020-05-05 03:51:103971 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3972 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3973 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissman2e458df2020-07-29 16:24:313974#elif defined(OS_MAC)
Maggie Caic08b7d42020-05-05 03:51:103975 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283976#else
Maggie Caic08b7d42020-05-05 03:51:103977 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283978#endif
Maggie Caic08b7d42020-05-05 03:51:103979 if (url_to_apps_throttle)
3980 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003981#endif
3982
brettw00899e62016-11-12 02:10:173983#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003984 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093985 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513986
Chris Hamiltonab4722122020-05-13 18:01:283987 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
3988 ->GetUserScriptListener()
3989 ->CreateNavigationThrottle(handle),
3990 &throttles);
naskob9164c42016-06-07 01:21:353991#endif
3992
bauerb8f9c37742017-03-30 15:04:123993#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213994 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283995 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
3996 &throttles);
bauerb8f9c37742017-03-30 15:04:123997#endif
3998
csharrisone985ebc2017-04-04 17:05:033999 content::WebContents* web_contents = handle->GetWebContents();
Colin Blundell0ec5d642020-10-06 17:29:524000 if (auto* throttle_manager =
4001 subresource_filter::ContentSubresourceFilterThrottleManager::
4002 FromWebContents(web_contents)) {
4003 throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles);
csharrisone985ebc2017-04-04 17:05:034004 }
4005
zhenw6edd49c2017-07-12 05:49:454006#if !defined(OS_ANDROID)
4007 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4008 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:284009 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
4010 MaybeCreateThrottleFor(handle),
4011 &throttles);
zhenw6edd49c2017-07-12 05:49:454012#endif
4013
Bettinafd0c1102020-08-06 00:23:434014#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Chris Hamiltonab4722122020-05-13 18:01:284015 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
4016 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:094017#endif
4018
Lukasz Anforowicz7724d092019-10-03 23:50:214019 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284020 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
4021 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:274022
Chris Hamiltonab4722122020-05-13 18:01:284023 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
4024 &throttles);
Amber Won6b5edc752017-08-17 19:23:544025
Chris Hamiltonab4722122020-05-13 18:01:284026 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:514027
Jonathan Mengedoht42a19bb2020-07-28 14:10:164028 MaybeAddThrottle(
4029 WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
4030 &throttles);
4031
Aaron Colwellf94fd97a2020-07-21 19:37:084032 throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534033 handle, handle->GetWebContents()->GetBrowserContext()));
4034
Colin Blundelleaa7377bf2020-01-22 08:49:104035 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
4036 // the relevant extension API whenever an SSL interstitial is shown.
4037 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
4038 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:284039 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4040 handle,
4041 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:384042 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:124043
Emily Starkd6896cd32019-08-21 04:55:544044 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4045
Dmitry Gozman57b92ce2017-12-28 22:24:544046#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284047 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4048 &throttles);
4049
4050 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4051 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544052#endif
4053
Carlos IL800e3502020-04-30 16:35:594054 throttles.push_back(
4055 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034056
Mustafa Emre Acer97be4752020-05-13 01:24:434057 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4058 throttles.push_back(
4059 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4060 handle));
4061 }
4062
Avi Drissman2e458df2020-07-29 16:24:314063#if defined(OS_WIN) || defined(OS_MAC) || \
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334064 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Chris Hamiltonab4722122020-05-13 18:01:284065 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4066 MaybeCreateThrottleFor(handle),
4067 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134068#endif
4069
Anatoliy Potapchuk762c40d2020-05-11 15:10:374070#if defined(OS_CHROMEOS)
4071 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284072 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
4073 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374074#endif
4075
Chris Hamiltonab4722122020-05-13 18:01:284076 auto* performance_manager_registry =
4077 performance_manager::PerformanceManagerRegistry::GetInstance();
4078 if (performance_manager_registry) {
4079 MaybeAddThrottles(
4080 performance_manager_registry->CreateThrottlesForNavigation(handle),
4081 &throttles);
4082 }
4083
Carlos IL06e6c8c2020-07-28 00:25:194084 Profile* profile = Profile::FromBrowserContext(
4085 handle->GetWebContents()->GetBrowserContext());
4086 if (profile && profile->GetPrefs()) {
4087 MaybeAddThrottle(
4088 security_interstitials::InsecureFormNavigationThrottle::
4089 MaybeCreateNavigationThrottle(
4090 handle, std::make_unique<ChromeSecurityBlockingPageFactory>(),
4091 profile->GetPrefs()),
4092 &throttles);
4093 }
Carlos IL1a5edec2020-06-12 17:56:574094
Ken Rockot4408a0f2020-07-27 19:40:544095 if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) {
4096 MaybeAddThrottle(
4097 error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle),
4098 &throttles);
4099 }
4100
dchenge73d8520c2015-12-27 01:19:094101 return throttles;
clamy40c9e142015-09-29 11:18:474102}
4103
clamy1e5574e2016-09-29 16:48:444104std::unique_ptr<content::NavigationUIData>
4105ChromeContentBrowserClient::GetNavigationUIData(
4106 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094107 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444108}
4109
Xiaohan Wanga4e41842018-06-26 18:45:104110void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4111 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104112 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124113 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104114#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264115 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104116 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334117 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104118 }
4119#endif
4120}
4121
[email protected]487974a2014-06-13 16:49:014122content::DevToolsManagerDelegate*
4123ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354124#if defined(OS_ANDROID)
4125 return new DevToolsManagerDelegateAndroid();
4126#else
[email protected]487974a2014-06-13 16:49:014127 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354128#endif
[email protected]487974a2014-06-13 16:49:014129}
4130
Rayan Kanso411e84e2019-02-13 15:27:404131void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4132 content::BrowserContext* browser_context,
4133 int service,
4134 base::Time expiration_time) {
4135 Profile* profile = Profile::FromBrowserContext(browser_context);
4136 DCHECK(profile);
4137
4138 auto* pref_service = profile->GetPrefs();
4139 DCHECK(pref_service);
4140
4141 DictionaryPrefUpdate pref_update(
4142 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4143 base::DictionaryValue* exp_dict = pref_update.Get();
4144
4145 // Convert |expiration_time| to minutes since that is the most granular
4146 // option that returns an int. base::Value does not accept int64.
4147 int expiration_time_minutes =
4148 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4149 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4150}
4151
4152base::flat_map<int, base::Time>
4153ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4154 content::BrowserContext* browser_context) {
4155 Profile* profile = Profile::FromBrowserContext(browser_context);
4156 DCHECK(profile);
4157
4158 auto* pref_service = profile->GetPrefs();
4159 DCHECK(pref_service);
4160
4161 auto* expiration_dict = pref_service->GetDictionary(
4162 prefs::kDevToolsBackgroundServicesExpirationDict);
4163 DCHECK(expiration_dict);
4164
4165 base::flat_map<int, base::Time> expiration_times;
4166 for (const auto& it : *expiration_dict) {
4167 // key.
4168 int service = 0;
4169 bool did_convert = base::StringToInt(it.first, &service);
4170 DCHECK(did_convert);
4171
4172 // value.
4173 DCHECK(it.second->is_int());
4174 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4175 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4176
4177 expiration_times[service] = expiration_time;
4178 }
4179
4180 return expiration_times;
4181}
4182
oysteinec563c582015-02-13 19:19:524183content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524184 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524185}
4186
[email protected]a6868c22013-10-09 02:50:294187bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4188 content::BrowserContext* browser_context,
4189 const GURL& url) {
brettw4b461082016-11-19 18:55:164190#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554191 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194192 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294193#else
4194 return false;
4195#endif
4196}
4197
[email protected]aec5ed52014-06-20 07:51:424198bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4199 content::BrowserContext* browser_context,
4200 const GURL& url) {
brettw4b461082016-11-19 18:55:164201#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554202 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194203 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064204#else
4205 return false;
4206#endif
4207}
4208
mlamourif8c23a2002015-01-27 13:10:104209void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014210 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434211 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524212 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104213
4214 WebContents* web_contents =
4215 WebContents::FromRenderFrameHost(render_frame_host);
4216 DCHECK(web_contents);
4217
mlamourif8c23a2002015-01-27 13:10:104218 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374219 prerender::PrerenderManagerFactory::GetForBrowserContext(
4220 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104221 if (prerender_manager &&
Hiroki Nakagawaee49bcd2020-09-09 23:09:084222 prerender_manager->IsWebContentsPrerendering(web_contents)) {
Collin Baker98457b52019-11-06 21:34:294223 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104224 }
4225}
4226
Robert Sesek466e43e2019-08-19 22:02:024227void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4228 base::FilePath user_data_dir;
4229 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4230 DCHECK(!user_data_dir.empty());
4231 network_contexts_parent_directory_.push_back(user_data_dir);
4232
4233 base::FilePath cache_dir;
4234 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4235 DCHECK(!cache_dir.empty());
4236 // On some platforms, the cache is a child of the user_data_dir so only
4237 // return the one path.
4238 if (!user_data_dir.IsParent(cache_dir))
4239 network_contexts_parent_directory_.push_back(cache_dir);
4240
4241 // If the cache location has been overridden by a switch or preference,
4242 // include that as well.
4243 if (auto* local_state = g_browser_process->local_state()) {
4244 base::FilePath pref_cache_dir =
4245 local_state->GetFilePath(prefs::kDiskCacheDir);
4246 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4247 network_contexts_parent_directory_.push_back(pref_cache_dir);
4248 }
4249}
4250
[email protected]30335fdf02014-02-26 19:51:274251void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174252 base::CommandLine* to_command_line,
4253 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544254 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274255#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544256 const version_info::Channel kMaxDisableEncryptionChannel =
4257 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274258#else
sdefresne6e883e42015-07-30 08:05:544259 const version_info::Channel kMaxDisableEncryptionChannel =
4260 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274261#endif
4262 if (channel <= kMaxDisableEncryptionChannel) {
4263 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444264 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274265 };
Avi Drissmand251e912018-12-26 15:46:374266 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4267 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274268 }
4269}
bashi933629552016-10-13 23:32:404270
miu54dca6c2016-11-17 10:59:384271#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4272void ChromeContentBrowserClient::CreateMediaRemoter(
4273 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504274 mojo::PendingRemote<media::mojom::RemotingSource> source,
4275 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384276 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504277 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384278}
4279#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464280
Michael Giuffrida6802ffe2017-09-29 03:40:254281base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4282 const base::CommandLine& command_line) {
4283 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164284}
4285
John Abd-El-Malek8efa11f2019-01-06 00:51:534286namespace {
4287// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024288class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534289 public:
4290 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174291 ProtocolHandlerRegistry* protocol_handler_registry)
Matt Falkenhagen7811fd42020-06-24 22:42:414292 : protocol_handler_registry_(protocol_handler_registry) {
4293 DCHECK(protocol_handler_registry);
4294 }
John Abd-El-Malek8efa11f2019-01-06 00:51:534295 ~ProtocolHandlerThrottle() override = default;
4296
4297 void WillStartRequest(network::ResourceRequest* request,
4298 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294299 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534300 }
4301
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584302 void WillRedirectRequest(
4303 net::RedirectInfo* redirect_info,
4304 const network::mojom::URLResponseHead& response_head,
4305 bool* defer,
4306 std::vector<std::string>* to_be_removed_headers,
4307 net::HttpRequestHeaders* modified_headers,
4308 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294309 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534310 }
4311
4312 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294313 void TranslateUrl(GURL* url) {
4314 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4315 return;
4316 GURL translated_url = protocol_handler_registry_->Translate(*url);
4317 if (!translated_url.is_empty())
4318 *url = translated_url;
4319 }
4320
Clark DuValla411bda2019-08-02 03:09:174321 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534322};
4323} // namespace
4324
Minggang Wangf6840ecf2019-07-29 05:15:024325std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194326ChromeContentBrowserClient::CreateURLLoaderThrottles(
4327 const network::ResourceRequest& request,
4328 content::BrowserContext* browser_context,
4329 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4330 content::NavigationUIData* navigation_ui_data,
4331 int frame_tree_node_id) {
4332 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4333
Minggang Wangf6840ecf2019-07-29 05:15:024334 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194335
Matt Falkenhagen7811fd42020-06-24 22:42:414336 DCHECK(browser_context);
Clark DuVallfffa41e2019-06-25 20:27:194337 Profile* profile = Profile::FromBrowserContext(browser_context);
Matt Falkenhagen7811fd42020-06-24 22:42:414338 DCHECK(profile);
Clark DuVallfffa41e2019-06-25 20:27:194339
4340 ChromeNavigationUIData* chrome_navigation_ui_data =
4341 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4342
Bettinafd0c1102020-08-06 00:23:434343#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
Clark DuVall5497288d2019-07-17 00:17:564344 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4345 request.url, *profile->GetPrefs());
4346 if (!matches_enterprise_whitelist) {
Xinghui Lucf23c902020-06-10 17:38:254347 bool is_enterprise_lookup_enabled =
Xinghui Luf45d7ef72020-06-09 02:16:384348#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
Xinghui Lucf23c902020-06-10 17:38:254349 safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
Zach Trudocc4aa4d2020-09-21 22:19:454350 profile->GetPrefs(), policy::GetDMToken(profile).is_valid(),
Xinghui Lucf23c902020-06-10 17:38:254351 profile->IsOffTheRecord());
4352#else
4353 false;
Xinghui Luf45d7ef72020-06-09 02:16:384354#endif
Xinghui Lucf23c902020-06-10 17:38:254355 bool is_consumer_lookup_enabled =
Xinghui Luf45d7ef72020-06-09 02:16:384356 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
4357 profile->GetPrefs(), profile->IsOffTheRecord(),
Xinghui Lucf23c902020-06-10 17:38:254358 g_browser_process->variations_service());
4359
4360 // |url_lookup_service| is used when real time url check is enabled.
4361 safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service =
4362 GetUrlLookupService(browser_context, is_enterprise_lookup_enabled,
4363 is_consumer_lookup_enabled);
Clark DuVall5497288d2019-07-17 00:17:564364 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4365 base::BindOnce(
4366 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534367 base::Unretained(this),
Xinghui Lucf23c902020-06-10 17:38:254368 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()),
4369 // Should check for enterprise when safe browsing is disabled.
4370 /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled),
Xinghui Lua142c102020-03-02 20:50:084371 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584372 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564373 }
Nico Weberbc5b06f2019-07-26 14:00:134374#endif
Clark DuVall5497288d2019-07-17 00:17:564375
dalykba7bbfc2019-12-18 19:59:214376#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4377 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014378 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4379 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214380#endif
4381
Clark DuVallfffa41e2019-06-25 20:27:194382 if (chrome_navigation_ui_data &&
Miyoung Shinf53c2e792020-06-19 03:20:254383 chrome_navigation_ui_data->prerender_mode() !=
4384 prerender::mojom::PrerenderMode::kNoPrerender) {
Clark DuVallfffa41e2019-06-25 20:27:194385 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4386 chrome_navigation_ui_data->prerender_mode(),
4387 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234388 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194389 }
4390
John Abd-El-Malek4f380d92020-02-19 16:43:364391#if defined(OS_ANDROID)
4392 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234393 bool night_mode_enabled = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374394 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4395 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364396 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4397 if (web_contents) {
4398 auto* client_data_header_observer =
4399 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4400 web_contents);
4401 if (client_data_header_observer)
4402 client_data_header = client_data_header_observer->header();
Brandon Wylie21a88ac92020-05-15 02:49:234403
Brandon Wylief6bfdab2020-08-12 21:49:364404 auto* delegate =
4405 TabAndroid::FromWebContents(web_contents)
4406 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4407 web_contents->GetDelegate())
4408 : nullptr;
4409 if (delegate)
4410 night_mode_enabled = delegate->IsNightModeEnabled();
Brandon Wylie21a88ac92020-05-15 02:49:234411 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374412 }
John Abd-El-Malek4f380d92020-02-19 16:43:364413#endif
4414
Clark DuVallfffa41e2019-06-25 20:27:194415 chrome::mojom::DynamicParams dynamic_params = {
4416 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4417 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274418 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4419 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364420#if defined(OS_ANDROID)
Brandon Wylie21a88ac92020-05-15 02:49:234421 client_data_header, night_mode_enabled,
John Abd-El-Malek4f380d92020-02-19 16:43:364422#endif
Alex Clarke3ebd9772020-02-28 10:50:274423 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194424
Matt Falkenhagen7811fd42020-06-24 22:42:414425 {
4426 auto* factory =
4427 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context);
4428 // null in unit tests.
4429 if (factory)
4430 result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory));
4431 }
Clark DuVall8512cee62019-06-26 01:14:214432
Clark DuVall39c2cfc2019-06-25 21:49:284433#if BUILDFLAG(ENABLE_PLUGINS)
4434 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464435 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284436#endif
4437
Robbie McElrath127ad2b2019-07-22 22:38:114438 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404439 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584440 auto signin_throttle =
4441 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114442 if (signin_throttle)
4443 result.push_back(std::move(signin_throttle));
4444
Clark DuVallfffa41e2019-06-25 20:27:194445 return result;
4446}
4447
Ken Rockot6414c4d92017-11-08 19:58:324448void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464449 int frame_tree_node_id,
Maks Orlovich5408ddfc2020-07-28 23:07:354450 base::UkmSourceId ukm_source_id,
Ken Rockot6414c4d92017-11-08 19:58:324451 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414452#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464453 content::WebContents* web_contents =
4454 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414455#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174456 factories->emplace(
Ken Rockot6414c4d92017-11-08 19:58:324457 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574458 extensions::CreateExtensionNavigationURLLoaderFactory(
Maks Orlovich5408ddfc2020-07-28 23:07:354459 web_contents->GetBrowserContext(), ukm_source_id,
John Abd-El-Malekea006302018-05-10 05:50:464460 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414461#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4462#if defined(OS_CHROMEOS)
4463 Profile* profile =
4464 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354465 factories->emplace(content::kExternalFileScheme,
4466 chromeos::ExternalFileURLLoaderFactory::Create(
4467 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414468#endif // defined(OS_CHROMEOS)
4469#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324470}
4471
Ting Shao2dc60582019-07-15 04:43:364472void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344473 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4474 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174475 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawa1efa31d2019-10-01 22:36:344476 DCHECK(browser_context);
4477 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174478
4479#if BUILDFLAG(ENABLE_EXTENSIONS)
Hiroki Nakagawa1efa31d2019-10-01 22:36:344480 factories->emplace(
4481 extensions::kExtensionScheme,
4482 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4483 browser_context));
4484#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4485}
4486
4487void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364488 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4489 content::BrowserContext* browser_context,
Lukasz Anforowicza782c5a2020-09-26 02:15:174490 NonNetworkURLLoaderFactoryMap* factories) {
Ting Shao2dc60582019-07-15 04:43:364491 DCHECK(browser_context);
4492 DCHECK(factories);
Lukasz Anforowicza782c5a2020-09-26 02:15:174493
4494#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364495 factories->emplace(
4496 extensions::kExtensionScheme,
4497 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4498 browser_context));
4499#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364500}
4501
Jay Civelli2578ebe2018-06-05 18:44:314502namespace {
4503
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384504// The SpecialAccessFileURLLoaderFactory provided to the extension background
4505// pages. Checks with the ChildProcessSecurityPolicy to validate the file
4506// access.
4507class SpecialAccessFileURLLoaderFactory
4508 : public content::NonNetworkURLLoaderFactoryBase {
Jay Civelli2578ebe2018-06-05 18:44:314509 public:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384510 // Returns mojo::PendingRemote to a newly constructed
4511 // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
4512 // delete itself once there are no more receivers (including the receiver
4513 // associated with the returned mojo::PendingRemote and the receivers bound by
4514 // the Clone method).
4515 static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
4516 int child_id) {
4517 mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
4518
4519 // The SpecialAccessFileURLLoaderFactory will delete itself when there are
4520 // no more receivers - see the NonNetworkURLLoaderFactoryBase::OnDisconnect
4521 // method.
4522 new SpecialAccessFileURLLoaderFactory(
4523 child_id, pending_remote.InitWithNewPipeAndPassReceiver());
4524
4525 return pending_remote;
4526 }
Jay Civelli2578ebe2018-06-05 18:44:314527
4528 private:
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384529 explicit SpecialAccessFileURLLoaderFactory(
4530 int child_id,
4531 mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
4532 : content::NonNetworkURLLoaderFactoryBase(std::move(factory_receiver)),
4533 child_id_(child_id) {}
4534
Jay Civelli2578ebe2018-06-05 18:44:314535 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274536 void CreateLoaderAndStart(
4537 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4538 int32_t routing_id,
4539 int32_t request_id,
4540 uint32_t options,
4541 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304542 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274543 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4544 override {
Jay Civelli2578ebe2018-06-05 18:44:314545 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4546 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304547 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4548 ->OnComplete(
4549 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314550 return;
4551 }
Yutaka Hiranodf83dca42020-01-07 06:24:554552 content::CreateFileURLLoaderBypassingSecurityChecks(
4553 request, std::move(loader), std::move(client),
4554 /*observer=*/nullptr,
4555 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314556 }
4557
Jay Civelli2578ebe2018-06-05 18:44:314558 int child_id_;
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384559 DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory);
Jay Civelli2578ebe2018-06-05 18:44:314560};
4561
Aya ElAttareb5fee12020-05-05 08:56:054562#if defined(OS_CHROMEOS)
4563bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4564 PrefService* const local_state = g_browser_process->local_state();
4565 if (!local_state) // Sometimes it's not available in tests.
4566 return false;
4567
4568 const base::ListValue* disabled_system_features_pref =
4569 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4570 if (!disabled_system_features_pref)
4571 return false;
4572
4573 const auto disabled_system_features =
4574 disabled_system_features_pref->GetList();
4575 return base::Contains(disabled_system_features, base::Value(system_feature));
4576}
4577
4578bool IsSystemFeatureURLDisabled(const GURL& url) {
4579 if (!url.SchemeIs(content::kChromeUIScheme))
4580 return false;
4581
4582 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4583 // installation complete successfully.
4584 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4585 url.path() != "/pwa.html" &&
4586 IsSystemFeatureDisabled(policy::SystemFeature::OS_SETTINGS)) {
4587 return true;
4588 }
4589
4590 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
4591 IsSystemFeatureDisabled(policy::SystemFeature::BROWSER_SETTINGS)) {
4592 return true;
4593 }
4594
Jesse Schettlerb7047f32020-09-18 14:50:404595 if (url.DomainIs(chromeos::kChromeUIScanningAppHost) &&
4596 IsSystemFeatureDisabled(policy::SystemFeature::SCANNING)) {
4597 return true;
4598 }
4599
Aya ElAttareb5fee12020-05-05 08:56:054600 return false;
4601}
4602#endif
Jay Civelli2578ebe2018-06-05 18:44:314603} // namespace
4604
Ken Rockot6414c4d92017-11-08 19:58:324605void ChromeContentBrowserClient::
4606 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464607 int render_process_id,
4608 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324609 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414610#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4611 content::RenderFrameHost* frame_host =
4612 RenderFrameHost::FromID(render_process_id, render_frame_id);
4613 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4614#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4615
4616#if defined(OS_CHROMEOS)
4617 if (web_contents) {
4618 Profile* profile =
4619 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Lukasz Anforowiczeb016c52020-10-03 02:15:354620 factories->emplace(content::kExternalFileScheme,
4621 chromeos::ExternalFileURLLoaderFactory::Create(
4622 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414623 }
4624#endif // defined(OS_CHROMEOS)
4625
Ken Rockot6414c4d92017-11-08 19:58:324626#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicza782c5a2020-09-26 02:15:174627 factories->emplace(extensions::kExtensionScheme,
4628 extensions::CreateExtensionURLLoaderFactory(
4629 render_process_id, render_frame_id));
Chris Mumfordbae8a742018-03-01 23:02:234630
4631 // This logic should match
4632 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314633 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234634 return;
Jay Civellic9bbf72d2018-03-24 01:58:314635
4636 Profile* profile =
4637 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4638 InstantService* instant_service =
4639 InstantServiceFactory::GetForProfile(profile);
4640 // The test below matches what's done by ShouldServiceRequestIOThread in
4641 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464642 if (instant_service->IsInstantProcess(render_process_id)) {
Lukasz Anforowicz7f695532020-09-15 16:05:224643 factories->emplace(
Jay Civellic9bbf72d2018-03-24 01:58:314644 chrome::kChromeSearchScheme,
Lukasz Anforowicz7f695532020-09-15 16:05:224645 content::CreateWebUIURLLoaderFactory(
Jay Civellic9bbf72d2018-03-24 01:58:314646 frame_host, chrome::kChromeSearchScheme,
4647 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234648 }
Jay Civellic9bbf72d2018-03-24 01:58:314649
Chris Mumfordbae8a742018-03-01 23:02:234650 extensions::ChromeExtensionWebContentsObserver* web_observer =
4651 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4652 web_contents);
4653
Karan Bhatia91928572018-03-06 01:18:074654 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4655 // to the |web_contents|.
4656 if (!web_observer)
4657 return;
4658
Chris Mumfordbae8a742018-03-01 23:02:234659 const Extension* extension =
4660 web_observer->GetExtensionFromFrame(frame_host, false);
4661 if (!extension)
4662 return;
4663
Sam McNally7414eeb72018-09-03 04:05:304664 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234665 // Support for chrome:// scheme if appropriate.
4666 if ((extension->is_extension() || extension->is_platform_app()) &&
4667 Manifest::IsComponentLocation(extension->location())) {
4668 // Components of chrome that are implemented as extensions or platform apps
4669 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304670 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4671 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4672 }
4673 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4674 (extension->is_platform_app() &&
4675 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234676 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024677 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4678 // URLs. Hosted apps are not allowed because they are served via web servers
4679 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304680 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4681 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024682 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304683 }
4684 if (!allowed_webui_hosts.empty()) {
Lukasz Anforowicz7f695532020-09-15 16:05:224685 factories->emplace(content::kChromeUIScheme,
4686 content::CreateWebUIURLLoaderFactory(
4687 frame_host, content::kChromeUIScheme,
4688 std::move(allowed_webui_hosts)));
Chris Mumfordbae8a742018-03-01 23:02:234689 }
Jay Civelli2578ebe2018-06-05 18:44:314690
4691 // Extension with a background page get file access that gets approval from
4692 // ChildProcessSecurityPolicy.
4693 extensions::ExtensionHost* host =
4694 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4695 ->GetBackgroundHostForExtension(extension->id());
4696 if (host) {
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384697 factories->emplace(
Lukasz Anforowiczb7d8b542020-09-03 19:50:344698 url::kFileScheme,
Lukasz Anforowicz44a0f9e2020-09-30 15:05:384699 SpecialAccessFileURLLoaderFactory::Create(render_process_id));
Jay Civelli2578ebe2018-06-05 18:44:314700 }
Chris Mumfordbae8a742018-03-01 23:02:234701#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324702}
4703
Ken Rockota0dfaca12018-02-15 07:26:254704bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214705 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254706 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384707 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444708 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264709 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004710 base::Optional<int64_t> navigation_id,
Maks Orlovichf334d642020-09-21 22:19:594711 base::UkmSourceId ukm_source_id,
Dominic Farolino1be897a2019-07-20 08:11:424712 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184713 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4714 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334715 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084716 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334717 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014718 bool use_proxy = false;
4719
Ken Rockota0dfaca12018-02-15 07:26:254720#if BUILDFLAG(ENABLE_EXTENSIONS)
4721 auto* web_request_api =
4722 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214723 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254724
4725 // NOTE: Some unit test environments do not initialize
4726 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014727 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124728 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384729 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004730 browser_context, frame, render_process_id, type,
Maks Orlovichf334d642020-09-21 22:19:594731 std::move(navigation_id), ukm_source_id, factory_receiver,
4732 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124733 if (bypass_redirect_checks)
4734 *bypass_redirect_checks = use_proxy_for_web_request;
4735 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014736 }
Ken Rockota0dfaca12018-02-15 07:26:254737#endif
Reilly Grant24bf8332018-08-27 21:55:014738
Reilly Grantcc22e602018-09-07 15:25:204739 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444740 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4741 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014742
Robert Ogden31b234712020-06-04 22:51:214743 auto* isolated_prerender_service =
4744 IsolatedPrerenderServiceFactory::GetForProfile(
4745 Profile::FromBrowserContext(browser_context));
4746 // |frame| is null when |type| is service worker.
4747 if (frame && isolated_prerender_service) {
4748 use_proxy |= isolated_prerender_service->MaybeProxyURLLoaderFactory(
Robert Ogden8c53bc52020-06-19 21:24:184749 frame, render_process_id, type, factory_receiver);
Robert Ogden31b234712020-06-04 22:51:214750 }
4751
dalyk0018c16f2020-01-08 20:20:084752#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4753 if (disable_secure_dns) {
4754 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4755 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014756 web_contents &&
4757 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4758 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084759 ->is_captive_portal_window();
4760 }
4761#endif
4762
Reilly Grant24bf8332018-08-27 21:55:014763 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254764}
4765
Jian Lide7b43792018-06-01 23:22:134766std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4767ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4768 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144769 int frame_tree_node_id,
4770 const scoped_refptr<network::SharedURLLoaderFactory>&
4771 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134772 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4773 interceptors;
4774#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234775 interceptors.push_back(
4776 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4777 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134778#endif
Ryan Sturmaf523742019-01-16 00:15:454779
Robert Ogden6946ad42020-01-13 18:01:304780 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4781 interceptors.push_back(
4782 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4783 frame_tree_node_id));
4784 }
4785
Jian Lide7b43792018-06-01 23:22:134786 return interceptors;
4787}
4788
Yutaka Hirano8e0b4d432019-07-04 07:12:384789bool ChromeContentBrowserClient::WillInterceptWebSocket(
4790 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334791#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384792 if (!frame) {
4793 return false;
4794 }
4795 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334796 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4797 frame->GetProcess()->GetBrowserContext());
4798
4799 // NOTE: Some unit test environments do not initialize
4800 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4801 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384802 return false;
Yutaka Hirano36c94952018-05-30 21:33:334803
Yutaka Hirano8e0b4d432019-07-04 07:12:384804 return web_request_api->MayHaveProxies();
4805#else
4806 return false;
4807#endif
4808}
4809
4810void ChromeContentBrowserClient::CreateWebSocket(
4811 content::RenderFrameHost* frame,
4812 WebSocketFactory factory,
4813 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394814 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384815 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404816 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4817 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384818#if BUILDFLAG(ENABLE_EXTENSIONS)
4819 if (!frame) {
4820 return;
4821 }
4822 auto* web_request_api =
4823 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4824 frame->GetProcess()->GetBrowserContext());
4825
4826 DCHECK(web_request_api);
4827 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394828 site_for_cookies.RepresentativeUrl(),
4829 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334830#endif
4831}
4832
Maks Orlovich710d5e32019-07-09 20:16:454833bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464834 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454835 content::BrowserContext* browser_context,
4836 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394837 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404838 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454839 bool is_service_worker,
4840 int process_id,
4841 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034842 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454843 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4844#if BUILDFLAG(ENABLE_EXTENSIONS)
4845 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464846 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454847 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404848 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4849 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454850 return true;
4851 }
4852#endif
4853 return false;
4854}
4855
Matt Menkeae4fdb12018-06-02 06:32:544856void ChromeContentBrowserClient::OnNetworkServiceCreated(
4857 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534858 PrefService* local_state;
4859 if (g_browser_process) {
4860 DCHECK(g_browser_process->local_state());
4861 local_state = g_browser_process->local_state();
4862 } else {
Xi Han85079c22019-04-18 21:43:054863 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4864 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534865 }
4866
4867 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4868 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4869
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494870 // Create SystemNetworkContextManager if it has not been created yet. We need
4871 // to set up global NetworkService state before anything else uses it and this
4872 // is the first opportunity to initialize SystemNetworkContextManager with the
4873 // NetworkService.
4874 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534875 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074876
Min Qin8caab1d2018-10-03 17:28:134877 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544878 network_service);
4879}
4880
Matthew Denton8888ae52020-05-14 08:20:024881void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:254882 content::BrowserContext* context,
4883 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:024884 const base::FilePath& relative_partition_path,
4885 network::mojom::NetworkContextParams* network_context_params,
4886 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504887 Profile* profile = Profile::FromBrowserContext(context);
Matthew Denton8888ae52020-05-14 08:20:024888 profile->ConfigureNetworkContextParams(in_memory, relative_partition_path,
4889 network_context_params,
4890 cert_verifier_creation_params);
Ken Rockota0dfaca12018-02-15 07:26:254891}
4892
Robert Sesek34f68f312019-01-14 20:25:114893std::vector<base::FilePath>
4894ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024895 DCHECK(!network_contexts_parent_directory_.empty());
4896 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114897}
4898
John Abd-El-Malekc240cfc42020-07-08 12:22:444899base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() {
4900 auto platform_dict = net_log::GetPlatformConstantsForNetLog(
4901 base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
4902 chrome::GetChannelName());
4903 if (platform_dict)
4904 return std::move(*platform_dict);
4905 else
4906 return base::DictionaryValue();
4907}
4908
Min Qin75ed6df2017-12-01 20:39:154909bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134910 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154911#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4912 // It is OK to load the saved offline copy, in MHTML format.
4913 ChromeNavigationUIData* chrome_navigation_ui_data =
4914 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4915 if (!chrome_navigation_ui_data)
4916 return false;
4917 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4918 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4919 return offline_page_data && offline_page_data->is_offline_page();
4920#else
4921 return false;
4922#endif
4923}
4924
Min Qin30a78a12017-12-06 01:29:134925bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4926 const GURL& url,
4927 const std::string& mime_type) {
4928#if BUILDFLAG(ENABLE_EXTENSIONS)
4929 // Special-case user scripts to get downloaded instead of viewed.
4930 return extensions::UserScript::IsURLUserScript(url, mime_type);
4931#else
4932 return false;
4933#endif
4934}
4935
Donna Wu838ac362018-08-10 10:36:334936void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344937 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044938 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:464939 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:344940 return;
4941
[email protected]95ebe7c2020-04-08 19:12:454942 CHECK(render_frame_host);
4943 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4944 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344945}
4946
Ovidio Henriquez3d729f62020-02-07 00:43:294947content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4948 if (!bluetooth_delegate_)
4949 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4950 return bluetooth_delegate_.get();
4951}
4952
Reilly Grant0d282322019-01-29 02:42:584953#if !defined(OS_ANDROID)
4954content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4955 if (!serial_delegate_)
4956 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4957 return serial_delegate_.get();
4958}
Matt Reynolds93616f9b2019-06-07 01:28:524959
4960content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4961 if (!hid_delegate_)
4962 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4963 return hid_delegate_.get();
4964}
Reilly Grant0d282322019-01-29 02:42:584965
Balazs Engedya7ff70982018-06-04 18:14:474966std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4967ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334968 content::RenderFrameHost* render_frame_host) {
4969 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4970 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474971}
Nina Satragno8c832df2019-07-29 15:59:394972#endif
Balazs Engedya7ff70982018-06-04 18:14:474973
Jun Cai9409ded2018-01-30 00:19:464974std::unique_ptr<net::ClientCertStore>
4975ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104976 content::BrowserContext* browser_context) {
4977 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464978 ->CreateClientCertStore();
4979}
4980
David Benjamineced01fc2019-02-27 18:29:024981std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394982ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584983 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024984 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034985 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244986 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394987 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034988 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394989 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564990 LoginAuthRequiredCallback auth_required_callback) {
Emily Stark63c884f2020-05-12 03:55:284991 // For subresources, create a LoginHandler directly, which may show a login
4992 // prompt to the user. Main frame resources go through LoginTabHelper, which
4993 // manages a more complicated flow to avoid confusion about which website is
4994 // showing the prompt.
4995 if (is_request_for_main_frame) {
4996 LoginTabHelper::CreateForWebContents(web_contents);
4997 return LoginTabHelper::FromWebContents(web_contents)
4998 ->CreateAndStartMainFrameLoginDelegate(
4999 auth_info, web_contents, request_id, url, response_headers,
5000 std::move(auth_required_callback));
5001 }
5002 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
5003 auth_info, web_contents, std::move(auth_required_callback));
5004 login_handler->StartSubresource(request_id, url, response_headers);
5005 return login_handler;
Jun Caibc561f412018-02-28 18:41:395006}
5007
John Abd-El-Maleka67add82018-03-09 18:22:015008bool ChromeContentBrowserClient::HandleExternalProtocol(
5009 const GURL& url,
danakjf4b9e942019-11-29 15:43:045010 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015011 int child_id,
5012 content::NavigationUIData* navigation_data,
5013 bool is_main_frame,
5014 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455015 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:455016 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:105017 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015018#if BUILDFLAG(ENABLE_EXTENSIONS)
5019 // External protocols are disabled for guests. An exception is made for the
5020 // "mailto" protocol, so that pages that utilize it work properly in a
5021 // WebView.
5022 ChromeNavigationUIData* chrome_data =
5023 static_cast<ChromeNavigationUIData*>(navigation_data);
5024 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5025 (chrome_data &&
5026 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5027 !url.SchemeIs(url::kMailToScheme)) {
5028 return false;
5029 }
5030#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5031
5032#if defined(OS_ANDROID)
5033 // Main frame external protocols are handled by
5034 // InterceptNavigationResourceThrottle.
5035 if (is_main_frame)
5036 return false;
5037#endif // defined(ANDROID)
5038
Gabriel Charettee7cdc5cd2020-05-27 23:35:055039 content::GetUIThreadTaskRunner({})->PostTask(
5040 FROM_HERE,
danakjf4b9e942019-11-29 15:43:045041 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
5042 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:015043 return true;
5044}
5045
Jennifer Apacible4f854a82018-04-06 22:22:115046std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285047ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5048 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115049 // Note: content::OverlayWindow::Create() is defined by platform-specific
5050 // implementation in chrome/browser/ui/views. This layering hack, which goes
5051 // through //content and ContentBrowserClient, allows us to work around the
5052 // dependency constraints that disallow directly calling
5053 // chrome/browser/ui/views code either from here or from other code in
5054 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285055 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115056}
5057
Kunihiko Sakamoto19aa7082019-02-25 03:14:435058void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565059 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115060 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565061 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435062 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5063 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565064}
5065
dbeam25472e0c2017-06-23 19:02:315066// Static; handles rewriting Web UI URLs.
5067bool ChromeContentBrowserClient::HandleWebUI(
5068 GURL* url,
5069 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:395070 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315071 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395072 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315073 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5074 chrome::kChromeUIHelpHost);
5075 return true; // Return true to update the displayed URL.
5076 }
5077
sauskib5f82762020-07-21 17:13:225078 // Replace deprecated cookie settings URL with the current version.
5079 if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) {
5080 *url = GURL(chrome::kChromeUICookieSettingsURL);
5081 return true;
5082 }
5083
Hector Carmona566a20b2019-09-13 22:44:425084#if defined(OS_WIN)
5085 // TODO(crbug.com/1003960): Remove when issue is resolved.
5086 if (url->SchemeIs(content::kChromeUIScheme) &&
5087 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5088 url::Replacements<char> replacements;
5089 replacements.SetHost(
5090 chrome::kChromeUIWelcomeHost,
5091 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5092 *url = url->ReplaceComponents(replacements);
5093 return true;
5094 }
5095#endif // defined(OS_WIN)
5096
dbeam25472e0c2017-06-23 19:02:315097 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5098 browser_context, *url)) {
5099 return false;
5100 }
5101
5102#if defined(OS_CHROMEOS)
5103 // Special case : in ChromeOS in Guest mode bookmarks and history are
5104 // disabled for security reasons. New tab page explains the reasons, so
5105 // we redirect user to new tab page.
5106 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5107 if (url->SchemeIs(content::kChromeUIScheme) &&
5108 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5109 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5110 // Rewrite with new tab URL
5111 *url = GURL(chrome::kChromeUINewTabURL);
5112 }
5113 }
Aya ElAttareb5fee12020-05-05 08:56:055114
5115 if (IsSystemFeatureURLDisabled(*url)) {
5116 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
5117 return true;
5118 }
5119
dbeam25472e0c2017-06-23 19:02:315120#endif
5121
5122 return true;
5123}
5124
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065125bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5126 content::BrowserContext* browser_context,
5127 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325128 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065129#if defined(OS_ANDROID)
5130 return false;
5131#else
5132 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5133 ->GetForBrowserContext(browser_context)
5134 ->ShowPaymentHandlerWindow(url, std::move(callback));
5135 return true;
5136#endif
5137}
5138
Dan Beam141c48932019-08-22 02:29:395139// static
dbeam25472e0c2017-06-23 19:02:315140bool ChromeContentBrowserClient::HandleWebUIReverse(
5141 GURL* url,
5142 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425143#if defined(OS_WIN)
5144 // TODO(crbug.com/1003960): Remove when issue is resolved.
5145 // No need to actually reverse-rewrite the URL, but return true to update the
5146 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5147 if (url->SchemeIs(content::kChromeUIScheme) &&
5148 url->host() == chrome::kChromeUIWelcomeHost) {
5149 return true;
5150 }
5151#endif // defined(OS_WIN)
5152
dbeam25472e0c2017-06-23 19:02:315153 // No need to actually reverse-rewrite the URL, but return true to update the
5154 // displayed URL when rewriting chrome://help to chrome://settings/help.
5155 return url->SchemeIs(content::kChromeUIScheme) &&
5156 url->host() == chrome::kChromeUISettingsHost;
5157}
5158
Alison Maher7f366dc62020-03-03 19:46:005159const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585160 return ui::NativeTheme::GetInstanceForWeb();
5161}
5162
Clark DuVall5497288d2019-07-17 00:17:565163scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505164ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Xinghui Lucf23c902020-06-10 17:38:255165 bool safe_browsing_enabled_for_profile,
5166 bool should_check_on_sb_disabled) {
Yuzhu Shen44094e22017-07-18 22:52:355167 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5168
Xinghui Lucf23c902020-06-10 17:38:255169 // Should not bypass safe browsing check if the check is for enterprise
5170 // lookup.
5171 if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled)
Yuzhu Shencb3011f62018-02-08 02:51:505172 return nullptr;
5173
Yuzhu Shen44094e22017-07-18 22:52:355174 // |safe_browsing_service_| may be unavailable in tests.
5175 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5176 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435177 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355178 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435179 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355180 }
5181
Clark DuVall5497288d2019-07-17 00:17:565182 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355183}
Daniel Vogelheim6008f572018-09-24 14:35:145184
Xinghui Lucf23c902020-06-10 17:38:255185safe_browsing::RealTimeUrlLookupServiceBase*
5186ChromeContentBrowserClient::GetUrlLookupService(
5187 content::BrowserContext* browser_context,
5188 bool is_enterprise_lookup_enabled,
5189 bool is_consumer_lookup_enabled) {
5190 // |safe_browsing_service_| may be unavailable in tests.
5191 if (!safe_browsing_service_) {
5192 return nullptr;
5193 }
5194
5195 Profile* profile = Profile::FromBrowserContext(browser_context);
5196
5197#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL)
5198 if (is_enterprise_lookup_enabled) {
5199 return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory::
5200 GetForProfile(profile);
5201 }
5202#endif
5203
5204 if (is_consumer_lookup_enabled) {
5205 return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
5206 profile);
5207 }
5208 return nullptr;
5209}
5210
Daniel Vogelheim6008f572018-09-24 14:35:145211base::Optional<std::string>
5212ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595213 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185214 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595215 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5216 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145217}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525218
Takashi Toyoshima5af383aa2019-07-22 15:24:225219bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525220 // We require --user-data-dir flag too so that no dangerous changes are made
5221 // in the user's regular profile.
5222 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5223 switches::kUserDataDir);
5224}
rajendrantfeea8592018-10-19 18:26:065225
5226void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5227 int32_t network_traffic_annotation_id_hash,
5228 int64_t recv_bytes,
5229 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035230 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5231 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5232 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5233 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065234 }
5235}
Ryan Sturmaa05092f2018-10-21 03:56:545236
Ken Rockot4e284d32020-03-06 06:26:495237base::FilePath
5238ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
5239 return g_browser_process->profile_manager()->user_data_dir();
5240}
5241
Guido Urdanetae02b5722020-07-22 05:58:215242bool ChromeContentBrowserClient::ShouldSandboxAudioService() {
5243 return IsAudioServiceSandboxEnabled();
5244}
5245
Hiroki Nakagawa41366152020-07-27 18:31:405246blink::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5247 blink::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395248 content::NavigationHandle* navigation_handle,
5249 const GURL& current_navigation_url) {
Sophie Changc4ddda6772020-07-15 15:08:325250 return DetermineAllowedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135251 initial_state, navigation_handle, current_navigation_url);
Robert Ogden30bbc9d2019-04-30 20:15:135252}
5253
Hiroki Nakagawa41366152020-07-27 18:31:405254blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135255ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405256 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135257 content::NavigationHandle* navigation_handle,
5258 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295260 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215261
Ryan Sturmaa05092f2018-10-21 03:56:545262 // If this is not a main frame, return the initial state. If there are no
5263 // previews in the state, return the state as is.
5264 if (!navigation_handle->IsInMainFrame() ||
5265 navigation_handle->IsSameDocument()) {
5266 return initial_state;
5267 }
5268
Robert Ogdena994eb42019-02-14 19:15:085269 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405270 return blink::PreviewsTypes::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085271
Doug Arnettb3b99bc2019-08-09 16:55:565272 // Check if initial state specifies no previews should be considered.
Hiroki Nakagawa41366152020-07-27 18:31:405273 if (initial_state == blink::PreviewsTypes::PREVIEWS_OFF)
Doug Arnettb3b99bc2019-08-09 16:55:565274 return initial_state;
5275
Robert Ogdena994eb42019-02-14 19:15:085276 // Do not allow previews on POST navigations since the primary opt-out
5277 // mechanism is to reload the page. Because POST navigations are not
5278 // idempotent, we do not want to show a preview on a POST navigation where
5279 // opting out would cause another navigation, i.e.: a reload.
5280 if (navigation_handle->IsPost())
Hiroki Nakagawa41366152020-07-27 18:31:405281 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395282
5283 content::WebContents* web_contents = navigation_handle->GetWebContents();
5284 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5285
Ryan Sturmda2a0e02018-10-25 01:52:215286 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545287
5288 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5289 Profile::FromBrowserContext(browser_context));
5290 auto* data_reduction_proxy_settings =
5291 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5292 browser_context);
5293 // If the profile does not support previews or Data Saver, do not turn on
5294 // Previews.
5295 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355296 !data_reduction_proxy_settings) {
Hiroki Nakagawa41366152020-07-27 18:31:405297 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545298 }
5299
5300 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215301 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545302 // If this tab does not have a PreviewsUITabHelper, no preview should be
5303 // served.
5304 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405305 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545306
5307 DCHECK(!browser_context->IsOffTheRecord());
5308
5309 // Other previews objects should all exist and be initialized if we have made
5310 // it past earlier checks.
5311 previews::PreviewsDeciderImpl* previews_decider_impl =
5312 previews_service->previews_ui_service()->previews_decider_impl();
5313 DCHECK(previews_decider_impl);
5314
Ryan Sturm647d1d92018-11-07 15:41:395315 // Start with an unspecified state.
Hiroki Nakagawa41366152020-07-27 18:31:405316 blink::PreviewsState previews_state =
5317 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturmaa05092f2018-10-21 03:56:545318
Ryan Sturm647d1d92018-11-07 15:41:395319 previews::PreviewsUserData* previews_data =
5320 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5321
5322 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315323 // previews) and cannot re-evaluate PreviewsState once previews triggering
5324 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375325 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315326 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395327 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375328 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395329 } else {
5330 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5331 navigation_handle, previews_decider_impl->GeneratePageId());
5332 }
5333
5334 DCHECK(previews_data);
5335
Robert Ogden01770b362019-05-22 17:36:435336 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5337 previews::switches::kForceEnablePreviews)) {
Hiroki Nakagawa41366152020-07-27 18:31:405338 return blink::ALL_SUPPORTED_PREVIEWS;
Robert Ogden01770b362019-05-22 17:36:435339 }
5340
Sophie Changa71fa5d2019-11-19 23:53:515341 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545342 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315343 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355344 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5345 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545346
Hiroki Nakagawa41366152020-07-27 18:31:405347 if (previews_state & blink::PreviewsTypes::PREVIEWS_OFF) {
5348 previews_data->set_allowed_previews_state(
5349 blink::PreviewsTypes::PREVIEWS_OFF);
5350 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545351 }
5352
Hiroki Nakagawa41366152020-07-27 18:31:405353 if (previews_state & blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM) {
5354 previews_data->set_allowed_previews_state(
5355 blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM);
5356 return blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM;
Ryan Sturmaa05092f2018-10-21 03:56:545357 }
5358
5359 // At this point, if no Preview is allowed, don't allow previews.
Hiroki Nakagawa41366152020-07-27 18:31:405360 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
5361 previews_data->set_allowed_previews_state(
5362 blink::PreviewsTypes::PREVIEWS_OFF);
5363 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395364 }
5365
Hiroki Nakagawa41366152020-07-27 18:31:405366 blink::PreviewsState embedder_state =
5367 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Ryan Sturm647d1d92018-11-07 15:41:395368 if (delegate) {
5369 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5370 }
Ryan Sturmaa05092f2018-10-21 03:56:545371
5372 // If the allowed previews are limited by the embedder, ensure previews honors
5373 // those limits.
Hiroki Nakagawa41366152020-07-27 18:31:405374 if (embedder_state != blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) {
Ryan Sturm647d1d92018-11-07 15:41:395375 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545376 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
Hiroki Nakagawa41366152020-07-27 18:31:405377 if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED)
5378 previews_state = blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545379 }
Ryan Sturm647d1d92018-11-07 15:41:395380 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545381 return previews_state;
5382}
5383
5384// static
Hiroki Nakagawa41366152020-07-27 18:31:405385blink::PreviewsState
Ryan Sturmaa05092f2018-10-21 03:56:545386ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5387 const GURL& url,
5388 data_reduction_proxy::DataReductionProxyData* drp_data,
5389 previews::PreviewsUserData* previews_user_data,
5390 const previews::PreviewsDecider* previews_decider,
Hiroki Nakagawa41366152020-07-27 18:31:405391 blink::PreviewsState initial_state,
Ryan Sturm737bd1d2019-02-28 01:38:055392 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545393 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5394 if (!previews::HasEnabledPreviews(initial_state))
Hiroki Nakagawa41366152020-07-27 18:31:405395 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545396
Ryan Sturmaa05092f2018-10-21 03:56:545397 // Check the various other client previews types.
5398 return previews::DetermineCommittedClientPreviewsState(
Sophie Changc4ddda6772020-07-15 15:08:325399 previews_user_data, url, initial_state, previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055400 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545401}
5402
Hiroki Nakagawa41366152020-07-27 18:31:405403blink::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5404 blink::PreviewsState initial_state,
Ryan Sturmaa05092f2018-10-21 03:56:545405 content::NavigationHandle* navigation_handle,
5406 const net::HttpResponseHeaders* response_headers) {
Hiroki Nakagawa41366152020-07-27 18:31:405407 blink::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
Robert Ogden30bbc9d2019-04-30 20:15:135408 initial_state, navigation_handle, response_headers);
5409
5410 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5411}
5412
Hiroki Nakagawa41366152020-07-27 18:31:405413blink::PreviewsState
Robert Ogden30bbc9d2019-04-30 20:15:135414ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
Hiroki Nakagawa41366152020-07-27 18:31:405415 blink::PreviewsState initial_state,
Robert Ogden30bbc9d2019-04-30 20:15:135416 content::NavigationHandle* navigation_handle,
5417 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545418 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arthursonzogni90bb0922020-05-28 09:22:235419 DCHECK(!navigation_handle->HasCommitted());
5420
Ryan Sturmaa05092f2018-10-21 03:56:545421 // Only support HTTP and HTTPS.
arthursonzogni90bb0922020-05-28 09:22:235422 if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS())
Hiroki Nakagawa41366152020-07-27 18:31:405423 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545424
5425 // If this is not a main frame, return the initial state. If there are no
5426 // previews in the state, return the state as is.
5427 if (!previews::HasEnabledPreviews(initial_state) ||
5428 !navigation_handle->IsInMainFrame() ||
5429 navigation_handle->IsSameDocument()) {
5430 return initial_state;
5431 }
5432
5433 // WebContents that don't have a PreviewsUITabHelper are not supported.
5434 PreviewsUITabHelper* ui_tab_helper =
5435 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5436 if (!ui_tab_helper)
Hiroki Nakagawa41366152020-07-27 18:31:405437 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545438
5439 // If we did not previously create a PreviewsUserData, do not go any further.
5440 previews::PreviewsUserData* previews_user_data =
5441 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5442 if (!previews_user_data)
Hiroki Nakagawa41366152020-07-27 18:31:405443 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545444
5445 PreviewsService* previews_service =
5446 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5447 navigation_handle->GetWebContents()->GetBrowserContext()));
5448
5449 if (!previews_service || !previews_service->previews_ui_service())
Hiroki Nakagawa41366152020-07-27 18:31:405450 return blink::PreviewsTypes::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545451
Ryan Sturmaa05092f2018-10-21 03:56:545452 // Annotate request if no-transform directive found in response headers.
5453 if (response_headers &&
5454 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265455 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545456 }
5457
5458 previews::PreviewsDeciderImpl* previews_decider_impl =
5459 previews_service->previews_ui_service()->previews_decider_impl();
5460 DCHECK(previews_decider_impl);
5461
Clark DuVall9c5a72cc2018-10-25 01:29:215462 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5463 auto* settings =
5464 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5465 navigation_handle->GetWebContents()->GetBrowserContext());
5466 if (settings) {
5467 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5468 // does not yet have all the response information.
5469 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5470 response_headers);
5471 }
Ryan Sturmaa05092f2018-10-21 03:56:545472
5473 // Determine effective PreviewsState for this committed main frame response.
Hiroki Nakagawa41366152020-07-27 18:31:405474 blink::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215475 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055476 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545477
5478 // Double check that we never serve a preview when we have a
5479 // cache-control:no-transform directive.
5480 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5481 !previews::HasEnabledPreviews(committed_state));
5482
Robert Ogdended292c6f2019-05-03 22:44:515483 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545484 previews_user_data->set_committed_previews_state(committed_state);
5485
5486 previews::PreviewsType committed_type =
5487 previews::GetMainFramePreviewsType(committed_state);
5488
5489 // Capture committed previews type, if any, in PreviewsUserData.
5490 // Note: this is for the subset of previews types that are decided upon
5491 // navigation commit. Previews types that are determined prior to
5492 // navigation (such as for offline pages or for redirecting to another
5493 // url), are not set here.
5494 previews_user_data->SetCommittedPreviewsType(committed_type);
5495
5496 // Log the commit decision.
5497 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5498 previews_decider_impl->LogPreviewDecisionMade(
5499 (previews_user_data->cache_control_no_transform_directive()
5500 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5501 : previews::PreviewsEligibilityReason::COMMITTED),
5502 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055503 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055504 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545505
5506 return committed_state;
5507}
Charlie Harrison650e11422018-12-04 00:37:265508
5509void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5510 content::RenderFrameHost* render_frame_host,
5511 blink::mojom::WebFeature feature) {
5512 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5513 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5514 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5515 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315516
5517 // For the SameSite-by-default-cookies related features, log
5518 // the site engagement score for the site whose cookie was blocked. This is to
5519 // gauge the user impact of the cookies being blocked.
5520 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265521}
Yutaka Hirano968d6252018-12-04 05:09:315522
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525523std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315524 return ::GetProduct();
5525}
5526
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525527std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315528 return ::GetUserAgent();
5529}
Sam McNallyd54e23f92019-01-16 04:42:395530
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525531blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175532 return ::GetUserAgentMetadata();
5533}
5534
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525535base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275536 // This icon is available on Android, but adds 19KiB to the APK. Since it
5537 // isn't used on Android we exclude it to avoid bloat.
5538#if !defined(OS_ANDROID)
5539 return base::Optional<gfx::ImageSkia>(
5540 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5541 IDR_PRODUCT_LOGO_256));
5542#else
5543 return base::nullopt;
5544#endif
5545}
5546
Sam McNallyd54e23f92019-01-16 04:42:395547bool ChromeContentBrowserClient::IsBuiltinComponent(
5548 content::BrowserContext* browser_context,
5549 const url::Origin& origin) {
5550#if BUILDFLAG(ENABLE_EXTENSIONS)
5551 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5552 browser_context, origin);
5553#else
5554 return false;
5555#endif
5556}
Oleg Davydov2cc0167b2019-02-05 14:32:485557
Aaron Colwelle1908d982020-06-26 22:08:155558bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:485559 const GURL& url,
5560 content::BrowserContext* context) {
Aaron Colwellf94fd97a2020-07-21 19:37:085561 PolicyBlocklistService* service =
5562 PolicyBlocklistFactory::GetForBrowserContext(context);
Oleg Davydov2cc0167b2019-02-05 14:32:485563
Aaron Colwellf94fd97a2020-07-21 19:37:085564 using URLBlocklistState = policy::URLBlocklist::URLBlocklistState;
5565 URLBlocklistState blocklist_state = service->GetURLBlocklistState(url);
5566 return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST;
Oleg Davydov2cc0167b2019-02-05 14:32:485567}
Dominic Mazzoni21fb0282019-02-13 18:32:475568
5569ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5570 content::BrowserContext* browser_context) {
5571 Profile* profile = Profile::FromBrowserContext(browser_context);
5572 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5573}
Eric Karld6cd75b2019-03-14 22:01:365574
5575#if defined(OS_ANDROID)
5576content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525577ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335578 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425579 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365580 return WideColorGamutHeuristic::kUseDisplay;
5581 }
Khushal1fc0da52019-10-09 00:38:565582
5583 if (display::Display::HasForceDisplayColorProfile() &&
5584 display::Display::GetForcedDisplayColorProfile() ==
5585 gfx::ColorSpace::CreateDisplayP3D65()) {
5586 return WideColorGamutHeuristic::kUseDisplay;
5587 }
5588
Eric Karld6cd75b2019-03-14 22:01:365589 return WideColorGamutHeuristic::kNone;
5590}
5591#endif
Ehsan Karamad91413d72019-03-22 16:37:485592
5593base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435594ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465595 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485596 base::flat_set<std::string> mime_types;
5597#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465598 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485599 for (const auto& pair : map)
5600 mime_types.insert(pair.first);
5601#endif
5602 return mime_types;
5603}
Yao Xiaod06607b2019-05-02 23:16:365604
5605void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5606 const content::WebContents* web_contents,
5607 const content::RenderFrameHost* frame_host,
5608 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525609 content::NavigationDownloadPolicy* download_policy) {
Colin Blundell0ec5d642020-10-06 17:29:525610 const auto* throttle_manager = subresource_filter::
5611 ContentSubresourceFilterThrottleManager::FromWebContents(web_contents);
5612 if (throttle_manager && throttle_manager->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045613 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365614 if (!user_gesture) {
5615 if (base::FeatureList::IsEnabled(
5616 blink::features::
5617 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5618 download_policy->SetDisallowed(
5619 content::NavigationDownloadType::kAdFrameNoGesture);
5620 } else {
5621 download_policy->SetAllowed(
5622 content::NavigationDownloadType::kAdFrameNoGesture);
5623 }
Yao Xiaod06607b2019-05-02 23:16:365624 }
5625 }
5626}
Jun Cai732a05e32019-05-29 19:34:195627
Yao Xiaoebed8c12020-09-26 07:51:205628std::string ChromeContentBrowserClient::GetInterestCohortForJsApi(
5629 content::BrowserContext* browser_context,
5630 const url::Origin& requesting_origin,
5631 const net::SiteForCookies& site_for_cookies) {
5632 federated_learning::FlocIdProvider* floc_id_provider =
5633 federated_learning::FlocIdProviderFactory::GetForProfile(
5634 Profile::FromBrowserContext(browser_context));
5635
5636 if (!floc_id_provider)
5637 return std::string();
5638
5639 return floc_id_provider->GetInterestCohortForJsApi(requesting_origin,
5640 site_for_cookies);
5641}
5642
Jun Cai732a05e32019-05-29 19:34:195643bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5644 content::BrowserContext* browser_context,
5645 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525646 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195647 const HostContentSettingsMap* const content_settings =
5648 HostContentSettingsMapFactory::GetForProfile(
5649 Profile::FromBrowserContext(browser_context));
5650
5651 if (content_settings->GetContentSetting(
5652 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455653 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195654 std::string()) == CONTENT_SETTING_BLOCK) {
5655 return true;
5656 }
5657
5658 return false;
5659}
5660
5661void ChromeContentBrowserClient::BlockBluetoothScanning(
5662 content::BrowserContext* browser_context,
5663 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525664 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195665 HostContentSettingsMap* const content_settings =
5666 HostContentSettingsMapFactory::GetForProfile(
5667 Profile::FromBrowserContext(browser_context));
5668
5669 content_settings->SetContentSettingDefaultScope(
5670 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455671 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195672 CONTENT_SETTING_BLOCK);
5673}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475674
5675bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5676#if defined(OS_ANDROID)
5677 return extra_icu::ModuleProvider::IsModuleInstalled();
5678#endif
5679 return false;
5680}
Guido Urdaneta4030d6a32019-10-17 09:38:165681
5682bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5683 content::BrowserContext* browser_context,
5684 const GURL& url,
5685 const GURL& site_for_cookies,
5686 const base::Optional<url::Origin>& top_frame_origin) {
5687 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5688 return CookieSettingsFactory::GetForProfile(
5689 Profile::FromBrowserContext(browser_context))
5690 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5691}
Sam Goto5cf068e82019-11-04 23:08:445692
5693#if !defined(OS_ANDROID)
5694void ChromeContentBrowserClient::FetchRemoteSms(
5695 content::BrowserContext* browser_context,
5696 const url::Origin& origin,
5697 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5698 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5699}
5700#endif
Roger Tawa03ffdbd2020-01-16 18:12:545701
5702void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5703 content::WebContents* web_contents,
5704 const GURL& url,
5705 const ui::ClipboardFormatType& data_type,
5706 const std::string& data,
5707 IsClipboardPasteAllowedCallback callback) {
5708#if BUILDFLAG(FULL_SAFE_BROWSING)
5709 // Safe browsing does not support images, so accept without checking.
5710 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5711 // types when it is implemented.
Darwin Huang0024dbf2020-08-04 00:53:555712 if (data_type == ui::ClipboardFormatType::GetBitmapType()) {
Roger Tawa03ffdbd2020-01-16 18:12:545713 std::move(callback).Run(ClipboardPasteAllowed(true));
5714 return;
5715 }
5716
5717 Profile* profile =
5718 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5719 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265720 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(
5721 profile, url, &dialog_data,
5722 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545723 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5724 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5725 web_contents, std::move(dialog_data),
5726 base::BindOnce(
5727 [](IsClipboardPasteAllowedCallback callback,
5728 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5729 const safe_browsing::DeepScanningDialogDelegate::Result&
5730 result) {
5731 std::move(callback).Run(
5732 ClipboardPasteAllowed(result.text_results[0]));
5733 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245734 std::move(callback)),
5735 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545736 } else {
5737 std::move(callback).Run(ClipboardPasteAllowed(true));
5738 }
5739#else
5740 std::move(callback).Run(ClipboardPasteAllowed(true));
5741#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5742}
Lukasz Anforowicz4600ea32020-01-18 02:37:485743
5744#if BUILDFLAG(ENABLE_PLUGINS)
5745bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5746 const url::Origin& embedder_origin,
5747 const content::PepperPluginInfo& plugin_info) {
5748#if BUILDFLAG(ENABLE_PDF)
5749 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5750#if BUILDFLAG(ENABLE_EXTENSIONS)
5751 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5752 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5753 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5754 return true;
5755 }
5756#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5757
5758 // Allow embedding the internal PDF plugin in chrome://print.
5759 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5760 return true;
5761
5762 // Only allow the PDF plugin in the known, trustworthy origins that are
5763 // allowlisted above. See also https://crbug.com/520422 and
5764 // https://crbug.com/1027173.
5765 return false;
5766 }
5767#endif // BUILDFLAG(ENABLE_PDF)
5768
5769 return true;
5770}
5771#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565772
5773#if BUILDFLAG(ENABLE_VR)
5774content::XrIntegrationClient*
5775ChromeContentBrowserClient::GetXrIntegrationClient() {
5776 if (!xr_integration_client_)
5777 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5778 util::PassKey<ChromeContentBrowserClient>());
5779 return xr_integration_client_.get();
5780}
5781#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185782
5783bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5784 content::BrowserContext* browser_context) {
5785 auto* profile = Profile::FromBrowserContext(browser_context);
5786 auto* prefs = profile->GetPrefs();
5787
5788 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5789 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5790 return false;
5791 }
5792 if (base::FeatureList::IsEnabled(
5793 blink::features::kAppCacheRequireOriginTrial)) {
5794 return true;
5795 }
5796
5797 return false;
5798}
Yutaka Hirano3e613662020-06-02 02:59:345799
Hidehiko Abeeaffbbce2020-06-23 19:41:525800void ChromeContentBrowserClient::BindBrowserControlInterface(
Hidehiko Abe23e45e82020-08-25 08:41:485801 mojo::ScopedMessagePipeHandle pipe) {
James Cook26d27122020-06-26 19:57:075802#if BUILDFLAG(IS_LACROS)
Hidehiko Abe23e45e82020-08-25 08:41:485803 chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(
5804 mojo::PendingReceiver<crosapi::mojom::LacrosChromeService>(
5805 std::move(pipe)));
Hidehiko Abeeaffbbce2020-06-23 19:41:525806#endif
5807}
5808
Yutaka Hirano3e613662020-06-02 02:59:345809bool ChromeContentBrowserClient::
5810 ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) {
5811#if BUILDFLAG(ENABLE_EXTENSIONS)
5812 return url.SchemeIs(extensions::kExtensionScheme);
5813#else
5814 return false;
5815#endif
5816}
John Abd-El-Malekdc026012020-06-15 23:28:565817
Titouan Rigoudycfc73552020-08-21 14:18:305818bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125819 content::BrowserContext* browser_context,
5820 const GURL& url) {
Titouan Rigoudycfc73552020-08-21 14:18:305821 return content_settings::ShouldAllowInsecurePrivateNetworkRequests(
Titouan Rigoudy9c2c0142020-08-19 17:57:125822 HostContentSettingsMapFactory::GetForProfile(browser_context), url);
5823}
5824
John Abd-El-Malekdc026012020-06-15 23:28:565825ukm::UkmService* ChromeContentBrowserClient::GetUkmService() {
5826 return g_browser_process->GetMetricsServicesManager()->GetUkmService();
5827}
Evan Liu054dc082020-09-30 14:09:425828
5829#if defined(OS_MAC)
5830bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters(
5831 sandbox::policy::SandboxType sandbox_type,
5832 sandbox::SeatbeltExecClient* client) {
5833 if (sandbox_type == sandbox::policy::SandboxType::kSpeechRecognition) {
5834 base::FilePath soda_component_path = speech::GetSodaDirectory();
5835 CHECK(!soda_component_path.empty());
5836 CHECK(client->SetParameter(
5837 sandbox::policy::SandboxMac::kSandboxSodaComponentPath,
5838 soda_component_path.value()));
5839
5840 base::FilePath soda_language_pack_path =
5841 speech::GetSodaLanguagePacksDirectory();
5842 CHECK(!soda_language_pack_path.empty());
5843 CHECK(client->SetParameter(
5844 sandbox::policy::SandboxMac::kSandboxSodaLanguagePackPath,
5845 soda_language_pack_path.value()));
5846 return true;
5847 }
5848
5849 return false;
5850}
5851
5852#endif // defined(OS_MAC)