blob: 9a87e5478d2d9b91207b686c4fa58e4e6c06dfe7 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
bmcquade5d2d9cf32015-06-19 17:42:287#include <map>
[email protected]7c3228a2011-11-11 21:35:228#include <set>
[email protected]1033acd2012-02-08 08:46:279#include <utility>
[email protected]7c3228a2011-11-11 21:35:2210#include <vector>
11
brettwf1958912015-10-07 19:43:1212#include "base/base_switches.h"
[email protected]317c58f02011-11-09 02:15:0313#include "base/bind.h"
estark3ba11132015-04-10 01:38:3314#include "base/bind_helpers.h"
[email protected]b80f68432011-05-02 17:22:3015#include "base/command_line.h"
Ken Rockot91c40da82019-08-12 20:07:1116#include "base/compiler_specific.h"
Will Harrisc196ed942019-08-03 03:45:3017#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2418#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0019#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1520#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5821#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2522#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1423#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3324#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3925#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0226#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3727#include "base/stl_util.h"
Aaron Tagliaboschi19ad8d32020-05-12 20:10:4428#include "base/strings/strcat.h"
[email protected]e7463412013-06-10 22:53:4629#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0330#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2831#include "base/strings/string_util.h"
32#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2033#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0334#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2835#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3236#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4137#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1838#include "build/build_config.h"
Ken Rockot341089f2019-01-11 23:11:5839#include "chrome/app/chrome_content_browser_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4740#include "chrome/browser/accessibility/accessibility_labels_service.h"
41#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
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"
[email protected]b1d97272013-08-17 13:38:4958#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3159#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4560#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0161#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1962#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5363#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5264#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1065#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2766#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2767#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3468#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4269#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
70#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1671#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3672#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3673#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5674#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0475#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0576#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0777#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2378#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1079#include "chrome/browser/net/profile_network_context_service.h"
80#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5481#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0282#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5983#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5684#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0685#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5486#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5187#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5688#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4289#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1190#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4891#include "chrome/browser/plugins/plugin_utils.h"
Robert Ogdenea4ea7392020-01-25 01:44:5392#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3093#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]190e5e22013-07-27 05:59:2394#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4195#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5096#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0797#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:0198#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:1999#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54100#include "chrome/browser/previews/previews_service.h"
101#include "chrome/browser/previews/previews_service_factory.h"
102#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03103#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14104#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32105#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49106#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06107#include "chrome/browser/profiles/renderer_updater.h"
108#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56109#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
110#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44111#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40113#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45114#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31115#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
116#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24117#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Carlos IL4ee307e2018-12-22 03:19:00118#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40119#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35120#include "chrome/browser/safe_browsing/ui_manager.h"
121#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58122#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43123#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44124#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20125#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35126#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40127#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23128#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28129#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02130#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48131#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38132#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32133#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07134#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23135#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10136#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.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"
Charlie Harrison804659a2018-10-16 16:43:38142#include "chrome/browser/ui/blocked_content/popup_blocker.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"
Makoto Shimazuc7502932018-08-15 02:12:56150#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25151#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44152#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58153#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50154#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01155#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45156#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53157#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25158#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59159#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23160#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22161#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01162#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48163#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51164#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14165#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22166#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30167#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02168#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50169#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34170#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37171#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12172#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12173#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22174#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32175#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38176#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28177#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02178#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09179#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47180#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37181#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18182#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30183#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12184#include "components/autofill/core/common/autofill_switches.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"
Clark DuVall84a33d612020-04-17 16:01:00192#include "components/content_settings/browser/tab_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"
mukai077089f2014-09-11 18:41:52196#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45197#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08198#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03199#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54200#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28201#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43202#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09203#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03204#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24205#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32206#include "components/embedder_support/switches.h"
blundella5e3240a2016-01-05 11:30:43207#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01208#include "components/feature_engagement/public/feature_constants.h"
209#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39210#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20211#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53212#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16213#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12214#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
215#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
216#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06217#include "components/payments/content/payment_request_display_manager.h"
Clark DuValla11361ad32020-02-20 22:14:27218#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54219#include "components/permissions/quota_permission_context_impl.h"
Doug Turner9dcaf5962017-12-21 04:38:53220#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54221#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18222#include "components/policy/core/common/policy_service.h"
223#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26224#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54225#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08226#include "components/prefs/pref_service.h"
227#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21228#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54229#include "components/previews/content/previews_decider_impl.h"
230#include "components/previews/content/previews_ui_service.h"
231#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54232#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45233#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43234#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56235#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56236#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13237#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47238#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
239#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
240#include "components/safe_browsing/core/browser/url_checker_delegate.h"
241#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
242#include "components/safe_browsing/core/db/database_manager.h"
243#include "components/safe_browsing/core/features.h"
244#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58245#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Daniel Vogelheim6008f572018-09-24 14:35:14246#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49247#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48248#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49249#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23250#include "components/signin/public/identity_manager/identity_manager.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54251#include "components/site_isolation/preloaded_isolated_origins.h"
csharrisone985ebc2017-04-04 17:05:03252#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17253#include "components/translate/core/common/translate_switches.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02254#include "components/ukm/app_source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21255#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28256#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33257#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46258#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22259#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39260#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33261#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43262#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30263#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38264#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28265#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03266#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31267#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41268#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09269#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03270#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59271#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19272#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31273#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35274#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47275#include "content/public/browser/navigation_handle.h"
276#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11277#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50278#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30279#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33280#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05281#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54282#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34283#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48284#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27285#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13286#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08287#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19288#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21289#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23290#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43291#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18292#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56293#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40294#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02295#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18296#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57297#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23298#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44299#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31300#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05301#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56302#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43303#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59304#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48305#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30306#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28307#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18308#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04309#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31310#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44311#include "media/media_buildflags.h"
312#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12313#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42314#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52315#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08316#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53317#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51318#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58319#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23320#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46321#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57322#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48323#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14324#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38325#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19326#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02327#include "services/metrics/public/cpp/ukm_builders.h"
328#include "services/metrics/public/cpp/ukm_recorder.h"
Takashi Toyoshima128441462019-10-16 04:19:17329#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37330#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50331#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50332#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13333#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05334#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34335#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03336#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06337#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02338#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02339#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02340#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19341#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31342#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17343#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21344#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26345#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18346#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54347#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39348#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08349#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35350#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56351#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21352#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49353#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57354#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45355#include "url/gurl.h"
356#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26357
[email protected]b48c9182011-10-26 18:03:30358#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20359#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14360#include "base/win/win_util.h"
361#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38362#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36363#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18364#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38365#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25366#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38367#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30368#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42369#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30370#include "chrome/app/chrome_crash_reporter_client.h"
Aya ElAttareb5fee12020-05-05 08:56:05371#include "chrome/browser/browser_process.h"
hashimotoa53e7e82016-10-26 06:30:47372#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17373#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30374#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24375#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18376#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08377#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48378#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41379#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32380#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58381#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00382#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
383#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44384#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39385#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31386#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33387#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05388#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Pavol Marko230ea2c92017-12-03 22:35:44389#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34390#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10391#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36392#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27393#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31394#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10395#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21396#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10397#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50398#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05399#include "components/policy/core/common/policy_pref_names.h"
400#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07401#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58402#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50403#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26404#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30405#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09406#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35407#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45408#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47409#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20410#include "chrome/browser/android/app_hooks.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36411#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36412#include "chrome/browser/android/devtools_manager_delegate_android.h"
413#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
414#include "chrome/browser/android/service_tab_launcher.h"
415#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42416#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09417#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56418#include "chrome/browser/download/android/available_offline_content_provider.h"
419#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07420#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38421#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11422#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07423#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47424#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36425#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54426#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00427#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36428#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45429#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04430#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45431#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30432#elif defined(OS_POSIX)
433#include "chrome/browser/chrome_browser_main_posix.h"
434#endif
435
tmartinofb341882017-02-10 19:36:53436#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40437#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36438#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54439#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59440#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02441#include "chrome/browser/search/instant_service.h"
442#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46443#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51444#include "chrome/browser/ui/browser.h"
445#include "chrome/browser/ui/browser_finder.h"
446#include "chrome/browser/ui/browser_list.h"
447#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20448#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51449#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39450#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
451#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43452#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27453#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28454#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36455
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33456#if defined(OS_WIN) || defined(OS_MACOSX) || \
457 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52458#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12459#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52460#endif
461
Joshua Perazace68e2f2019-09-23 18:44:24462#if defined(OS_LINUX)
Rohit Rao92f84b6a2020-03-25 14:57:50463#include "components/crash/core/app/crash_switches.h"
464#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24465#endif
466
[email protected]a220b5932013-09-21 03:47:44467#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02468#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02469#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50470#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02471#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13472#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43473#endif
[email protected]b80f68432011-05-02 17:22:30474
Maggie Caia2f03f52019-04-02 02:13:28475// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
476// single navigation throttle to display the intent picker on all platforms.
477#if !defined(OS_ANDROID)
478#if defined(OS_CHROMEOS)
479#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51480#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28481#else
482#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
483#endif
484#endif
485
[email protected]e8b6ca02013-07-10 18:00:51486#if defined(TOOLKIT_VIEWS)
487#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
488#endif
489
estaded3aa0e82016-02-17 22:55:21490#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
491#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51492#endif
493
Mohsen Izadif1958f22019-01-18 20:29:31494#if defined(USE_OZONE)
495#include "ui/ozone/public/ozone_platform.h"
496#endif
497
[email protected]e8b6ca02013-07-10 18:00:51498#if defined(USE_X11)
499#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
500#endif
501
brettwab78fef2016-10-12 02:56:05502#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10503#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38504#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19505#endif
506
Nico Weberaf3b00b2017-09-11 17:58:17507#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55508#include "components/nacl/browser/nacl_browser.h"
509#include "components/nacl/browser/nacl_host_message_filter.h"
510#include "components/nacl/browser/nacl_process_host.h"
511#include "components/nacl/common/nacl_process_type.h"
512#include "components/nacl/common/nacl_switches.h"
513#endif
514
brettw00899e62016-11-12 02:10:17515#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05516#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20517#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27518#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23519#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32520#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51521#include "chrome/browser/extensions/user_script_listener.h"
522#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28523#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49524#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46525#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39526#include "components/guest_view/browser/guest_view_base.h"
527#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25528#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31529#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35530#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32531#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12532#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57533#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48534#include "extensions/browser/guest_view/web_view/web_view_guest.h"
535#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
536#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31537#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27538#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28539#include "extensions/common/extension.h"
540#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13541#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28542#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33543#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28544#include "extensions/common/permissions/permissions_data.h"
545#include "extensions/common/permissions/socket_permission.h"
546#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34547#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25548
brettw4b461082016-11-19 18:55:16549#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55550#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27551#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39552#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55553#endif
554
bauerb8f9c37742017-03-30 15:04:12555#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
556#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
557#endif
558
yilkal240b4f22019-11-27 19:09:06559#if defined(OS_CHROMEOS)
Anatoliy Potapchuk762c40d2020-05-11 15:10:37560#include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06561#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
562#endif // defined(OS_CHROMEOS)
563
thakis678822e2017-04-20 17:20:34564#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38565#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09566#endif
567
weilifabbf7572017-05-22 19:05:16568#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21569#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16570#endif
Lei Zhanga2fa14c2018-05-15 00:05:21571
Xiaohan Wanga4e41842018-06-26 18:45:10572#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49573#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26574#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10575#include "chrome/browser/media/widevine_hardware_caps_win.h"
576#include "third_party/widevine/cdm/widevine_cdm_common.h"
577#endif
578#endif
579
mmenkedb2637ff2017-03-30 23:59:42580#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
581#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
582#endif
583
Nico Weberbc5b06f2019-07-26 14:00:13584#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35585#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32586#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35587#endif
588
Jian Lide7b43792018-06-01 23:22:13589#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54590#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13591#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
592#endif
593
Will Cassella40837ba2019-07-01 21:32:00594#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43595#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
596#endif
597
John Lee0ee748bf2019-12-11 21:35:44598#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
599#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
600#endif
601
Roger Tawa03ffdbd2020-01-16 18:12:54602#if BUILDFLAG(FULL_SAFE_BROWSING)
603#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
604#endif
605
Alexander Cooperc8448702020-03-14 01:39:56606#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23607#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56608#endif
609
[email protected]c7abd422012-09-25 00:20:08610using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39611using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31612using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13613using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59614using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00615using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02616using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11617using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33618using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13619using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05620using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38621using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39622
[email protected]0daaebfe2014-03-15 00:09:05623#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20624using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05625#endif
626
brettw00899e62016-11-12 02:10:17627#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28628using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27629using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28630using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28631using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27632#endif
633
brettw4b461082016-11-19 18:55:16634#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55635using plugins::ChromeContentBrowserClientPluginsPart;
636#endif
637
[email protected]c5dbef02011-05-13 05:06:09638namespace {
639
Will Harris1b9b4152019-08-21 22:33:50640#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30641// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
642// running on Windows 10 1511 and above. See
643// https://blogs.windows.com/blog/tag/code-integrity-guard/.
644const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35645 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50646#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
647 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30648
Colin Blundell9ee731dd2020-01-23 10:42:38649// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
650// parameters.
651void HandleSSLErrorWrapper(
652 content::WebContents* web_contents,
653 int cert_error,
654 const net::SSLInfo& ssl_info,
655 const GURL& request_url,
656 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38657 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
658 Profile* profile =
659 Profile::FromBrowserContext(web_contents->GetBrowserContext());
660
661 // This can happen if GetBrowserContext no longer exists by the time this
662 // gets called (e.g. the SSL error was in a webview that has since been
663 // destroyed); if that's the case we don't need to handle the error (and will
664 // crash if we attempt to).
665 if (!profile)
666 return;
667
Colin Blundell27331f92020-02-05 21:13:01668 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51669
670#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
671 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
672#endif
673
Colin Blundell9ee731dd2020-01-23 10:42:38674 SSLErrorHandler::HandleSSLError(
675 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53676 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51677 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38678 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38679 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
680}
681
lazyboy5d5fede02016-03-10 04:10:14682enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53683 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14684 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53685
686 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14687 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53688
689 // An extension or app tried to load a resource of a different platform app in
690 // a tab.
691 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
692
693 // A non-app and non-extension page tried to load a platform app in a tab.
694 APP_LOADED_IN_TAB_SOURCE_OTHER,
695
lazyboy5d5fede02016-03-10 04:10:14696 APP_LOADED_IN_TAB_SOURCE_MAX
697};
698
Lei Zhang2cfceac2018-11-14 19:36:33699// Cached version of the locale so we can return the locale on the I/O
700// thread.
701std::string& GetIOThreadApplicationLocale() {
702 static base::NoDestructor<std::string> s;
703 return *s;
704}
705
[email protected]f8f93eb2012-09-25 03:06:24706// Returns a copy of the given url with its host set to given host and path set
707// to given path. Other parts of the url will be the same.
708GURL ReplaceURLHostAndPath(const GURL& url,
709 const std::string& host,
710 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05711 url::Replacements<char> replacements;
712 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
713 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24714 return url.ReplaceComponents(replacements);
715}
716
madfbd10852017-01-20 03:15:33717// Handles the rewriting of the new tab page URL based on group policy.
718bool HandleNewTabPageLocationOverride(
719 GURL* url,
720 content::BrowserContext* browser_context) {
721 if (!url->SchemeIs(content::kChromeUIScheme) ||
722 url->host() != chrome::kChromeUINewTabHost)
723 return false;
724
725 Profile* profile = Profile::FromBrowserContext(browser_context);
726 std::string ntp_location =
727 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
728 if (ntp_location.empty())
729 return false;
730
731 *url = GURL(ntp_location);
732 return true;
733}
734
Becca Hughesfe8c32c2018-03-21 13:36:56735#if !defined(OS_ANDROID)
736// Check if the current url is whitelisted based on a list of whitelisted urls.
737bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57738 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56739 // Only check on HTTP and HTTPS pages.
740 if (!current_url.SchemeIsHTTPOrHTTPS())
741 return false;
742
743 for (auto const& value : whitelisted_urls) {
744 ContentSettingsPattern pattern =
745 ContentSettingsPattern::FromString(value.GetString());
746 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
747 continue;
748 if (pattern.Matches(current_url))
749 return true;
750 }
751
752 return false;
753}
754
755// Check if autoplay is allowed by policy configuration.
756bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
757 PrefService* prefs) {
758 DCHECK(prefs);
759
760 // Check if we have globally allowed autoplay by policy.
761 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
762 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
763 return true;
764 }
765
766 if (!contents)
767 return false;
768
769 // Check if the current URL matches a URL pattern on the whitelist.
770 const base::ListValue* autoplay_whitelist =
771 prefs->GetList(prefs::kAutoplayWhitelist);
772 return autoplay_whitelist &&
773 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
774 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
775}
776#endif
777
Joshua Perazaf890e4b2019-01-03 19:19:02778#if defined(OS_ANDROID)
779int GetCrashSignalFD(const base::CommandLine& command_line) {
780 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
781}
782#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03783breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
784 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02785 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52786 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02787 {
788 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31789 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03790 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50791 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02792 crash_handler->StartUploaderThread();
793 return crash_handler;
794 }
795}
796
avi3ef9ec9e2014-12-22 22:50:17797int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24798 if (crash_reporter::IsCrashpadEnabled()) {
799 int fd;
800 pid_t pid;
801 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
802 }
803
[email protected]9de4da52014-05-24 12:26:50804 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39805 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31806 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02807 if (!crash_handler)
808 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18809 return crash_handler->GetDeathSignalSocket();
810 }
811
812 std::string process_type =
813 command_line.GetSwitchValueASCII(switches::kProcessType);
814
[email protected]779dd282013-10-19 15:57:02815 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31816 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02817 if (!crash_handler)
818 crash_handler = CreateCrashHandlerHost(process_type);
819 return crash_handler->GetDeathSignalSocket();
820 }
[email protected]a1733df2012-06-22 11:24:18821
[email protected]779dd282013-10-19 15:57:02822 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31823 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02824 if (!crash_handler)
825 crash_handler = CreateCrashHandlerHost(process_type);
826 return crash_handler->GetDeathSignalSocket();
827 }
[email protected]a1733df2012-06-22 11:24:18828
[email protected]779dd282013-10-19 15:57:02829 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31830 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02831 if (!crash_handler)
832 crash_handler = CreateCrashHandlerHost(process_type);
833 return crash_handler->GetDeathSignalSocket();
834 }
[email protected]a1733df2012-06-22 11:24:18835
James Cook9207cc12017-10-19 17:08:39836 if (process_type == switches::kUtilityProcess) {
837 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
838 if (!crash_handler)
839 crash_handler = CreateCrashHandlerHost(process_type);
840 return crash_handler->GetDeathSignalSocket();
841 }
842
[email protected]a1733df2012-06-22 11:24:18843 return -1;
844}
Joshua Perazaf890e4b2019-01-03 19:19:02845#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18846
[email protected]eabbfb12013-04-05 23:28:35847void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52848 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33849 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35850}
851
estark3ba11132015-04-10 01:38:33852// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31853// SSLErrorHandler. Uses CertificateReportingService to send reports. The
854// service handles queueing and re-sending of failed reports. Each certificate
855// error creates a new instance of this class.
856class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33857 public:
meacerf43117a2016-12-27 21:02:31858 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12859 content::WebContents* web_contents)
860 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
861 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31862 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33863
864 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55865 void ReportInvalidCertificateChain(
866 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31867 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33868 }
869
870 private:
meacerf43117a2016-12-27 21:02:31871 CertificateReportingService* service_;
872
873 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33874};
875
brettw00899e62016-11-12 02:10:17876#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53877
878AppLoadedInTabSource ClassifyAppLoadedInTabSource(
879 const GURL& opener_url,
880 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58881 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
882 // The forbidden app URL was being opened by a non-extension page (e.g.
883 // http).
884 return APP_LOADED_IN_TAB_SOURCE_OTHER;
885 }
886
887 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53888 // The forbidden app URL was being opened by a different app or extension.
889 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
890 }
Lei Zhang7d0b0f42019-10-12 03:47:58891
892 // This platform app was trying to window.open() one of its own URLs.
893 if (opener_url ==
894 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
895 // Source was the background page.
896 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
897 }
898
899 // Source was a different page inside the app.
900 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53901}
[email protected]9c7656382014-08-08 21:02:30902
Charles Harrison34f67862017-08-22 01:04:17903// Returns true if there is is an extension matching |url| in
904// |opener_render_process_id| with APIPermission::kBackground.
905//
906// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
907// hosted app, even though normal extensions just use the host.
908bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35909 extensions::ProcessMap* process_map,
910 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17911 const GURL& url,
csharrison95f01e922017-04-24 18:52:35912 int opener_render_process_id) {
913 // Note: includes web URLs that are part of an extension's web extent.
914 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17915 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35916 return extension &&
917 extension->permissions_data()->HasAPIPermission(
918 APIPermission::kBackground) &&
919 process_map->Contains(extension->id(), opener_render_process_id);
920}
Kevin Marshall32f99d7e2017-07-11 23:17:46921
csharrison95f01e922017-04-24 18:52:35922#endif
923
Darin Fishere41aab52020-01-29 18:31:23924mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12925 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23926 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
927 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
928 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
929 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12930}
931
Julian Pastarmovb4773b82020-04-21 16:34:14932// Encapculates logic to determine if enterprise policies should be honored.
933// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
934// as a new central class to replace those checks is in the making.
935bool ShouldHonorPolicies() {
936#if defined(OS_WIN)
937 bool is_enterprise_version =
938 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
939 return base::win::IsEnrolledToDomain() ||
940 (base::win::IsDeviceRegisteredWithManagement() &&
941 is_enterprise_version);
942#else // defined(OS_WIN)
943 // TODO(pastarmovj): Replace this with check for MacOS and the new management
944 // service once it is ready.
945 return true;
946#endif // defined(OS_WIN)
947}
948
John Abd-El-Malek92bf3602019-07-31 02:25:48949void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04950 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48951 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45952 bool has_user_gesture,
953 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01954 // If there is no longer a WebContents, the request may have raced with tab
955 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04956 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01957 if (!web_contents)
958 return;
959
960 // Do not launch external requests attached to unswapped prerenders.
961 prerender::PrerenderContents* prerender_contents =
962 prerender::PrerenderContents::FromWebContents(web_contents);
963 if (prerender_contents) {
964 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:01965 return;
966 }
967
Robbie McElrath1294d242019-05-31 20:46:22968 // Do not launch external requests for schemes that have a handler registered.
969 ProtocolHandlerRegistry* protocol_handler_registry =
970 ProtocolHandlerRegistryFactory::GetForBrowserContext(
971 web_contents->GetBrowserContext());
972 if (protocol_handler_registry &&
973 protocol_handler_registry->IsHandledProtocol(url.scheme()))
974 return;
975
John Abd-El-Maleka67add82018-03-09 18:22:01976 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01977 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19978 PolicyBlacklistFactory::GetForBrowserContext(
979 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:14980 if (ShouldHonorPolicies() && service) {
John Abd-El-Maleka67add82018-03-09 18:22:01981 const policy::URLBlacklist::URLBlacklistState url_state =
982 service->GetURLBlacklistState(url);
983 is_whitelisted =
984 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
985 }
986
987 // If the URL is in whitelist, we launch it without asking the user and
988 // without any additional security checks. Since the URL is whitelisted,
989 // we assume it can be executed.
990 if (is_whitelisted) {
991 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
992 } else {
993 ExternalProtocolHandler::LaunchUrl(
994 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
995 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45996 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:01997 }
998}
999
Yutaka Hirano968d6252018-12-04 05:09:311000std::string GetProduct() {
1001 return version_info::GetProductNameAndVersionForUserAgent();
1002}
1003
Lukasz Anforowicz60d1253d2019-05-08 16:31:371004void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1005 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1006 // For renderer and utility (e.g. NetworkService) processes the switch is the
1007 // only available source, so below the combined (pref/policy + cmdline)
1008 // allowlist of secure origins is injected into |cmdline| for these other
1009 // processes.
1010 std::vector<std::string> allowlist =
1011 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1012 if (!allowlist.empty()) {
1013 cmdline->AppendSwitchASCII(
1014 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1015 base::JoinString(allowlist, ","));
1016 }
1017}
1018
Will Harris1b9b4152019-08-21 22:33:501019#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301020// Returns the full path to |module_name|. Both dev builds (where |module_name|
1021// is in the current executable's directory) and proper installs (where
1022// |module_name| is in a versioned sub-directory of the current executable's
1023// directory) are supported. The identified file is not guaranteed to exist.
1024base::FilePath GetModulePath(base::StringPiece16 module_name) {
1025 base::FilePath exe_dir;
1026 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1027 DCHECK(has_path);
1028
1029 // Look for the module in a versioned sub-directory of the current
1030 // executable's directory and return the path if it can be read. This is the
1031 // expected location of modules for proper installs.
1032 const base::FilePath module_path =
1033 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1034 if (base::PathExists(module_path))
1035 return module_path;
1036
1037 // Otherwise, return the path to the module in the current executable's
1038 // directory. This is the expected location of modules for dev builds.
1039 return exe_dir.Append(module_name);
1040}
Will Harris1b9b4152019-08-21 22:33:501041#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1042 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301043
Lukasz Anforowicz7724d092019-10-03 23:50:211044void MaybeAddThrottle(
1045 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles,
1046 std::unique_ptr<content::NavigationThrottle> maybe_throttle) {
1047 if (maybe_throttle)
1048 throttles->push_back(std::move(maybe_throttle));
1049}
1050
Evan Stade1e71d6dd2019-10-29 03:04:491051// Returns whether |web_contents| is within a hosted app.
1052bool IsInHostedApp(WebContents* web_contents) {
1053#if BUILDFLAG(ENABLE_EXTENSIONS)
1054 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1055 return (browser &&
1056 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1057#else
1058 return false;
1059#endif
1060}
1061
Lily Chenc2c9e9f2019-12-05 19:55:311062void MaybeRecordSameSiteCookieEngagementHistogram(
1063 content::RenderFrameHost* render_frame_host,
1064 blink::mojom::WebFeature feature) {
1065 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1066 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1067 return;
1068 }
1069
1070 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1071 DCHECK(render_frame_host);
1072
1073 content::BrowserContext* browser_context =
1074 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1075 Profile* profile = Profile::FromBrowserContext(browser_context);
1076 SiteEngagementService* site_engagement_service =
1077 SiteEngagementService::Get(profile);
1078 if (!site_engagement_service)
1079 return;
1080
1081 blink::mojom::EngagementLevel engagement_level =
1082 site_engagement_service->GetEngagementLevel(
1083 render_frame_host->GetLastCommittedURL());
1084 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1085 UMA_HISTOGRAM_ENUMERATION(
1086 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1087 engagement_level);
1088 } else {
1089 UMA_HISTOGRAM_ENUMERATION(
1090 "Net.SameSiteBlockedCookieSiteEngagement."
1091 "CookieInsecureAndSameSiteNone",
1092 engagement_level);
1093 }
1094}
1095
[email protected]9dbfff12011-07-01 19:37:071096} // namespace
[email protected]c5dbef02011-05-13 05:06:091097
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441098// Generate a pseudo-random permutation of the following brand/version pairs:
1099// 1. The base project (i.e. Chromium)
1100// 2. The browser brand, if available
1101// 3. A randomized string containing escaped characters to ensure proper
1102// header parsing, along with an arbitrarily low version to ensure proper
1103// version checking.
1104blink::UserAgentBrandList GenerateBrandVersionList(
1105 int seed,
1106 base::Optional<std::string> brand,
1107 std::string major_version) {
1108 DCHECK_GE(seed, 0);
1109 const int npermutations = 6; // 3!
1110 int permutation = seed % npermutations;
1111
1112 // Pick a stable permutation seeded by major version number. any values here
1113 // and in order should be under three.
1114 const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
1115 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
1116 const std::vector<int> order = orders[permutation];
1117 DCHECK_EQ(6u, orders.size());
1118 DCHECK_EQ(3u, order.size());
1119
1120 const std::vector<std::string> escaped_chars = {"\\", "\"", ";"};
1121 std::string greasey_brand =
1122 base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]],
1123 "A", escaped_chars[order[2]], "Brand"});
1124
1125 blink::UserAgentBrandVersion greasey_bv = {greasey_brand, "99"};
1126 blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version};
1127
1128 blink::UserAgentBrandList greased_brand_version_list(3);
1129
1130 if (brand) {
1131 blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version};
1132
1133 greased_brand_version_list[order[0]] = greasey_bv;
1134 greased_brand_version_list[order[1]] = chromium_bv;
1135 greased_brand_version_list[order[2]] = brand_bv;
1136 } else {
1137 greased_brand_version_list[seed % 2] = greasey_bv;
1138 greased_brand_version_list[(seed + 1) % 2] = chromium_bv;
1139
1140 // If left, the last element would make a blank "" at the end of the header.
1141 greased_brand_version_list.pop_back();
1142 }
1143
1144 return greased_brand_version_list;
1145}
1146
1147const blink::UserAgentBrandList& GetBrandVersionList() {
1148 static const base::NoDestructor<blink::UserAgentBrandList>
1149 greased_brand_version_list([] {
1150 int major_version_number;
1151 std::string major_version = version_info::GetMajorVersionNumber();
1152 base::StringToInt(major_version, &major_version_number);
1153 base::Optional<std::string> brand;
1154#if !BUILDFLAG(CHROMIUM_BRANDING)
1155 brand = version_info::GetProductName();
1156#endif
1157 return GenerateBrandVersionList(major_version_number, brand,
1158 major_version);
1159 }());
1160 return *greased_brand_version_list;
1161}
1162
Yutaka Hirano968d6252018-12-04 05:09:311163std::string GetUserAgent() {
1164 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1165 if (command_line->HasSwitch(switches::kUserAgent)) {
1166 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1167 if (net::HttpUtil::IsValidHeaderValue(ua))
1168 return ua;
1169 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1170 }
1171
John Delaneyac24e572019-04-30 19:47:021172 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1173 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351174 command_line->HasSwitch(switches::kUseMobileUserAgent),
1175 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021176 }
1177
Yutaka Hirano968d6252018-12-04 05:09:311178 std::string product = GetProduct();
1179#if defined(OS_ANDROID)
1180 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1181 product += " Mobile";
1182#endif
1183 return content::BuildUserAgentFromProduct(product);
1184}
1185
Mike West6e4cbb32019-02-13 09:40:171186blink::UserAgentMetadata GetUserAgentMetadata() {
1187 blink::UserAgentMetadata metadata;
Aaron Tagliaboschi9f01b682020-05-05 21:03:171188
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441189 metadata.brand_version_list = GetBrandVersionList();
Mike Weste555be862019-02-20 16:17:301190 metadata.full_version = version_info::GetVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171191 metadata.platform = version_info::GetOSType();
Yoav Weiss4838f1b2020-04-30 21:37:001192 metadata.platform_version =
1193 content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude,
1194 content::IncludeAndroidModel::Exclude);
Aaron Tagliaboschi0585bc932020-05-08 20:03:171195 metadata.architecture = content::GetLowEntropyCpuArchitecture();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361196 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171197
Aaron Tagliaboschibe775e12019-12-09 19:33:041198 metadata.mobile = false;
1199#if defined(OS_ANDROID)
1200 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1201 switches::kUseMobileUserAgent);
1202#endif
1203
Mike West6e4cbb32019-02-13 09:40:171204 return metadata;
1205}
1206
Ran Jia96d43d42018-05-02 17:14:531207ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051208 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311209 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161210#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551211 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401212#endif
[email protected]1deace22013-05-22 06:14:461213
Ahmed Fakhryd70bf37b2018-04-04 17:07:241214#if defined(OS_CHROMEOS)
1215 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1216#endif // defined(OS_CHROMEOS)
1217
John Lee0ee748bf2019-12-11 21:35:441218#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1219 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1220#endif
1221
brettw00899e62016-11-12 02:10:171222#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131223 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271224#endif
bena06f7d62017-04-04 20:48:521225
Sigurdur Asgeirsson70696672019-02-08 16:14:511226 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401227}
1228
1229ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031230 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1231 delete extra_parts_[i];
1232 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401233}
1234
[email protected]bca18382012-06-25 19:15:231235// static
Chris Palmerac7d75642017-11-22 20:12:541236void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1237 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131238 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1239 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541240 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1241 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461242 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541243}
1244
1245// static
[email protected]37ca3fe02013-07-05 15:32:441246void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341247 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251248 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1249 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1250 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281251 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1252 // user policy in addition to the same named ones in Local State (which are
1253 // used for mapping the command-line flags).
1254 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1255 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571256 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401257 registry->RegisterDictionaryPref(
1258 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041259 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101260#if !defined(OS_ANDROID)
1261 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561262 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101263#endif
Takashi Toyoshima128441462019-10-16 04:19:171264 registry->RegisterListPref(prefs::kCorsMitigationList);
1265 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231266}
1267
[email protected]eabbfb12013-04-05 23:28:351268// static
1269void ChromeContentBrowserClient::SetApplicationLocale(
1270 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481271 // The common case is that this function is called early in Chrome startup
1272 // before any threads are created or registered. When there are no threads,
1273 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001274 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331275 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481276 return;
1277 }
1278
1279 // Otherwise we're being called to change the locale. In this case set it on
1280 // the IO thread.
thestig00844cea2015-09-08 21:44:521281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351282
Sami Kyostila5e1306d2019-08-14 11:01:291283 base::PostTask(FROM_HERE, {BrowserThread::IO},
1284 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351285}
1286
Patrick Monette61dfef92019-05-30 23:06:271287std::unique_ptr<content::BrowserMainParts>
1288ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311289 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271290 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301291 // Construct the Main browser parts based on the OS type.
1292#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051293 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271294 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1295#elif defined(OS_MACOSX)
1296 main_parts =
1297 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1298#elif defined(OS_CHROMEOS)
1299 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1300 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261301#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271302 main_parts =
1303 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141304#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271305 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1306 startup_data_);
[email protected]b48c9182011-10-26 18:03:301307#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271308 main_parts =
1309 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041310#else
[email protected]b48c9182011-10-26 18:03:301311 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271312 main_parts =
1313 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301314#endif
1315
Xi Han9fd44002019-04-30 17:39:361316 bool add_profiles_extra_parts = true;
1317#if defined(OS_ANDROID)
1318 if (startup_data_->HasBuiltProfilePrefService())
1319 add_profiles_extra_parts = false;
1320#endif
1321 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271322 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031323
Xi Han9fd44002019-04-30 17:39:361324 // Construct additional browser parts. Stages are called in the order in
1325 // which they are added.
[email protected]c7480942011-11-08 19:18:271326#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221327#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
estaded3aa0e82016-02-17 22:55:211328 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
1329#else
riajiang7d6ec5c2017-01-25 16:40:331330 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351331#endif
1332#endif
1333
1334#if defined(OS_CHROMEOS)
1335 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331336 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221337#endif
[email protected]dc04be7c2012-03-15 23:57:491338
[email protected]e8b6ca02013-07-10 18:00:511339#if defined(USE_X11)
1340 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241341#endif
1342
Sigurdur Asgeirsson54b72702019-04-12 14:18:541343 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001344
Albert J. Wong59d85acb2017-08-10 00:50:571345 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571346
Sebastien Marchand8c0088102019-10-11 16:47:561347 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1348
Patrick Monette61dfef92019-05-30 23:06:271349 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041350
Zhenyao Mo73144652020-04-06 18:55:051351 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1352 // GpuDataManager initialization could pick up about:flags settings.
1353 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1354
[email protected]50462bf02011-11-21 19:13:311355 return main_parts;
[email protected]f967b722011-09-07 00:58:041356}
1357
michaeln96f887e22015-04-13 23:58:311358void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091359 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021360 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211361 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121362 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291363
Robert Sesek466e43e2019-08-19 22:02:021364 InitNetworkContextsParentDirectory();
1365
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1367 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311368}
1369
falkenb09d443f2016-04-07 12:36:121370bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1371 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1372}
1373
Gabriel Charettec8cca992017-08-10 18:21:491374void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1375 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1376}
1377
John Abd-El-Malek9d57f9c2019-02-20 18:50:041378bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361379 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041380}
1381
[email protected]e94bbcb2012-09-07 05:33:571382std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191383 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571384 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531385 std::string partition_id;
1386
1387 // The partition ID for webview guest processes is the string value of its
1388 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451389 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531390 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171391#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501392 // The partition ID for extensions with isolated storage is treated similarly
1393 // to the above.
1394 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1395 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1396 partition_id = site.spec();
1397#endif
[email protected]1bc28312012-11-08 08:31:531398
[email protected]056efdc2013-04-06 00:14:531399 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531400 return partition_id;
1401}
1402
1403bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1404 content::BrowserContext* browser_context,
1405 const std::string& partition_id) {
1406 // The default ID is empty and is always valid.
1407 if (partition_id.empty())
1408 return true;
1409
1410 return GURL(partition_id).is_valid();
1411}
1412
1413void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1414 content::BrowserContext* browser_context,
1415 const GURL& site,
[email protected]14acc642012-11-17 12:20:101416 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531417 std::string* partition_domain,
1418 std::string* partition_name,
1419 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101420 // Default to the browser-wide storage partition and override based on |site|
1421 // below.
1422 partition_domain->clear();
1423 partition_name->clear();
1424 *in_memory = false;
1425
brettw00899e62016-11-12 02:10:171426#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451427 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331428 site, partition_domain, partition_name, in_memory);
1429
1430 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101431 // If |can_be_default| is false, the caller is stating that the |site|
1432 // should be parsed as if it had isolated storage. In particular it is
1433 // important to NOT check ExtensionService for the is_storage_isolated()
1434 // attribute because this code path is run during Extension uninstall
1435 // to do cleanup after the Extension has already been unloaded from the
1436 // ExtensionService.
1437 bool is_isolated = !can_be_default;
1438 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341439 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1440 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101441 }
[email protected]1bc28312012-11-08 08:31:531442
[email protected]14acc642012-11-17 12:20:101443 if (is_isolated) {
1444 CHECK(site.has_host());
1445 // For extensions with isolated storage, the the host of the |site| is
1446 // the |partition_domain|. The |in_memory| and |partition_name| are only
1447 // used in guest schemes so they are cleared here.
1448 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531449 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101450 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531451 }
[email protected]1df3d972014-06-11 04:55:181452 success = true;
1453 }
1454#endif
1455
[email protected]14acc642012-11-17 12:20:101456 // Assert that if |can_be_default| is false, the code above must have found a
1457 // non-default partition. If this fails, the caller has a serious logic
1458 // error about which StoragePartition they expect to be in and it is not
1459 // safe to continue.
1460 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441461}
1462
[email protected]38b098f2012-03-14 21:11:571463content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441464ChromeContentBrowserClient::GetWebContentsViewDelegate(
1465 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101466 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321467}
1468
Bo Liu4ade6b1b22017-11-28 02:26:351469bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1470#if defined(OS_ANDROID)
1471 const base::android::ApplicationState app_state =
1472 base::android::ApplicationStatusListener::GetState();
1473 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1474 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1475 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1476#else
1477 return true;
1478#endif
1479}
1480
[email protected]6f2862742013-12-20 07:53:191481void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231482 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301483 int id = host->GetID();
1484 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341485#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491486 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061487#endif
Brett Wilson65f951c2016-11-03 22:06:121488#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401489 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031490#endif
Darin Fisher54cba872020-02-06 21:12:551491 host->AddFilter(new prerender::PrerenderMessageFilter(id));
Darin Fisher8c84328c2019-07-23 02:50:001492
Darin Fisher09aa7222019-08-29 09:27:361493 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001494 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021495
grunell086a4112017-03-02 09:23:041496 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1497 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021498 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121499 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021500 host->SetUserData(
1501 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091502 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021503 audio_debug_recordings_handler));
1504
Nico Weberaf3b00b2017-09-11 17:58:171505#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031506 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1507 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351508#endif
jeremyim364ac1182015-03-03 18:49:431509
Xiaohan Wang9b34281b2017-09-08 23:48:331510#if defined(OS_ANDROID)
1511 // Data cannot be persisted if the profile is off the record.
1512 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061513 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071514
1515 // Register CrashMemoryMetricsCollector to report oom related metrics.
1516 host->SetUserData(
1517 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1518 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331519#endif
1520
Jun Caidb3f93cc2018-07-09 21:54:551521 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061522 RendererUpdaterFactory::GetForProfile(original_profile)
1523 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071524
[email protected]a48ab7112014-08-01 16:48:031525 for (size_t i = 0; i < extra_parts_.size(); ++i)
1526 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141527}
1528
[email protected]3d7474ff2011-07-27 17:47:371529GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571530 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301531 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371532 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521533 if (!profile)
1534 return url;
1535
Marc Treib7d467b792017-12-04 13:31:031536#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291537 // If the input |url| should be assigned to the Instant renderer, make its
1538 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311539 // This needs to happen even if |url| corresponds to an isolated origin; see
1540 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131541 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1542 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031543#endif
[email protected]b3cb3a32013-07-31 01:32:291544
brettw00899e62016-11-12 02:10:171545#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301546 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1547 url);
[email protected]d5a74be2014-08-08 01:01:271548#else
1549 return url;
1550#endif
[email protected]36fb2c7c2011-04-04 15:49:081551}
1552
Alexander Yashkin6aedc6e2018-08-15 08:58:451553bool ChromeContentBrowserClient::
1554 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1555 content::BrowserContext* browser_context,
1556 content::SiteInstance* candidate_site_instance,
1557 bool is_main_frame,
1558 const GURL& candidate_url,
1559 const GURL& destination_url) {
1560 DCHECK(browser_context);
1561 DCHECK(candidate_site_instance);
1562#if BUILDFLAG(ENABLE_EXTENSIONS)
1563 return ChromeContentBrowserClientExtensionsPart::
1564 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1565 browser_context, candidate_site_instance, is_main_frame,
1566 candidate_url, destination_url);
1567#else
1568 return true;
1569#endif
1570}
1571
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521572bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411573#if defined(OS_ANDROID)
1574 return true;
1575#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421576 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411577#else
1578 return false;
1579#endif // defined(OS_ANDROID)
1580}
1581
[email protected]056ad2a2011-07-12 02:13:551582bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441583 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591584 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521585 Profile* profile = Profile::FromBrowserContext(browser_context);
1586 if (!profile)
1587 return false;
1588
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301589 // NTP should use process-per-site. This is a performance optimization to
1590 // reduce process count associated with NTP tabs.
Aaron Colwellabb540b2020-05-05 19:15:591591 if (site_url == GURL(chrome::kChromeUINewTabURL))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301592 return true;
Peter Boström8e9b1632019-08-22 23:12:471593
1594 // The web footer experiment should share its renderer to not effectively
1595 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591596 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471597 return true;
1598
Marc Treib7d467b792017-12-04 13:31:031599#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591600 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521601 return true;
Marc Treib7d467b792017-12-04 13:31:031602#endif
[email protected]c5dec6292013-01-25 04:54:521603
brettw00899e62016-11-12 02:10:171604#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301605 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591606 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301607 return true;
[email protected]d5a74be2014-08-08 01:01:271608#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301609
1610 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1611 // (rather than process-per-site).
1612 return false;
[email protected]056ad2a2011-07-12 02:13:551613}
1614
Lukasz Anforowicz32d27122018-04-09 21:48:331615bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1616 content::BrowserContext* browser_context,
1617 const GURL& site_url) {
1618 Profile* profile = Profile::FromBrowserContext(browser_context);
1619 if (!profile)
1620 return false;
1621
1622#if !defined(OS_ANDROID)
1623 // Instant renderers should not use a spare process, because they require
1624 // passing switches::kInstantProcess to the renderer process when it
1625 // launches. A spare process is launched earlier, before it is known which
1626 // navigation will use it, so it lacks this flag.
1627 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1628 return false;
1629#endif
1630
1631#if BUILDFLAG(ENABLE_EXTENSIONS)
1632 return ChromeContentBrowserClientExtensionsPart::
1633 ShouldUseSpareRenderProcessHost(profile, site_url);
1634#else
1635 return true;
1636#endif
1637}
1638
nickcc0d9142015-10-14 16:27:101639bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421640 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101641 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421642 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171643#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101644 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421645 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101646 return true;
1647 }
1648#endif
1649 return false;
1650}
1651
nick7d0984c2015-08-29 00:13:461652// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1653// origin-lock enforcement, where we don't have a way to efficiently know
1654// effective URLs on the IO thread, and wind up killing processes that e.g.
1655// request cookies for their actual URL. This whole function (and its
1656// ExtensionsPart) should be removed once we add that ability to the IO thread.
1657bool ChromeContentBrowserClient::ShouldLockToOrigin(
1658 content::BrowserContext* browser_context,
1659 const GURL& effective_site_url) {
1660 // Origin lock to the search scheme would kill processes upon legitimate
1661 // requests for cookies from the search engine's domain.
1662 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1663 return false;
1664
brettw00899e62016-11-12 02:10:171665#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461666 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1667 browser_context, effective_site_url)) {
1668 return false;
1669 }
1670#endif
1671 return true;
creise5d6d1732015-08-25 19:47:061672}
1673
Nasko Oskov39023672020-05-06 17:31:141674bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1675 base::StringPiece scheme) {
1676 // Note: This method can be called from multiple threads. It is not safe to
1677 // assume it runs only on the UI thread.
1678
1679 // chrome-search: documents commit only in the NTP instant process and are not
1680 // locked to chrome-search: origin.
1681 if (scheme == chrome::kChromeSearchScheme)
1682 return false;
1683
1684 // All other WebUIs must be locked to origin.
1685 return true;
1686}
1687
Maks Orlovich0e23e312019-07-16 13:13:561688bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021689 base::StringPiece scheme,
1690 bool is_embedded_origin_secure) {
1691 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1692 return true;
Maks Orlovich0e23e312019-07-16 13:13:561693#if BUILDFLAG(ENABLE_EXTENSIONS)
1694 return scheme == extensions::kExtensionScheme;
1695#else
1696 return false;
1697#endif
1698}
1699
Lily Chen0db055b2019-11-15 20:29:021700bool ChromeContentBrowserClient::
1701 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1702 base::StringPiece scheme,
1703 bool is_embedded_origin_secure) {
1704 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1705}
1706
Lukasz Anforowicz7097890d2019-11-20 21:49:221707void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021708 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591709 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021710 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221711 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071712#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221713 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021714 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071715#endif
1716}
1717
[email protected]73b718f2014-01-27 02:59:461718// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1719// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411720void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1721 std::vector<std::string>* additional_schemes) {
1722 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241723 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351724 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061725}
1726
alexmos94875b3b2017-03-16 22:19:011727void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1728 std::vector<std::string>* additional_schemes) {
1729 GetAdditionalWebUISchemes(additional_schemes);
1730
1731#if BUILDFLAG(ENABLE_EXTENSIONS)
1732 additional_schemes->push_back(extensions::kExtensionScheme);
1733#endif
1734}
1735
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521736bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011737 return webui::LogWebUIUrl(web_ui_url);
1738}
1739
John Abd-El-Malek04bfa8532018-07-12 05:28:221740bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1741 const url::Origin& origin) {
1742 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1743 origin);
1744}
1745
[email protected]46fb9442011-12-09 17:57:471746bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1747 return ProfileIOData::IsHandledURL(url);
1748}
1749
[email protected]c4365fa42013-05-14 01:08:241750bool ChromeContentBrowserClient::CanCommitURL(
1751 content::RenderProcessHost* process_host,
1752 const GURL& url) {
brettw00899e62016-11-12 02:10:171753#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441754 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1755 url);
[email protected]d5a74be2014-08-08 01:01:271756#else
1757 return true;
1758#endif
[email protected]c4365fa42013-05-14 01:08:241759}
1760
rdevlin.cronina32a0902016-11-09 15:50:201761void ChromeContentBrowserClient::OverrideNavigationParams(
1762 SiteInstance* site_instance,
1763 ui::PageTransition* transition,
1764 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581765 content::Referrer* referrer,
1766 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201767 DCHECK(transition);
1768 DCHECK(is_renderer_initiated);
1769 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471770 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1771 // use for making security decisions 99.44% of the time, for detecting the NTP
1772 // it is reliable and the correct way. See http://crbug.com/624410.
1773 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201774 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581775 // Clicks on tiles of the new tab page should be treated as if a user
1776 // clicked on a bookmark. This is consistent with native implementations
1777 // like Android's. This also helps ensure that security features (like
1778 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1779 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201780 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1781 *is_renderer_initiated = false;
1782 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581783 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421784 }
1785}
1786
Charles Reis29e9dd12017-09-28 00:59:151787bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1788 const GURL& url,
1789 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471790 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1791 // use for making security decisions 99.44% of the time, for detecting the NTP
1792 // it is reliable and the correct way. See http://crbug.com/624410.
1793 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1794 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151795}
1796
[email protected]2a5221b2011-09-27 23:07:311797bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301798 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311799 const GURL& site_url) {
1800 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301801 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441802 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521803 // share any host.
1804 if (!profile)
1805 return true;
1806
Marc Treib7895941d2017-11-28 12:37:021807#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141808 // Instant URLs should only be in the instant process and instant process
1809 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521810 InstantService* instant_service =
1811 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141812 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441813 bool is_instant_process =
1814 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141815 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131816 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141817 if (is_instant_process || should_be_in_instant_process)
1818 return is_instant_process && should_be_in_instant_process;
1819 }
Marc Treib7895941d2017-11-28 12:37:021820#endif
[email protected]c5dec6292013-01-25 04:54:521821
brettw00899e62016-11-12 02:10:171822#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131823 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1824 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271825#else
1826 return true;
1827#endif
[email protected]2a5221b2011-09-27 23:07:311828}
1829
[email protected]28c5d0b72014-05-13 08:19:591830bool ChromeContentBrowserClient::MayReuseHost(
1831 content::RenderProcessHost* process_host) {
1832 // If there is currently a prerender in progress for the host provided,
1833 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041834 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591835 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371836 prerender::PrerenderManagerFactory::GetForBrowserContext(
1837 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591838 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491839 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591840 return false;
1841 }
1842
1843 return true;
1844}
1845
[email protected]76411f412012-02-22 18:56:061846bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441847 content::BrowserContext* browser_context,
1848 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061849 // It has to be a valid URL for us to check for an extension.
1850 if (!url.is_valid())
1851 return false;
1852
brettw00899e62016-11-12 02:10:171853#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061854 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131855 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441856 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271857#else
1858 return false;
1859#endif
[email protected]76411f412012-02-22 18:56:061860}
1861
Alex Moshchuk9c9e3882018-11-02 19:57:031862bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1863 content::RenderFrameHost* main_frame) {
1864#if BUILDFLAG(ENABLE_EXTENSIONS)
1865 return ChromeContentBrowserClientExtensionsPart::
1866 ShouldSubframesTryToReuseExistingProcess(main_frame);
1867#else
1868 return true;
1869#endif
1870}
1871
[email protected]6f371442011-11-09 06:45:461872void ChromeContentBrowserClient::SiteInstanceGotProcess(
1873 SiteInstance* site_instance) {
1874 CHECK(site_instance->HasProcess());
1875
Aran Gilmanf010bdd2019-08-28 19:55:441876 Profile* profile =
1877 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521878 if (!profile)
1879 return;
1880
Marc Treib7895941d2017-11-28 12:37:021881#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521882 // Remember the ID of the Instant process to signal the renderer process
1883 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131884 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1885 profile)) {
[email protected]c5dec6292013-01-25 04:54:521886 InstantService* instant_service =
1887 InstantServiceFactory::GetForProfile(profile);
1888 if (instant_service)
1889 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1890 }
Marc Treib7895941d2017-11-28 12:37:021891#endif
[email protected]c5dec6292013-01-25 04:54:521892
[email protected]a48ab7112014-08-01 16:48:031893 for (size_t i = 0; i < extra_parts_.size(); ++i)
1894 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461895}
1896
1897void ChromeContentBrowserClient::SiteInstanceDeleting(
1898 SiteInstance* site_instance) {
1899 if (!site_instance->HasProcess())
1900 return;
1901
[email protected]a48ab7112014-08-01 16:48:031902 for (size_t i = 0; i < extra_parts_.size(); ++i)
1903 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461904}
1905
[email protected]453f5432013-11-26 19:43:001906bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141907 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561908 const GURL& current_effective_url,
1909 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171910#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131911 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561912 ShouldSwapBrowsingInstancesForNavigation(
1913 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271914#else
1915 return false;
1916#endif
[email protected]e3daf3c2011-10-05 21:17:081917}
1918
Nasko Oskovd83b5712018-05-04 04:50:571919bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1920 // TODO(nasko): Consider supporting error page isolation in subframes if
1921 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381922 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571923}
1924
[email protected]3d831992013-07-04 01:13:291925bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1926 return !url.SchemeIs(chrome::kChromeNativeScheme);
1927}
1928
Alex Moshchukd252c192017-07-17 22:03:481929std::vector<url::Origin>
1930ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1931 std::vector<url::Origin> isolated_origin_list;
1932
Alex Moshchuk89352a72017-10-25 20:25:591933// Sign-in process isolation is not needed on Android, see
1934// https://crbug.com/739418.
1935#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381936 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121937 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591938#endif
Alex Moshchukd252c192017-07-17 22:03:481939
Alex Moshchuk81d2a29e2019-07-16 01:14:381940#if BUILDFLAG(ENABLE_EXTENSIONS)
1941 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1942 GetOriginsRequiringDedicatedProcess();
1943 std::move(std::begin(origins_from_extensions),
1944 std::end(origins_from_extensions),
1945 std::back_inserter(isolated_origin_list));
1946#endif
1947
Alex Moshchuk51e1428b2020-04-22 18:00:541948 // Include additional origins preloaded with specific browser configurations,
1949 // if any. For example, this is used on Google Chrome for Android to preload
1950 // a list of important sites to isolate.
1951 auto built_in_origins =
1952 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
1953 std::move(std::begin(built_in_origins), std::end(built_in_origins),
1954 std::back_inserter(isolated_origin_list));
1955
Alex Moshchukd252c192017-07-17 22:03:481956 return isolated_origin_list;
1957}
1958
Lukasz Anforowicz5e201abd2018-03-24 00:41:061959bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341960 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1961}
1962
1963bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371964 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061965}
1966
Alex Moshchuk082b5f82019-03-14 01:34:161967std::vector<std::string>
1968ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1969 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1970 return {"Isolate Password Sites"};
1971 else
1972 return {};
1973}
1974
Alex Moshchuke256d562019-04-26 21:43:571975void ChromeContentBrowserClient::PersistIsolatedOrigin(
1976 content::BrowserContext* context,
1977 const url::Origin& origin) {
1978 DCHECK(!context->IsOffTheRecord());
1979 Profile* profile = Profile::FromBrowserContext(context);
1980 ListPrefUpdate update(profile->GetPrefs(),
1981 prefs::kUserTriggeredIsolatedOrigins);
1982 base::ListValue* list = update.Get();
1983 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361984 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121985 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571986}
1987
Ken Rockot314714c2017-11-05 23:36:241988bool ChromeContentBrowserClient::IsFileAccessAllowed(
1989 const base::FilePath& path,
1990 const base::FilePath& absolute_path,
1991 const base::FilePath& profile_path) {
1992 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1993 profile_path);
1994}
1995
[email protected]d2e1a0a2014-06-16 15:49:371996namespace {
1997
1998bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171999 const base::CommandLine& browser_command_line =
2000 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:352001 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372002 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:352003 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372004 return false;
[email protected]9ef49b42014-08-07 16:44:242005 return true;
[email protected]d2e1a0a2014-06-16 15:49:372006}
2007
bmcquade5d2d9cf32015-06-19 17:42:282008void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2009 const base::CommandLine& browser_command_line,
2010 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522011 // List of field trials that modify the blink-settings command line flag. No
2012 // two field trials in the list should specify the same keys, otherwise one
2013 // field trial may overwrite another. See Source/core/frame/Settings.in in
2014 // Blink for the list of valid keys.
2015 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162016 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2017 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2018 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2019 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522020 };
2021
2022 std::vector<std::string> blink_settings;
2023 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2024 // Each blink-settings field trial should include a forcing_flag group,
2025 // to make sure that clients that specify the blink-settings flag on the
2026 // command line are excluded from the experiment groups. To make
2027 // sure we assign clients that specify this flag to the forcing_flag
2028 // group, we must call GetVariationParams for each field trial first
2029 // (for example, before checking HasSwitch() and returning), since
2030 // GetVariationParams has the side-effect of assigning the client to
2031 // a field trial group.
2032 std::map<std::string, std::string> params;
2033 if (variations::GetVariationParams(field_trial_name, &params)) {
2034 for (const auto& param : params) {
2035 blink_settings.push_back(base::StringPrintf(
2036 "%s=%s", param.first.c_str(), param.second.c_str()));
2037 }
2038 }
2039 }
pmeenan9ac669682015-08-17 14:57:032040
bmcquade9dd54cc2015-06-22 16:56:522041 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282042 return;
2043 }
2044
2045 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2046 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032047 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522048 // blink-settings flag into a group with no params, and we return
2049 // above if no params were specified, so it's an error if we reach
2050 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282051 LOG(WARNING) << "Received field trial params, "
2052 "but blink-settings switch already specified.";
2053 return;
2054 }
2055
bmcquade5d2d9cf32015-06-19 17:42:282056 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262057 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282058}
2059
[email protected]d2e1a0a2014-06-16 15:49:372060} // namespace
2061
[email protected]b80f68432011-05-02 17:22:302062void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172063 base::CommandLine* command_line,
2064 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062065#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352066 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062067 GoogleUpdateSettings::LoadMetricsClientInfo();
2068 if (client_info) {
2069 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2070 client_info->client_id);
2071 }
2072#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022073#if defined(OS_ANDROID)
2074 bool enable_crash_reporter = true;
2075#else
Joshua Perazace68e2f2019-09-23 18:44:242076 bool enable_crash_reporter = false;
2077 if (crash_reporter::IsCrashpadEnabled()) {
2078 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2079 enable_crash_reporter = true;
2080
2081 int fd;
2082 pid_t pid;
2083 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2084 command_line->AppendSwitchASCII(
2085 crash_reporter::switches::kCrashpadHandlerPid,
2086 base::NumberToString(pid));
2087 }
2088 } else {
2089 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2090 }
Joshua Perazaf890e4b2019-01-03 19:19:022091#endif
2092 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512093 std::string switch_value;
dcheng4af48582016-04-19 00:29:352094 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532095 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512096 if (client_info)
2097 switch_value = client_info->client_id;
2098 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252099 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302100 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512101 switch_value);
[email protected]b80f68432011-05-02 17:22:302102 }
Mark Mentovaic67fa64f2015-03-24 14:00:062103#endif
[email protected]b80f68432011-05-02 17:22:302104
[email protected]f1933792011-06-14 00:49:342105 if (logging::DialogsAreSuppressed())
2106 command_line->AppendSwitch(switches::kNoErrorDialogs);
2107
[email protected]b80f68432011-05-02 17:22:302108 std::string process_type =
2109 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172110 const base::CommandLine& browser_command_line =
2111 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322112
[email protected]7c9b6f92013-09-10 18:11:352113 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442114 switches::kUserAgent,
2115 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352116 };
2117 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372118 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322119
fqj15ff3f72015-10-09 19:20:022120 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432121 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312122 };
fqj15ff3f72015-10-09 19:20:022123 command_line->CopySwitchesFrom(browser_command_line,
2124 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372125 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312126
David Van Cleve3df6abb2019-11-26 17:52:512127 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2128 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2129
fqj15ff3f72015-10-09 19:20:022130#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332131 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2132 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522133 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332134 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2135 homedir.value().c_str());
2136#endif
2137
[email protected]718eab62011-10-05 21:16:522138 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032139 content::RenderProcessHost* process =
2140 content::RenderProcessHost::FromID(child_process_id);
2141 Profile* profile =
2142 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442143 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032144 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442145 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2146 process, profile);
[email protected]a48ab7112014-08-01 16:48:032147 }
2148
[email protected]b80f68432011-05-02 17:22:302149#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442150 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2151 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302152 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442153 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2154 login_profile);
[email protected]b80f68432011-05-02 17:22:302155#endif
2156
Aran Gilmanf010bdd2019-08-28 19:55:442157 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222158 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372159 if (process) {
[email protected]a8d851f82011-12-21 00:32:372160 PrefService* prefs = profile->GetPrefs();
2161 // Currently this pref is only registered if applied via a policy.
2162 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2163 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2164 // Turn this policy into a command line switch.
2165 command_line->AppendSwitch(switches::kDisable3DAPIs);
2166 }
[email protected]718eab62011-10-05 21:16:522167
[email protected]1733b782014-06-19 18:51:552168 const base::ListValue* switches =
2169 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2170 if (switches) {
2171 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112172 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552173 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142174 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552175 command_line->AppendSwitch(switch_to_enable);
2176 }
2177 }
2178
Daniel Rubery9eb1e0912020-05-08 17:57:322179#if defined(FULL_SAFE_BROWSING)
[email protected]a8d851f82011-12-21 00:32:372180 // Disable client-side phishing detection in the renderer if it is
Daniel Rubery9eb1e0912020-05-08 17:57:322181 // disabled in the Profile preferences, or by command line flag.
Bettinae83f522c72020-03-12 01:52:332182 if (!safe_browsing::IsSafeBrowsingEnabled(*prefs) ||
Daniel Rubery9eb1e0912020-05-08 17:57:322183 !safe_browsing::ClientSideDetectionServiceFactory::GetForProfile(
2184 profile)) {
[email protected]a8d851f82011-12-21 00:32:372185 command_line->AppendSwitch(
2186 switches::kDisableClientSidePhishingDetection);
2187 }
Daniel Rubery9eb1e0912020-05-08 17:57:322188#endif
[email protected]0045b0f42012-07-26 11:52:082189
vitalybukaa7ae5052014-09-26 04:11:132190 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2191 command_line->AppendSwitch(switches::kDisablePrintPreview);
2192
Marc Treib7895941d2017-11-28 12:37:022193#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522194 InstantService* instant_service =
2195 InstantServiceFactory::GetForProfile(profile);
2196 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542197 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522198 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542199 }
Marc Treib7895941d2017-11-28 12:37:022200#endif
fqjba8749c2015-10-29 15:33:072201
fqj38306f7b2015-11-02 16:59:062202 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542203 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432204 command_line->AppendSwitch(
2205 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542206 }
Daniel Vogelheim976f1c22017-11-22 16:26:032207
Lukasz Anforowicz60d1253d2019-05-08 16:31:372208 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2209
Amr Aboelkherb04cbf32019-04-29 15:17:102210 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2211 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292212 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102213 }
Katie Dillonc25ee5c92019-09-12 17:05:422214
2215 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2216 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2217 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2218 }
Takashi Toyoshima128441462019-10-16 04:19:172219
Mason Freed490f2a22019-11-05 21:41:292220 if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) &&
2221 prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) {
2222 command_line->AppendSwitch(switches::kWebComponentsV0Enabled);
2223 }
Mason Freed52fa36d72020-02-27 17:52:482224 if (prefs->HasPrefPath(prefs::kUseLegacyFormControls) &&
2225 prefs->GetBoolean(prefs::kUseLegacyFormControls)) {
2226 command_line->AppendSwitch(switches::kUseLegacyFormControls);
2227 }
Mason Freed490f2a22019-11-05 21:41:292228
Daniel Libbyc5bfd91f2020-03-07 03:44:102229 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2230 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2231 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2232 }
2233
Takashi Toyoshima0dab73302019-10-18 01:51:362234 if (!profile->ShouldEnableOutOfBlinkCors()) {
2235 command_line->AppendSwitch(
2236 network::switches::kForceToDisableOutOfBlinkCors);
2237 }
Adrienne Walker297651292020-05-08 00:23:182238
2239 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2240 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2241 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2242 }
[email protected]47c7ec82012-01-18 03:29:212243 }
[email protected]4287a3d2011-06-13 23:56:512244
[email protected]d2e1a0a2014-06-16 15:49:372245 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352246 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042247
Aran Gilmanf010bdd2019-08-28 19:55:442248 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2249 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282250
mdjonesa6b9e172016-09-23 16:24:302251#if defined(OS_ANDROID)
2252 // If the platform is Android, force the distillability service on.
2253 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2254#endif
2255
[email protected]47c7ec82012-01-18 03:29:212256 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512257 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192258 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412259 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302260#if defined(OS_CHROMEOS)
2261 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2262#endif
brettw00899e62016-11-12 02:10:172263#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512264 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272265 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172266 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512267 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272268 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172269 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172270 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282271#endif
estark4b003b332015-02-14 01:07:052272 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512273 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482274 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512275 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502276 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572277 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462278 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302279 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512280 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172281#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242282 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482283 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552284#endif
[email protected]ce304ce2013-02-22 21:54:452285 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342286#if defined(OS_CHROMEOS)
2287 switches::kForceAppMode,
2288#endif
Nico Weberaf3b00b2017-09-11 17:58:172289#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592290 switches::kForcePNaClSubzero,
2291#endif
Marc Treibad33cf942017-08-24 11:19:002292 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512293 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102294 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322295 embedder_support::kOriginTrialDisabledFeatures,
2296 embedder_support::kOriginTrialDisabledTokens,
2297 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512298 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512299 switches::kPpapiFlashPath,
2300 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032301 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092302 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512303 };
2304
2305 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372306 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172307 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172308#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382309 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442310 extensions::switches::kAllowHTTPBackgroundPage,
2311 extensions::switches::kEnableExperimentalExtensionApis,
2312 extensions::switches::kExtensionsOnChromeURLs,
2313 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382314 };
2315
2316 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372317 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282318#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372319 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132320 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512321 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512322 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502323 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172324#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242325 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582326 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592327 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412328 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552329#endif
[email protected]4287a3d2011-06-13 23:56:512330 switches::kPpapiFlashPath,
2331 switches::kPpapiFlashVersion,
2332 };
2333
2334 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372335 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112336 } else if (process_type == switches::kGpuProcess) {
2337 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2338 // because GPU is expected to be unreliable.
2339 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2340 !command_line->HasSwitch(switches::kDisableBreakpad))
2341 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302342 }
[email protected]6f08af82011-09-15 01:19:032343
Ian Barkley-Yeung550aae052019-07-11 00:11:112344#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302345 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112346 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292347 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112348 };
2349 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2350 base::size(kSwitchNames));
2351 }
2352#endif
2353
wittman832321f52016-10-10 18:18:382354 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442355 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342356
2357#if defined(OS_LINUX)
2358 // Processes may only query perf_event_open with the BPF sandbox disabled.
2359 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2360 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2361 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2362 }
2363#endif
[email protected]b80f68432011-05-02 17:22:302364}
2365
Olivier Yiptong0daa93f2019-08-22 19:40:082366std::string
2367ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2368 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2369}
2370
[email protected]b80f68432011-05-02 17:22:302371std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432372 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332373 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302374 return g_browser_process->GetApplicationLocale();
2375}
2376
[email protected]597a867b2011-11-18 18:31:202377std::string ChromeContentBrowserClient::GetAcceptLangs(
2378 content::BrowserContext* context) {
2379 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202380 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082381}
2382
Dana Fried34d580002019-04-24 20:05:482383gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492384 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482385 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082386}
2387
bengre8a146f2016-03-10 01:20:222388bool ChromeContentBrowserClient::IsDataSaverEnabled(
2389 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382390 if (!browser_context || browser_context->IsOffTheRecord())
2391 return false;
2392
Robert Ogdenc995d4fe2019-03-25 19:18:372393 Profile* profile = Profile::FromBrowserContext(browser_context);
2394 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412395 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2396 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222397}
2398
Kenichi Ishibashi46329872018-07-17 09:43:402399void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2400 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192401 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402402 DCHECK(browser_context);
2403 DCHECK(out_prefs);
2404 renderer_preferences_util::UpdateFromSystemSettings(
2405 out_prefs, Profile::FromBrowserContext(browser_context));
2406}
2407
Clark DuVall5690e742019-07-17 18:26:172408bool ChromeContentBrowserClient::AllowAppCache(
2409 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172410 const GURL& site_for_cookies,
2411 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172412 content::BrowserContext* context) {
2413 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2414 return CookieSettingsFactory::GetForProfile(
2415 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172416 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172417}
2418
Alexander Timin17edc742020-04-23 18:22:182419content::AllowServiceWorkerResult
2420ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072421 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542422 const GURL& site_for_cookies,
2423 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362424 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182425 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522426 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542427 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452428
brettw00899e62016-11-12 02:10:172429#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452430 // Check if this is an extension-related service worker, and, if so, if it's
2431 // allowed (this can return false if, e.g., the extension is disabled).
2432 // If it's not allowed, return immediately. We deliberately do *not* report
2433 // to the TabSpecificContentSettings, since the service worker is blocked
2434 // because of the extension, rather than because of the user's content
2435 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022436 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362437 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182438 return content::AllowServiceWorkerResult::No();
rdevlin.croninf5863da2015-09-10 19:21:452439 }
2440#endif
2441
falken3dbc36e2014-10-10 16:48:072442 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202443
shimazuce8af88122016-10-06 23:49:212444 // Check if JavaScript is allowed.
2445 content_settings::SettingInfo info;
2446 std::unique_ptr<base::Value> value =
2447 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452448 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212449 std::string(), &info);
2450 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2451 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2452
2453 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542454 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2455 scope, site_for_cookies, top_frame_origin);
Alexander Timin17edc742020-04-23 18:22:182456
2457 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2458 !allow_cookies);
falken3dbc36e2014-10-10 16:48:072459}
2460
Alexander Timin17edc742020-04-23 18:22:182461content::AllowServiceWorkerResult
2462ChromeContentBrowserClient::AllowServiceWorkerOnUI(
Matt Falkenhagen7b509e52019-08-15 23:11:412463 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542464 const GURL& site_for_cookies,
2465 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412466 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182467 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412468 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542469 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412470
2471#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022472 // Check if this is an extension-related service worker, and, if so, if it's
2473 // allowed (this can return false if, e.g., the extension is disabled).
2474 // If it's not allowed, return immediately. We deliberately do *not* report
2475 // to the TabSpecificContentSettings, since the service worker is blocked
2476 // because of the extension, rather than because of the user's content
2477 // settings.
2478 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2479 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182480 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022481 }
Matt Falkenhagen7b509e52019-08-15 23:11:412482#endif
2483
2484 Profile* profile = Profile::FromBrowserContext(context);
2485
2486 // Check if JavaScript is allowed.
2487 content_settings::SettingInfo info;
2488 std::unique_ptr<base::Value> value =
2489 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452490 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412491 std::string(), &info);
2492 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2493 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2494
2495 // Check if cookies are allowed.
2496 bool allow_cookies =
2497 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542498 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412499
Alexander Timin17edc742020-04-23 18:22:182500 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2501 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412502}
2503
Jochen Eisinger0ff7645c2017-11-28 08:11:262504bool ChromeContentBrowserClient::AllowSharedWorker(
2505 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542506 const GURL& site_for_cookies,
2507 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262508 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372509 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262510 content::BrowserContext* context,
2511 int render_process_id,
2512 int render_frame_id) {
2513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2514
2515 // Check if cookies are allowed.
2516 bool allow =
2517 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542518 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2519 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262520
Clark DuVall84a33d612020-04-17 16:01:002521 content_settings::TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372522 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2523 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262524 return allow;
2525}
2526
Patrick Monette6cb099a2019-09-18 19:31:272527bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2528 const std::string& scheme) {
2529#if BUILDFLAG(ENABLE_EXTENSIONS)
2530 // Extensions are allowed to start cross-origin shared workers.
2531 if (scheme == extensions::kExtensionScheme)
2532 return true;
2533#endif
2534
2535 return false;
2536}
2537
Clark DuVallab63d142019-07-23 04:24:362538bool ChromeContentBrowserClient::AllowSignedExchange(
2539 content::BrowserContext* browser_context) {
2540 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2541 Profile* profile = Profile::FromBrowserContext(browser_context);
2542 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2543}
2544
[email protected]f917df22014-07-10 07:45:492545void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352546 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572547 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172548 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572549 base::OnceCallback<void(bool)> callback) {
2550 Profile* profile = Profile::FromBrowserContext(browser_context);
2551 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172552 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352553
brettw00899e62016-11-12 02:10:172554#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572555 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492556#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572557 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492558#endif
2559}
2560
brettw00899e62016-11-12 02:10:172561#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492562void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2563 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172564 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572565 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492566 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572567 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492568 std::map<int, int> process_map;
2569 std::map<int, int>::const_iterator it;
2570 bool has_web_view_guest = false;
2571 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172572 for (const auto& it : render_frames) {
2573 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492574 continue;
2575
Lukasz Anforowicz09060bdf72018-08-23 15:53:172576 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492577
Lukasz Anforowicz09060bdf72018-08-23 15:53:172578 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492579 has_web_view_guest = true;
2580 }
2581 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572582 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492583 return;
2584 }
[email protected]dffb9fc2014-07-16 04:14:022585 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492586 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492587
[email protected]140d6cd92014-08-12 18:26:462588 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572589 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2590 web_view_permission_helper->RequestFileSystemPermission(
2591 url, allow,
2592 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2593 weak_factory_.GetWeakPtr(), url, render_frames,
2594 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492595}
2596#endif
2597
2598void ChromeContentBrowserClient::FileSystemAccessed(
2599 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172600 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572601 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492602 bool allow) {
[email protected]62151052012-02-01 18:40:482603 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172604 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002605 content_settings::TabSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572606 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352607 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572608 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352609}
2610
[email protected]7c5ff9a2012-03-02 07:42:492611bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2612 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572613 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172614 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572615 Profile* profile = Profile::FromBrowserContext(browser_context);
2616 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2617
Christian Dullweber77740152020-05-12 09:54:172618 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492619
2620 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172621 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002622 content_settings::TabSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572623 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492624 }
2625
2626 return allow;
2627}
2628
Ben Kelly6b2e61c2019-03-14 16:06:292629bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2630 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572631 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292632 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572633 Profile* profile = Profile::FromBrowserContext(browser_context);
2634 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172635 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292636
2637 // Record access to CacheStorage for potential display in UI.
2638 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002639 content_settings::TabSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572640 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292641 }
2642
2643 return allow;
2644}
2645
Joshua Bell1ebc8df2019-11-06 00:27:582646bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2647 const GURL& url,
2648 content::BrowserContext* browser_context,
2649 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2650 Profile* profile = Profile::FromBrowserContext(browser_context);
2651 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172652 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582653}
2654
jyasskinc993ce8d2016-03-31 00:38:342655ChromeContentBrowserClient::AllowWebBluetoothResult
2656ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452657 content::BrowserContext* browser_context,
2658 const url::Origin& requesting_origin,
2659 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342660 // TODO(crbug.com/598890): Don't disable if
2661 // base::CommandLine::ForCurrentProcess()->
2662 // HasSwitch(switches::kEnableWebBluetooth) is true.
2663 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272664 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342665 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272666 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342667 // The kill switch is enabled for this permission. Block requests.
2668 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2669 }
2670
jyasskin98bdd3992016-02-26 20:25:452671 const HostContentSettingsMap* const content_settings =
2672 HostContentSettingsMapFactory::GetForProfile(
2673 Profile::FromBrowserContext(browser_context));
2674
csharrisonaec2c542016-10-12 19:40:362675 if (content_settings->GetContentSetting(
2676 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452677 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362678 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342679 return AllowWebBluetoothResult::BLOCK_POLICY;
2680 }
2681 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452682}
2683
beaufort.francois01135bf2016-11-23 14:37:362684std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2685 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2686 "blocklist_additions");
scheib74250322016-04-07 03:32:212687}
2688
John Abd-El-Malek21bca7c2018-10-26 22:13:332689#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522690void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072691 content::BrowserContext* browser_context) {
2692 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2693 if (user_manager) {
2694 const user_manager::User* user =
2695 chromeos::ProfileHelper::Get()->GetUserByProfile(
2696 Profile::FromBrowserContext(browser_context));
2697 if (user && !user->username_hash().empty()) {
2698 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2699 user->username_hash());
2700 }
2701 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332702}
2703#endif
2704
Reilly Grant19aaccd2018-07-16 22:06:372705scoped_refptr<network::SharedURLLoaderFactory>
2706ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2708 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2709
2710 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372711 return nullptr;
2712
Min Qinda0d55b2018-10-12 18:30:052713 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372714 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042715}
2716
Sean Gilhulyda1ee4b2018-11-13 21:56:092717network::mojom::NetworkContext*
2718ChromeContentBrowserClient::GetSystemNetworkContext() {
2719 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2720 DCHECK(g_browser_process->system_network_context_manager());
2721 return g_browser_process->system_network_context_manager()->GetContext();
2722}
2723
Andrew Moylan17329fc2017-09-25 07:43:302724std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2725 return google_apis::GetAPIKey();
2726}
2727
Ke He21ee87f2018-05-30 02:35:322728#if defined(OS_ANDROID)
2729bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2730 // Indicate that Chrome uses the GMS core location provider.
2731 return true;
2732}
2733#endif
2734
Yeolf3dc22ca2019-04-18 17:25:322735scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412736ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542737 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412738}
2739
Mythri Alle0b8de0d2018-10-22 11:06:222740content::GeneratedCodeCacheSettings
2741ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2742 content::BrowserContext* context) {
2743 base::FilePath cache_path;
2744 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2745 // If we pass 0 for size, disk_cache will pick a default size using the
2746 // heuristics based on available disk size. These are implemented in
2747 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162748 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132749 DCHECK(g_browser_process);
2750 PrefService* local_state = g_browser_process->local_state();
2751 if (local_state) {
2752 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2753 base::FilePath disk_cache_dir =
2754 local_state->GetFilePath(prefs::kDiskCacheDir);
2755 if (!disk_cache_dir.empty())
2756 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2757 }
Mythri Ab2486572019-06-13 14:48:162758 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222759}
2760
[email protected]848dd042011-06-04 18:24:032761void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262762 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172763 int cert_error,
2764 const net::SSLInfo& ssl_info,
2765 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232766 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222767 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262768 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262769 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232770 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142771 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022772 // have a context for making the right decision, so block the
2773 // request hard, without an info bar to allow showing the insecure
2774 // content.
estark719dde52016-08-09 03:14:272775 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262776 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022777 return;
2778 }
2779
[email protected]f9034cf2011-07-21 12:43:412780 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572781 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262782 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572783 if (prerender_contents) {
2784 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272785 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262786 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272787 }
[email protected]09667f02014-01-06 15:37:572788 return;
[email protected]f9034cf2011-07-21 12:43:412789 }
2790
Erik Staaba65a6032019-11-27 22:23:262791 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282792 return;
[email protected]848dd042011-06-04 18:24:032793}
2794
Katie D1882617e2020-05-06 20:06:012795#if !defined(OS_ANDROID)
2796bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2797 const GURL main_page_url) {
2798 // Desktop Reader Mode pages should never load resources with certificate
2799 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2800 // on Android: the desktop version has its own security indicator and
2801 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2802 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2803 // pages).
2804 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2805}
2806#endif
2807
Alexander Hendrichbcf2616e2018-05-18 08:21:102808namespace {
2809
Pavol Markob211ab22019-01-23 20:03:042810certificate_matching::CertificatePrincipalPattern
2811ParseCertificatePrincipalPattern(const base::Value* pattern) {
2812 return certificate_matching::CertificatePrincipalPattern::
2813 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2814}
2815
Alexander Hendrichbcf2616e2018-05-18 08:21:102816// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452817// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102818// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2819std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2820 Profile* profile,
2821 const GURL& requesting_url,
2822 net::ClientCertIdentityList& client_certs) {
2823 HostContentSettingsMap* host_content_settings_map =
2824 HostContentSettingsMapFactory::GetForProfile(profile);
2825 std::unique_ptr<base::Value> setting =
2826 host_content_settings_map->GetWebsiteSetting(
2827 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452828 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102829
Pavol Markob211ab22019-01-23 20:03:042830 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102831 return nullptr;
2832
Alexander Hendrichbcf2616e2018-05-18 08:21:102833 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042834 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2835 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102836 // |setting_dict| has the wrong format (e.g. single filter instead of a
2837 // list of filters). This content setting is only provided by
2838 // the |PolicyProvider|, which should always set it to a valid format.
2839 // Therefore, delete the invalid value.
2840 host_content_settings_map->SetWebsiteSettingDefaultScope(
2841 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452842 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042843 return nullptr;
2844 }
2845
2846 for (const base::Value& filter : filters->GetList()) {
2847 DCHECK(filter.is_dict());
2848
2849 auto issuer_pattern = ParseCertificatePrincipalPattern(
2850 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2851 auto subject_pattern = ParseCertificatePrincipalPattern(
2852 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2853 // Use the first certificate that is matched by the filter.
2854 for (auto& client_cert : client_certs) {
2855 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2856 subject_pattern.Matches(client_cert->certificate()->subject())) {
2857 return std::move(client_cert);
2858 }
2859 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102860 }
2861
2862 return nullptr;
2863}
2864
2865} // namespace
2866
Daniel McArdle85735f52019-06-25 03:27:062867base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192868 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402869 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082870 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352871 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022872 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192873 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022874 if (prerender_contents) {
2875 prerender_contents->Destroy(
2876 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062877 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452878 }
2879
[email protected]791879c2013-12-17 07:22:412880 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2881 DCHECK(requesting_url.is_valid())
2882 << "Invalid URL string: https://"
2883 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452884
Pavol Marko230ea2c92017-12-03 22:35:442885 bool may_show_cert_selection = true;
2886
davidben3b8455ae72015-03-11 19:42:192887 Profile* profile =
2888 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442889#if defined(OS_CHROMEOS)
2890 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252891 // On the sign-in profile, never show certificate selection to the user. A
2892 // client certificate is an identifier that can be stable for a long time,
2893 // so only the administrator is allowed to decide which endpoints should see
2894 // it.
2895 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442896
2897 content::StoragePartition* storage_partition =
2898 content::BrowserContext::GetStoragePartition(
2899 profile, web_contents->GetSiteInstance());
2900 chromeos::login::SigninPartitionManager* signin_partition_manager =
2901 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2902 profile);
2903
2904 // On the sign-in profile, only allow client certs in the context of the
2905 // sign-in frame.
2906 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2907 storage_partition)) {
2908 LOG(WARNING)
2909 << "Client cert requested in sign-in profile in wrong context.";
2910 // Continue without client certificate. We do this to mimic the case of no
2911 // client certificate being present in the profile's certificate store.
2912 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062913 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442914 }
2915 VLOG(1) << "Client cert requested in sign-in profile.";
2916 }
2917#endif // defined(OS_CHROMEOS)
2918
Alexander Hendrichbcf2616e2018-05-18 08:21:102919 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2920 AutoSelectCertificate(profile, requesting_url, client_certs);
2921 if (auto_selected_identity) {
2922 // The callback will own |auto_selected_identity| and |delegate|, keeping
2923 // them alive until after ContinueWithCertificate is called.
2924 scoped_refptr<net::X509Certificate> cert =
2925 auto_selected_identity->certificate();
2926 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2927 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582928 base::BindOnce(
2929 &content::ClientCertificateDelegate::ContinueWithCertificate,
2930 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322931 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062932 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452933 }
2934
Pavol Marko230ea2c92017-12-03 22:35:442935 if (!may_show_cert_selection) {
2936 LOG(WARNING) << "No client cert matched by policy and user selection is "
2937 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322938 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442939 // Continue without client certificate. We do this to mimic the case of no
2940 // client certificate being present in the profile's certificate store.
2941 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062942 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442943 }
2944
Daniel McArdle85735f52019-06-25 03:27:062945 return chrome::ShowSSLClientCertificateSelector(
2946 web_contents, cert_request_info, std::move(client_certs),
2947 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452948}
2949
[email protected]dc73a7b2012-03-25 15:27:182950content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562951 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182952}
2953
Adrienne Walker80d95f02020-02-07 22:37:042954content::FeatureObserverClient*
2955ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:242956 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:042957 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:052958}
2959
peterc26c6c62014-12-10 14:13:592960content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022961ChromeContentBrowserClient::GetPlatformNotificationService(
2962 content::BrowserContext* browser_context) {
2963 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2964 Profile* profile = Profile::FromBrowserContext(browser_context);
2965 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042966}
2967
[email protected]9f3fba52011-06-08 20:37:192968bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352969 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352970 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572971 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352972 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032973 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232974 const GURL& target_url,
2975 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212976 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232977 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482978 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232979 bool user_gesture,
2980 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012981 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352982 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2983 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012984
csharrison95f01e922017-04-24 18:52:352985 content::WebContents* web_contents =
2986 content::WebContents::FromRenderFrameHost(opener);
2987 Profile* profile =
2988 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2989 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012990 *no_javascript_access = false;
2991
[email protected]9f3fba52011-06-08 20:37:192992 // If the opener is trying to create a background window but doesn't have
2993 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032994 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172995#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352996 auto* process_map = extensions::ProcessMap::Get(profile);
2997 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172998 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2999 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013000 return false;
3001 }
3002
[email protected]7b54ca02012-03-02 18:06:533003 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3004 // return a recently installed Extension even if this CanCreateWindow call
3005 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013006 // because the permission check above would have caused an early return
3007 // already. We must use the full URL to find hosted apps, though, and not
3008 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553009 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353010 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293011 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013012 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023013#endif
[email protected]190e5e22013-07-27 05:59:233014
3015 return true;
[email protected]9f3fba52011-06-08 20:37:193016 }
[email protected]056efdc2013-04-06 00:14:533017
brettw00899e62016-11-12 02:10:173018#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463019 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353020 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233021 return true;
lazyboy04b75d32016-02-25 03:12:183022 }
3023
nick0fbc3922016-12-16 20:52:073024 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353025 // Intentionally duplicating |registry| code from above because we want to
3026 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3027 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183028 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353029 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143030 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533031 UMA_HISTOGRAM_ENUMERATION(
3032 "Extensions.AppLoadedInTab",
3033 ClassifyAppLoadedInTabSource(opener_url, extension),
3034 APP_LOADED_IN_TAB_SOURCE_MAX);
3035
3036 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163037 return false;
lazyboy5d5fede02016-03-10 04:10:143038 }
lazyboy04b75d32016-02-25 03:12:183039 }
[email protected]5940b0d2014-07-01 00:18:263040#endif
[email protected]190e5e22013-07-27 05:59:233041
Charles Harrisonaf2acd02017-08-18 22:46:023042#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:233043 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:353044 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:583045 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
3046 content_settings, opener_top_level_frame_url, target_url,
3047 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353048 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3049 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583050 return false;
3051 }
3052#endif
3053
Ryan Sturm0ec75df2020-04-23 14:39:153054 DCHECK(!prerender::PrerenderContents::FromWebContents(web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023055
Aaron Colwell9dab1652019-12-09 18:29:493056 BlockedWindowParams blocked_params(
3057 target_url, source_origin, opener->GetSiteInstance(), referrer,
3058 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133059 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:193060 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
3061 &nav_params, nullptr /*=open_url_params*/,
3062 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:193063}
3064
[email protected]c52b2892012-03-07 11:01:023065content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443066ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003067 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513068}
3069
Katie D840d9532018-11-27 06:20:483070content::TtsControllerDelegate*
3071ChromeContentBrowserClient::GetTtsControllerDelegate() {
3072 TtsControllerDelegateImpl* delegate =
3073 TtsControllerDelegateImpl::GetInstance();
3074#if !defined(OS_ANDROID)
3075 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3076 delegate->SetTtsEngineDelegate(tts_extension_engine);
3077#endif
3078 return delegate;
3079}
3080
Katie D4713ee42018-11-30 01:48:273081content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3082#ifdef OS_CHROMEOS
3083 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273084#else
3085 return nullptr;
3086#endif
3087}
3088
[email protected]64d69de42012-02-06 00:19:543089void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443090 RenderViewHost* rvh,
3091 WebPreferences* web_prefs) {
3092 Profile* profile =
3093 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063094 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063095
aelias0df335a2017-03-02 23:43:513096// Fill font preferences. These are not registered on Android
3097// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453098#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193099 FontFamilyCache::FillFontFamilyMap(profile,
3100 prefs::kWebKitStandardFontFamilyMap,
3101 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443102 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193103 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443104 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193105 &web_prefs->serif_font_family_map);
3106 FontFamilyCache::FillFontFamilyMap(profile,
3107 prefs::kWebKitSansSerifFontFamilyMap,
3108 &web_prefs->sans_serif_font_family_map);
3109 FontFamilyCache::FillFontFamilyMap(profile,
3110 prefs::kWebKitCursiveFontFamilyMap,
3111 &web_prefs->cursive_font_family_map);
3112 FontFamilyCache::FillFontFamilyMap(profile,
3113 prefs::kWebKitFantasyFontFamilyMap,
3114 &web_prefs->fantasy_font_family_map);
3115 FontFamilyCache::FillFontFamilyMap(profile,
3116 prefs::kWebKitPictographFontFamilyMap,
3117 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063118
[email protected]64d69de42012-02-06 00:19:543119 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403120 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543121 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403122 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543123 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403124 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543125 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403126 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513127#endif
[email protected]f3986f82012-01-03 20:00:063128
[email protected]ddf72142012-05-22 04:52:403129 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063130
[email protected]64d69de42012-02-06 00:19:543131 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063132 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213133 web_prefs->javascript_can_access_clipboard =
3134 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543135 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063136
[email protected]ddf72142012-05-22 04:52:403137 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543138 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573139
Avi Drissman1aa6cb92019-01-23 15:58:383140 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543141 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573142
[email protected]ddf72142012-05-22 04:52:403143 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543144 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543145 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403146 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063147
Zhenyao Moa3fda9972017-09-16 01:34:403148 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3149 web_prefs->webgl1_enabled = false;
3150 web_prefs->webgl2_enabled = false;
3151 }
[email protected]f3986f82012-01-03 20:00:063152
[email protected]64d69de42012-02-06 00:19:543153 web_prefs->allow_running_insecure_content =
3154 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323155#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053156 web_prefs->font_scale_factor =
3157 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323158 web_prefs->force_enable_zoom =
3159 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493160#endif
Becky Zhoubbfbde32019-02-20 17:07:593161 web_prefs->force_dark_mode_enabled =
3162 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393163
[email protected]af4256d52013-06-04 20:39:073164#if defined(OS_ANDROID)
3165 web_prefs->password_echo_enabled =
3166 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3167#else
[email protected]9d06d88d2012-02-23 22:37:083168 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073169#endif
3170
[email protected]64d69de42012-02-06 00:19:543171 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063172 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543173 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063174 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3175
brettw00899e62016-11-12 02:10:173176#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053177 std::string image_animation_policy =
3178 prefs->GetString(prefs::kAnimationPolicy);
3179 if (image_animation_policy == kAnimationPolicyOnce)
3180 web_prefs->animation_policy =
3181 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3182 else if (image_animation_policy == kAnimationPolicyNone)
3183 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3184 else
3185 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3186#endif
3187
[email protected]f3986f82012-01-03 20:00:063188 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153189 web_prefs->default_encoding =
3190 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543191 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403192 prefs->ClearPref(prefs::kDefaultCharset);
3193 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063194 }
[email protected]64d69de42012-02-06 00:19:543195 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063196
mkwst05544102015-01-10 20:26:163197 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3198 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073199 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163200 web_prefs->strict_mixed_content_checking = true;
3201 web_prefs->strict_powerful_feature_restrictions = true;
3202 }
3203
Robert Ogdencf2872d2019-03-19 18:59:373204 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213205
Tarun Bansal333819e2018-05-15 16:38:423206 web_prefs->data_saver_holdback_web_api_enabled =
3207 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3208 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423209
Jinsuk Kima3d393ce2019-05-27 00:57:423210 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133211 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533212#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423213 auto* delegate = TabAndroid::FromWebContents(contents)
3214 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3215 contents->GetDelegate())
3216 : nullptr;
3217 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133218 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423219 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133220
Mounir Lamouri9c99a1602018-07-05 15:01:443221 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423222 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383223
Alison Maher7f366dc62020-03-03 19:46:003224 web_prefs->preferred_color_scheme =
3225 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3226 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113227 }
Ian Vollick6243dfe02018-03-08 01:08:533228#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533229
Mounir Lamouri6926107f2019-01-31 18:17:433230 // web_app_scope value is platform specific.
3231#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423232 if (delegate)
3233 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433234#elif BUILDFLAG(ENABLE_EXTENSIONS)
3235 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253236 web_prefs->web_app_scope = GURL();
3237 // Set |web_app_scope| based on the app associated with the app window if
3238 // any. Note that the app associated with the window never changes, even
3239 // if the app navigates off scope. This is not a problem because we still
3240 // want to use the scope of the app associated with the window, not the
3241 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433242 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233243 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593244 browser->app_controller()->HasAppId()) {
3245 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3246 const web_app::AppRegistrar& registrar =
3247 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3248 if (registrar.IsLocallyInstalled(app_id))
3249 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433250 }
Mounir Lamouri6926107f2019-01-31 18:17:433251 }
3252#endif
3253
Ian Vollick6243dfe02018-03-08 01:08:533254 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113255 }
zqzhang93e959d12017-03-16 13:10:203256
Tarun Bansal73d67f02018-01-17 05:56:253257 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3258 // Obtain the maximum effective connection type at which the feature is
3259 // enabled.
3260 std::string effective_connection_type_param =
3261 base::GetFieldTrialParamValueByFeature(
3262 features::kLowPriorityIframes,
3263 "max_effective_connection_type_threshold");
3264
3265 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3266 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3267 if (effective_connection_type) {
3268 web_prefs->low_priority_iframes_threshold =
3269 effective_connection_type.value();
3270 }
3271 }
3272
rajendrant0521cee2019-07-29 06:09:263273 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3274 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003275
Scott Little878f7d6702018-05-31 22:09:063276 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3277 const char* param_name =
3278 web_prefs->data_saver_enabled
3279 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3280 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3281 "saver_enabled";
3282
3283 base::StringPairs pairs;
3284 base::SplitStringIntoKeyValuePairs(
3285 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3286 param_name),
3287 ':', ',', &pairs);
3288
3289 for (const auto& pair : pairs) {
3290 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3291 net::GetEffectiveConnectionTypeForName(pair.first);
3292 int value = 0;
3293 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3294 web_prefs->lazy_frame_loading_distance_thresholds_px
3295 [effective_connection_type.value()] = value;
3296 }
3297 }
3298 }
3299
rajendrantd8026342018-08-29 08:08:393300 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3301 const char* param_name =
3302 web_prefs->data_saver_enabled
3303 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3304 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3305 "saver_enabled";
3306
3307 base::StringPairs pairs;
3308 base::SplitStringIntoKeyValuePairs(
3309 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3310 param_name),
3311 ':', ',', &pairs);
3312
3313 for (const auto& pair : pairs) {
3314 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3315 net::GetEffectiveConnectionTypeForName(pair.first);
3316 int value = 0;
3317 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3318 web_prefs->lazy_image_loading_distance_thresholds_px
3319 [effective_connection_type.value()] = value;
3320 }
3321 }
rajendrant3daeae292019-09-20 07:57:543322
3323 pairs.clear();
3324 base::SplitStringIntoKeyValuePairs(
3325 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3326 "lazy_image_first_k_fully_load"),
3327 ':', ',', &pairs);
3328
3329 for (const auto& pair : pairs) {
3330 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3331 net::GetEffectiveConnectionTypeForName(pair.first);
3332 int value = 0;
3333 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3334 web_prefs
3335 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3336 value;
3337 }
3338 }
rajendrantd8026342018-08-29 08:08:393339 }
3340
Tarun Bansald10f17a02018-09-13 00:23:173341 if (base::FeatureList::IsEnabled(
3342 features::kNetworkQualityEstimatorWebHoldback)) {
3343 std::string effective_connection_type_param =
3344 base::GetFieldTrialParamValueByFeature(
3345 features::kNetworkQualityEstimatorWebHoldback,
3346 "web_effective_connection_type_override");
3347
3348 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3349 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3350 DCHECK(effective_connection_type_param.empty() ||
3351 effective_connection_type);
3352 if (effective_connection_type) {
3353 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3354 effective_connection_type.value());
3355 web_prefs->network_quality_estimator_web_holdback =
3356 effective_connection_type.value();
3357 }
3358 }
3359
François Beaufort4f8107d2018-03-05 12:12:103360#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563361 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593362 // If autoplay is allowed by policy then force the no user gesture required
3363 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103364 web_prefs->autoplay_policy =
3365 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553366 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593367 web_prefs->autoplay_policy ==
3368 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553369 // If the autoplay disable settings feature is enabled and the autoplay
3370 // policy is set to using the unified policy then set the default autoplay
3371 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593372 web_prefs->autoplay_policy =
3373 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3374 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3375 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103376 }
Alison Maher7f366dc62020-03-03 19:46:003377
Abigail Kleina81f2e22020-05-04 14:32:413378 auto* native_theme = GetWebTheme();
Alison Maher7f366dc62020-03-03 19:46:003379 switch (native_theme->GetPreferredColorScheme()) {
3380 case ui::NativeTheme::PreferredColorScheme::kDark:
3381 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3382 break;
3383 case ui::NativeTheme::PreferredColorScheme::kLight:
3384 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3385 break;
3386 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3387 web_prefs->preferred_color_scheme =
3388 blink::PreferredColorScheme::kNoPreference;
3389 }
François Beaufort4f8107d2018-03-05 12:12:103390#endif // !defined(OS_ANDROID)
3391
Dave Tapuskac6627e12018-08-30 15:07:193392 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493393
Alison Maher7f366dc62020-03-03 19:46:003394 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3395 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3396 // explicitly uses light (instead of not dark), which is why we don't reset
3397 // back to no-preference. https://crbug.com/965811
3398 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3399 const GURL url = rvh->GetSiteInstance()->GetSiteURL();
3400 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3401#if BUILDFLAG(ENABLE_EXTENSIONS)
3402 if (!force_light) {
3403 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3404 url.host_piece() == extension_misc::kPdfExtensionId;
3405 }
3406#endif
3407 if (force_light)
3408 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3409 }
3410
Abigail Kleina81f2e22020-05-04 14:32:413411 base::Optional<ui::CaptionStyle> style =
3412 captions::GetCaptionStyleFromUserSettings(prefs,
3413 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213414 if (style) {
3415 web_prefs->text_track_background_color = style->background_color;
3416 web_prefs->text_track_text_color = style->text_color;
3417 web_prefs->text_track_text_size = style->text_size;
3418 web_prefs->text_track_text_shadow = style->text_shadow;
3419 web_prefs->text_track_font_family = style->font_family;
3420 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563421 web_prefs->text_track_window_color = style->window_color;
3422 web_prefs->text_track_window_padding = style->window_padding;
3423 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213424 }
Elly Fong-Jonesf92897392019-01-24 16:05:493425
[email protected]a48ab7112014-08-01 16:48:033426 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503427 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363428}
3429
[email protected]b8148ac2011-07-13 22:03:253430void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3431 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033432 for (size_t i = 0; i < extra_parts_.size(); ++i)
3433 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253434
[email protected]b3adbd02011-11-30 22:23:273435 // about: handler. Must come before chrome: handler, since it will
3436 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053437 // actually handle them. Also relies on a preliminary fixup phase.
3438 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253439 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3440 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033441
madfbd10852017-01-20 03:15:333442 // The group policy NTP URL handler must be registered before the other NTP
3443 // URL handlers below.
3444 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3445 BrowserURLHandler::null_handler());
3446
zpengdb4a58e2017-01-10 17:40:323447#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033448 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353449 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033450 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453451#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033452 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133453 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3454 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453455#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033456
[email protected]b8148ac2011-07-13 22:03:253457 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313458 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3459 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253460}
3461
[email protected]650b2d52013-02-10 03:41:453462base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493463 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323464}
3465
[email protected]c9b6eb62011-10-18 20:49:393466std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3467 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3468}
3469
Dominik Röttsches47347832019-03-12 17:45:013470base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3471 base::FilePath user_data_dir;
3472 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3473 DCHECK(!user_data_dir.empty());
3474 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3475}
3476
jmadill57b52d42015-08-21 18:16:133477base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3478 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523479 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133480 DCHECK(!user_data_dir.empty());
3481 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3482}
3483
Khushal7ca0b782018-07-20 05:53:273484base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3485 base::FilePath user_data_dir;
3486 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3487 DCHECK(!user_data_dir.empty());
3488 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3489}
3490
[email protected]b7631cc2012-09-15 05:08:383491void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3492 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163493#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553494 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543495#endif
[email protected]b7631cc2012-09-15 05:08:383496}
3497
[email protected]0c7193742012-11-07 19:05:033498content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443499ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173500#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553501 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033502 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443503 nacl::NaClProcessHost* host =
3504 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3505 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033506 // Found the plugin.
3507 return host->browser_ppapi_host();
3508 }
3509 ++iter;
3510 }
[email protected]a56f8322014-07-16 21:13:553511#endif
Aran Gilmanf010bdd2019-08-28 19:55:443512 return nullptr;
[email protected]0c7193742012-11-07 19:05:033513}
3514
[email protected]38cd8f7f2012-06-15 22:06:073515bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583516 content::BrowserContext* browser_context,
3517 const GURL& url,
[email protected]dda54822013-06-15 01:26:393518 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123519 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163520#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553521 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193522 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403523#else
[email protected]a658d452012-03-02 12:45:293524 return false;
[email protected]93f72062013-05-29 20:29:403525#endif
[email protected]e461da2f2012-02-16 19:06:403526}
3527
adrian.belgund54465ba2016-05-18 10:03:583528bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3529 content::BrowserContext* browser_context,
3530 const GURL& url) {
brettw4b461082016-11-19 18:55:163531#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583532 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3533 browser_context, url);
3534#else
3535 return false;
3536#endif
3537}
3538
adrian.belgun5b341c72016-06-22 22:24:083539std::unique_ptr<content::VpnServiceProxy>
3540ChromeContentBrowserClient::GetVpnServiceProxy(
3541 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173542#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083543 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3544 browser_context);
3545#else
3546 return nullptr;
3547#endif
3548}
3549
Brett Wilson804e83c2017-08-18 22:57:333550std::unique_ptr<ui::SelectFilePolicy>
3551ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3552 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433553}
3554
[email protected]7d9424702013-04-14 13:14:163555void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3556 std::vector<std::string>* additional_allowed_schemes) {
3557 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3558 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483559 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293560 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033561 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3562 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3563 additional_allowed_schemes);
3564 }
[email protected]7d9424702013-04-14 13:14:163565}
3566
falkenad185092016-06-16 06:10:023567void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3568 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043569 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023570}
3571
[email protected]c79859b82014-03-20 22:43:553572void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313573 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033574 for (size_t i = 0; i < extra_parts_.size(); ++i)
3575 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553576}
3577
nzolghadrd87a308d2016-12-07 15:45:563578::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3579 return g_browser_process->rappor_service();
3580}
3581
[email protected]f19bbf62013-07-09 01:22:323582void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313583 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533584 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003585 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3586 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313587#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313588 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313589 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313590 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093591 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093592 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3593 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473594 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093595 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3596 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053597 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3598 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343599 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3600 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473601 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323602 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313603 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003604 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313605#endif
[email protected]445b7db2013-08-02 04:58:273606
[email protected]a48ab7112014-08-01 16:48:033607 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3608 extra_parts_[i]->GetAdditionalFileSystemBackends(
3609 browser_context, storage_partition_path, additional_backends);
3610 }
[email protected]02250952013-04-24 23:52:533611}
3612
jcivellie6f550742017-01-06 19:29:123613#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183614void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173615 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383616 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203617 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123618#if defined(OS_ANDROID)
3619 base::MemoryMappedFile::Region region;
3620 int fd = ui::GetMainAndroidPackFd(&region);
3621 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003622
Samuel Huang31eadf082019-08-28 19:50:433623 // For Android: Native resources for DFMs should only be used by the browser
3624 // process. Their file descriptors and memory mapped file regions are not
3625 // passed to child processes.
3626
jcivellie6f550742017-01-06 19:29:123627 fd = ui::GetCommonResourcesPackFd(&region);
3628 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393629
jcivellie6f550742017-01-06 19:29:123630 fd = ui::GetLocalePackFd(&region);
3631 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383632
zpeng368afac82017-07-17 18:47:453633 // Optional secondary locale .pak file.
3634 fd = ui::GetSecondaryLocalePackFd(&region);
3635 if (fd != -1) {
3636 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3637 }
3638
[email protected]09560f7f2014-06-10 18:40:283639 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523640 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283641 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023642#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383643 int crash_signal_fd = GetCrashSignalFD(command_line);
3644 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133645 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383646 }
jcivellie6f550742017-01-06 19:29:123647}
3648#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303649
[email protected]4a65826d2011-08-25 16:04:013650#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033651base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223652 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033653 // TODO(wfh): Add support for more process types here. crbug.com/499523
3654 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223655 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363656 return base::string16(install_static::GetSandboxSidPrefix()) +
3657 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223658 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033659 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223660 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033661 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223662 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363663 return base::string16(install_static::GetSandboxSidPrefix()) +
3664 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223665 case service_manager::SandboxType::kNoSandbox:
3666 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3667 case service_manager::SandboxType::kXrCompositing:
3668 case service_manager::SandboxType::kNetwork:
3669 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523670 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223671 case service_manager::SandboxType::kAudio:
evliu2e5dbee42020-04-09 23:35:293672 case service_manager::SandboxType::kSpeechRecognition:
Will Harrise705a642020-02-26 20:57:053673 case service_manager::SandboxType::kProxyResolver:
Cliff Smolinsky0aa7ca72020-03-09 21:32:463674 case service_manager::SandboxType::kPdfConversion:
Alex Gough63617352020-03-20 02:34:593675 case service_manager::SandboxType::kSharingService:
Sharon Yangefd8e882020-04-28 20:56:433676 case service_manager::SandboxType::kVideoCapture:
Alex Gough9ab468a6c32019-12-10 19:10:223677 // Should never reach here.
3678 CHECK(0);
wfh182da09c2015-06-24 19:23:033679 return base::string16();
wfh182da09c2015-06-24 19:23:033680 }
wfh182da09c2015-06-24 19:23:033681}
3682
Will Harris956e0ca2019-08-23 20:47:393683bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3684 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503685// Does not work under component build because all the component DLLs would need
3686// to be manually added and maintained. Does not work under ASAN build because
3687// ASAN has not yet fully initialized its instrumentation by the time the CIG
3688// intercepts run.
3689#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393690 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3691 return true;
Will Harrisc196ed942019-08-03 03:45:303692 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3693 return true;
3694
3695 // Only enable signing mitigation if launching from chrome.exe.
3696 base::FilePath exe_path;
3697 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3698 return true;
3699 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3700 return true;
3701
3702 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3703 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093704 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303705 if (result != sandbox::SBOX_ALL_OK)
3706 return false;
3707
Nico Weberc36b0152020-04-18 03:12:463708 // Allow loading Chrome's DLLs.
3709 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303710 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3711 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3712 GetModulePath(dll).value().c_str());
3713 if (result != sandbox::SBOX_ALL_OK)
3714 return false;
3715 }
Will Harris1b9b4152019-08-21 22:33:503716#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303717
3718 return true;
[email protected]34f48682013-03-20 00:30:183719}
Will Harris956e0ca2019-08-23 20:47:393720
3721bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3722 PrefService* local_state = g_browser_process->local_state();
3723 if (local_state &&
3724 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3725 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3726 return false;
3727 return true;
3728}
3729
wfhc91e9672016-01-27 00:14:203730#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013731
Armando Miraglia3a7be232019-11-08 00:33:323732#if defined(OS_WIN) || defined(OS_MACOSX) || \
3733 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3734bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3735 const base::Value* audio_sandbox_enabled_policy_value =
3736 policies.GetValue(policy::key::kAudioSandboxEnabled);
3737 if (audio_sandbox_enabled_policy_value) {
3738 bool force_enable_audio_sandbox;
3739 audio_sandbox_enabled_policy_value->GetAsBoolean(
3740 &force_enable_audio_sandbox);
3741 return force_enable_audio_sandbox;
3742 }
3743
3744 return base::FeatureList::IsEnabled(
3745 service_manager::features::kAudioServiceSandbox);
3746}
3747#endif
3748
Ken Rockotfa5d57112019-05-29 20:57:143749void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123750#if defined(OS_WIN) || defined(OS_MACOSX) || \
3751 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053752 if (startup_data_) {
3753 auto* chrome_feature_list_creator =
3754 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183755 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123756 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053757 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183758 ->GetPolicyService()
3759 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123760 std::string()));
3761
Armando Miraglia3a7be232019-11-08 00:33:323762 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
John Abd-El-Malek27b3ebd22019-02-12 18:59:183763 }
3764#endif
xhwang5e630462015-10-30 03:18:483765}
3766
Ken Rockot8f39a272018-12-21 23:38:353767base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173768ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583769 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583770 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583771 return base::nullopt;
benc70c0e32016-09-22 03:50:373772}
3773
peterbbcccc12015-02-11 22:23:333774void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373775 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333776 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293777 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083778 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373779
3780 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083781
zpengdb4a58e2017-01-10 17:40:323782#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223783 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293784 std::move(callback));
jam1c5a91492016-02-24 20:47:533785#else
cm.sanchi2522bc92017-12-04 08:04:133786 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3787 params.url, params.transition);
3788 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083789
3790 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293791 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333792#endif
mlamourieb40d552015-02-05 00:57:083793}
3794
zhaobinf3704f82017-01-12 07:19:363795content::ControllerPresentationServiceDelegate*
3796ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3797 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463798 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093799 return media_router::PresentationServiceDelegateImpl::
3800 GetOrCreateForWebContents(web_contents);
3801 }
haibinlu9e605a92015-06-06 03:45:093802 return nullptr;
3803}
3804
zhaobinf3704f82017-01-12 07:19:363805content::ReceiverPresentationServiceDelegate*
3806ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3807 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363808 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3809 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3810 // created for offscreen presentations. The WebContents must belong to
3811 // an incognito profile.
3812 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3813 FromWebContents(web_contents)) {
3814 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3815 return impl;
3816 }
3817 }
zhaobinf3704f82017-01-12 07:19:363818 return nullptr;
3819}
3820
horo48d4d3e2015-02-27 03:04:003821void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3822 const GURL& url) {
mathp46284f32015-03-11 13:06:413823 if (url.is_valid()) {
3824 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3825 metric, url);
3826 }
horo48d4d3e2015-02-27 03:04:003827}
3828
Matt Falkenhagen8479b202017-07-14 04:35:313829std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3830 // Don't change these returned strings. They are written (in hashed form) into
3831 // UMA logs. If you add more strings, you must update histograms.xml and get
3832 // histograms review. Only Google domains should be here for privacy purposes.
3833 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3834 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193835 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313836 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193837 if (url.host() == "docs.google.com")
3838 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313839 return std::string();
3840}
3841
avid6d88b912017-01-13 00:16:003842std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473843ChromeContentBrowserClient::CreateThrottlesForNavigation(
3844 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003845 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273846
bmcquadeb4556552017-03-24 22:24:373847 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3848 // that may delay or cancel navigations, so only NavigationThrottles that
3849 // don't delay or cancel navigations (e.g. throttles that are only observing
3850 // callbacks without affecting navigation behavior) should be added before
3851 // MetricsNavigationThrottle.
3852 if (handle->IsInMainFrame()) {
3853 throttles.push_back(
3854 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3855 }
3856
brettw4b461082016-11-19 18:55:163857#if BUILDFLAG(ENABLE_PLUGINS)
Lukasz Anforowicz7724d092019-10-03 23:50:213858 MaybeAddThrottle(&throttles,
3859 FlashDownloadInterception::MaybeCreateThrottleFor(handle));
trizzofo8ddaeb72016-09-01 23:18:273860#endif
3861
yilkal240b4f22019-11-27 19:09:063862#if defined(OS_CHROMEOS)
3863 MaybeAddThrottle(
3864 &throttles,
3865 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle));
3866#endif // defined(OS_CHROMEOS)
3867
mmenkedb2637ff2017-03-30 23:59:423868#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213869 MaybeAddThrottle(
3870 &throttles,
3871 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle));
mmenkedb2637ff2017-03-30 23:59:423872#endif
3873
clamy40c9e142015-09-29 11:18:473874#if defined(OS_ANDROID)
3875 // TODO(davidben): This is insufficient to integrate with prerender properly.
3876 // https://crbug.com/370595
3877 prerender::PrerenderContents* prerender_contents =
3878 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3879 if (!prerender_contents && handle->IsInMainFrame()) {
3880 throttles.push_back(
3881 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303882 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473883 }
Min Qin0ab0e162017-11-14 21:57:193884 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043885
3886#if BUILDFLAG(DFMIFY_DEV_UI)
3887 // If the DevUI DFM is already installed, then this is a no-op, except for the
3888 // side effect of ensuring that the DevUI DFM is loaded.
3889 MaybeAddThrottle(&throttles,
3890 dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle));
3891#endif // BUILDFLAG(DFMIFY_DEV_UI)
3892
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573893#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473894 if (handle->IsInMainFrame()) {
3895 // Redirect some navigations to apps that have registered matching URL
3896 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573897 auto url_to_app_throttle =
3898 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:473899 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:093900 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:473901 }
3902#endif
clamy49678312015-10-22 21:59:003903
3904#if defined(OS_CHROMEOS)
3905 // Check if we need to add merge session throttle. This throttle will postpone
3906 // loading of main frames.
3907 if (handle->IsInMainFrame()) {
3908 // Add interstitial page while merge session process (cookie reconstruction
3909 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3910 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023911 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3912 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003913 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3914 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3915 }
Maggie Caia2f03f52019-04-02 02:13:283916 }
3917#endif
djacobo21e56e02016-07-02 01:14:313918
Maggie Caia2f03f52019-04-02 02:13:283919#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:103920 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283921#if defined(OS_CHROMEOS)
Maggie Caic08b7d42020-05-05 03:51:103922 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3923 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3924 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253925#elif defined(OS_MACOSX)
Maggie Caic08b7d42020-05-05 03:51:103926 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283927#else
Maggie Caic08b7d42020-05-05 03:51:103928 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283929#endif
Maggie Caic08b7d42020-05-05 03:51:103930 if (url_to_apps_throttle)
3931 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003932#endif
3933
brettw00899e62016-11-12 02:10:173934#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003935 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093936 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513937
Lukasz Anforowicz7724d092019-10-03 23:50:213938 MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get()
3939 ->GetUserScriptListener()
3940 ->CreateNavigationThrottle(handle));
naskob9164c42016-06-07 01:21:353941#endif
3942
bauerb8f9c37742017-03-30 15:04:123943#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213944 MaybeAddThrottle(
3945 &throttles,
3946 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle));
bauerb8f9c37742017-03-30 15:04:123947#endif
3948
csharrisone985ebc2017-04-04 17:05:033949 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103950 if (auto* subresource_filter_client =
3951 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3952 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3953 &throttles);
csharrisone985ebc2017-04-04 17:05:033954 }
3955
zhenw6edd49c2017-07-12 05:49:453956#if !defined(OS_ANDROID)
3957 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3958 // enabled on non-Android platforms.
Lukasz Anforowicz7724d092019-10-03 23:50:213959 MaybeAddThrottle(&throttles,
3960 resource_coordinator::BackgroundTabNavigationThrottle::
3961 MaybeCreateThrottleFor(handle));
zhenw6edd49c2017-07-12 05:49:453962#endif
3963
Nico Weberbc5b06f2019-07-26 14:00:133964#if BUILDFLAG(FULL_SAFE_BROWSING)
Lukasz Anforowicz7724d092019-10-03 23:50:213965 MaybeAddThrottle(&throttles,
3966 safe_browsing::MaybeCreateNavigationThrottle(handle));
Jialiu Linbdbb81d2017-10-11 21:29:093967#endif
3968
Lukasz Anforowicz7724d092019-10-03 23:50:213969 MaybeAddThrottle(
3970 &throttles,
Emily Starkfa0ddb42019-10-24 15:49:583971 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
Joe DeBlasio6e8409a2019-02-20 23:08:273972
Lukasz Anforowicz7724d092019-10-03 23:50:213973 MaybeAddThrottle(&throttles,
3974 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
Amber Won6b5edc752017-08-17 19:23:543975
Lukasz Anforowicz7724d092019-10-03 23:50:213976 MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle));
Charles Harrison6dd11d282017-10-03 06:14:513977
Jeremy Romanec48d7a2018-03-01 17:35:093978 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533979 handle, handle->GetWebContents()->GetBrowserContext()));
3980
Colin Blundelleaa7377bf2020-01-22 08:49:103981 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
3982 // the relevant extension API whenever an SSL interstitial is shown.
3983 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
3984 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:283985 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3986 handle,
3987 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:383988 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123989
Emily Starkd6896cd32019-08-21 04:55:543990 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3991
Lukasz Anforowicz7724d092019-10-03 23:50:213992 MaybeAddThrottle(
3993 &throttles,
3994 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle));
Christopher Thompson4137cec2017-12-19 05:34:233995
Dmitry Gozman57b92ce2017-12-28 22:24:543996#if !defined(OS_ANDROID)
Lukasz Anforowicz7724d092019-10-03 23:50:213997 MaybeAddThrottle(&throttles,
3998 DevToolsWindow::MaybeCreateNavigationThrottle(handle));
Conley Owensaafcf122018-02-26 18:53:513999
Lukasz Anforowicz7724d092019-10-03 23:50:214000 MaybeAddThrottle(
4001 &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle));
jdoerrie4f9376f2018-12-12 18:26:204002
Lukasz Anforowicz7724d092019-10-03 23:50:214003 MaybeAddThrottle(
4004 &throttles,
4005 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle));
Dmitry Gozman57b92ce2017-12-28 22:24:544006#endif
4007
Carlos IL800e3502020-04-30 16:35:594008 throttles.push_back(
4009 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034010
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334011#if defined(OS_WIN) || defined(OS_MACOSX) || \
4012 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Lukasz Anforowicz7724d092019-10-03 23:50:214013 MaybeAddThrottle(&throttles,
4014 browser_switcher::BrowserSwitcherNavigationThrottle::
4015 MaybeCreateThrottleFor(handle));
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134016#endif
4017
Anatoliy Potapchuk762c40d2020-05-11 15:10:374018#if defined(OS_CHROMEOS)
4019 MaybeAddThrottle(
4020 &throttles,
4021 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(
4022 handle));
4023#endif
4024
dchenge73d8520c2015-12-27 01:19:094025 return throttles;
clamy40c9e142015-09-29 11:18:474026}
4027
clamy1e5574e2016-09-29 16:48:444028std::unique_ptr<content::NavigationUIData>
4029ChromeContentBrowserClient::GetNavigationUIData(
4030 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094031 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444032}
4033
Xiaohan Wanga4e41842018-06-26 18:45:104034void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4035 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104036 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124037 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104038#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264039 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104040 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334041 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104042 }
4043#endif
4044}
4045
[email protected]487974a2014-06-13 16:49:014046content::DevToolsManagerDelegate*
4047ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354048#if defined(OS_ANDROID)
4049 return new DevToolsManagerDelegateAndroid();
4050#else
[email protected]487974a2014-06-13 16:49:014051 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354052#endif
[email protected]487974a2014-06-13 16:49:014053}
4054
Rayan Kanso411e84e2019-02-13 15:27:404055void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4056 content::BrowserContext* browser_context,
4057 int service,
4058 base::Time expiration_time) {
4059 Profile* profile = Profile::FromBrowserContext(browser_context);
4060 DCHECK(profile);
4061
4062 auto* pref_service = profile->GetPrefs();
4063 DCHECK(pref_service);
4064
4065 DictionaryPrefUpdate pref_update(
4066 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4067 base::DictionaryValue* exp_dict = pref_update.Get();
4068
4069 // Convert |expiration_time| to minutes since that is the most granular
4070 // option that returns an int. base::Value does not accept int64.
4071 int expiration_time_minutes =
4072 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4073 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4074}
4075
4076base::flat_map<int, base::Time>
4077ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4078 content::BrowserContext* browser_context) {
4079 Profile* profile = Profile::FromBrowserContext(browser_context);
4080 DCHECK(profile);
4081
4082 auto* pref_service = profile->GetPrefs();
4083 DCHECK(pref_service);
4084
4085 auto* expiration_dict = pref_service->GetDictionary(
4086 prefs::kDevToolsBackgroundServicesExpirationDict);
4087 DCHECK(expiration_dict);
4088
4089 base::flat_map<int, base::Time> expiration_times;
4090 for (const auto& it : *expiration_dict) {
4091 // key.
4092 int service = 0;
4093 bool did_convert = base::StringToInt(it.first, &service);
4094 DCHECK(did_convert);
4095
4096 // value.
4097 DCHECK(it.second->is_int());
4098 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4099 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4100
4101 expiration_times[service] = expiration_time;
4102 }
4103
4104 return expiration_times;
4105}
4106
oysteinec563c582015-02-13 19:19:524107content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524108 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524109}
4110
[email protected]a6868c22013-10-09 02:50:294111bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4112 content::BrowserContext* browser_context,
4113 const GURL& url) {
brettw4b461082016-11-19 18:55:164114#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554115 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194116 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294117#else
4118 return false;
4119#endif
4120}
4121
[email protected]aec5ed52014-06-20 07:51:424122bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4123 content::BrowserContext* browser_context,
4124 const GURL& url) {
brettw4b461082016-11-19 18:55:164125#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554126 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194127 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064128#else
4129 return false;
4130#endif
4131}
4132
mlamourif8c23a2002015-01-27 13:10:104133void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014134 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434135 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524136 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104137
4138 WebContents* web_contents =
4139 WebContents::FromRenderFrameHost(render_frame_host);
4140 DCHECK(web_contents);
4141
mlamourif8c23a2002015-01-27 13:10:104142 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374143 prerender::PrerenderManagerFactory::GetForBrowserContext(
4144 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104145 if (prerender_manager &&
4146 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294147 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104148 }
4149}
4150
Robert Sesek466e43e2019-08-19 22:02:024151void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4152 base::FilePath user_data_dir;
4153 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4154 DCHECK(!user_data_dir.empty());
4155 network_contexts_parent_directory_.push_back(user_data_dir);
4156
4157 base::FilePath cache_dir;
4158 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4159 DCHECK(!cache_dir.empty());
4160 // On some platforms, the cache is a child of the user_data_dir so only
4161 // return the one path.
4162 if (!user_data_dir.IsParent(cache_dir))
4163 network_contexts_parent_directory_.push_back(cache_dir);
4164
4165 // If the cache location has been overridden by a switch or preference,
4166 // include that as well.
4167 if (auto* local_state = g_browser_process->local_state()) {
4168 base::FilePath pref_cache_dir =
4169 local_state->GetFilePath(prefs::kDiskCacheDir);
4170 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4171 network_contexts_parent_directory_.push_back(pref_cache_dir);
4172 }
4173}
4174
[email protected]30335fdf02014-02-26 19:51:274175void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174176 base::CommandLine* to_command_line,
4177 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544178 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274179#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544180 const version_info::Channel kMaxDisableEncryptionChannel =
4181 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274182#else
sdefresne6e883e42015-07-30 08:05:544183 const version_info::Channel kMaxDisableEncryptionChannel =
4184 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274185#endif
4186 if (channel <= kMaxDisableEncryptionChannel) {
4187 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444188 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274189 };
Avi Drissmand251e912018-12-26 15:46:374190 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4191 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274192 }
4193}
bashi933629552016-10-13 23:32:404194
miu54dca6c2016-11-17 10:59:384195#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4196void ChromeContentBrowserClient::CreateMediaRemoter(
4197 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504198 mojo::PendingRemote<media::mojom::RemotingSource> source,
4199 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384200 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504201 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384202}
4203#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464204
Michael Giuffrida6802ffe2017-09-29 03:40:254205base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4206 const base::CommandLine& command_line) {
4207 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164208}
4209
John Abd-El-Malek8efa11f2019-01-06 00:51:534210namespace {
4211// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024212class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534213 public:
4214 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174215 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534216 : protocol_handler_registry_(protocol_handler_registry) {}
4217 ~ProtocolHandlerThrottle() override = default;
4218
4219 void WillStartRequest(network::ResourceRequest* request,
4220 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294221 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534222 }
4223
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584224 void WillRedirectRequest(
4225 net::RedirectInfo* redirect_info,
4226 const network::mojom::URLResponseHead& response_head,
4227 bool* defer,
4228 std::vector<std::string>* to_be_removed_headers,
4229 net::HttpRequestHeaders* modified_headers,
4230 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294231 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534232 }
4233
4234 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294235 void TranslateUrl(GURL* url) {
4236 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4237 return;
4238 GURL translated_url = protocol_handler_registry_->Translate(*url);
4239 if (!translated_url.is_empty())
4240 *url = translated_url;
4241 }
4242
Clark DuValla411bda2019-08-02 03:09:174243 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534244};
4245} // namespace
4246
Minggang Wangf6840ecf2019-07-29 05:15:024247std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194248ChromeContentBrowserClient::CreateURLLoaderThrottles(
4249 const network::ResourceRequest& request,
4250 content::BrowserContext* browser_context,
4251 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4252 content::NavigationUIData* navigation_ui_data,
4253 int frame_tree_node_id) {
4254 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4255
Minggang Wangf6840ecf2019-07-29 05:15:024256 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194257
4258 Profile* profile = Profile::FromBrowserContext(browser_context);
4259
4260 ChromeNavigationUIData* chrome_navigation_ui_data =
4261 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4262
Nico Weberbc5b06f2019-07-26 14:00:134263#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564264 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4265 request.url, *profile->GetPrefs());
4266 if (!matches_enterprise_whitelist) {
Xinghui Lue17b19942020-02-24 21:19:584267 // |url_lookup_service| is used when real time url check is enabled.
4268 safe_browsing::RealTimeUrlLookupService* url_lookup_service =
4269 // |safe_browsing_service_| may be unavailable in tests.
4270 safe_browsing_service_ &&
4271 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
Xinghui Lu8fe39982020-03-02 22:31:384272 profile->GetPrefs(), profile->IsOffTheRecord())
Xinghui Lue17b19942020-02-24 21:19:584273 ? safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
4274 profile)
4275 : nullptr;
Xinghui Lu0abc17b2020-02-20 22:50:194276
Clark DuVall5497288d2019-07-17 00:17:564277 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4278 base::BindOnce(
4279 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534280 base::Unretained(this),
Bettinae83f522c72020-03-12 01:52:334281 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs())),
Xinghui Lua142c102020-03-02 20:50:084282 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584283 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564284 }
Nico Weberbc5b06f2019-07-26 14:00:134285#endif
Clark DuVall5497288d2019-07-17 00:17:564286
dalykba7bbfc2019-12-18 19:59:214287#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4288 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014289 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4290 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214291#endif
4292
Clark DuVallfffa41e2019-06-25 20:27:194293 if (chrome_navigation_ui_data &&
4294 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4295 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4296 chrome_navigation_ui_data->prerender_mode(),
4297 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234298 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194299 }
4300
John Abd-El-Malek4f380d92020-02-19 16:43:364301#if defined(OS_ANDROID)
4302 std::string client_data_header;
John Abd-El-Malekfb9f5462020-02-20 01:18:374303 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4304 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364305 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4306 if (web_contents) {
4307 auto* client_data_header_observer =
4308 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4309 web_contents);
4310 if (client_data_header_observer)
4311 client_data_header = client_data_header_observer->header();
4312 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374313 }
John Abd-El-Malek4f380d92020-02-19 16:43:364314#endif
4315
Clark DuVallfffa41e2019-06-25 20:27:194316 chrome::mojom::DynamicParams dynamic_params = {
4317 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4318 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274319 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4320 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364321#if defined(OS_ANDROID)
Alex Clarke3ebd9772020-02-28 10:50:274322 client_data_header,
John Abd-El-Malek4f380d92020-02-19 16:43:364323#endif
Alex Clarke3ebd9772020-02-28 10:50:274324 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194325
Clark DuValla411bda2019-08-02 03:09:174326 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4327 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214328
Clark DuVall39c2cfc2019-06-25 21:49:284329#if BUILDFLAG(ENABLE_PLUGINS)
4330 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464331 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284332#endif
4333
Robbie McElrath127ad2b2019-07-22 22:38:114334 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404335 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584336 auto signin_throttle =
4337 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114338 if (signin_throttle)
4339 result.push_back(std::move(signin_throttle));
4340
Clark DuVallfffa41e2019-06-25 20:27:194341 return result;
4342}
4343
Ken Rockot6414c4d92017-11-08 19:58:324344void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464345 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324346 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414347#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464348 content::WebContents* web_contents =
4349 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414350#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324351 factories->emplace(
4352 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574353 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464354 web_contents->GetBrowserContext(),
4355 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414356#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4357#if defined(OS_CHROMEOS)
4358 Profile* profile =
4359 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304360 factories->emplace(content::kExternalFileScheme,
4361 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4362 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414363#endif // defined(OS_CHROMEOS)
4364#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324365}
4366
Ting Shao2dc60582019-07-15 04:43:364367void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344368 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4369 content::BrowserContext* browser_context,
4370 NonNetworkURLLoaderFactoryMap* factories) {
4371#if BUILDFLAG(ENABLE_EXTENSIONS)
4372 DCHECK(browser_context);
4373 DCHECK(factories);
4374 factories->emplace(
4375 extensions::kExtensionScheme,
4376 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4377 browser_context));
4378#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4379}
4380
4381void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364382 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4383 content::BrowserContext* browser_context,
4384 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114385#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364386 DCHECK(browser_context);
4387 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364388 factories->emplace(
4389 extensions::kExtensionScheme,
4390 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4391 browser_context));
4392#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364393}
4394
Jay Civelli2578ebe2018-06-05 18:44:314395namespace {
4396
4397// The FileURLLoaderFactory provided to the extension background pages.
4398// Checks with the ChildProcessSecurityPolicy to validate the file access.
4399class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4400 public:
4401 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4402
4403 private:
4404 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274405 void CreateLoaderAndStart(
4406 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4407 int32_t routing_id,
4408 int32_t request_id,
4409 uint32_t options,
4410 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304411 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274412 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4413 override {
Jay Civelli2578ebe2018-06-05 18:44:314414 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4415 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304416 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4417 ->OnComplete(
4418 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314419 return;
4420 }
Yutaka Hiranodf83dca42020-01-07 06:24:554421 content::CreateFileURLLoaderBypassingSecurityChecks(
4422 request, std::move(loader), std::move(client),
4423 /*observer=*/nullptr,
4424 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314425 }
4426
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524427 void Clone(
4428 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4429 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314430 }
4431
4432 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524433 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314434 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4435};
4436
Aya ElAttareb5fee12020-05-05 08:56:054437#if defined(OS_CHROMEOS)
4438bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4439 PrefService* const local_state = g_browser_process->local_state();
4440 if (!local_state) // Sometimes it's not available in tests.
4441 return false;
4442
4443 const base::ListValue* disabled_system_features_pref =
4444 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4445 if (!disabled_system_features_pref)
4446 return false;
4447
4448 const auto disabled_system_features =
4449 disabled_system_features_pref->GetList();
4450 return base::Contains(disabled_system_features, base::Value(system_feature));
4451}
4452
4453bool IsSystemFeatureURLDisabled(const GURL& url) {
4454 if (!url.SchemeIs(content::kChromeUIScheme))
4455 return false;
4456
4457 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4458 // installation complete successfully.
4459 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4460 url.path() != "/pwa.html" &&
4461 IsSystemFeatureDisabled(policy::SystemFeature::OS_SETTINGS)) {
4462 return true;
4463 }
4464
4465 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
4466 IsSystemFeatureDisabled(policy::SystemFeature::BROWSER_SETTINGS)) {
4467 return true;
4468 }
4469
4470 return false;
4471}
4472#endif
Jay Civelli2578ebe2018-06-05 18:44:314473} // namespace
4474
Ken Rockot6414c4d92017-11-08 19:58:324475void ChromeContentBrowserClient::
4476 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464477 int render_process_id,
4478 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324479 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414480#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4481 content::RenderFrameHost* frame_host =
4482 RenderFrameHost::FromID(render_process_id, render_frame_id);
4483 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4484#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4485
4486#if defined(OS_CHROMEOS)
4487 if (web_contents) {
4488 Profile* profile =
4489 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304490 factories->emplace(content::kExternalFileScheme,
4491 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4492 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414493 }
4494#endif // defined(OS_CHROMEOS)
4495
Ken Rockot6414c4d92017-11-08 19:58:324496#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464497 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4498 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324499 if (factory)
4500 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234501
4502 // This logic should match
4503 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314504 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234505 return;
Jay Civellic9bbf72d2018-03-24 01:58:314506
4507 Profile* profile =
4508 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4509 InstantService* instant_service =
4510 InstantServiceFactory::GetForProfile(profile);
4511 // The test below matches what's done by ShouldServiceRequestIOThread in
4512 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464513 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314514 factories->emplace(
4515 chrome::kChromeSearchScheme,
4516 content::CreateWebUIURLLoader(
4517 frame_host, chrome::kChromeSearchScheme,
4518 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234519 }
Jay Civellic9bbf72d2018-03-24 01:58:314520
Chris Mumfordbae8a742018-03-01 23:02:234521 extensions::ChromeExtensionWebContentsObserver* web_observer =
4522 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4523 web_contents);
4524
Karan Bhatia91928572018-03-06 01:18:074525 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4526 // to the |web_contents|.
4527 if (!web_observer)
4528 return;
4529
Chris Mumfordbae8a742018-03-01 23:02:234530 const Extension* extension =
4531 web_observer->GetExtensionFromFrame(frame_host, false);
4532 if (!extension)
4533 return;
4534
Sam McNally7414eeb72018-09-03 04:05:304535 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234536 // Support for chrome:// scheme if appropriate.
4537 if ((extension->is_extension() || extension->is_platform_app()) &&
4538 Manifest::IsComponentLocation(extension->location())) {
4539 // Components of chrome that are implemented as extensions or platform apps
4540 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304541 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4542 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4543 }
4544 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4545 (extension->is_platform_app() &&
4546 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234547 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024548 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4549 // URLs. Hosted apps are not allowed because they are served via web servers
4550 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304551 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4552 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024553 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304554 }
4555 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234556 factories->emplace(
4557 content::kChromeUIScheme,
4558 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4559 std::move(allowed_webui_hosts)));
4560 }
Jay Civelli2578ebe2018-06-05 18:44:314561
4562 // Extension with a background page get file access that gets approval from
4563 // ChildProcessSecurityPolicy.
4564 extensions::ExtensionHost* host =
4565 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4566 ->GetBackgroundHostForExtension(extension->id());
4567 if (host) {
4568 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4569 render_process_id));
4570 }
Chris Mumfordbae8a742018-03-01 23:02:234571#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324572}
4573
Ken Rockota0dfaca12018-02-15 07:26:254574bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214575 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254576 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384577 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444578 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264579 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004580 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424581 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184582 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4583 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334584 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084585 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334586 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014587 bool use_proxy = false;
4588
Ken Rockota0dfaca12018-02-15 07:26:254589#if BUILDFLAG(ENABLE_EXTENSIONS)
4590 auto* web_request_api =
4591 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214592 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254593
4594 // NOTE: Some unit test environments do not initialize
4595 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014596 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124597 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384598 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004599 browser_context, frame, render_process_id, type,
4600 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124601 if (bypass_redirect_checks)
4602 *bypass_redirect_checks = use_proxy_for_web_request;
4603 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014604 }
Ken Rockota0dfaca12018-02-15 07:26:254605#endif
Reilly Grant24bf8332018-08-27 21:55:014606
Reilly Grantcc22e602018-09-07 15:25:204607 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444608 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4609 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014610
dalyk0018c16f2020-01-08 20:20:084611#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4612 if (disable_secure_dns) {
4613 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4614 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014615 web_contents &&
4616 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4617 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084618 ->is_captive_portal_window();
4619 }
4620#endif
4621
Reilly Grant24bf8332018-08-27 21:55:014622 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254623}
4624
Jian Lide7b43792018-06-01 23:22:134625std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4626ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4627 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144628 int frame_tree_node_id,
4629 const scoped_refptr<network::SharedURLLoaderFactory>&
4630 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134631 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4632 interceptors;
4633#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234634 interceptors.push_back(
4635 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4636 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134637#endif
Ryan Sturmaf523742019-01-16 00:15:454638
Robert Ogden6946ad42020-01-13 18:01:304639 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4640 interceptors.push_back(
4641 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4642 frame_tree_node_id));
4643 }
4644
Jian Lide7b43792018-06-01 23:22:134645 return interceptors;
4646}
4647
Yutaka Hirano8e0b4d432019-07-04 07:12:384648bool ChromeContentBrowserClient::WillInterceptWebSocket(
4649 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334650#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384651 if (!frame) {
4652 return false;
4653 }
4654 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334655 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4656 frame->GetProcess()->GetBrowserContext());
4657
4658 // NOTE: Some unit test environments do not initialize
4659 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4660 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384661 return false;
Yutaka Hirano36c94952018-05-30 21:33:334662
Yutaka Hirano8e0b4d432019-07-04 07:12:384663 return web_request_api->MayHaveProxies();
4664#else
4665 return false;
4666#endif
4667}
4668
4669void ChromeContentBrowserClient::CreateWebSocket(
4670 content::RenderFrameHost* frame,
4671 WebSocketFactory factory,
4672 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394673 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384674 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404675 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4676 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384677#if BUILDFLAG(ENABLE_EXTENSIONS)
4678 if (!frame) {
4679 return;
4680 }
4681 auto* web_request_api =
4682 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4683 frame->GetProcess()->GetBrowserContext());
4684
4685 DCHECK(web_request_api);
4686 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394687 site_for_cookies.RepresentativeUrl(),
4688 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334689#endif
4690}
4691
Maks Orlovich710d5e32019-07-09 20:16:454692bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464693 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454694 content::BrowserContext* browser_context,
4695 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394696 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404697 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454698 bool is_service_worker,
4699 int process_id,
4700 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034701 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454702 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4703#if BUILDFLAG(ENABLE_EXTENSIONS)
4704 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464705 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454706 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404707 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4708 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454709 return true;
4710 }
4711#endif
4712 return false;
4713}
4714
Matt Menkeae4fdb12018-06-02 06:32:544715void ChromeContentBrowserClient::OnNetworkServiceCreated(
4716 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534717 PrefService* local_state;
4718 if (g_browser_process) {
4719 DCHECK(g_browser_process->local_state());
4720 local_state = g_browser_process->local_state();
4721 } else {
Xi Han85079c22019-04-18 21:43:054722 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4723 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534724 }
4725
4726 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4727 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4728
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494729 // Create SystemNetworkContextManager if it has not been created yet. We need
4730 // to set up global NetworkService state before anything else uses it and this
4731 // is the first opportunity to initialize SystemNetworkContextManager with the
4732 // NetworkService.
4733 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534734 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074735
Min Qin8caab1d2018-10-03 17:28:134736 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544737 network_service);
4738}
4739
Julie Jeongeun Kim5984e992019-09-11 11:00:464740mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254741ChromeContentBrowserClient::CreateNetworkContext(
4742 content::BrowserContext* context,
4743 bool in_memory,
4744 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504745 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454746 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254747}
4748
Robert Sesek34f68f312019-01-14 20:25:114749std::vector<base::FilePath>
4750ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024751 DCHECK(!network_contexts_parent_directory_.empty());
4752 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114753}
4754
Min Qin75ed6df2017-12-01 20:39:154755bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134756 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154757#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4758 // It is OK to load the saved offline copy, in MHTML format.
4759 ChromeNavigationUIData* chrome_navigation_ui_data =
4760 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4761 if (!chrome_navigation_ui_data)
4762 return false;
4763 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4764 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4765 return offline_page_data && offline_page_data->is_offline_page();
4766#else
4767 return false;
4768#endif
4769}
4770
Min Qin30a78a12017-12-06 01:29:134771bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4772 const GURL& url,
4773 const std::string& mime_type) {
4774#if BUILDFLAG(ENABLE_EXTENSIONS)
4775 // Special-case user scripts to get downloaded instead of viewed.
4776 return extensions::UserScript::IsURLUserScript(url, mime_type);
4777#else
4778 return false;
4779#endif
4780}
4781
Donna Wu838ac362018-08-10 10:36:334782void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344783 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044784 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:464785 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:344786 return;
4787
[email protected]95ebe7c2020-04-08 19:12:454788 CHECK(render_frame_host);
4789 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4790 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344791}
4792
Ovidio Henriquez3d729f62020-02-07 00:43:294793content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4794 if (!bluetooth_delegate_)
4795 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4796 return bluetooth_delegate_.get();
4797}
4798
Reilly Grant0d282322019-01-29 02:42:584799#if !defined(OS_ANDROID)
4800content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4801 if (!serial_delegate_)
4802 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4803 return serial_delegate_.get();
4804}
Matt Reynolds93616f9b2019-06-07 01:28:524805
4806content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4807 if (!hid_delegate_)
4808 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4809 return hid_delegate_.get();
4810}
Reilly Grant0d282322019-01-29 02:42:584811
Balazs Engedya7ff70982018-06-04 18:14:474812std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4813ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334814 content::RenderFrameHost* render_frame_host) {
4815 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4816 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474817}
Nina Satragno8c832df2019-07-29 15:59:394818#endif
Balazs Engedya7ff70982018-06-04 18:14:474819
Jun Cai9409ded2018-01-30 00:19:464820std::unique_ptr<net::ClientCertStore>
4821ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104822 content::BrowserContext* browser_context) {
4823 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464824 ->CreateClientCertStore();
4825}
4826
David Benjamineced01fc2019-02-27 18:29:024827std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394828ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584829 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024830 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034831 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244832 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394833 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034834 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394835 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564836 LoginAuthRequiredCallback auth_required_callback) {
Emily Stark63c884f2020-05-12 03:55:284837 // For subresources, create a LoginHandler directly, which may show a login
4838 // prompt to the user. Main frame resources go through LoginTabHelper, which
4839 // manages a more complicated flow to avoid confusion about which website is
4840 // showing the prompt.
4841 if (is_request_for_main_frame) {
4842 LoginTabHelper::CreateForWebContents(web_contents);
4843 return LoginTabHelper::FromWebContents(web_contents)
4844 ->CreateAndStartMainFrameLoginDelegate(
4845 auth_info, web_contents, request_id, url, response_headers,
4846 std::move(auth_required_callback));
4847 }
4848 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
4849 auth_info, web_contents, std::move(auth_required_callback));
4850 login_handler->StartSubresource(request_id, url, response_headers);
4851 return login_handler;
Jun Caibc561f412018-02-28 18:41:394852}
4853
John Abd-El-Maleka67add82018-03-09 18:22:014854bool ChromeContentBrowserClient::HandleExternalProtocol(
4855 const GURL& url,
danakjf4b9e942019-11-29 15:43:044856 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014857 int child_id,
4858 content::NavigationUIData* navigation_data,
4859 bool is_main_frame,
4860 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454861 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454862 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104863 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014864#if BUILDFLAG(ENABLE_EXTENSIONS)
4865 // External protocols are disabled for guests. An exception is made for the
4866 // "mailto" protocol, so that pages that utilize it work properly in a
4867 // WebView.
4868 ChromeNavigationUIData* chrome_data =
4869 static_cast<ChromeNavigationUIData*>(navigation_data);
4870 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4871 (chrome_data &&
4872 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4873 !url.SchemeIs(url::kMailToScheme)) {
4874 return false;
4875 }
4876#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4877
4878#if defined(OS_ANDROID)
4879 // Main frame external protocols are handled by
4880 // InterceptNavigationResourceThrottle.
4881 if (is_main_frame)
4882 return false;
4883#endif // defined(ANDROID)
4884
Emily Stark13b66bdf2019-10-04 17:11:454885 base::PostTask(
4886 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044887 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4888 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014889 return true;
4890}
4891
Jennifer Apacible4f854a82018-04-06 22:22:114892std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284893ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4894 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114895 // Note: content::OverlayWindow::Create() is defined by platform-specific
4896 // implementation in chrome/browser/ui/views. This layering hack, which goes
4897 // through //content and ContentBrowserClient, allows us to work around the
4898 // dependency constraints that disallow directly calling
4899 // chrome/browser/ui/views code either from here or from other code in
4900 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284901 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114902}
4903
Kunihiko Sakamoto19aa7082019-02-25 03:14:434904void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564905 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114906 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564907 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434908 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4909 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564910}
4911
dbeam25472e0c2017-06-23 19:02:314912// Static; handles rewriting Web UI URLs.
4913bool ChromeContentBrowserClient::HandleWebUI(
4914 GURL* url,
4915 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394916 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314917 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394918 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314919 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4920 chrome::kChromeUIHelpHost);
4921 return true; // Return true to update the displayed URL.
4922 }
4923
Hector Carmona566a20b2019-09-13 22:44:424924#if defined(OS_WIN)
4925 // TODO(crbug.com/1003960): Remove when issue is resolved.
4926 if (url->SchemeIs(content::kChromeUIScheme) &&
4927 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4928 url::Replacements<char> replacements;
4929 replacements.SetHost(
4930 chrome::kChromeUIWelcomeHost,
4931 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4932 *url = url->ReplaceComponents(replacements);
4933 return true;
4934 }
4935#endif // defined(OS_WIN)
4936
dbeam25472e0c2017-06-23 19:02:314937 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4938 browser_context, *url)) {
4939 return false;
4940 }
4941
4942#if defined(OS_CHROMEOS)
4943 // Special case : in ChromeOS in Guest mode bookmarks and history are
4944 // disabled for security reasons. New tab page explains the reasons, so
4945 // we redirect user to new tab page.
4946 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4947 if (url->SchemeIs(content::kChromeUIScheme) &&
4948 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4949 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4950 // Rewrite with new tab URL
4951 *url = GURL(chrome::kChromeUINewTabURL);
4952 }
4953 }
Aya ElAttareb5fee12020-05-05 08:56:054954
4955 if (IsSystemFeatureURLDisabled(*url)) {
4956 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
4957 return true;
4958 }
4959
dbeam25472e0c2017-06-23 19:02:314960#endif
4961
4962 return true;
4963}
4964
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064965bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
4966 content::BrowserContext* browser_context,
4967 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:324968 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064969#if defined(OS_ANDROID)
4970 return false;
4971#else
4972 payments::PaymentRequestDisplayManagerFactory::GetInstance()
4973 ->GetForBrowserContext(browser_context)
4974 ->ShowPaymentHandlerWindow(url, std::move(callback));
4975 return true;
4976#endif
4977}
4978
Dan Beam141c48932019-08-22 02:29:394979// static
dbeam25472e0c2017-06-23 19:02:314980bool ChromeContentBrowserClient::HandleWebUIReverse(
4981 GURL* url,
4982 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:424983#if defined(OS_WIN)
4984 // TODO(crbug.com/1003960): Remove when issue is resolved.
4985 // No need to actually reverse-rewrite the URL, but return true to update the
4986 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
4987 if (url->SchemeIs(content::kChromeUIScheme) &&
4988 url->host() == chrome::kChromeUIWelcomeHost) {
4989 return true;
4990 }
4991#endif // defined(OS_WIN)
4992
dbeam25472e0c2017-06-23 19:02:314993 // No need to actually reverse-rewrite the URL, but return true to update the
4994 // displayed URL when rewriting chrome://help to chrome://settings/help.
4995 return url->SchemeIs(content::kChromeUIScheme) &&
4996 url->host() == chrome::kChromeUISettingsHost;
4997}
4998
Alison Maher7f366dc62020-03-03 19:46:004999const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585000 return ui::NativeTheme::GetInstanceForWeb();
5001}
5002
Clark DuVall5497288d2019-07-17 00:17:565003scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505004ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:535005 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:355006 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5007
Matt Menke562675cfe2020-01-07 15:50:535008 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:505009 return nullptr;
5010
Yuzhu Shen44094e22017-07-18 22:52:355011 // |safe_browsing_service_| may be unavailable in tests.
5012 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5013 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435014 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355015 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435016 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355017 }
5018
Clark DuVall5497288d2019-07-17 00:17:565019 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355020}
Daniel Vogelheim6008f572018-09-24 14:35:145021
5022base::Optional<std::string>
5023ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595024 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185025 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595026 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5027 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145028}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525029
Takashi Toyoshima5af383aa2019-07-22 15:24:225030bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525031 // We require --user-data-dir flag too so that no dangerous changes are made
5032 // in the user's regular profile.
5033 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5034 switches::kUserDataDir);
5035}
rajendrantfeea8592018-10-19 18:26:065036
5037void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5038 int32_t network_traffic_annotation_id_hash,
5039 int64_t recv_bytes,
5040 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035041 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5042 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5043 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5044 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065045 }
5046}
Ryan Sturmaa05092f2018-10-21 03:56:545047
Ken Rockot4e284d32020-03-06 06:26:495048base::FilePath
5049ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
5050 return g_browser_process->profile_manager()->user_data_dir();
5051}
5052
Ryan Sturmaa05092f2018-10-21 03:56:545053content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5054 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395055 content::NavigationHandle* navigation_handle,
5056 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135057 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5058 initial_state, navigation_handle, current_navigation_url);
5059
5060 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5061}
5062
5063content::PreviewsState
5064ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5065 content::PreviewsState initial_state,
5066 content::NavigationHandle* navigation_handle,
5067 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545068 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295069 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215070
Ryan Sturmaa05092f2018-10-21 03:56:545071 // If this is not a main frame, return the initial state. If there are no
5072 // previews in the state, return the state as is.
5073 if (!navigation_handle->IsInMainFrame() ||
5074 navigation_handle->IsSameDocument()) {
5075 return initial_state;
5076 }
5077
Robert Ogdena994eb42019-02-14 19:15:085078 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395079 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085080
Doug Arnettb3b99bc2019-08-09 16:55:565081 // Check if initial state specifies no previews should be considered.
5082 if (initial_state == content::PREVIEWS_OFF)
5083 return initial_state;
5084
Robert Ogdena994eb42019-02-14 19:15:085085 // Do not allow previews on POST navigations since the primary opt-out
5086 // mechanism is to reload the page. Because POST navigations are not
5087 // idempotent, we do not want to show a preview on a POST navigation where
5088 // opting out would cause another navigation, i.e.: a reload.
5089 if (navigation_handle->IsPost())
5090 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395091
5092 content::WebContents* web_contents = navigation_handle->GetWebContents();
5093 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5094
Ryan Sturmda2a0e02018-10-25 01:52:215095 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545096
5097 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5098 Profile::FromBrowserContext(browser_context));
5099 auto* data_reduction_proxy_settings =
5100 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5101 browser_context);
5102 // If the profile does not support previews or Data Saver, do not turn on
5103 // Previews.
5104 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355105 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545106 return content::PREVIEWS_OFF;
5107 }
5108
5109 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215110 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545111 // If this tab does not have a PreviewsUITabHelper, no preview should be
5112 // served.
5113 if (!ui_tab_helper)
5114 return content::PREVIEWS_OFF;
5115
5116 DCHECK(!browser_context->IsOffTheRecord());
5117
5118 // Other previews objects should all exist and be initialized if we have made
5119 // it past earlier checks.
5120 previews::PreviewsDeciderImpl* previews_decider_impl =
5121 previews_service->previews_ui_service()->previews_decider_impl();
5122 DCHECK(previews_decider_impl);
5123
Ryan Sturm647d1d92018-11-07 15:41:395124 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545125 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5126
Ryan Sturm647d1d92018-11-07 15:41:395127 previews::PreviewsUserData* previews_data =
5128 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5129
5130 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315131 // previews) and cannot re-evaluate PreviewsState once previews triggering
5132 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375133 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315134 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395135 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375136 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395137 } else {
5138 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5139 navigation_handle, previews_decider_impl->GeneratePageId());
5140 }
5141
5142 DCHECK(previews_data);
5143
Robert Ogden01770b362019-05-22 17:36:435144 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5145 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435146 return content::ALL_SUPPORTED_PREVIEWS;
5147 }
5148
Ryan Sturmaa05092f2018-10-21 03:56:545149 bool is_reload =
5150 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5151
Ryan Sturm647d1d92018-11-07 15:41:395152 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515153 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395154
5155 // For now, treat server previews types as a single decision, and do not
5156 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5157 // header, nor does the plumbing exist to modify the PreviewsState within the
5158 // URLLoader.
Seanac57e9b92019-04-29 19:19:315159 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395160 // Copy the server state that was used before the redirect for the initial
5161 // URL.
Robert Ogden869986f2019-06-20 19:12:055162 previews_state |=
5163 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395164 } else {
Doug Arnetta3dc71582018-11-08 00:25:105165 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215166 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305167 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395168 previews_state |= server_previews_enabled_state;
5169 }
Ryan Sturmaa05092f2018-10-21 03:56:545170 }
5171
Sophie Changa71fa5d2019-11-19 23:53:515172 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545173 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315174 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355175 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5176 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545177
5178 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395179 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545180 return content::PREVIEWS_OFF;
5181 }
5182
5183 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395184 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545185 return content::PREVIEWS_NO_TRANSFORM;
5186 }
5187
5188 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395189 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5190 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545191 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395192 }
5193
5194 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5195 if (delegate) {
5196 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5197 }
Ryan Sturmaa05092f2018-10-21 03:56:545198
5199 // If the allowed previews are limited by the embedder, ensure previews honors
5200 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395201 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5202 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545203 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5204 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5205 previews_state = content::PREVIEWS_OFF;
5206 }
Ryan Sturm647d1d92018-11-07 15:41:395207 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545208 return previews_state;
5209}
5210
5211// static
5212content::PreviewsState
5213ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5214 const GURL& url,
5215 data_reduction_proxy::DataReductionProxyData* drp_data,
5216 previews::PreviewsUserData* previews_user_data,
5217 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055218 content::PreviewsState initial_state,
5219 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545220 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5221 if (!previews::HasEnabledPreviews(initial_state))
5222 return content::PREVIEWS_OFF;
5223
5224 // Check if the server sent a preview directive.
5225 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555226 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545227
Ryan Sturmaa05092f2018-10-21 03:56:545228 // Check the various other client previews types.
5229 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055230 previews_user_data, url, previews_state, previews_decider,
5231 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545232}
5233
5234content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5235 content::PreviewsState initial_state,
5236 content::NavigationHandle* navigation_handle,
5237 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135238 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5239 initial_state, navigation_handle, response_headers);
5240
5241 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5242}
5243
5244content::PreviewsState
5245ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5246 content::PreviewsState initial_state,
5247 content::NavigationHandle* navigation_handle,
5248 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545249 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5250 // Only support HTTP and HTTPS.
5251 if (navigation_handle->IsErrorPage() ||
5252 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5253 return content::PREVIEWS_OFF;
5254 }
5255
5256 // If this is not a main frame, return the initial state. If there are no
5257 // previews in the state, return the state as is.
5258 if (!previews::HasEnabledPreviews(initial_state) ||
5259 !navigation_handle->IsInMainFrame() ||
5260 navigation_handle->IsSameDocument()) {
5261 return initial_state;
5262 }
5263
5264 // WebContents that don't have a PreviewsUITabHelper are not supported.
5265 PreviewsUITabHelper* ui_tab_helper =
5266 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5267 if (!ui_tab_helper)
5268 return content::PREVIEWS_OFF;
5269
5270 // If we did not previously create a PreviewsUserData, do not go any further.
5271 previews::PreviewsUserData* previews_user_data =
5272 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5273 if (!previews_user_data)
5274 return content::PREVIEWS_OFF;
5275
5276 PreviewsService* previews_service =
5277 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5278 navigation_handle->GetWebContents()->GetBrowserContext()));
5279
5280 if (!previews_service || !previews_service->previews_ui_service())
5281 return content::PREVIEWS_OFF;
5282
5283// Check if offline previews are being used and set it in the user data.
5284#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5285 offline_pages::OfflinePageTabHelper* tab_helper =
5286 offline_pages::OfflinePageTabHelper::FromWebContents(
5287 navigation_handle->GetWebContents());
5288
Ryan Sturmfc7d92f2019-02-12 02:24:235289 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5290 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5291
5292 // If this is an offline page, but not a preview, then we should not attempt
5293 // any previews or surface the previews UI.
5294 if (is_offline_page && !is_offline_preview)
5295 return content::PREVIEWS_OFF;
5296
5297 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545298#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5299
5300 // Annotate request if no-transform directive found in response headers.
5301 if (response_headers &&
5302 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265303 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545304 }
5305
5306 previews::PreviewsDeciderImpl* previews_decider_impl =
5307 previews_service->previews_ui_service()->previews_decider_impl();
5308 DCHECK(previews_decider_impl);
5309
Clark DuVall9c5a72cc2018-10-25 01:29:215310 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5311 auto* settings =
5312 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5313 navigation_handle->GetWebContents()->GetBrowserContext());
5314 if (settings) {
5315 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5316 // does not yet have all the response information.
5317 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5318 response_headers);
5319 }
Ryan Sturmaa05092f2018-10-21 03:56:545320
5321 // Determine effective PreviewsState for this committed main frame response.
5322 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215323 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055324 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545325
5326 // Double check that we never serve a preview when we have a
5327 // cache-control:no-transform directive.
5328 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5329 !previews::HasEnabledPreviews(committed_state));
5330
Robert Ogdended292c6f2019-05-03 22:44:515331 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545332 previews_user_data->set_committed_previews_state(committed_state);
5333
5334 previews::PreviewsType committed_type =
5335 previews::GetMainFramePreviewsType(committed_state);
5336
5337 // Capture committed previews type, if any, in PreviewsUserData.
5338 // Note: this is for the subset of previews types that are decided upon
5339 // navigation commit. Previews types that are determined prior to
5340 // navigation (such as for offline pages or for redirecting to another
5341 // url), are not set here.
5342 previews_user_data->SetCommittedPreviewsType(committed_type);
5343
5344 // Log the commit decision.
5345 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5346 previews_decider_impl->LogPreviewDecisionMade(
5347 (previews_user_data->cache_control_no_transform_directive()
5348 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5349 : previews::PreviewsEligibilityReason::COMMITTED),
5350 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055351 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055352 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545353
5354 return committed_state;
5355}
Charlie Harrison650e11422018-12-04 00:37:265356
5357void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5358 content::RenderFrameHost* render_frame_host,
5359 blink::mojom::WebFeature feature) {
5360 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5361 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5362 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5363 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315364
5365 // For the SameSite-by-default-cookies related features, log
5366 // the site engagement score for the site whose cookie was blocked. This is to
5367 // gauge the user impact of the cookies being blocked.
5368 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265369}
Yutaka Hirano968d6252018-12-04 05:09:315370
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525371std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315372 return ::GetProduct();
5373}
5374
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525375std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315376 return ::GetUserAgent();
5377}
Sam McNallyd54e23f92019-01-16 04:42:395378
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525379blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175380 return ::GetUserAgentMetadata();
5381}
5382
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525383base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275384 // This icon is available on Android, but adds 19KiB to the APK. Since it
5385 // isn't used on Android we exclude it to avoid bloat.
5386#if !defined(OS_ANDROID)
5387 return base::Optional<gfx::ImageSkia>(
5388 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5389 IDR_PRODUCT_LOGO_256));
5390#else
5391 return base::nullopt;
5392#endif
5393}
5394
Sam McNallyd54e23f92019-01-16 04:42:395395bool ChromeContentBrowserClient::IsBuiltinComponent(
5396 content::BrowserContext* browser_context,
5397 const url::Origin& origin) {
5398#if BUILDFLAG(ENABLE_EXTENSIONS)
5399 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5400 browser_context, origin);
5401#else
5402 return false;
5403#endif
5404}
Oleg Davydov2cc0167b2019-02-05 14:32:485405
5406bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5407 const GURL& url,
5408 content::BrowserContext* context) {
5409 PolicyBlacklistService* service =
5410 PolicyBlacklistFactory::GetForBrowserContext(context);
5411
5412 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5413 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5414 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5415}
Dominic Mazzoni21fb0282019-02-13 18:32:475416
5417ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5418 content::BrowserContext* browser_context) {
5419 Profile* profile = Profile::FromBrowserContext(browser_context);
5420 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5421}
Eric Karld6cd75b2019-03-14 22:01:365422
5423#if defined(OS_ANDROID)
5424content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525425ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335426 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425427 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365428 return WideColorGamutHeuristic::kUseDisplay;
5429 }
Khushal1fc0da52019-10-09 00:38:565430
5431 if (display::Display::HasForceDisplayColorProfile() &&
5432 display::Display::GetForcedDisplayColorProfile() ==
5433 gfx::ColorSpace::CreateDisplayP3D65()) {
5434 return WideColorGamutHeuristic::kUseDisplay;
5435 }
5436
Eric Karld6cd75b2019-03-14 22:01:365437 return WideColorGamutHeuristic::kNone;
5438}
5439#endif
Ehsan Karamad91413d72019-03-22 16:37:485440
5441base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435442ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465443 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485444 base::flat_set<std::string> mime_types;
5445#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465446 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485447 for (const auto& pair : map)
5448 mime_types.insert(pair.first);
5449#endif
5450 return mime_types;
5451}
Yao Xiaod06607b2019-05-02 23:16:365452
5453void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5454 const content::WebContents* web_contents,
5455 const content::RenderFrameHost* frame_host,
5456 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525457 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365458 const ChromeSubresourceFilterClient* client =
5459 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5460 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045461 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365462 if (!user_gesture) {
5463 if (base::FeatureList::IsEnabled(
5464 blink::features::
5465 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5466 download_policy->SetDisallowed(
5467 content::NavigationDownloadType::kAdFrameNoGesture);
5468 } else {
5469 download_policy->SetAllowed(
5470 content::NavigationDownloadType::kAdFrameNoGesture);
5471 }
Yao Xiaod06607b2019-05-02 23:16:365472 }
5473 }
5474}
Jun Cai732a05e32019-05-29 19:34:195475
5476bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5477 content::BrowserContext* browser_context,
5478 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525479 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195480 const HostContentSettingsMap* const content_settings =
5481 HostContentSettingsMapFactory::GetForProfile(
5482 Profile::FromBrowserContext(browser_context));
5483
5484 if (content_settings->GetContentSetting(
5485 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455486 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195487 std::string()) == CONTENT_SETTING_BLOCK) {
5488 return true;
5489 }
5490
5491 return false;
5492}
5493
5494void ChromeContentBrowserClient::BlockBluetoothScanning(
5495 content::BrowserContext* browser_context,
5496 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525497 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195498 HostContentSettingsMap* const content_settings =
5499 HostContentSettingsMapFactory::GetForProfile(
5500 Profile::FromBrowserContext(browser_context));
5501
5502 content_settings->SetContentSettingDefaultScope(
5503 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455504 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195505 CONTENT_SETTING_BLOCK);
5506}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475507
5508bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5509#if defined(OS_ANDROID)
5510 return extra_icu::ModuleProvider::IsModuleInstalled();
5511#endif
5512 return false;
5513}
Guido Urdaneta4030d6a32019-10-17 09:38:165514
5515bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5516 content::BrowserContext* browser_context,
5517 const GURL& url,
5518 const GURL& site_for_cookies,
5519 const base::Optional<url::Origin>& top_frame_origin) {
5520 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5521 return CookieSettingsFactory::GetForProfile(
5522 Profile::FromBrowserContext(browser_context))
5523 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5524}
Sam Goto5cf068e82019-11-04 23:08:445525
5526#if !defined(OS_ANDROID)
5527void ChromeContentBrowserClient::FetchRemoteSms(
5528 content::BrowserContext* browser_context,
5529 const url::Origin& origin,
5530 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5531 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5532}
5533#endif
Roger Tawa03ffdbd2020-01-16 18:12:545534
5535void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5536 content::WebContents* web_contents,
5537 const GURL& url,
5538 const ui::ClipboardFormatType& data_type,
5539 const std::string& data,
5540 IsClipboardPasteAllowedCallback callback) {
5541#if BUILDFLAG(FULL_SAFE_BROWSING)
5542 // Safe browsing does not support images, so accept without checking.
5543 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5544 // types when it is implemented.
5545 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5546 std::move(callback).Run(ClipboardPasteAllowed(true));
5547 return;
5548 }
5549
5550 Profile* profile =
5551 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5552 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265553 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(
5554 profile, url, &dialog_data,
5555 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545556 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5557 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5558 web_contents, std::move(dialog_data),
5559 base::BindOnce(
5560 [](IsClipboardPasteAllowedCallback callback,
5561 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5562 const safe_browsing::DeepScanningDialogDelegate::Result&
5563 result) {
5564 std::move(callback).Run(
5565 ClipboardPasteAllowed(result.text_results[0]));
5566 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245567 std::move(callback)),
5568 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545569 } else {
5570 std::move(callback).Run(ClipboardPasteAllowed(true));
5571 }
5572#else
5573 std::move(callback).Run(ClipboardPasteAllowed(true));
5574#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5575}
Lukasz Anforowicz4600ea32020-01-18 02:37:485576
Lukasz Anforowicz1feeba182020-03-16 20:32:025577void ChromeContentBrowserClient::
5578 LogUkmEventForCrossOriginFetchFromContentScript3(
5579 const std::string& isolated_world_host) {
5580#if BUILDFLAG(ENABLE_EXTENSIONS)
5581 const std::string& extension_id = isolated_world_host;
5582 ukm::SourceId source_id =
5583 ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id);
5584 if (source_id != ukm::kInvalidSourceId) {
5585 ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event(
5586 source_id);
5587 ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get());
5588 }
5589#endif
5590}
5591
Lukasz Anforowicz4600ea32020-01-18 02:37:485592#if BUILDFLAG(ENABLE_PLUGINS)
5593bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5594 const url::Origin& embedder_origin,
5595 const content::PepperPluginInfo& plugin_info) {
5596#if BUILDFLAG(ENABLE_PDF)
5597 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5598#if BUILDFLAG(ENABLE_EXTENSIONS)
5599 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5600 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5601 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5602 return true;
5603 }
5604#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5605
5606 // Allow embedding the internal PDF plugin in chrome://print.
5607 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5608 return true;
5609
5610 // Only allow the PDF plugin in the known, trustworthy origins that are
5611 // allowlisted above. See also https://crbug.com/520422 and
5612 // https://crbug.com/1027173.
5613 return false;
5614 }
5615#endif // BUILDFLAG(ENABLE_PDF)
5616
5617 return true;
5618}
5619#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565620
5621#if BUILDFLAG(ENABLE_VR)
5622content::XrIntegrationClient*
5623ChromeContentBrowserClient::GetXrIntegrationClient() {
5624 if (!xr_integration_client_)
5625 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5626 util::PassKey<ChromeContentBrowserClient>());
5627 return xr_integration_client_.get();
5628}
5629#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185630
5631bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5632 content::BrowserContext* browser_context) {
5633 auto* profile = Profile::FromBrowserContext(browser_context);
5634 auto* prefs = profile->GetPrefs();
5635
5636 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5637 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5638 return false;
5639 }
5640 if (base::FeatureList::IsEnabled(
5641 blink::features::kAppCacheRequireOriginTrial)) {
5642 return true;
5643 }
5644
5645 return false;
5646}