blob: 9d563c36c0020485e122425d1f314d5ba6c257e5 [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"
evliuedcbb87d2019-11-22 19:49:4123#include "base/metrics/histogram_functions.h"
lazyboy5d5fede02016-03-10 04:10:1424#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3325#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3926#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0227#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3728#include "base/stl_util.h"
[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"
michaeln96f887e22015-04-13 23:58:3142#include "chrome/browser/after_startup_task_utils.h"
Ovidio Henriquez3d729f62020-02-07 00:43:2943#include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h"
[email protected]b8148ac2011-07-13 22:03:2544#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3045#include "chrome/browser/browser_process.h"
msramek1c2b3ca2017-03-14 17:57:5646#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5147#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
[email protected]d5a74be2014-08-08 01:01:2748#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0949#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0850#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2251#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
52#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3053#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
54#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0655#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0856#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4957#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3158#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4559#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0160#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1961#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5362#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5263#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1064#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2765#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2766#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3467#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4268#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
69#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1670#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3671#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3672#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5673#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0474#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0575#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0776#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2377#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1078#include "chrome/browser/net/profile_network_context_service.h"
79#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5480#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0281#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5982#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5683#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0684#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5485#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5186#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5687#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4288#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1189#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4890#include "chrome/browser/plugins/plugin_utils.h"
Robert Ogdenea4ea7392020-01-25 01:44:5391#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3092#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]190e5e22013-07-27 05:59:2393#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4194#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5095#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0796#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:0197#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:1998#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:5499#include "chrome/browser/previews/previews_service.h"
100#include "chrome/browser/previews/previews_service_factory.h"
101#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03102#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14103#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32104#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49105#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06106#include "chrome/browser/profiles/renderer_updater.h"
107#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56108#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
109#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44110#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38111#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40112#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45113#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31114#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
115#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24116#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Carlos IL4ee307e2018-12-22 03:19:00117#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40118#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35119#include "chrome/browser/safe_browsing/ui_manager.h"
120#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58121#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43122#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44123#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20124#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35125#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40126#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23127#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28128#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02129#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48130#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38131#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32132#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07133#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23134#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10135#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35136#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45137#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52138#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19139#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44140#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38141#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51142#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08143#include "chrome/browser/ui/browser_navigator.h"
144#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43145#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39146#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54147#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56148#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25149#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44150#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58151#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50152#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01153#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45154#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53155#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25156#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59157#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23158#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22159#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01160#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48161#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51162#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14163#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22164#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30165#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02166#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50167#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34168#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37169#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12170#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19171#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12172#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22173#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32174#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38175#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28176#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02177#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09178#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47179#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37180#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18181#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30182#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12183#include "components/autofill/core/common/autofill_switches.h"
Clark DuVallf5189252020-04-15 22:33:34184#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53185#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51186#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49187#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44188#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04189#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48190#include "components/cloud_devices/common/cloud_devices_switches.h"
Clark DuVall84a33d612020-04-17 16:01:00191#include "components/content_settings/browser/tab_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16192#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09193#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16194#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52195#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45196#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08197#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03198#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54199#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28200#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43201#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09202#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03203#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24204#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32205#include "components/embedder_support/switches.h"
blundella5e3240a2016-01-05 11:30:43206#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01207#include "components/feature_engagement/public/feature_constants.h"
208#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39209#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20210#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53211#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16212#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12213#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
214#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
215#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06216#include "components/payments/content/payment_request_display_manager.h"
Clark DuValla11361ad32020-02-20 22:14:27217#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54218#include "components/permissions/quota_permission_context_impl.h"
Doug Turner9dcaf5962017-12-21 04:38:53219#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54220#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18221#include "components/policy/core/common/policy_service.h"
222#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26223#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54224#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08225#include "components/prefs/pref_service.h"
226#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21227#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54228#include "components/previews/content/previews_decider_impl.h"
229#include "components/previews/content/previews_ui_service.h"
230#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54231#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45232#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43233#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56234#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56235#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13236#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47237#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
238#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
239#include "components/safe_browsing/core/browser/url_checker_delegate.h"
240#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
241#include "components/safe_browsing/core/db/database_manager.h"
242#include "components/safe_browsing/core/features.h"
243#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58244#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Daniel Vogelheim6008f572018-09-24 14:35:14245#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49246#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48247#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49248#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23249#include "components/signin/public/identity_manager/identity_manager.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54250#include "components/site_isolation/preloaded_isolated_origins.h"
csharrisone985ebc2017-04-04 17:05:03251#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17252#include "components/translate/core/common/translate_switches.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02253#include "components/ukm/app_source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21254#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28255#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33256#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46257#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22258#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39259#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33260#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43261#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30262#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38263#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28264#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03265#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31266#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41267#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09268#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03269#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59270#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19271#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31272#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35273#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47274#include "content/public/browser/navigation_handle.h"
275#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11276#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50277#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30278#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33279#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05280#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54281#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34282#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48283#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27284#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13285#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08286#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19287#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21288#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23289#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43290#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18291#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56292#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40293#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02294#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18295#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57296#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23297#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44298#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31299#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05300#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56301#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43302#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59303#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48304#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30305#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28306#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18307#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04308#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31309#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44310#include "media/media_buildflags.h"
311#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12312#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42313#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52314#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08315#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53316#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51317#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58318#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23319#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46320#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57321#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48322#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14323#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38324#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19325#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02326#include "services/metrics/public/cpp/ukm_builders.h"
327#include "services/metrics/public/cpp/ukm_recorder.h"
Takashi Toyoshima128441462019-10-16 04:19:17328#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37329#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50330#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50331#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13332#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05333#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34334#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03335#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06336#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02337#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02338#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02339#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19340#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31341#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17342#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21343#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26344#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18345#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54346#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39347#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08348#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35349#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21350#include "ui/base/ui_base_switches.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/caption_style.h"
354#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57355#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45356#include "url/gurl.h"
357#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26358
[email protected]b48c9182011-10-26 18:03:30359#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20360#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14361#include "base/win/win_util.h"
362#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38363#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36364#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18365#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38366#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25367#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38368#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30369#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42370#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30371#include "chrome/app/chrome_crash_reporter_client.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"
Pavol Marko230ea2c92017-12-03 22:35:44388#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34389#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10390#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36391#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27392#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31393#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10394#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21395#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10396#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50397#include "components/crash/core/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07398#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58399#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50400#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26401#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30402#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09403#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35404#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45405#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47406#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20407#include "chrome/browser/android/app_hooks.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36408#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36409#include "chrome/browser/android/devtools_manager_delegate_android.h"
410#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
411#include "chrome/browser/android/service_tab_launcher.h"
412#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42413#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09414#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56415#include "chrome/browser/download/android/available_offline_content_provider.h"
416#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07417#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38418#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11419#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07420#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47421#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36422#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54423#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00424#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36425#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45426#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04427#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45428#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30429#elif defined(OS_POSIX)
430#include "chrome/browser/chrome_browser_main_posix.h"
431#endif
432
tmartinofb341882017-02-10 19:36:53433#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40434#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36435#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54436#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59437#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02438#include "chrome/browser/search/instant_service.h"
439#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46440#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51441#include "chrome/browser/ui/browser.h"
442#include "chrome/browser/ui/browser_finder.h"
443#include "chrome/browser/ui/browser_list.h"
444#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20445#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51446#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39447#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
448#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43449#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27450#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28451#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36452
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33453#if defined(OS_WIN) || defined(OS_MACOSX) || \
454 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52455#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12456#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52457#endif
458
Joshua Perazace68e2f2019-09-23 18:44:24459#if defined(OS_LINUX)
Rohit Rao92f84b6a2020-03-25 14:57:50460#include "components/crash/core/app/crash_switches.h"
461#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24462#endif
463
[email protected]a220b5932013-09-21 03:47:44464#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02465#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02466#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50467#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02468#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13469#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43470#endif
[email protected]b80f68432011-05-02 17:22:30471
Maggie Caia2f03f52019-04-02 02:13:28472// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
473// single navigation throttle to display the intent picker on all platforms.
474#if !defined(OS_ANDROID)
475#if defined(OS_CHROMEOS)
476#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51477#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28478#else
479#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
480#endif
481#endif
482
[email protected]e8b6ca02013-07-10 18:00:51483#if defined(TOOLKIT_VIEWS)
484#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
485#endif
486
estaded3aa0e82016-02-17 22:55:21487#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
488#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51489#endif
490
Mohsen Izadif1958f22019-01-18 20:29:31491#if defined(USE_OZONE)
492#include "ui/ozone/public/ozone_platform.h"
493#endif
494
[email protected]e8b6ca02013-07-10 18:00:51495#if defined(USE_X11)
496#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
497#endif
498
brettwab78fef2016-10-12 02:56:05499#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10500#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38501#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19502#endif
503
Nico Weberaf3b00b2017-09-11 17:58:17504#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55505#include "components/nacl/browser/nacl_browser.h"
506#include "components/nacl/browser/nacl_host_message_filter.h"
507#include "components/nacl/browser/nacl_process_host.h"
508#include "components/nacl/common/nacl_process_type.h"
509#include "components/nacl/common/nacl_switches.h"
510#endif
511
brettw00899e62016-11-12 02:10:17512#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05513#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20514#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27515#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23516#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32517#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51518#include "chrome/browser/extensions/user_script_listener.h"
519#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28520#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49521#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46522#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39523#include "components/guest_view/browser/guest_view_base.h"
524#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25525#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31526#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35527#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32528#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12529#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57530#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48531#include "extensions/browser/guest_view/web_view/web_view_guest.h"
532#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
533#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31534#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27535#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28536#include "extensions/common/extension.h"
537#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13538#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28539#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33540#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28541#include "extensions/common/permissions/permissions_data.h"
542#include "extensions/common/permissions/socket_permission.h"
543#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34544#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25545
brettw4b461082016-11-19 18:55:16546#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55547#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27548#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39549#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55550#endif
551
bauerb8f9c37742017-03-30 15:04:12552#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
553#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
554#endif
555
yilkal240b4f22019-11-27 19:09:06556#if defined(OS_CHROMEOS)
557#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
558#endif // defined(OS_CHROMEOS)
559
thakis678822e2017-04-20 17:20:34560#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38561#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09562#endif
563
weilifabbf7572017-05-22 19:05:16564#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21565#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16566#endif
Lei Zhanga2fa14c2018-05-15 00:05:21567
Xiaohan Wanga4e41842018-06-26 18:45:10568#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49569#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26570#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10571#include "chrome/browser/media/widevine_hardware_caps_win.h"
572#include "third_party/widevine/cdm/widevine_cdm_common.h"
573#endif
574#endif
575
mmenkedb2637ff2017-03-30 23:59:42576#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
577#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
578#endif
579
Nico Weberbc5b06f2019-07-26 14:00:13580#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35581#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
582#endif
583
Jian Lide7b43792018-06-01 23:22:13584#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54585#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13586#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
587#endif
588
Will Cassella40837ba2019-07-01 21:32:00589#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43590#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
591#endif
592
John Lee0ee748bf2019-12-11 21:35:44593#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
594#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
595#endif
596
Roger Tawa03ffdbd2020-01-16 18:12:54597#if BUILDFLAG(FULL_SAFE_BROWSING)
598#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
599#endif
600
Alexander Cooperc8448702020-03-14 01:39:56601#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23602#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56603#endif
604
[email protected]c7abd422012-09-25 00:20:08605using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39606using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31607using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13608using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59609using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00610using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02611using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11612using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33613using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13614using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05615using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38616using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39617
[email protected]0daaebfe2014-03-15 00:09:05618#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20619using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05620#endif
621
brettw00899e62016-11-12 02:10:17622#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28623using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27624using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28625using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28626using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27627#endif
628
brettw4b461082016-11-19 18:55:16629#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55630using plugins::ChromeContentBrowserClientPluginsPart;
631#endif
632
[email protected]c5dbef02011-05-13 05:06:09633namespace {
634
Will Harris1b9b4152019-08-21 22:33:50635#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30636// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
637// running on Windows 10 1511 and above. See
638// https://blogs.windows.com/blog/tag/code-integrity-guard/.
639const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35640 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50641#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
642 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30643
Colin Blundell9ee731dd2020-01-23 10:42:38644// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
645// parameters.
646void HandleSSLErrorWrapper(
647 content::WebContents* web_contents,
648 int cert_error,
649 const net::SSLInfo& ssl_info,
650 const GURL& request_url,
651 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38652 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
653 Profile* profile =
654 Profile::FromBrowserContext(web_contents->GetBrowserContext());
655
656 // This can happen if GetBrowserContext no longer exists by the time this
657 // gets called (e.g. the SSL error was in a webview that has since been
658 // destroyed); if that's the case we don't need to handle the error (and will
659 // crash if we attempt to).
660 if (!profile)
661 return;
662
Colin Blundell27331f92020-02-05 21:13:01663 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51664
665#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
666 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
667#endif
668
Colin Blundell9ee731dd2020-01-23 10:42:38669 SSLErrorHandler::HandleSSLError(
670 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53671 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51672 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38673 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38674 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
675}
676
lazyboy5d5fede02016-03-10 04:10:14677enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53678 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14679 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53680
681 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14682 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53683
684 // An extension or app tried to load a resource of a different platform app in
685 // a tab.
686 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
687
688 // A non-app and non-extension page tried to load a platform app in a tab.
689 APP_LOADED_IN_TAB_SOURCE_OTHER,
690
lazyboy5d5fede02016-03-10 04:10:14691 APP_LOADED_IN_TAB_SOURCE_MAX
692};
693
Lei Zhang2cfceac2018-11-14 19:36:33694// Cached version of the locale so we can return the locale on the I/O
695// thread.
696std::string& GetIOThreadApplicationLocale() {
697 static base::NoDestructor<std::string> s;
698 return *s;
699}
700
[email protected]f8f93eb2012-09-25 03:06:24701// Returns a copy of the given url with its host set to given host and path set
702// to given path. Other parts of the url will be the same.
703GURL ReplaceURLHostAndPath(const GURL& url,
704 const std::string& host,
705 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05706 url::Replacements<char> replacements;
707 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
708 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24709 return url.ReplaceComponents(replacements);
710}
711
madfbd10852017-01-20 03:15:33712// Handles the rewriting of the new tab page URL based on group policy.
713bool HandleNewTabPageLocationOverride(
714 GURL* url,
715 content::BrowserContext* browser_context) {
716 if (!url->SchemeIs(content::kChromeUIScheme) ||
717 url->host() != chrome::kChromeUINewTabHost)
718 return false;
719
720 Profile* profile = Profile::FromBrowserContext(browser_context);
721 std::string ntp_location =
722 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
723 if (ntp_location.empty())
724 return false;
725
726 *url = GURL(ntp_location);
727 return true;
728}
729
Becca Hughesfe8c32c2018-03-21 13:36:56730#if !defined(OS_ANDROID)
731// Check if the current url is whitelisted based on a list of whitelisted urls.
732bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57733 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56734 // Only check on HTTP and HTTPS pages.
735 if (!current_url.SchemeIsHTTPOrHTTPS())
736 return false;
737
738 for (auto const& value : whitelisted_urls) {
739 ContentSettingsPattern pattern =
740 ContentSettingsPattern::FromString(value.GetString());
741 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
742 continue;
743 if (pattern.Matches(current_url))
744 return true;
745 }
746
747 return false;
748}
749
750// Check if autoplay is allowed by policy configuration.
751bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
752 PrefService* prefs) {
753 DCHECK(prefs);
754
755 // Check if we have globally allowed autoplay by policy.
756 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
757 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
758 return true;
759 }
760
761 if (!contents)
762 return false;
763
764 // Check if the current URL matches a URL pattern on the whitelist.
765 const base::ListValue* autoplay_whitelist =
766 prefs->GetList(prefs::kAutoplayWhitelist);
767 return autoplay_whitelist &&
768 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
769 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
770}
771#endif
772
Joshua Perazaf890e4b2019-01-03 19:19:02773#if defined(OS_ANDROID)
774int GetCrashSignalFD(const base::CommandLine& command_line) {
775 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
776}
777#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03778breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
779 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02780 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52781 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02782 {
783 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31784 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03785 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50786 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02787 crash_handler->StartUploaderThread();
788 return crash_handler;
789 }
790}
791
avi3ef9ec9e2014-12-22 22:50:17792int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24793 if (crash_reporter::IsCrashpadEnabled()) {
794 int fd;
795 pid_t pid;
796 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
797 }
798
[email protected]9de4da52014-05-24 12:26:50799 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39800 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31801 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02802 if (!crash_handler)
803 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18804 return crash_handler->GetDeathSignalSocket();
805 }
806
807 std::string process_type =
808 command_line.GetSwitchValueASCII(switches::kProcessType);
809
[email protected]779dd282013-10-19 15:57:02810 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31811 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02812 if (!crash_handler)
813 crash_handler = CreateCrashHandlerHost(process_type);
814 return crash_handler->GetDeathSignalSocket();
815 }
[email protected]a1733df2012-06-22 11:24:18816
[email protected]779dd282013-10-19 15:57:02817 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31818 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02819 if (!crash_handler)
820 crash_handler = CreateCrashHandlerHost(process_type);
821 return crash_handler->GetDeathSignalSocket();
822 }
[email protected]a1733df2012-06-22 11:24:18823
[email protected]779dd282013-10-19 15:57:02824 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31825 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02826 if (!crash_handler)
827 crash_handler = CreateCrashHandlerHost(process_type);
828 return crash_handler->GetDeathSignalSocket();
829 }
[email protected]a1733df2012-06-22 11:24:18830
James Cook9207cc12017-10-19 17:08:39831 if (process_type == switches::kUtilityProcess) {
832 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
833 if (!crash_handler)
834 crash_handler = CreateCrashHandlerHost(process_type);
835 return crash_handler->GetDeathSignalSocket();
836 }
837
[email protected]a1733df2012-06-22 11:24:18838 return -1;
839}
Joshua Perazaf890e4b2019-01-03 19:19:02840#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18841
[email protected]eabbfb12013-04-05 23:28:35842void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52843 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33844 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35845}
846
estark3ba11132015-04-10 01:38:33847// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31848// SSLErrorHandler. Uses CertificateReportingService to send reports. The
849// service handles queueing and re-sending of failed reports. Each certificate
850// error creates a new instance of this class.
851class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33852 public:
meacerf43117a2016-12-27 21:02:31853 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12854 content::WebContents* web_contents)
855 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
856 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31857 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33858
859 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55860 void ReportInvalidCertificateChain(
861 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31862 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33863 }
864
865 private:
meacerf43117a2016-12-27 21:02:31866 CertificateReportingService* service_;
867
868 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33869};
870
brettw00899e62016-11-12 02:10:17871#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53872
873AppLoadedInTabSource ClassifyAppLoadedInTabSource(
874 const GURL& opener_url,
875 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58876 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
877 // The forbidden app URL was being opened by a non-extension page (e.g.
878 // http).
879 return APP_LOADED_IN_TAB_SOURCE_OTHER;
880 }
881
882 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53883 // The forbidden app URL was being opened by a different app or extension.
884 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
885 }
Lei Zhang7d0b0f42019-10-12 03:47:58886
887 // This platform app was trying to window.open() one of its own URLs.
888 if (opener_url ==
889 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
890 // Source was the background page.
891 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
892 }
893
894 // Source was a different page inside the app.
895 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53896}
[email protected]9c7656382014-08-08 21:02:30897
Charles Harrison34f67862017-08-22 01:04:17898// Returns true if there is is an extension matching |url| in
899// |opener_render_process_id| with APIPermission::kBackground.
900//
901// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
902// hosted app, even though normal extensions just use the host.
903bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35904 extensions::ProcessMap* process_map,
905 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17906 const GURL& url,
csharrison95f01e922017-04-24 18:52:35907 int opener_render_process_id) {
908 // Note: includes web URLs that are part of an extension's web extent.
909 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17910 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35911 return extension &&
912 extension->permissions_data()->HasAPIPermission(
913 APIPermission::kBackground) &&
914 process_map->Contains(extension->id(), opener_render_process_id);
915}
Kevin Marshall32f99d7e2017-07-11 23:17:46916
csharrison95f01e922017-04-24 18:52:35917#endif
918
Darin Fishere41aab52020-01-29 18:31:23919mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12920 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23921 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
922 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
923 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
924 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12925}
926
Julian Pastarmovb4773b82020-04-21 16:34:14927// Encapculates logic to determine if enterprise policies should be honored.
928// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
929// as a new central class to replace those checks is in the making.
930bool ShouldHonorPolicies() {
931#if defined(OS_WIN)
932 bool is_enterprise_version =
933 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
934 return base::win::IsEnrolledToDomain() ||
935 (base::win::IsDeviceRegisteredWithManagement() &&
936 is_enterprise_version);
937#else // defined(OS_WIN)
938 // TODO(pastarmovj): Replace this with check for MacOS and the new management
939 // service once it is ready.
940 return true;
941#endif // defined(OS_WIN)
942}
943
John Abd-El-Malek92bf3602019-07-31 02:25:48944void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04945 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48946 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45947 bool has_user_gesture,
948 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01949 // If there is no longer a WebContents, the request may have raced with tab
950 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04951 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01952 if (!web_contents)
953 return;
954
955 // Do not launch external requests attached to unswapped prerenders.
956 prerender::PrerenderContents* prerender_contents =
957 prerender::PrerenderContents::FromWebContents(web_contents);
958 if (prerender_contents) {
959 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:01960 return;
961 }
962
Robbie McElrath1294d242019-05-31 20:46:22963 // Do not launch external requests for schemes that have a handler registered.
964 ProtocolHandlerRegistry* protocol_handler_registry =
965 ProtocolHandlerRegistryFactory::GetForBrowserContext(
966 web_contents->GetBrowserContext());
967 if (protocol_handler_registry &&
968 protocol_handler_registry->IsHandledProtocol(url.scheme()))
969 return;
970
John Abd-El-Maleka67add82018-03-09 18:22:01971 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01972 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19973 PolicyBlacklistFactory::GetForBrowserContext(
974 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:14975 if (ShouldHonorPolicies() && service) {
John Abd-El-Maleka67add82018-03-09 18:22:01976 const policy::URLBlacklist::URLBlacklistState url_state =
977 service->GetURLBlacklistState(url);
978 is_whitelisted =
979 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
980 }
981
982 // If the URL is in whitelist, we launch it without asking the user and
983 // without any additional security checks. Since the URL is whitelisted,
984 // we assume it can be executed.
985 if (is_whitelisted) {
986 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
987 } else {
988 ExternalProtocolHandler::LaunchUrl(
989 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
990 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45991 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:01992 }
993}
994
Yutaka Hirano968d6252018-12-04 05:09:31995std::string GetProduct() {
996 return version_info::GetProductNameAndVersionForUserAgent();
997}
998
Lukasz Anforowicz60d1253d2019-05-08 16:31:37999void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1000 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1001 // For renderer and utility (e.g. NetworkService) processes the switch is the
1002 // only available source, so below the combined (pref/policy + cmdline)
1003 // allowlist of secure origins is injected into |cmdline| for these other
1004 // processes.
1005 std::vector<std::string> allowlist =
1006 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1007 if (!allowlist.empty()) {
1008 cmdline->AppendSwitchASCII(
1009 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1010 base::JoinString(allowlist, ","));
1011 }
1012}
1013
Will Harris1b9b4152019-08-21 22:33:501014#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301015// Returns the full path to |module_name|. Both dev builds (where |module_name|
1016// is in the current executable's directory) and proper installs (where
1017// |module_name| is in a versioned sub-directory of the current executable's
1018// directory) are supported. The identified file is not guaranteed to exist.
1019base::FilePath GetModulePath(base::StringPiece16 module_name) {
1020 base::FilePath exe_dir;
1021 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1022 DCHECK(has_path);
1023
1024 // Look for the module in a versioned sub-directory of the current
1025 // executable's directory and return the path if it can be read. This is the
1026 // expected location of modules for proper installs.
1027 const base::FilePath module_path =
1028 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1029 if (base::PathExists(module_path))
1030 return module_path;
1031
1032 // Otherwise, return the path to the module in the current executable's
1033 // directory. This is the expected location of modules for dev builds.
1034 return exe_dir.Append(module_name);
1035}
Will Harris1b9b4152019-08-21 22:33:501036#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1037 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301038
Lukasz Anforowicz7724d092019-10-03 23:50:211039void MaybeAddThrottle(
1040 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles,
1041 std::unique_ptr<content::NavigationThrottle> maybe_throttle) {
1042 if (maybe_throttle)
1043 throttles->push_back(std::move(maybe_throttle));
1044}
1045
Evan Stade1e71d6dd2019-10-29 03:04:491046// Returns whether |web_contents| is within a hosted app.
1047bool IsInHostedApp(WebContents* web_contents) {
1048#if BUILDFLAG(ENABLE_EXTENSIONS)
1049 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1050 return (browser &&
1051 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1052#else
1053 return false;
1054#endif
1055}
1056
Lily Chenc2c9e9f2019-12-05 19:55:311057void MaybeRecordSameSiteCookieEngagementHistogram(
1058 content::RenderFrameHost* render_frame_host,
1059 blink::mojom::WebFeature feature) {
1060 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1061 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1062 return;
1063 }
1064
1065 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1066 DCHECK(render_frame_host);
1067
1068 content::BrowserContext* browser_context =
1069 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1070 Profile* profile = Profile::FromBrowserContext(browser_context);
1071 SiteEngagementService* site_engagement_service =
1072 SiteEngagementService::Get(profile);
1073 if (!site_engagement_service)
1074 return;
1075
1076 blink::mojom::EngagementLevel engagement_level =
1077 site_engagement_service->GetEngagementLevel(
1078 render_frame_host->GetLastCommittedURL());
1079 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1080 UMA_HISTOGRAM_ENUMERATION(
1081 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1082 engagement_level);
1083 } else {
1084 UMA_HISTOGRAM_ENUMERATION(
1085 "Net.SameSiteBlockedCookieSiteEngagement."
1086 "CookieInsecureAndSameSiteNone",
1087 engagement_level);
1088 }
1089}
1090
[email protected]9dbfff12011-07-01 19:37:071091} // namespace
[email protected]c5dbef02011-05-13 05:06:091092
Yutaka Hirano968d6252018-12-04 05:09:311093std::string GetUserAgent() {
1094 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1095 if (command_line->HasSwitch(switches::kUserAgent)) {
1096 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1097 if (net::HttpUtil::IsValidHeaderValue(ua))
1098 return ua;
1099 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1100 }
1101
John Delaneyac24e572019-04-30 19:47:021102 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1103 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351104 command_line->HasSwitch(switches::kUseMobileUserAgent),
1105 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021106 }
1107
Yutaka Hirano968d6252018-12-04 05:09:311108 std::string product = GetProduct();
1109#if defined(OS_ANDROID)
1110 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1111 product += " Mobile";
1112#endif
1113 return content::BuildUserAgentFromProduct(product);
1114}
1115
Mike West6e4cbb32019-02-13 09:40:171116blink::UserAgentMetadata GetUserAgentMetadata() {
1117 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171118 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301119 metadata.full_version = version_info::GetVersionNumber();
1120 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171121 metadata.platform = version_info::GetOSType();
Yoav Weiss1aeefa82020-03-06 12:02:171122 metadata.platform_version = content::GetOSVersion(false);
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361123 metadata.architecture = content::BuildCpuInfo();
1124 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171125
Aaron Tagliaboschibe775e12019-12-09 19:33:041126 metadata.mobile = false;
1127#if defined(OS_ANDROID)
1128 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1129 switches::kUseMobileUserAgent);
1130#endif
1131
Mike West6e4cbb32019-02-13 09:40:171132 return metadata;
1133}
1134
Ran Jia96d43d42018-05-02 17:14:531135ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051136 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311137 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161138#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551139 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401140#endif
[email protected]1deace22013-05-22 06:14:461141
Ahmed Fakhryd70bf37b2018-04-04 17:07:241142#if defined(OS_CHROMEOS)
1143 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1144#endif // defined(OS_CHROMEOS)
1145
John Lee0ee748bf2019-12-11 21:35:441146#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1147 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1148#endif
1149
brettw00899e62016-11-12 02:10:171150#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131151 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271152#endif
bena06f7d62017-04-04 20:48:521153
Sigurdur Asgeirsson70696672019-02-08 16:14:511154 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401155}
1156
1157ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031158 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1159 delete extra_parts_[i];
1160 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401161}
1162
[email protected]bca18382012-06-25 19:15:231163// static
Chris Palmerac7d75642017-11-22 20:12:541164void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1165 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131166 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1167 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541168 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1169 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461170 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541171}
1172
1173// static
[email protected]37ca3fe02013-07-05 15:32:441174void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341175 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251176 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1177 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1178 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281179 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1180 // user policy in addition to the same named ones in Local State (which are
1181 // used for mapping the command-line flags).
1182 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1183 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571184 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401185 registry->RegisterDictionaryPref(
1186 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041187 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101188#if !defined(OS_ANDROID)
1189 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561190 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101191#endif
Takashi Toyoshima128441462019-10-16 04:19:171192 registry->RegisterListPref(prefs::kCorsMitigationList);
1193 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231194}
1195
[email protected]eabbfb12013-04-05 23:28:351196// static
1197void ChromeContentBrowserClient::SetApplicationLocale(
1198 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481199 // The common case is that this function is called early in Chrome startup
1200 // before any threads are created or registered. When there are no threads,
1201 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001202 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331203 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481204 return;
1205 }
1206
1207 // Otherwise we're being called to change the locale. In this case set it on
1208 // the IO thread.
thestig00844cea2015-09-08 21:44:521209 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351210
Sami Kyostila5e1306d2019-08-14 11:01:291211 base::PostTask(FROM_HERE, {BrowserThread::IO},
1212 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351213}
1214
Patrick Monette61dfef92019-05-30 23:06:271215std::unique_ptr<content::BrowserMainParts>
1216ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311217 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271218 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301219 // Construct the Main browser parts based on the OS type.
1220#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051221 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271222 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1223#elif defined(OS_MACOSX)
1224 main_parts =
1225 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1226#elif defined(OS_CHROMEOS)
1227 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1228 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261229#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271230 main_parts =
1231 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141232#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271233 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1234 startup_data_);
[email protected]b48c9182011-10-26 18:03:301235#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271236 main_parts =
1237 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041238#else
[email protected]b48c9182011-10-26 18:03:301239 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271240 main_parts =
1241 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301242#endif
1243
Xi Han9fd44002019-04-30 17:39:361244 bool add_profiles_extra_parts = true;
1245#if defined(OS_ANDROID)
1246 if (startup_data_->HasBuiltProfilePrefService())
1247 add_profiles_extra_parts = false;
1248#endif
1249 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271250 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031251
Xi Han9fd44002019-04-30 17:39:361252 // Construct additional browser parts. Stages are called in the order in
1253 // which they are added.
[email protected]c7480942011-11-08 19:18:271254#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221255#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
estaded3aa0e82016-02-17 22:55:211256 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
1257#else
riajiang7d6ec5c2017-01-25 16:40:331258 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351259#endif
1260#endif
1261
1262#if defined(OS_CHROMEOS)
1263 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331264 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221265#endif
[email protected]dc04be7c2012-03-15 23:57:491266
[email protected]e8b6ca02013-07-10 18:00:511267#if defined(USE_X11)
1268 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241269#endif
1270
Sigurdur Asgeirsson54b72702019-04-12 14:18:541271 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001272
Albert J. Wong59d85acb2017-08-10 00:50:571273 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571274
Sebastien Marchand8c0088102019-10-11 16:47:561275 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1276
Patrick Monette61dfef92019-05-30 23:06:271277 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041278
Zhenyao Mo73144652020-04-06 18:55:051279 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1280 // GpuDataManager initialization could pick up about:flags settings.
1281 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1282
[email protected]50462bf02011-11-21 19:13:311283 return main_parts;
[email protected]f967b722011-09-07 00:58:041284}
1285
michaeln96f887e22015-04-13 23:58:311286void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091287 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021288 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211289 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121290 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291291
Robert Sesek466e43e2019-08-19 22:02:021292 InitNetworkContextsParentDirectory();
1293
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291294 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1295 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311296}
1297
falkenb09d443f2016-04-07 12:36:121298bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1299 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1300}
1301
Gabriel Charettec8cca992017-08-10 18:21:491302void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1303 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1304}
1305
John Abd-El-Malek9d57f9c2019-02-20 18:50:041306bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361307 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041308}
1309
[email protected]e94bbcb2012-09-07 05:33:571310std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191311 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571312 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531313 std::string partition_id;
1314
1315 // The partition ID for webview guest processes is the string value of its
1316 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451317 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531318 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171319#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501320 // The partition ID for extensions with isolated storage is treated similarly
1321 // to the above.
1322 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1323 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1324 partition_id = site.spec();
1325#endif
[email protected]1bc28312012-11-08 08:31:531326
[email protected]056efdc2013-04-06 00:14:531327 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531328 return partition_id;
1329}
1330
1331bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1332 content::BrowserContext* browser_context,
1333 const std::string& partition_id) {
1334 // The default ID is empty and is always valid.
1335 if (partition_id.empty())
1336 return true;
1337
1338 return GURL(partition_id).is_valid();
1339}
1340
1341void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1342 content::BrowserContext* browser_context,
1343 const GURL& site,
[email protected]14acc642012-11-17 12:20:101344 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531345 std::string* partition_domain,
1346 std::string* partition_name,
1347 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101348 // Default to the browser-wide storage partition and override based on |site|
1349 // below.
1350 partition_domain->clear();
1351 partition_name->clear();
1352 *in_memory = false;
1353
brettw00899e62016-11-12 02:10:171354#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451355 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331356 site, partition_domain, partition_name, in_memory);
1357
1358 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101359 // If |can_be_default| is false, the caller is stating that the |site|
1360 // should be parsed as if it had isolated storage. In particular it is
1361 // important to NOT check ExtensionService for the is_storage_isolated()
1362 // attribute because this code path is run during Extension uninstall
1363 // to do cleanup after the Extension has already been unloaded from the
1364 // ExtensionService.
1365 bool is_isolated = !can_be_default;
1366 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341367 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1368 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101369 }
[email protected]1bc28312012-11-08 08:31:531370
[email protected]14acc642012-11-17 12:20:101371 if (is_isolated) {
1372 CHECK(site.has_host());
1373 // For extensions with isolated storage, the the host of the |site| is
1374 // the |partition_domain|. The |in_memory| and |partition_name| are only
1375 // used in guest schemes so they are cleared here.
1376 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531377 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101378 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531379 }
[email protected]1df3d972014-06-11 04:55:181380 success = true;
1381 }
1382#endif
1383
[email protected]14acc642012-11-17 12:20:101384 // Assert that if |can_be_default| is false, the code above must have found a
1385 // non-default partition. If this fails, the caller has a serious logic
1386 // error about which StoragePartition they expect to be in and it is not
1387 // safe to continue.
1388 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441389}
1390
[email protected]38b098f2012-03-14 21:11:571391content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441392ChromeContentBrowserClient::GetWebContentsViewDelegate(
1393 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101394 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321395}
1396
Bo Liu4ade6b1b22017-11-28 02:26:351397bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1398#if defined(OS_ANDROID)
1399 const base::android::ApplicationState app_state =
1400 base::android::ApplicationStatusListener::GetState();
1401 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1402 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1403 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1404#else
1405 return true;
1406#endif
1407}
1408
[email protected]6f2862742013-12-20 07:53:191409void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231410 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301411 int id = host->GetID();
1412 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341413#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491414 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061415#endif
Brett Wilson65f951c2016-11-03 22:06:121416#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401417 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031418#endif
Darin Fisher54cba872020-02-06 21:12:551419 host->AddFilter(new prerender::PrerenderMessageFilter(id));
Darin Fisher8c84328c2019-07-23 02:50:001420
Darin Fisher09aa7222019-08-29 09:27:361421 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001422 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021423
grunell086a4112017-03-02 09:23:041424 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1425 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021426 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121427 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021428 host->SetUserData(
1429 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091430 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021431 audio_debug_recordings_handler));
1432
Nico Weberaf3b00b2017-09-11 17:58:171433#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031434 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1435 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351436#endif
jeremyim364ac1182015-03-03 18:49:431437
Xiaohan Wang9b34281b2017-09-08 23:48:331438#if defined(OS_ANDROID)
1439 // Data cannot be persisted if the profile is off the record.
1440 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061441 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071442
1443 // Register CrashMemoryMetricsCollector to report oom related metrics.
1444 host->SetUserData(
1445 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1446 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331447#endif
1448
Jun Caidb3f93cc2018-07-09 21:54:551449 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061450 RendererUpdaterFactory::GetForProfile(original_profile)
1451 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071452
[email protected]a48ab7112014-08-01 16:48:031453 for (size_t i = 0; i < extra_parts_.size(); ++i)
1454 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141455}
1456
[email protected]3d7474ff2011-07-27 17:47:371457GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571458 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301459 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371460 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521461 if (!profile)
1462 return url;
1463
Marc Treib7d467b792017-12-04 13:31:031464#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291465 // If the input |url| should be assigned to the Instant renderer, make its
1466 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311467 // This needs to happen even if |url| corresponds to an isolated origin; see
1468 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131469 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1470 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031471#endif
[email protected]b3cb3a32013-07-31 01:32:291472
brettw00899e62016-11-12 02:10:171473#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301474 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1475 url);
[email protected]d5a74be2014-08-08 01:01:271476#else
1477 return url;
1478#endif
[email protected]36fb2c7c2011-04-04 15:49:081479}
1480
Alexander Yashkin6aedc6e2018-08-15 08:58:451481bool ChromeContentBrowserClient::
1482 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1483 content::BrowserContext* browser_context,
1484 content::SiteInstance* candidate_site_instance,
1485 bool is_main_frame,
1486 const GURL& candidate_url,
1487 const GURL& destination_url) {
1488 DCHECK(browser_context);
1489 DCHECK(candidate_site_instance);
1490#if BUILDFLAG(ENABLE_EXTENSIONS)
1491 return ChromeContentBrowserClientExtensionsPart::
1492 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1493 browser_context, candidate_site_instance, is_main_frame,
1494 candidate_url, destination_url);
1495#else
1496 return true;
1497#endif
1498}
1499
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521500bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411501#if defined(OS_ANDROID)
1502 return true;
1503#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421504 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411505#else
1506 return false;
1507#endif // defined(OS_ANDROID)
1508}
1509
[email protected]056ad2a2011-07-12 02:13:551510bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441511 content::BrowserContext* browser_context,
1512 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521513 Profile* profile = Profile::FromBrowserContext(browser_context);
1514 if (!profile)
1515 return false;
1516
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301517 // NTP should use process-per-site. This is a performance optimization to
1518 // reduce process count associated with NTP tabs.
1519 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1520 return true;
Peter Boström8e9b1632019-08-22 23:12:471521
1522 // The web footer experiment should share its renderer to not effectively
1523 // instantiate one per window. See https://crbug.com/993502.
1524 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1525 return true;
1526
Marc Treib7d467b792017-12-04 13:31:031527#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131528 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521529 return true;
Marc Treib7d467b792017-12-04 13:31:031530#endif
[email protected]c5dec6292013-01-25 04:54:521531
brettw00899e62016-11-12 02:10:171532#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301533 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1534 profile, effective_url))
1535 return true;
[email protected]d5a74be2014-08-08 01:01:271536#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301537
1538 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1539 // (rather than process-per-site).
1540 return false;
[email protected]056ad2a2011-07-12 02:13:551541}
1542
Lukasz Anforowicz32d27122018-04-09 21:48:331543bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1544 content::BrowserContext* browser_context,
1545 const GURL& site_url) {
1546 Profile* profile = Profile::FromBrowserContext(browser_context);
1547 if (!profile)
1548 return false;
1549
1550#if !defined(OS_ANDROID)
1551 // Instant renderers should not use a spare process, because they require
1552 // passing switches::kInstantProcess to the renderer process when it
1553 // launches. A spare process is launched earlier, before it is known which
1554 // navigation will use it, so it lacks this flag.
1555 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1556 return false;
1557#endif
1558
1559#if BUILDFLAG(ENABLE_EXTENSIONS)
1560 return ChromeContentBrowserClientExtensionsPart::
1561 ShouldUseSpareRenderProcessHost(profile, site_url);
1562#else
1563 return true;
1564#endif
1565}
1566
nickcc0d9142015-10-14 16:27:101567bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421568 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101569 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421570 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171571#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101572 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421573 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101574 return true;
1575 }
1576#endif
1577 return false;
1578}
1579
nick7d0984c2015-08-29 00:13:461580// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1581// origin-lock enforcement, where we don't have a way to efficiently know
1582// effective URLs on the IO thread, and wind up killing processes that e.g.
1583// request cookies for their actual URL. This whole function (and its
1584// ExtensionsPart) should be removed once we add that ability to the IO thread.
1585bool ChromeContentBrowserClient::ShouldLockToOrigin(
1586 content::BrowserContext* browser_context,
1587 const GURL& effective_site_url) {
1588 // Origin lock to the search scheme would kill processes upon legitimate
1589 // requests for cookies from the search engine's domain.
1590 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1591 return false;
1592
brettw00899e62016-11-12 02:10:171593#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461594 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1595 browser_context, effective_site_url)) {
1596 return false;
1597 }
1598#endif
1599 return true;
creise5d6d1732015-08-25 19:47:061600}
1601
Maks Orlovich0e23e312019-07-16 13:13:561602bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021603 base::StringPiece scheme,
1604 bool is_embedded_origin_secure) {
1605 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1606 return true;
Maks Orlovich0e23e312019-07-16 13:13:561607#if BUILDFLAG(ENABLE_EXTENSIONS)
1608 return scheme == extensions::kExtensionScheme;
1609#else
1610 return false;
1611#endif
1612}
1613
Lily Chen0db055b2019-11-15 20:29:021614bool ChromeContentBrowserClient::
1615 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1616 base::StringPiece scheme,
1617 bool is_embedded_origin_secure) {
1618 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1619}
1620
Lukasz Anforowicz7097890d2019-11-20 21:49:221621void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021622 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591623 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021624 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221625 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071626#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221627 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021628 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071629#endif
1630}
1631
[email protected]73b718f2014-01-27 02:59:461632// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1633// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411634void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1635 std::vector<std::string>* additional_schemes) {
1636 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241637 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351638 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061639}
1640
alexmos94875b3b2017-03-16 22:19:011641void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1642 std::vector<std::string>* additional_schemes) {
1643 GetAdditionalWebUISchemes(additional_schemes);
1644
1645#if BUILDFLAG(ENABLE_EXTENSIONS)
1646 additional_schemes->push_back(extensions::kExtensionScheme);
1647#endif
1648}
1649
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521650bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011651 return webui::LogWebUIUrl(web_ui_url);
1652}
1653
John Abd-El-Malek04bfa8532018-07-12 05:28:221654bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1655 const url::Origin& origin) {
1656 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1657 origin);
1658}
1659
[email protected]46fb9442011-12-09 17:57:471660bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1661 return ProfileIOData::IsHandledURL(url);
1662}
1663
[email protected]c4365fa42013-05-14 01:08:241664bool ChromeContentBrowserClient::CanCommitURL(
1665 content::RenderProcessHost* process_host,
1666 const GURL& url) {
brettw00899e62016-11-12 02:10:171667#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441668 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1669 url);
[email protected]d5a74be2014-08-08 01:01:271670#else
1671 return true;
1672#endif
[email protected]c4365fa42013-05-14 01:08:241673}
1674
rdevlin.cronina32a0902016-11-09 15:50:201675void ChromeContentBrowserClient::OverrideNavigationParams(
1676 SiteInstance* site_instance,
1677 ui::PageTransition* transition,
1678 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581679 content::Referrer* referrer,
1680 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201681 DCHECK(transition);
1682 DCHECK(is_renderer_initiated);
1683 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471684 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1685 // use for making security decisions 99.44% of the time, for detecting the NTP
1686 // it is reliable and the correct way. See http://crbug.com/624410.
1687 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201688 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581689 // Clicks on tiles of the new tab page should be treated as if a user
1690 // clicked on a bookmark. This is consistent with native implementations
1691 // like Android's. This also helps ensure that security features (like
1692 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1693 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201694 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1695 *is_renderer_initiated = false;
1696 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581697 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421698 }
1699}
1700
Charles Reis29e9dd12017-09-28 00:59:151701bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1702 const GURL& url,
1703 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471704 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1705 // use for making security decisions 99.44% of the time, for detecting the NTP
1706 // it is reliable and the correct way. See http://crbug.com/624410.
1707 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1708 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151709}
1710
[email protected]2a5221b2011-09-27 23:07:311711bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301712 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311713 const GURL& site_url) {
1714 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301715 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441716 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521717 // share any host.
1718 if (!profile)
1719 return true;
1720
Marc Treib7895941d2017-11-28 12:37:021721#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141722 // Instant URLs should only be in the instant process and instant process
1723 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521724 InstantService* instant_service =
1725 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141726 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441727 bool is_instant_process =
1728 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141729 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131730 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141731 if (is_instant_process || should_be_in_instant_process)
1732 return is_instant_process && should_be_in_instant_process;
1733 }
Marc Treib7895941d2017-11-28 12:37:021734#endif
[email protected]c5dec6292013-01-25 04:54:521735
brettw00899e62016-11-12 02:10:171736#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131737 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1738 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271739#else
1740 return true;
1741#endif
[email protected]2a5221b2011-09-27 23:07:311742}
1743
[email protected]28c5d0b72014-05-13 08:19:591744bool ChromeContentBrowserClient::MayReuseHost(
1745 content::RenderProcessHost* process_host) {
1746 // If there is currently a prerender in progress for the host provided,
1747 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041748 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591749 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371750 prerender::PrerenderManagerFactory::GetForBrowserContext(
1751 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591752 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491753 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591754 return false;
1755 }
1756
1757 return true;
1758}
1759
[email protected]76411f412012-02-22 18:56:061760bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441761 content::BrowserContext* browser_context,
1762 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061763 // It has to be a valid URL for us to check for an extension.
1764 if (!url.is_valid())
1765 return false;
1766
brettw00899e62016-11-12 02:10:171767#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061768 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131769 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441770 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271771#else
1772 return false;
1773#endif
[email protected]76411f412012-02-22 18:56:061774}
1775
Alex Moshchuk9c9e3882018-11-02 19:57:031776bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1777 content::RenderFrameHost* main_frame) {
1778#if BUILDFLAG(ENABLE_EXTENSIONS)
1779 return ChromeContentBrowserClientExtensionsPart::
1780 ShouldSubframesTryToReuseExistingProcess(main_frame);
1781#else
1782 return true;
1783#endif
1784}
1785
[email protected]6f371442011-11-09 06:45:461786void ChromeContentBrowserClient::SiteInstanceGotProcess(
1787 SiteInstance* site_instance) {
1788 CHECK(site_instance->HasProcess());
1789
Aran Gilmanf010bdd2019-08-28 19:55:441790 Profile* profile =
1791 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521792 if (!profile)
1793 return;
1794
Marc Treib7895941d2017-11-28 12:37:021795#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521796 // Remember the ID of the Instant process to signal the renderer process
1797 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131798 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1799 profile)) {
[email protected]c5dec6292013-01-25 04:54:521800 InstantService* instant_service =
1801 InstantServiceFactory::GetForProfile(profile);
1802 if (instant_service)
1803 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1804 }
Marc Treib7895941d2017-11-28 12:37:021805#endif
[email protected]c5dec6292013-01-25 04:54:521806
[email protected]a48ab7112014-08-01 16:48:031807 for (size_t i = 0; i < extra_parts_.size(); ++i)
1808 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461809}
1810
1811void ChromeContentBrowserClient::SiteInstanceDeleting(
1812 SiteInstance* site_instance) {
1813 if (!site_instance->HasProcess())
1814 return;
1815
[email protected]a48ab7112014-08-01 16:48:031816 for (size_t i = 0; i < extra_parts_.size(); ++i)
1817 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461818}
1819
[email protected]453f5432013-11-26 19:43:001820bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141821 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561822 const GURL& current_effective_url,
1823 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171824#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131825 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561826 ShouldSwapBrowsingInstancesForNavigation(
1827 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271828#else
1829 return false;
1830#endif
[email protected]e3daf3c2011-10-05 21:17:081831}
1832
Nasko Oskovd83b5712018-05-04 04:50:571833bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1834 // TODO(nasko): Consider supporting error page isolation in subframes if
1835 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381836 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571837}
1838
[email protected]3d831992013-07-04 01:13:291839bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1840 return !url.SchemeIs(chrome::kChromeNativeScheme);
1841}
1842
Alex Moshchukd252c192017-07-17 22:03:481843std::vector<url::Origin>
1844ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1845 std::vector<url::Origin> isolated_origin_list;
1846
Alex Moshchuk89352a72017-10-25 20:25:591847// Sign-in process isolation is not needed on Android, see
1848// https://crbug.com/739418.
1849#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381850 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121851 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591852#endif
Alex Moshchukd252c192017-07-17 22:03:481853
Alex Moshchuk81d2a29e2019-07-16 01:14:381854#if BUILDFLAG(ENABLE_EXTENSIONS)
1855 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1856 GetOriginsRequiringDedicatedProcess();
1857 std::move(std::begin(origins_from_extensions),
1858 std::end(origins_from_extensions),
1859 std::back_inserter(isolated_origin_list));
1860#endif
1861
Alex Moshchuk51e1428b2020-04-22 18:00:541862 // Include additional origins preloaded with specific browser configurations,
1863 // if any. For example, this is used on Google Chrome for Android to preload
1864 // a list of important sites to isolate.
1865 auto built_in_origins =
1866 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
1867 std::move(std::begin(built_in_origins), std::end(built_in_origins),
1868 std::back_inserter(isolated_origin_list));
1869
Alex Moshchukd252c192017-07-17 22:03:481870 return isolated_origin_list;
1871}
1872
Lukasz Anforowicz5e201abd2018-03-24 00:41:061873bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341874 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1875}
1876
1877bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371878 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061879}
1880
Alex Moshchuk082b5f82019-03-14 01:34:161881std::vector<std::string>
1882ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1883 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1884 return {"Isolate Password Sites"};
1885 else
1886 return {};
1887}
1888
Alex Moshchuke256d562019-04-26 21:43:571889void ChromeContentBrowserClient::PersistIsolatedOrigin(
1890 content::BrowserContext* context,
1891 const url::Origin& origin) {
1892 DCHECK(!context->IsOffTheRecord());
1893 Profile* profile = Profile::FromBrowserContext(context);
1894 ListPrefUpdate update(profile->GetPrefs(),
1895 prefs::kUserTriggeredIsolatedOrigins);
1896 base::ListValue* list = update.Get();
1897 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361898 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121899 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571900}
1901
Ken Rockot314714c2017-11-05 23:36:241902bool ChromeContentBrowserClient::IsFileAccessAllowed(
1903 const base::FilePath& path,
1904 const base::FilePath& absolute_path,
1905 const base::FilePath& profile_path) {
1906 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1907 profile_path);
1908}
1909
[email protected]d2e1a0a2014-06-16 15:49:371910namespace {
1911
1912bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171913 const base::CommandLine& browser_command_line =
1914 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351915 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371916 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351917 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371918 return false;
[email protected]9ef49b42014-08-07 16:44:241919 return true;
[email protected]d2e1a0a2014-06-16 15:49:371920}
1921
bmcquade5d2d9cf32015-06-19 17:42:281922void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1923 const base::CommandLine& browser_command_line,
1924 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521925 // List of field trials that modify the blink-settings command line flag. No
1926 // two field trials in the list should specify the same keys, otherwise one
1927 // field trial may overwrite another. See Source/core/frame/Settings.in in
1928 // Blink for the list of valid keys.
1929 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161930 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1931 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1932 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1933 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521934 };
1935
1936 std::vector<std::string> blink_settings;
1937 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1938 // Each blink-settings field trial should include a forcing_flag group,
1939 // to make sure that clients that specify the blink-settings flag on the
1940 // command line are excluded from the experiment groups. To make
1941 // sure we assign clients that specify this flag to the forcing_flag
1942 // group, we must call GetVariationParams for each field trial first
1943 // (for example, before checking HasSwitch() and returning), since
1944 // GetVariationParams has the side-effect of assigning the client to
1945 // a field trial group.
1946 std::map<std::string, std::string> params;
1947 if (variations::GetVariationParams(field_trial_name, &params)) {
1948 for (const auto& param : params) {
1949 blink_settings.push_back(base::StringPrintf(
1950 "%s=%s", param.first.c_str(), param.second.c_str()));
1951 }
1952 }
1953 }
pmeenan9ac669682015-08-17 14:57:031954
bmcquade9dd54cc2015-06-22 16:56:521955 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281956 return;
1957 }
1958
1959 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1960 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031961 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521962 // blink-settings flag into a group with no params, and we return
1963 // above if no params were specified, so it's an error if we reach
1964 // this point.
bmcquade5d2d9cf32015-06-19 17:42:281965 LOG(WARNING) << "Received field trial params, "
1966 "but blink-settings switch already specified.";
1967 return;
1968 }
1969
bmcquade5d2d9cf32015-06-19 17:42:281970 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:261971 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:281972}
1973
[email protected]d2e1a0a2014-06-16 15:49:371974} // namespace
1975
[email protected]b80f68432011-05-02 17:22:301976void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:171977 base::CommandLine* command_line,
1978 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:061979#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:351980 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:061981 GoogleUpdateSettings::LoadMetricsClientInfo();
1982 if (client_info) {
1983 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1984 client_info->client_id);
1985 }
1986#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:021987#if defined(OS_ANDROID)
1988 bool enable_crash_reporter = true;
1989#else
Joshua Perazace68e2f2019-09-23 18:44:241990 bool enable_crash_reporter = false;
1991 if (crash_reporter::IsCrashpadEnabled()) {
1992 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
1993 enable_crash_reporter = true;
1994
1995 int fd;
1996 pid_t pid;
1997 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
1998 command_line->AppendSwitchASCII(
1999 crash_reporter::switches::kCrashpadHandlerPid,
2000 base::NumberToString(pid));
2001 }
2002 } else {
2003 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2004 }
Joshua Perazaf890e4b2019-01-03 19:19:022005#endif
2006 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512007 std::string switch_value;
dcheng4af48582016-04-19 00:29:352008 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532009 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512010 if (client_info)
2011 switch_value = client_info->client_id;
2012 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252013 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302014 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512015 switch_value);
[email protected]b80f68432011-05-02 17:22:302016 }
Mark Mentovaic67fa64f2015-03-24 14:00:062017#endif
[email protected]b80f68432011-05-02 17:22:302018
[email protected]f1933792011-06-14 00:49:342019 if (logging::DialogsAreSuppressed())
2020 command_line->AppendSwitch(switches::kNoErrorDialogs);
2021
[email protected]b80f68432011-05-02 17:22:302022 std::string process_type =
2023 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172024 const base::CommandLine& browser_command_line =
2025 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322026
[email protected]7c9b6f92013-09-10 18:11:352027 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442028 switches::kUserAgent,
2029 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352030 };
2031 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372032 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322033
fqj15ff3f72015-10-09 19:20:022034 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432035 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312036 };
fqj15ff3f72015-10-09 19:20:022037 command_line->CopySwitchesFrom(browser_command_line,
2038 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372039 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312040
David Van Cleve3df6abb2019-11-26 17:52:512041 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2042 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2043
fqj15ff3f72015-10-09 19:20:022044#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332045 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2046 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522047 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332048 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2049 homedir.value().c_str());
2050#endif
2051
[email protected]718eab62011-10-05 21:16:522052 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032053 content::RenderProcessHost* process =
2054 content::RenderProcessHost::FromID(child_process_id);
2055 Profile* profile =
2056 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442057 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032058 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442059 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2060 process, profile);
[email protected]a48ab7112014-08-01 16:48:032061 }
2062
[email protected]b80f68432011-05-02 17:22:302063#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442064 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2065 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302066 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442067 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2068 login_profile);
[email protected]b80f68432011-05-02 17:22:302069#endif
2070
Aran Gilmanf010bdd2019-08-28 19:55:442071 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222072 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372073 if (process) {
[email protected]a8d851f82011-12-21 00:32:372074 PrefService* prefs = profile->GetPrefs();
2075 // Currently this pref is only registered if applied via a policy.
2076 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2077 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2078 // Turn this policy into a command line switch.
2079 command_line->AppendSwitch(switches::kDisable3DAPIs);
2080 }
[email protected]718eab62011-10-05 21:16:522081
[email protected]1733b782014-06-19 18:51:552082 const base::ListValue* switches =
2083 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2084 if (switches) {
2085 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112086 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552087 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142088 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552089 command_line->AppendSwitch(switch_to_enable);
2090 }
2091 }
2092
[email protected]a8d851f82011-12-21 00:32:372093 // Disable client-side phishing detection in the renderer if it is
2094 // disabled in the Profile preferences or the browser process.
Bettinae83f522c72020-03-12 01:52:332095 if (!safe_browsing::IsSafeBrowsingEnabled(*prefs) ||
[email protected]a8d851f82011-12-21 00:32:372096 !g_browser_process->safe_browsing_detection_service()) {
2097 command_line->AppendSwitch(
2098 switches::kDisableClientSidePhishingDetection);
2099 }
[email protected]0045b0f42012-07-26 11:52:082100
vitalybukaa7ae5052014-09-26 04:11:132101 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2102 command_line->AppendSwitch(switches::kDisablePrintPreview);
2103
Marc Treib7895941d2017-11-28 12:37:022104#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522105 InstantService* instant_service =
2106 InstantServiceFactory::GetForProfile(profile);
2107 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542108 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522109 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542110 }
Marc Treib7895941d2017-11-28 12:37:022111#endif
fqjba8749c2015-10-29 15:33:072112
fqj38306f7b2015-11-02 16:59:062113 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542114 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432115 command_line->AppendSwitch(
2116 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542117 }
Daniel Vogelheim976f1c22017-11-22 16:26:032118
Lukasz Anforowicz60d1253d2019-05-08 16:31:372119 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2120
Amr Aboelkherb04cbf32019-04-29 15:17:102121 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2122 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292123 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102124 }
Katie Dillonc25ee5c92019-09-12 17:05:422125
2126 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2127 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2128 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2129 }
Takashi Toyoshima128441462019-10-16 04:19:172130
Mason Freed490f2a22019-11-05 21:41:292131 if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) &&
2132 prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) {
2133 command_line->AppendSwitch(switches::kWebComponentsV0Enabled);
2134 }
Mason Freed52fa36d72020-02-27 17:52:482135 if (prefs->HasPrefPath(prefs::kUseLegacyFormControls) &&
2136 prefs->GetBoolean(prefs::kUseLegacyFormControls)) {
2137 command_line->AppendSwitch(switches::kUseLegacyFormControls);
2138 }
Mason Freed490f2a22019-11-05 21:41:292139
Daniel Libbyc5bfd91f2020-03-07 03:44:102140 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2141 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2142 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2143 }
2144
Takashi Toyoshima0dab73302019-10-18 01:51:362145 if (!profile->ShouldEnableOutOfBlinkCors()) {
2146 command_line->AppendSwitch(
2147 network::switches::kForceToDisableOutOfBlinkCors);
2148 }
[email protected]47c7ec82012-01-18 03:29:212149 }
[email protected]4287a3d2011-06-13 23:56:512150
[email protected]d2e1a0a2014-06-16 15:49:372151 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352152 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042153
Aran Gilmanf010bdd2019-08-28 19:55:442154 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2155 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282156
mdjonesa6b9e172016-09-23 16:24:302157#if defined(OS_ANDROID)
2158 // If the platform is Android, force the distillability service on.
2159 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2160#endif
2161
[email protected]47c7ec82012-01-18 03:29:212162 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512163 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192164 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412165 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302166#if defined(OS_CHROMEOS)
2167 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2168#endif
brettw00899e62016-11-12 02:10:172169#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512170 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272171 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172172 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512173 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272174 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172175 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172176 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282177#endif
estark4b003b332015-02-14 01:07:052178 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512179 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482180 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512181 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502182 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572183 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462184 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302185 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512186 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172187#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242188 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482189 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552190#endif
[email protected]ce304ce2013-02-22 21:54:452191 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342192#if defined(OS_CHROMEOS)
2193 switches::kForceAppMode,
2194#endif
Nico Weberaf3b00b2017-09-11 17:58:172195#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592196 switches::kForcePNaClSubzero,
2197#endif
Marc Treibad33cf942017-08-24 11:19:002198 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512199 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102200 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322201 embedder_support::kOriginTrialDisabledFeatures,
2202 embedder_support::kOriginTrialDisabledTokens,
2203 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512204 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512205 switches::kPpapiFlashPath,
2206 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032207 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092208 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512209 };
2210
2211 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372212 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172213 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172214#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382215 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442216 extensions::switches::kAllowHTTPBackgroundPage,
2217 extensions::switches::kEnableExperimentalExtensionApis,
2218 extensions::switches::kExtensionsOnChromeURLs,
2219 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382220 };
2221
2222 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372223 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282224#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372225 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132226 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512227 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512228 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502229 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172230#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242231 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582232 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592233 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412234 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552235#endif
[email protected]4287a3d2011-06-13 23:56:512236 switches::kPpapiFlashPath,
2237 switches::kPpapiFlashVersion,
2238 };
2239
2240 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372241 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112242 } else if (process_type == switches::kGpuProcess) {
2243 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2244 // because GPU is expected to be unreliable.
2245 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2246 !command_line->HasSwitch(switches::kDisableBreakpad))
2247 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302248 }
[email protected]6f08af82011-09-15 01:19:032249
Ian Barkley-Yeung550aae052019-07-11 00:11:112250#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302251 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112252 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292253 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112254 };
2255 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2256 base::size(kSwitchNames));
2257 }
2258#endif
2259
wittman832321f52016-10-10 18:18:382260 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442261 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342262
2263#if defined(OS_LINUX)
2264 // Processes may only query perf_event_open with the BPF sandbox disabled.
2265 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2266 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2267 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2268 }
2269#endif
[email protected]b80f68432011-05-02 17:22:302270}
2271
Olivier Yiptong0daa93f2019-08-22 19:40:082272std::string
2273ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2274 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2275}
2276
[email protected]b80f68432011-05-02 17:22:302277std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432278 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332279 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302280 return g_browser_process->GetApplicationLocale();
2281}
2282
[email protected]597a867b2011-11-18 18:31:202283std::string ChromeContentBrowserClient::GetAcceptLangs(
2284 content::BrowserContext* context) {
2285 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202286 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082287}
2288
Dana Fried34d580002019-04-24 20:05:482289gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492290 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482291 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082292}
2293
bengre8a146f2016-03-10 01:20:222294bool ChromeContentBrowserClient::IsDataSaverEnabled(
2295 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382296 if (!browser_context || browser_context->IsOffTheRecord())
2297 return false;
2298
Robert Ogdenc995d4fe2019-03-25 19:18:372299 Profile* profile = Profile::FromBrowserContext(browser_context);
2300 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412301 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2302 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222303}
2304
Kenichi Ishibashi46329872018-07-17 09:43:402305void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2306 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192307 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402308 DCHECK(browser_context);
2309 DCHECK(out_prefs);
2310 renderer_preferences_util::UpdateFromSystemSettings(
2311 out_prefs, Profile::FromBrowserContext(browser_context));
2312}
2313
Clark DuVall5690e742019-07-17 18:26:172314bool ChromeContentBrowserClient::AllowAppCache(
2315 const GURL& manifest_url,
2316 const GURL& first_party,
2317 content::BrowserContext* context) {
2318 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2319 return CookieSettingsFactory::GetForProfile(
2320 Profile::FromBrowserContext(context))
2321 ->IsCookieAccessAllowed(manifest_url, first_party);
2322}
2323
Alexander Timin17edc742020-04-23 18:22:182324content::AllowServiceWorkerResult
2325ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072326 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542327 const GURL& site_for_cookies,
2328 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362329 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182330 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522331 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542332 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452333
brettw00899e62016-11-12 02:10:172334#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452335 // Check if this is an extension-related service worker, and, if so, if it's
2336 // allowed (this can return false if, e.g., the extension is disabled).
2337 // If it's not allowed, return immediately. We deliberately do *not* report
2338 // to the TabSpecificContentSettings, since the service worker is blocked
2339 // because of the extension, rather than because of the user's content
2340 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022341 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362342 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182343 return content::AllowServiceWorkerResult::No();
rdevlin.croninf5863da2015-09-10 19:21:452344 }
2345#endif
2346
falken3dbc36e2014-10-10 16:48:072347 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202348
shimazuce8af88122016-10-06 23:49:212349 // Check if JavaScript is allowed.
2350 content_settings::SettingInfo info;
2351 std::unique_ptr<base::Value> value =
2352 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452353 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212354 std::string(), &info);
2355 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2356 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2357
2358 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542359 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2360 scope, site_for_cookies, top_frame_origin);
Alexander Timin17edc742020-04-23 18:22:182361
2362 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2363 !allow_cookies);
falken3dbc36e2014-10-10 16:48:072364}
2365
Alexander Timin17edc742020-04-23 18:22:182366content::AllowServiceWorkerResult
2367ChromeContentBrowserClient::AllowServiceWorkerOnUI(
Matt Falkenhagen7b509e52019-08-15 23:11:412368 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542369 const GURL& site_for_cookies,
2370 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412371 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182372 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412373 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542374 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412375
2376#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022377 // Check if this is an extension-related service worker, and, if so, if it's
2378 // allowed (this can return false if, e.g., the extension is disabled).
2379 // If it's not allowed, return immediately. We deliberately do *not* report
2380 // to the TabSpecificContentSettings, since the service worker is blocked
2381 // because of the extension, rather than because of the user's content
2382 // settings.
2383 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2384 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182385 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022386 }
Matt Falkenhagen7b509e52019-08-15 23:11:412387#endif
2388
2389 Profile* profile = Profile::FromBrowserContext(context);
2390
2391 // Check if JavaScript is allowed.
2392 content_settings::SettingInfo info;
2393 std::unique_ptr<base::Value> value =
2394 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452395 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412396 std::string(), &info);
2397 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2398 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2399
2400 // Check if cookies are allowed.
2401 bool allow_cookies =
2402 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542403 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412404
Alexander Timin17edc742020-04-23 18:22:182405 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2406 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412407}
2408
Jochen Eisinger0ff7645c2017-11-28 08:11:262409bool ChromeContentBrowserClient::AllowSharedWorker(
2410 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542411 const GURL& site_for_cookies,
2412 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262413 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372414 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262415 content::BrowserContext* context,
2416 int render_process_id,
2417 int render_frame_id) {
2418 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2419
2420 // Check if cookies are allowed.
2421 bool allow =
2422 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542423 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2424 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262425
Clark DuVall84a33d612020-04-17 16:01:002426 content_settings::TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372427 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2428 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262429 return allow;
2430}
2431
Patrick Monette6cb099a2019-09-18 19:31:272432bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2433 const std::string& scheme) {
2434#if BUILDFLAG(ENABLE_EXTENSIONS)
2435 // Extensions are allowed to start cross-origin shared workers.
2436 if (scheme == extensions::kExtensionScheme)
2437 return true;
2438#endif
2439
2440 return false;
2441}
2442
Clark DuVallab63d142019-07-23 04:24:362443bool ChromeContentBrowserClient::AllowSignedExchange(
2444 content::BrowserContext* browser_context) {
2445 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2446 Profile* profile = Profile::FromBrowserContext(browser_context);
2447 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2448}
2449
[email protected]f917df22014-07-10 07:45:492450void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352451 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572452 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172453 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572454 base::OnceCallback<void(bool)> callback) {
2455 Profile* profile = Profile::FromBrowserContext(browser_context);
2456 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002457 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352458
brettw00899e62016-11-12 02:10:172459#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572460 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492461#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572462 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492463#endif
2464}
2465
brettw00899e62016-11-12 02:10:172466#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492467void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2468 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172469 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572470 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492471 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572472 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492473 std::map<int, int> process_map;
2474 std::map<int, int>::const_iterator it;
2475 bool has_web_view_guest = false;
2476 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172477 for (const auto& it : render_frames) {
2478 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492479 continue;
2480
Lukasz Anforowicz09060bdf72018-08-23 15:53:172481 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492482
Lukasz Anforowicz09060bdf72018-08-23 15:53:172483 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492484 has_web_view_guest = true;
2485 }
2486 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572487 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492488 return;
2489 }
[email protected]dffb9fc2014-07-16 04:14:022490 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492491 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492492
[email protected]140d6cd92014-08-12 18:26:462493 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572494 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2495 web_view_permission_helper->RequestFileSystemPermission(
2496 url, allow,
2497 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2498 weak_factory_.GetWeakPtr(), url, render_frames,
2499 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492500}
2501#endif
2502
2503void ChromeContentBrowserClient::FileSystemAccessed(
2504 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172505 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572506 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492507 bool allow) {
[email protected]62151052012-02-01 18:40:482508 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172509 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002510 content_settings::TabSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572511 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352512 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572513 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352514}
2515
[email protected]7c5ff9a2012-03-02 07:42:492516bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2517 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572518 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172519 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572520 Profile* profile = Profile::FromBrowserContext(browser_context);
2521 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2522
falken71691402017-01-27 03:38:002523 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492524
2525 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172526 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002527 content_settings::TabSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572528 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492529 }
2530
2531 return allow;
2532}
2533
Ben Kelly6b2e61c2019-03-14 16:06:292534bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2535 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572536 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292537 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572538 Profile* profile = Profile::FromBrowserContext(browser_context);
2539 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292540 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2541
2542 // Record access to CacheStorage for potential display in UI.
2543 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002544 content_settings::TabSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572545 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292546 }
2547
2548 return allow;
2549}
2550
Joshua Bell1ebc8df2019-11-06 00:27:582551bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2552 const GURL& url,
2553 content::BrowserContext* browser_context,
2554 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2555 Profile* profile = Profile::FromBrowserContext(browser_context);
2556 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2557 return cookie_settings->IsCookieAccessAllowed(url, url);
2558}
2559
jyasskinc993ce8d2016-03-31 00:38:342560ChromeContentBrowserClient::AllowWebBluetoothResult
2561ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452562 content::BrowserContext* browser_context,
2563 const url::Origin& requesting_origin,
2564 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342565 // TODO(crbug.com/598890): Don't disable if
2566 // base::CommandLine::ForCurrentProcess()->
2567 // HasSwitch(switches::kEnableWebBluetooth) is true.
2568 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272569 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342570 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272571 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342572 // The kill switch is enabled for this permission. Block requests.
2573 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2574 }
2575
jyasskin98bdd3992016-02-26 20:25:452576 const HostContentSettingsMap* const content_settings =
2577 HostContentSettingsMapFactory::GetForProfile(
2578 Profile::FromBrowserContext(browser_context));
2579
csharrisonaec2c542016-10-12 19:40:362580 if (content_settings->GetContentSetting(
2581 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452582 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362583 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342584 return AllowWebBluetoothResult::BLOCK_POLICY;
2585 }
2586 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452587}
2588
beaufort.francois01135bf2016-11-23 14:37:362589std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2590 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2591 "blocklist_additions");
scheib74250322016-04-07 03:32:212592}
2593
John Abd-El-Malek21bca7c2018-10-26 22:13:332594#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522595void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072596 content::BrowserContext* browser_context) {
2597 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2598 if (user_manager) {
2599 const user_manager::User* user =
2600 chromeos::ProfileHelper::Get()->GetUserByProfile(
2601 Profile::FromBrowserContext(browser_context));
2602 if (user && !user->username_hash().empty()) {
2603 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2604 user->username_hash());
2605 }
2606 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332607}
2608#endif
2609
Reilly Grant19aaccd2018-07-16 22:06:372610scoped_refptr<network::SharedURLLoaderFactory>
2611ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2613 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2614
2615 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372616 return nullptr;
2617
Min Qinda0d55b2018-10-12 18:30:052618 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372619 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042620}
2621
Sean Gilhulyda1ee4b2018-11-13 21:56:092622network::mojom::NetworkContext*
2623ChromeContentBrowserClient::GetSystemNetworkContext() {
2624 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2625 DCHECK(g_browser_process->system_network_context_manager());
2626 return g_browser_process->system_network_context_manager()->GetContext();
2627}
2628
Andrew Moylan17329fc2017-09-25 07:43:302629std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2630 return google_apis::GetAPIKey();
2631}
2632
Ke He21ee87f2018-05-30 02:35:322633#if defined(OS_ANDROID)
2634bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2635 // Indicate that Chrome uses the GMS core location provider.
2636 return true;
2637}
2638#endif
2639
Yeolf3dc22ca2019-04-18 17:25:322640scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412641ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542642 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412643}
2644
Mythri Alle0b8de0d2018-10-22 11:06:222645content::GeneratedCodeCacheSettings
2646ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2647 content::BrowserContext* context) {
2648 base::FilePath cache_path;
2649 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2650 // If we pass 0 for size, disk_cache will pick a default size using the
2651 // heuristics based on available disk size. These are implemented in
2652 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162653 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132654 DCHECK(g_browser_process);
2655 PrefService* local_state = g_browser_process->local_state();
2656 if (local_state) {
2657 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2658 base::FilePath disk_cache_dir =
2659 local_state->GetFilePath(prefs::kDiskCacheDir);
2660 if (!disk_cache_dir.empty())
2661 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2662 }
Mythri Ab2486572019-06-13 14:48:162663 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222664}
2665
[email protected]848dd042011-06-04 18:24:032666void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262667 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172668 int cert_error,
2669 const net::SSLInfo& ssl_info,
2670 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232671 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222672 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262673 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262674 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232675 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142676 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022677 // have a context for making the right decision, so block the
2678 // request hard, without an info bar to allow showing the insecure
2679 // content.
estark719dde52016-08-09 03:14:272680 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262681 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022682 return;
2683 }
2684
[email protected]f9034cf2011-07-21 12:43:412685 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572686 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262687 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572688 if (prerender_contents) {
2689 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272690 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262691 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272692 }
[email protected]09667f02014-01-06 15:37:572693 return;
[email protected]f9034cf2011-07-21 12:43:412694 }
2695
Erik Staaba65a6032019-11-27 22:23:262696 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282697 return;
[email protected]848dd042011-06-04 18:24:032698}
2699
Alexander Hendrichbcf2616e2018-05-18 08:21:102700namespace {
2701
Pavol Markob211ab22019-01-23 20:03:042702certificate_matching::CertificatePrincipalPattern
2703ParseCertificatePrincipalPattern(const base::Value* pattern) {
2704 return certificate_matching::CertificatePrincipalPattern::
2705 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2706}
2707
Alexander Hendrichbcf2616e2018-05-18 08:21:102708// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452709// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102710// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2711std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2712 Profile* profile,
2713 const GURL& requesting_url,
2714 net::ClientCertIdentityList& client_certs) {
2715 HostContentSettingsMap* host_content_settings_map =
2716 HostContentSettingsMapFactory::GetForProfile(profile);
2717 std::unique_ptr<base::Value> setting =
2718 host_content_settings_map->GetWebsiteSetting(
2719 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452720 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102721
Pavol Markob211ab22019-01-23 20:03:042722 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102723 return nullptr;
2724
Alexander Hendrichbcf2616e2018-05-18 08:21:102725 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042726 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2727 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102728 // |setting_dict| has the wrong format (e.g. single filter instead of a
2729 // list of filters). This content setting is only provided by
2730 // the |PolicyProvider|, which should always set it to a valid format.
2731 // Therefore, delete the invalid value.
2732 host_content_settings_map->SetWebsiteSettingDefaultScope(
2733 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452734 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042735 return nullptr;
2736 }
2737
2738 for (const base::Value& filter : filters->GetList()) {
2739 DCHECK(filter.is_dict());
2740
2741 auto issuer_pattern = ParseCertificatePrincipalPattern(
2742 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2743 auto subject_pattern = ParseCertificatePrincipalPattern(
2744 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2745 // Use the first certificate that is matched by the filter.
2746 for (auto& client_cert : client_certs) {
2747 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2748 subject_pattern.Matches(client_cert->certificate()->subject())) {
2749 return std::move(client_cert);
2750 }
2751 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102752 }
2753
2754 return nullptr;
2755}
2756
2757} // namespace
2758
Daniel McArdle85735f52019-06-25 03:27:062759base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192760 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402761 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082762 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352763 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022764 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192765 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022766 if (prerender_contents) {
2767 prerender_contents->Destroy(
2768 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062769 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452770 }
2771
[email protected]791879c2013-12-17 07:22:412772 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2773 DCHECK(requesting_url.is_valid())
2774 << "Invalid URL string: https://"
2775 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452776
Pavol Marko230ea2c92017-12-03 22:35:442777 bool may_show_cert_selection = true;
2778
davidben3b8455ae72015-03-11 19:42:192779 Profile* profile =
2780 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442781#if defined(OS_CHROMEOS)
2782 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252783 // On the sign-in profile, never show certificate selection to the user. A
2784 // client certificate is an identifier that can be stable for a long time,
2785 // so only the administrator is allowed to decide which endpoints should see
2786 // it.
2787 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442788
2789 content::StoragePartition* storage_partition =
2790 content::BrowserContext::GetStoragePartition(
2791 profile, web_contents->GetSiteInstance());
2792 chromeos::login::SigninPartitionManager* signin_partition_manager =
2793 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2794 profile);
2795
2796 // On the sign-in profile, only allow client certs in the context of the
2797 // sign-in frame.
2798 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2799 storage_partition)) {
2800 LOG(WARNING)
2801 << "Client cert requested in sign-in profile in wrong context.";
2802 // Continue without client certificate. We do this to mimic the case of no
2803 // client certificate being present in the profile's certificate store.
2804 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062805 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442806 }
2807 VLOG(1) << "Client cert requested in sign-in profile.";
2808 }
2809#endif // defined(OS_CHROMEOS)
2810
Alexander Hendrichbcf2616e2018-05-18 08:21:102811 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2812 AutoSelectCertificate(profile, requesting_url, client_certs);
2813 if (auto_selected_identity) {
2814 // The callback will own |auto_selected_identity| and |delegate|, keeping
2815 // them alive until after ContinueWithCertificate is called.
2816 scoped_refptr<net::X509Certificate> cert =
2817 auto_selected_identity->certificate();
2818 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2819 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582820 base::BindOnce(
2821 &content::ClientCertificateDelegate::ContinueWithCertificate,
2822 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322823 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062824 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452825 }
2826
Pavol Marko230ea2c92017-12-03 22:35:442827 if (!may_show_cert_selection) {
2828 LOG(WARNING) << "No client cert matched by policy and user selection is "
2829 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322830 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442831 // Continue without client certificate. We do this to mimic the case of no
2832 // client certificate being present in the profile's certificate store.
2833 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062834 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442835 }
2836
Daniel McArdle85735f52019-06-25 03:27:062837 return chrome::ShowSSLClientCertificateSelector(
2838 web_contents, cert_request_info, std::move(client_certs),
2839 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452840}
2841
[email protected]dc73a7b2012-03-25 15:27:182842content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562843 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182844}
2845
Adrienne Walker80d95f02020-02-07 22:37:042846content::FeatureObserverClient*
2847ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:242848 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:042849 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:052850}
2851
peterc26c6c62014-12-10 14:13:592852content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022853ChromeContentBrowserClient::GetPlatformNotificationService(
2854 content::BrowserContext* browser_context) {
2855 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2856 Profile* profile = Profile::FromBrowserContext(browser_context);
2857 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042858}
2859
[email protected]9f3fba52011-06-08 20:37:192860bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352861 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352862 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572863 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352864 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032865 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232866 const GURL& target_url,
2867 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212868 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232869 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482870 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232871 bool user_gesture,
2872 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012873 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352874 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2875 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012876
csharrison95f01e922017-04-24 18:52:352877 content::WebContents* web_contents =
2878 content::WebContents::FromRenderFrameHost(opener);
2879 Profile* profile =
2880 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2881 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012882 *no_javascript_access = false;
2883
[email protected]9f3fba52011-06-08 20:37:192884 // If the opener is trying to create a background window but doesn't have
2885 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032886 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172887#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352888 auto* process_map = extensions::ProcessMap::Get(profile);
2889 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172890 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2891 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012892 return false;
2893 }
2894
[email protected]7b54ca02012-03-02 18:06:532895 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2896 // return a recently installed Extension even if this CanCreateWindow call
2897 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012898 // because the permission check above would have caused an early return
2899 // already. We must use the full URL to find hosted apps, though, and not
2900 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552901 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352902 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292903 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012904 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022905#endif
[email protected]190e5e22013-07-27 05:59:232906
2907 return true;
[email protected]9f3fba52011-06-08 20:37:192908 }
[email protected]056efdc2013-04-06 00:14:532909
brettw00899e62016-11-12 02:10:172910#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462911 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352912 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232913 return true;
lazyboy04b75d32016-02-25 03:12:182914 }
2915
nick0fbc3922016-12-16 20:52:072916 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352917 // Intentionally duplicating |registry| code from above because we want to
2918 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2919 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182920 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352921 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142922 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532923 UMA_HISTOGRAM_ENUMERATION(
2924 "Extensions.AppLoadedInTab",
2925 ClassifyAppLoadedInTabSource(opener_url, extension),
2926 APP_LOADED_IN_TAB_SOURCE_MAX);
2927
2928 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162929 return false;
lazyboy5d5fede02016-03-10 04:10:142930 }
lazyboy04b75d32016-02-25 03:12:182931 }
[email protected]5940b0d2014-07-01 00:18:262932#endif
[email protected]190e5e22013-07-27 05:59:232933
Charles Harrisonaf2acd02017-08-18 22:46:022934#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232935 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352936 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582937 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2938 content_settings, opener_top_level_frame_url, target_url,
2939 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352940 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2941 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582942 return false;
2943 }
2944#endif
2945
Ryan Sturm0ec75df2020-04-23 14:39:152946 DCHECK(!prerender::PrerenderContents::FromWebContents(web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:022947
Aaron Colwell9dab1652019-12-09 18:29:492948 BlockedWindowParams blocked_params(
2949 target_url, source_origin, opener->GetSiteInstance(), referrer,
2950 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132951 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:192952 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
2953 &nav_params, nullptr /*=open_url_params*/,
2954 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:192955}
2956
[email protected]c52b2892012-03-07 11:01:022957content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:442958ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002959 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:512960}
2961
Katie D840d9532018-11-27 06:20:482962content::TtsControllerDelegate*
2963ChromeContentBrowserClient::GetTtsControllerDelegate() {
2964 TtsControllerDelegateImpl* delegate =
2965 TtsControllerDelegateImpl::GetInstance();
2966#if !defined(OS_ANDROID)
2967 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
2968 delegate->SetTtsEngineDelegate(tts_extension_engine);
2969#endif
2970 return delegate;
2971}
2972
Katie D4713ee42018-11-30 01:48:272973content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
2974#ifdef OS_CHROMEOS
2975 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:272976#else
2977 return nullptr;
2978#endif
2979}
2980
[email protected]64d69de42012-02-06 00:19:542981void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:442982 RenderViewHost* rvh,
2983 WebPreferences* web_prefs) {
2984 Profile* profile =
2985 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062986 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062987
aelias0df335a2017-03-02 23:43:512988// Fill font preferences. These are not registered on Android
2989// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:452990#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:192991 FontFamilyCache::FillFontFamilyMap(profile,
2992 prefs::kWebKitStandardFontFamilyMap,
2993 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:442994 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:192995 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:442996 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:192997 &web_prefs->serif_font_family_map);
2998 FontFamilyCache::FillFontFamilyMap(profile,
2999 prefs::kWebKitSansSerifFontFamilyMap,
3000 &web_prefs->sans_serif_font_family_map);
3001 FontFamilyCache::FillFontFamilyMap(profile,
3002 prefs::kWebKitCursiveFontFamilyMap,
3003 &web_prefs->cursive_font_family_map);
3004 FontFamilyCache::FillFontFamilyMap(profile,
3005 prefs::kWebKitFantasyFontFamilyMap,
3006 &web_prefs->fantasy_font_family_map);
3007 FontFamilyCache::FillFontFamilyMap(profile,
3008 prefs::kWebKitPictographFontFamilyMap,
3009 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063010
[email protected]64d69de42012-02-06 00:19:543011 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403012 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543013 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403014 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543015 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403016 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543017 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403018 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513019#endif
[email protected]f3986f82012-01-03 20:00:063020
[email protected]ddf72142012-05-22 04:52:403021 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063022
[email protected]64d69de42012-02-06 00:19:543023 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063024 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213025 web_prefs->javascript_can_access_clipboard =
3026 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543027 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063028
[email protected]ddf72142012-05-22 04:52:403029 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543030 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573031
Avi Drissman1aa6cb92019-01-23 15:58:383032 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543033 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573034
[email protected]ddf72142012-05-22 04:52:403035 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543036 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543037 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403038 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063039
Zhenyao Moa3fda9972017-09-16 01:34:403040 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3041 web_prefs->webgl1_enabled = false;
3042 web_prefs->webgl2_enabled = false;
3043 }
[email protected]f3986f82012-01-03 20:00:063044
[email protected]64d69de42012-02-06 00:19:543045 web_prefs->allow_running_insecure_content =
3046 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323047#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053048 web_prefs->font_scale_factor =
3049 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323050 web_prefs->force_enable_zoom =
3051 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493052#endif
Becky Zhoubbfbde32019-02-20 17:07:593053 web_prefs->force_dark_mode_enabled =
3054 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393055
[email protected]af4256d52013-06-04 20:39:073056#if defined(OS_ANDROID)
3057 web_prefs->password_echo_enabled =
3058 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3059#else
[email protected]9d06d88d2012-02-23 22:37:083060 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073061#endif
3062
[email protected]64d69de42012-02-06 00:19:543063 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063064 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543065 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063066 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3067
brettw00899e62016-11-12 02:10:173068#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053069 std::string image_animation_policy =
3070 prefs->GetString(prefs::kAnimationPolicy);
3071 if (image_animation_policy == kAnimationPolicyOnce)
3072 web_prefs->animation_policy =
3073 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3074 else if (image_animation_policy == kAnimationPolicyNone)
3075 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3076 else
3077 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3078#endif
3079
[email protected]f3986f82012-01-03 20:00:063080 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153081 web_prefs->default_encoding =
3082 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543083 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403084 prefs->ClearPref(prefs::kDefaultCharset);
3085 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063086 }
[email protected]64d69de42012-02-06 00:19:543087 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063088
mkwst05544102015-01-10 20:26:163089 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3090 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073091 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163092 web_prefs->strict_mixed_content_checking = true;
3093 web_prefs->strict_powerful_feature_restrictions = true;
3094 }
3095
Robert Ogdencf2872d2019-03-19 18:59:373096 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213097
Tarun Bansal333819e2018-05-15 16:38:423098 web_prefs->data_saver_holdback_web_api_enabled =
3099 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3100 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423101
Jinsuk Kima3d393ce2019-05-27 00:57:423102 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133103 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533104#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423105 auto* delegate = TabAndroid::FromWebContents(contents)
3106 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3107 contents->GetDelegate())
3108 : nullptr;
3109 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133110 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423111 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133112
Mounir Lamouri9c99a1602018-07-05 15:01:443113 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423114 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383115
Alison Maher7f366dc62020-03-03 19:46:003116 web_prefs->preferred_color_scheme =
3117 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3118 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113119 }
Ian Vollick6243dfe02018-03-08 01:08:533120#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533121
Mounir Lamouri6926107f2019-01-31 18:17:433122 // web_app_scope value is platform specific.
3123#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423124 if (delegate)
3125 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433126#elif BUILDFLAG(ENABLE_EXTENSIONS)
3127 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253128 web_prefs->web_app_scope = GURL();
3129 // Set |web_app_scope| based on the app associated with the app window if
3130 // any. Note that the app associated with the window never changes, even
3131 // if the app navigates off scope. This is not a problem because we still
3132 // want to use the scope of the app associated with the window, not the
3133 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433134 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233135 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593136 browser->app_controller()->HasAppId()) {
3137 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3138 const web_app::AppRegistrar& registrar =
3139 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3140 if (registrar.IsLocallyInstalled(app_id))
3141 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433142 }
Mounir Lamouri6926107f2019-01-31 18:17:433143 }
3144#endif
3145
Ian Vollick6243dfe02018-03-08 01:08:533146 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113147 }
zqzhang93e959d12017-03-16 13:10:203148
Tarun Bansal73d67f02018-01-17 05:56:253149 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3150 // Obtain the maximum effective connection type at which the feature is
3151 // enabled.
3152 std::string effective_connection_type_param =
3153 base::GetFieldTrialParamValueByFeature(
3154 features::kLowPriorityIframes,
3155 "max_effective_connection_type_threshold");
3156
3157 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3158 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3159 if (effective_connection_type) {
3160 web_prefs->low_priority_iframes_threshold =
3161 effective_connection_type.value();
3162 }
3163 }
3164
rajendrant0521cee2019-07-29 06:09:263165 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3166 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003167
Scott Little878f7d6702018-05-31 22:09:063168 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3169 const char* param_name =
3170 web_prefs->data_saver_enabled
3171 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3172 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3173 "saver_enabled";
3174
3175 base::StringPairs pairs;
3176 base::SplitStringIntoKeyValuePairs(
3177 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3178 param_name),
3179 ':', ',', &pairs);
3180
3181 for (const auto& pair : pairs) {
3182 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3183 net::GetEffectiveConnectionTypeForName(pair.first);
3184 int value = 0;
3185 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3186 web_prefs->lazy_frame_loading_distance_thresholds_px
3187 [effective_connection_type.value()] = value;
3188 }
3189 }
3190 }
3191
rajendrantd8026342018-08-29 08:08:393192 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3193 const char* param_name =
3194 web_prefs->data_saver_enabled
3195 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3196 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3197 "saver_enabled";
3198
3199 base::StringPairs pairs;
3200 base::SplitStringIntoKeyValuePairs(
3201 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3202 param_name),
3203 ':', ',', &pairs);
3204
3205 for (const auto& pair : pairs) {
3206 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3207 net::GetEffectiveConnectionTypeForName(pair.first);
3208 int value = 0;
3209 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3210 web_prefs->lazy_image_loading_distance_thresholds_px
3211 [effective_connection_type.value()] = value;
3212 }
3213 }
rajendrant3daeae292019-09-20 07:57:543214
3215 pairs.clear();
3216 base::SplitStringIntoKeyValuePairs(
3217 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3218 "lazy_image_first_k_fully_load"),
3219 ':', ',', &pairs);
3220
3221 for (const auto& pair : pairs) {
3222 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3223 net::GetEffectiveConnectionTypeForName(pair.first);
3224 int value = 0;
3225 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3226 web_prefs
3227 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3228 value;
3229 }
3230 }
rajendrantd8026342018-08-29 08:08:393231 }
3232
Tarun Bansald10f17a02018-09-13 00:23:173233 if (base::FeatureList::IsEnabled(
3234 features::kNetworkQualityEstimatorWebHoldback)) {
3235 std::string effective_connection_type_param =
3236 base::GetFieldTrialParamValueByFeature(
3237 features::kNetworkQualityEstimatorWebHoldback,
3238 "web_effective_connection_type_override");
3239
3240 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3241 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3242 DCHECK(effective_connection_type_param.empty() ||
3243 effective_connection_type);
3244 if (effective_connection_type) {
3245 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3246 effective_connection_type.value());
3247 web_prefs->network_quality_estimator_web_holdback =
3248 effective_connection_type.value();
3249 }
3250 }
3251
Alison Maher7f366dc62020-03-03 19:46:003252 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103253#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563254 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593255 // If autoplay is allowed by policy then force the no user gesture required
3256 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103257 web_prefs->autoplay_policy =
3258 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553259 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593260 web_prefs->autoplay_policy ==
3261 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553262 // If the autoplay disable settings feature is enabled and the autoplay
3263 // policy is set to using the unified policy then set the default autoplay
3264 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593265 web_prefs->autoplay_policy =
3266 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3267 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3268 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103269 }
Alison Maher7f366dc62020-03-03 19:46:003270
3271 switch (native_theme->GetPreferredColorScheme()) {
3272 case ui::NativeTheme::PreferredColorScheme::kDark:
3273 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3274 break;
3275 case ui::NativeTheme::PreferredColorScheme::kLight:
3276 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3277 break;
3278 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3279 web_prefs->preferred_color_scheme =
3280 blink::PreferredColorScheme::kNoPreference;
3281 }
François Beaufort4f8107d2018-03-05 12:12:103282#endif // !defined(OS_ANDROID)
3283
Dave Tapuskac6627e12018-08-30 15:07:193284 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493285
Alison Maher7f366dc62020-03-03 19:46:003286 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3287 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3288 // explicitly uses light (instead of not dark), which is why we don't reset
3289 // back to no-preference. https://crbug.com/965811
3290 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3291 const GURL url = rvh->GetSiteInstance()->GetSiteURL();
3292 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3293#if BUILDFLAG(ENABLE_EXTENSIONS)
3294 if (!force_light) {
3295 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3296 url.host_piece() == extension_misc::kPdfExtensionId;
3297 }
3298#endif
3299 if (force_light)
3300 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3301 }
3302
Elly Fong-Jonesf92897392019-01-24 16:05:493303 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213304 base::Optional<ui::CaptionStyle> style;
3305
3306 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3307 ::switches::kForceCaptionStyle)) {
3308 style = ui::CaptionStyle::FromSpec(
3309 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3310 switches::kForceCaptionStyle));
3311 }
3312
3313 // Apply system caption style.
3314 if (!style) {
3315 style = native_theme->GetSystemCaptionStyle();
evliu7a8acef22020-02-27 21:32:323316
3317 base::UmaHistogramBoolean(
3318 "Accessibility.CaptionSettingsLoadedFromSystemSettings",
3319 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213320 }
3321
3322 // Apply caption style from preferences if system caption style is undefined.
evliu21b2a902020-01-27 21:12:563323 if (!style) {
evliubc2aa0472019-08-09 20:19:193324 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
evliuedcbb87d2019-11-22 19:49:413325
3326 base::UmaHistogramBoolean("Accessibility.CaptionSettingsLoadedFromPrefs",
3327 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213328 }
3329
3330 if (style) {
3331 web_prefs->text_track_background_color = style->background_color;
3332 web_prefs->text_track_text_color = style->text_color;
3333 web_prefs->text_track_text_size = style->text_size;
3334 web_prefs->text_track_text_shadow = style->text_shadow;
3335 web_prefs->text_track_font_family = style->font_family;
3336 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563337 web_prefs->text_track_window_color = style->window_color;
3338 web_prefs->text_track_window_padding = style->window_padding;
3339 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213340 }
Elly Fong-Jonesf92897392019-01-24 16:05:493341
[email protected]a48ab7112014-08-01 16:48:033342 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503343 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363344}
3345
[email protected]b8148ac2011-07-13 22:03:253346void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3347 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033348 for (size_t i = 0; i < extra_parts_.size(); ++i)
3349 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253350
[email protected]b3adbd02011-11-30 22:23:273351 // about: handler. Must come before chrome: handler, since it will
3352 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053353 // actually handle them. Also relies on a preliminary fixup phase.
3354 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253355 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3356 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033357
madfbd10852017-01-20 03:15:333358 // The group policy NTP URL handler must be registered before the other NTP
3359 // URL handlers below.
3360 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3361 BrowserURLHandler::null_handler());
3362
zpengdb4a58e2017-01-10 17:40:323363#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033364 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353365 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033366 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453367#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033368 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133369 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3370 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453371#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033372
[email protected]b8148ac2011-07-13 22:03:253373 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313374 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3375 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253376}
3377
[email protected]650b2d52013-02-10 03:41:453378base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493379 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323380}
3381
[email protected]c9b6eb62011-10-18 20:49:393382std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3383 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3384}
3385
Dominik Röttsches47347832019-03-12 17:45:013386base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3387 base::FilePath user_data_dir;
3388 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3389 DCHECK(!user_data_dir.empty());
3390 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3391}
3392
jmadill57b52d42015-08-21 18:16:133393base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3394 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523395 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133396 DCHECK(!user_data_dir.empty());
3397 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3398}
3399
Khushal7ca0b782018-07-20 05:53:273400base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3401 base::FilePath user_data_dir;
3402 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3403 DCHECK(!user_data_dir.empty());
3404 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3405}
3406
[email protected]b7631cc2012-09-15 05:08:383407void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3408 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163409#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553410 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543411#endif
[email protected]b7631cc2012-09-15 05:08:383412}
3413
[email protected]0c7193742012-11-07 19:05:033414content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443415ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173416#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553417 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033418 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443419 nacl::NaClProcessHost* host =
3420 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3421 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033422 // Found the plugin.
3423 return host->browser_ppapi_host();
3424 }
3425 ++iter;
3426 }
[email protected]a56f8322014-07-16 21:13:553427#endif
Aran Gilmanf010bdd2019-08-28 19:55:443428 return nullptr;
[email protected]0c7193742012-11-07 19:05:033429}
3430
[email protected]38cd8f7f2012-06-15 22:06:073431bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583432 content::BrowserContext* browser_context,
3433 const GURL& url,
[email protected]dda54822013-06-15 01:26:393434 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123435 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163436#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553437 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193438 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403439#else
[email protected]a658d452012-03-02 12:45:293440 return false;
[email protected]93f72062013-05-29 20:29:403441#endif
[email protected]e461da2f2012-02-16 19:06:403442}
3443
adrian.belgund54465ba2016-05-18 10:03:583444bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3445 content::BrowserContext* browser_context,
3446 const GURL& url) {
brettw4b461082016-11-19 18:55:163447#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583448 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3449 browser_context, url);
3450#else
3451 return false;
3452#endif
3453}
3454
adrian.belgun5b341c72016-06-22 22:24:083455std::unique_ptr<content::VpnServiceProxy>
3456ChromeContentBrowserClient::GetVpnServiceProxy(
3457 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173458#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083459 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3460 browser_context);
3461#else
3462 return nullptr;
3463#endif
3464}
3465
Brett Wilson804e83c2017-08-18 22:57:333466std::unique_ptr<ui::SelectFilePolicy>
3467ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3468 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433469}
3470
[email protected]7d9424702013-04-14 13:14:163471void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3472 std::vector<std::string>* additional_allowed_schemes) {
3473 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3474 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483475 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293476 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033477 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3478 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3479 additional_allowed_schemes);
3480 }
[email protected]7d9424702013-04-14 13:14:163481}
3482
falkenad185092016-06-16 06:10:023483void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3484 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043485 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023486}
3487
[email protected]c79859b82014-03-20 22:43:553488void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313489 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033490 for (size_t i = 0; i < extra_parts_.size(); ++i)
3491 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553492}
3493
nzolghadrd87a308d2016-12-07 15:45:563494::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3495 return g_browser_process->rappor_service();
3496}
3497
[email protected]f19bbf62013-07-09 01:22:323498void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313499 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533500 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003501 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3502 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313503#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313504 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313505 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313506 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093507 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093508 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3509 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473510 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093511 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3512 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053513 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3514 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343515 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3516 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473517 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323518 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313519 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003520 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313521#endif
[email protected]445b7db2013-08-02 04:58:273522
[email protected]a48ab7112014-08-01 16:48:033523 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3524 extra_parts_[i]->GetAdditionalFileSystemBackends(
3525 browser_context, storage_partition_path, additional_backends);
3526 }
[email protected]02250952013-04-24 23:52:533527}
3528
jcivellie6f550742017-01-06 19:29:123529#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183530void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173531 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383532 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203533 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123534#if defined(OS_ANDROID)
3535 base::MemoryMappedFile::Region region;
3536 int fd = ui::GetMainAndroidPackFd(&region);
3537 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003538
Samuel Huang31eadf082019-08-28 19:50:433539 // For Android: Native resources for DFMs should only be used by the browser
3540 // process. Their file descriptors and memory mapped file regions are not
3541 // passed to child processes.
3542
jcivellie6f550742017-01-06 19:29:123543 fd = ui::GetCommonResourcesPackFd(&region);
3544 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393545
jcivellie6f550742017-01-06 19:29:123546 fd = ui::GetLocalePackFd(&region);
3547 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383548
zpeng368afac82017-07-17 18:47:453549 // Optional secondary locale .pak file.
3550 fd = ui::GetSecondaryLocalePackFd(&region);
3551 if (fd != -1) {
3552 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3553 }
3554
[email protected]09560f7f2014-06-10 18:40:283555 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523556 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283557 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023558#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383559 int crash_signal_fd = GetCrashSignalFD(command_line);
3560 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133561 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383562 }
jcivellie6f550742017-01-06 19:29:123563}
3564#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303565
[email protected]4a65826d2011-08-25 16:04:013566#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033567base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223568 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033569 // TODO(wfh): Add support for more process types here. crbug.com/499523
3570 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223571 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363572 return base::string16(install_static::GetSandboxSidPrefix()) +
3573 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223574 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033575 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223576 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033577 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223578 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363579 return base::string16(install_static::GetSandboxSidPrefix()) +
3580 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223581 case service_manager::SandboxType::kNoSandbox:
3582 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3583 case service_manager::SandboxType::kXrCompositing:
3584 case service_manager::SandboxType::kNetwork:
3585 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523586 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223587 case service_manager::SandboxType::kAudio:
evliu2e5dbee42020-04-09 23:35:293588 case service_manager::SandboxType::kSpeechRecognition:
Will Harrise705a642020-02-26 20:57:053589 case service_manager::SandboxType::kProxyResolver:
Cliff Smolinsky0aa7ca72020-03-09 21:32:463590 case service_manager::SandboxType::kPdfConversion:
Alex Gough63617352020-03-20 02:34:593591 case service_manager::SandboxType::kSharingService:
Sharon Yangefd8e882020-04-28 20:56:433592 case service_manager::SandboxType::kVideoCapture:
Alex Gough9ab468a6c32019-12-10 19:10:223593 // Should never reach here.
3594 CHECK(0);
wfh182da09c2015-06-24 19:23:033595 return base::string16();
wfh182da09c2015-06-24 19:23:033596 }
wfh182da09c2015-06-24 19:23:033597}
3598
Will Harris956e0ca2019-08-23 20:47:393599bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3600 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503601// Does not work under component build because all the component DLLs would need
3602// to be manually added and maintained. Does not work under ASAN build because
3603// ASAN has not yet fully initialized its instrumentation by the time the CIG
3604// intercepts run.
3605#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393606 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3607 return true;
Will Harrisc196ed942019-08-03 03:45:303608 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3609 return true;
3610
3611 // Only enable signing mitigation if launching from chrome.exe.
3612 base::FilePath exe_path;
3613 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3614 return true;
3615 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3616 return true;
3617
3618 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3619 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093620 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303621 if (result != sandbox::SBOX_ALL_OK)
3622 return false;
3623
Nico Weberc36b0152020-04-18 03:12:463624 // Allow loading Chrome's DLLs.
3625 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303626 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3627 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3628 GetModulePath(dll).value().c_str());
3629 if (result != sandbox::SBOX_ALL_OK)
3630 return false;
3631 }
Will Harris1b9b4152019-08-21 22:33:503632#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303633
3634 return true;
[email protected]34f48682013-03-20 00:30:183635}
Will Harris956e0ca2019-08-23 20:47:393636
3637bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3638 PrefService* local_state = g_browser_process->local_state();
3639 if (local_state &&
3640 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3641 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3642 return false;
3643 return true;
3644}
3645
wfhc91e9672016-01-27 00:14:203646#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013647
Armando Miraglia3a7be232019-11-08 00:33:323648#if defined(OS_WIN) || defined(OS_MACOSX) || \
3649 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3650bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3651 const base::Value* audio_sandbox_enabled_policy_value =
3652 policies.GetValue(policy::key::kAudioSandboxEnabled);
3653 if (audio_sandbox_enabled_policy_value) {
3654 bool force_enable_audio_sandbox;
3655 audio_sandbox_enabled_policy_value->GetAsBoolean(
3656 &force_enable_audio_sandbox);
3657 return force_enable_audio_sandbox;
3658 }
3659
3660 return base::FeatureList::IsEnabled(
3661 service_manager::features::kAudioServiceSandbox);
3662}
3663#endif
3664
Ken Rockotfa5d57112019-05-29 20:57:143665void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123666#if defined(OS_WIN) || defined(OS_MACOSX) || \
3667 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053668 if (startup_data_) {
3669 auto* chrome_feature_list_creator =
3670 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183671 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123672 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053673 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183674 ->GetPolicyService()
3675 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123676 std::string()));
3677
3678#if defined(OS_WIN)
3679 const base::Value* force_network_in_process_value =
3680 policies.GetValue(policy::key::kForceNetworkInProcess);
John Abd-El-Malek27b3ebd22019-02-12 18:59:183681 bool force_network_in_process = false;
3682 if (force_network_in_process_value)
3683 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3684 if (force_network_in_process)
3685 content::ForceInProcessNetworkService(true);
Guido Urdanetad06ae842019-10-10 20:04:123686#endif
Armando Miraglia3a7be232019-11-08 00:33:323687
3688 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
John Abd-El-Malek27b3ebd22019-02-12 18:59:183689 }
3690#endif
xhwang5e630462015-10-30 03:18:483691}
3692
Ken Rockot8f39a272018-12-21 23:38:353693base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173694ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583695 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583696 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583697 return base::nullopt;
benc70c0e32016-09-22 03:50:373698}
3699
peterbbcccc12015-02-11 22:23:333700void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373701 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333702 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293703 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083704 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373705
3706 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083707
zpengdb4a58e2017-01-10 17:40:323708#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223709 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293710 std::move(callback));
jam1c5a91492016-02-24 20:47:533711#else
cm.sanchi2522bc92017-12-04 08:04:133712 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3713 params.url, params.transition);
3714 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083715
3716 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293717 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333718#endif
mlamourieb40d552015-02-05 00:57:083719}
3720
zhaobinf3704f82017-01-12 07:19:363721content::ControllerPresentationServiceDelegate*
3722ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3723 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463724 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093725 return media_router::PresentationServiceDelegateImpl::
3726 GetOrCreateForWebContents(web_contents);
3727 }
haibinlu9e605a92015-06-06 03:45:093728 return nullptr;
3729}
3730
zhaobinf3704f82017-01-12 07:19:363731content::ReceiverPresentationServiceDelegate*
3732ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3733 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363734 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3735 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3736 // created for offscreen presentations. The WebContents must belong to
3737 // an incognito profile.
3738 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3739 FromWebContents(web_contents)) {
3740 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3741 return impl;
3742 }
3743 }
zhaobinf3704f82017-01-12 07:19:363744 return nullptr;
3745}
3746
horo48d4d3e2015-02-27 03:04:003747void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3748 const GURL& url) {
mathp46284f32015-03-11 13:06:413749 if (url.is_valid()) {
3750 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3751 metric, url);
3752 }
horo48d4d3e2015-02-27 03:04:003753}
3754
Matt Falkenhagen8479b202017-07-14 04:35:313755std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3756 // Don't change these returned strings. They are written (in hashed form) into
3757 // UMA logs. If you add more strings, you must update histograms.xml and get
3758 // histograms review. Only Google domains should be here for privacy purposes.
3759 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3760 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193761 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313762 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193763 if (url.host() == "docs.google.com")
3764 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313765 return std::string();
3766}
3767
avid6d88b912017-01-13 00:16:003768std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473769ChromeContentBrowserClient::CreateThrottlesForNavigation(
3770 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003771 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273772
bmcquadeb4556552017-03-24 22:24:373773 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3774 // that may delay or cancel navigations, so only NavigationThrottles that
3775 // don't delay or cancel navigations (e.g. throttles that are only observing
3776 // callbacks without affecting navigation behavior) should be added before
3777 // MetricsNavigationThrottle.
3778 if (handle->IsInMainFrame()) {
3779 throttles.push_back(
3780 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3781 }
3782
brettw4b461082016-11-19 18:55:163783#if BUILDFLAG(ENABLE_PLUGINS)
Lukasz Anforowicz7724d092019-10-03 23:50:213784 MaybeAddThrottle(&throttles,
3785 FlashDownloadInterception::MaybeCreateThrottleFor(handle));
trizzofo8ddaeb72016-09-01 23:18:273786#endif
3787
yilkal240b4f22019-11-27 19:09:063788#if defined(OS_CHROMEOS)
3789 MaybeAddThrottle(
3790 &throttles,
3791 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle));
3792#endif // defined(OS_CHROMEOS)
3793
mmenkedb2637ff2017-03-30 23:59:423794#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213795 MaybeAddThrottle(
3796 &throttles,
3797 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle));
mmenkedb2637ff2017-03-30 23:59:423798#endif
3799
clamy40c9e142015-09-29 11:18:473800#if defined(OS_ANDROID)
3801 // TODO(davidben): This is insufficient to integrate with prerender properly.
3802 // https://crbug.com/370595
3803 prerender::PrerenderContents* prerender_contents =
3804 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3805 if (!prerender_contents && handle->IsInMainFrame()) {
3806 throttles.push_back(
3807 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303808 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473809 }
Min Qin0ab0e162017-11-14 21:57:193810 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043811
3812#if BUILDFLAG(DFMIFY_DEV_UI)
3813 // If the DevUI DFM is already installed, then this is a no-op, except for the
3814 // side effect of ensuring that the DevUI DFM is loaded.
3815 MaybeAddThrottle(&throttles,
3816 dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle));
3817#endif // BUILDFLAG(DFMIFY_DEV_UI)
3818
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573819#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473820 if (handle->IsInMainFrame()) {
3821 // Redirect some navigations to apps that have registered matching URL
3822 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573823 auto url_to_app_throttle =
3824 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:473825 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:093826 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:473827 }
3828#endif
clamy49678312015-10-22 21:59:003829
3830#if defined(OS_CHROMEOS)
3831 // Check if we need to add merge session throttle. This throttle will postpone
3832 // loading of main frames.
3833 if (handle->IsInMainFrame()) {
3834 // Add interstitial page while merge session process (cookie reconstruction
3835 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3836 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023837 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3838 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003839 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3840 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3841 }
Maggie Caia2f03f52019-04-02 02:13:283842 }
3843#endif
djacobo21e56e02016-07-02 01:14:313844
Maggie Caia2f03f52019-04-02 02:13:283845#if !defined(OS_ANDROID)
3846 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:153847 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283848#if defined(OS_CHROMEOS)
Maggie Cai00e2a21e2019-10-16 00:47:513849 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3850 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3851 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253852#elif defined(OS_MACOSX)
3853 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283854#else
3855 apps::AppsNavigationThrottle::MaybeCreate(handle);
3856#endif
Dominick Ng7c289942018-03-27 05:57:153857 if (url_to_apps_throttle)
3858 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003859 }
3860#endif
3861
brettw00899e62016-11-12 02:10:173862#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003863 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093864 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513865
Lukasz Anforowicz7724d092019-10-03 23:50:213866 MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get()
3867 ->GetUserScriptListener()
3868 ->CreateNavigationThrottle(handle));
naskob9164c42016-06-07 01:21:353869#endif
3870
bauerb8f9c37742017-03-30 15:04:123871#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213872 MaybeAddThrottle(
3873 &throttles,
3874 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle));
bauerb8f9c37742017-03-30 15:04:123875#endif
3876
csharrisone985ebc2017-04-04 17:05:033877 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103878 if (auto* subresource_filter_client =
3879 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3880 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3881 &throttles);
csharrisone985ebc2017-04-04 17:05:033882 }
3883
zhenw6edd49c2017-07-12 05:49:453884#if !defined(OS_ANDROID)
3885 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3886 // enabled on non-Android platforms.
Lukasz Anforowicz7724d092019-10-03 23:50:213887 MaybeAddThrottle(&throttles,
3888 resource_coordinator::BackgroundTabNavigationThrottle::
3889 MaybeCreateThrottleFor(handle));
zhenw6edd49c2017-07-12 05:49:453890#endif
3891
Nico Weberbc5b06f2019-07-26 14:00:133892#if BUILDFLAG(FULL_SAFE_BROWSING)
Lukasz Anforowicz7724d092019-10-03 23:50:213893 MaybeAddThrottle(&throttles,
3894 safe_browsing::MaybeCreateNavigationThrottle(handle));
Jialiu Linbdbb81d2017-10-11 21:29:093895#endif
3896
Lukasz Anforowicz7724d092019-10-03 23:50:213897 MaybeAddThrottle(
3898 &throttles,
Emily Starkfa0ddb42019-10-24 15:49:583899 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
Joe DeBlasio6e8409a2019-02-20 23:08:273900
Lukasz Anforowicz7724d092019-10-03 23:50:213901 MaybeAddThrottle(&throttles,
3902 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
Amber Won6b5edc752017-08-17 19:23:543903
Lukasz Anforowicz7724d092019-10-03 23:50:213904 MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle));
Charles Harrison6dd11d282017-10-03 06:14:513905
Jeremy Romanec48d7a2018-03-01 17:35:093906 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533907 handle, handle->GetWebContents()->GetBrowserContext()));
3908
Colin Blundelleaa7377bf2020-01-22 08:49:103909 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
3910 // the relevant extension API whenever an SSL interstitial is shown.
3911 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
3912 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:283913 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3914 handle,
3915 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:383916 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123917
Emily Starkd6896cd32019-08-21 04:55:543918 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3919
Lukasz Anforowicz7724d092019-10-03 23:50:213920 MaybeAddThrottle(
3921 &throttles,
3922 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle));
Christopher Thompson4137cec2017-12-19 05:34:233923
Dmitry Gozman57b92ce2017-12-28 22:24:543924#if !defined(OS_ANDROID)
Lukasz Anforowicz7724d092019-10-03 23:50:213925 MaybeAddThrottle(&throttles,
3926 DevToolsWindow::MaybeCreateNavigationThrottle(handle));
Conley Owensaafcf122018-02-26 18:53:513927
Lukasz Anforowicz7724d092019-10-03 23:50:213928 MaybeAddThrottle(
3929 &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle));
jdoerrie4f9376f2018-12-12 18:26:203930
Lukasz Anforowicz7724d092019-10-03 23:50:213931 MaybeAddThrottle(
3932 &throttles,
3933 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle));
Dmitry Gozman57b92ce2017-12-28 22:24:543934#endif
3935
Carlos IL800e3502020-04-30 16:35:593936 throttles.push_back(
3937 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:033938
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:333939#if defined(OS_WIN) || defined(OS_MACOSX) || \
3940 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Lukasz Anforowicz7724d092019-10-03 23:50:213941 MaybeAddThrottle(&throttles,
3942 browser_switcher::BrowserSwitcherNavigationThrottle::
3943 MaybeCreateThrottleFor(handle));
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:133944#endif
3945
dchenge73d8520c2015-12-27 01:19:093946 return throttles;
clamy40c9e142015-09-29 11:18:473947}
3948
clamy1e5574e2016-09-29 16:48:443949std::unique_ptr<content::NavigationUIData>
3950ChromeContentBrowserClient::GetNavigationUIData(
3951 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:093952 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:443953}
3954
Xiaohan Wanga4e41842018-06-26 18:45:103955void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
3956 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:103957 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:123958 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:103959#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:263960 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:103961 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:333962 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:103963 }
3964#endif
3965}
3966
[email protected]487974a2014-06-13 16:49:013967content::DevToolsManagerDelegate*
3968ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:353969#if defined(OS_ANDROID)
3970 return new DevToolsManagerDelegateAndroid();
3971#else
[email protected]487974a2014-06-13 16:49:013972 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:353973#endif
[email protected]487974a2014-06-13 16:49:013974}
3975
Rayan Kanso411e84e2019-02-13 15:27:403976void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
3977 content::BrowserContext* browser_context,
3978 int service,
3979 base::Time expiration_time) {
3980 Profile* profile = Profile::FromBrowserContext(browser_context);
3981 DCHECK(profile);
3982
3983 auto* pref_service = profile->GetPrefs();
3984 DCHECK(pref_service);
3985
3986 DictionaryPrefUpdate pref_update(
3987 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
3988 base::DictionaryValue* exp_dict = pref_update.Get();
3989
3990 // Convert |expiration_time| to minutes since that is the most granular
3991 // option that returns an int. base::Value does not accept int64.
3992 int expiration_time_minutes =
3993 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
3994 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
3995}
3996
3997base::flat_map<int, base::Time>
3998ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
3999 content::BrowserContext* browser_context) {
4000 Profile* profile = Profile::FromBrowserContext(browser_context);
4001 DCHECK(profile);
4002
4003 auto* pref_service = profile->GetPrefs();
4004 DCHECK(pref_service);
4005
4006 auto* expiration_dict = pref_service->GetDictionary(
4007 prefs::kDevToolsBackgroundServicesExpirationDict);
4008 DCHECK(expiration_dict);
4009
4010 base::flat_map<int, base::Time> expiration_times;
4011 for (const auto& it : *expiration_dict) {
4012 // key.
4013 int service = 0;
4014 bool did_convert = base::StringToInt(it.first, &service);
4015 DCHECK(did_convert);
4016
4017 // value.
4018 DCHECK(it.second->is_int());
4019 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4020 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4021
4022 expiration_times[service] = expiration_time;
4023 }
4024
4025 return expiration_times;
4026}
4027
oysteinec563c582015-02-13 19:19:524028content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524029 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524030}
4031
[email protected]a6868c22013-10-09 02:50:294032bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4033 content::BrowserContext* browser_context,
4034 const GURL& url) {
brettw4b461082016-11-19 18:55:164035#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554036 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194037 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294038#else
4039 return false;
4040#endif
4041}
4042
[email protected]aec5ed52014-06-20 07:51:424043bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4044 content::BrowserContext* browser_context,
4045 const GURL& url) {
brettw4b461082016-11-19 18:55:164046#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554047 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194048 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064049#else
4050 return false;
4051#endif
4052}
4053
mlamourif8c23a2002015-01-27 13:10:104054void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014055 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434056 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524057 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104058
4059 WebContents* web_contents =
4060 WebContents::FromRenderFrameHost(render_frame_host);
4061 DCHECK(web_contents);
4062
mlamourif8c23a2002015-01-27 13:10:104063 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374064 prerender::PrerenderManagerFactory::GetForBrowserContext(
4065 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104066 if (prerender_manager &&
4067 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294068 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104069 }
4070}
4071
Robert Sesek466e43e2019-08-19 22:02:024072void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4073 base::FilePath user_data_dir;
4074 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4075 DCHECK(!user_data_dir.empty());
4076 network_contexts_parent_directory_.push_back(user_data_dir);
4077
4078 base::FilePath cache_dir;
4079 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4080 DCHECK(!cache_dir.empty());
4081 // On some platforms, the cache is a child of the user_data_dir so only
4082 // return the one path.
4083 if (!user_data_dir.IsParent(cache_dir))
4084 network_contexts_parent_directory_.push_back(cache_dir);
4085
4086 // If the cache location has been overridden by a switch or preference,
4087 // include that as well.
4088 if (auto* local_state = g_browser_process->local_state()) {
4089 base::FilePath pref_cache_dir =
4090 local_state->GetFilePath(prefs::kDiskCacheDir);
4091 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4092 network_contexts_parent_directory_.push_back(pref_cache_dir);
4093 }
4094}
4095
[email protected]30335fdf02014-02-26 19:51:274096void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174097 base::CommandLine* to_command_line,
4098 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544099 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274100#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544101 const version_info::Channel kMaxDisableEncryptionChannel =
4102 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274103#else
sdefresne6e883e42015-07-30 08:05:544104 const version_info::Channel kMaxDisableEncryptionChannel =
4105 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274106#endif
4107 if (channel <= kMaxDisableEncryptionChannel) {
4108 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444109 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274110 };
Avi Drissmand251e912018-12-26 15:46:374111 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4112 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274113 }
4114}
bashi933629552016-10-13 23:32:404115
miu54dca6c2016-11-17 10:59:384116#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4117void ChromeContentBrowserClient::CreateMediaRemoter(
4118 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504119 mojo::PendingRemote<media::mojom::RemotingSource> source,
4120 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384121 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504122 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384123}
4124#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464125
Michael Giuffrida6802ffe2017-09-29 03:40:254126base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4127 const base::CommandLine& command_line) {
4128 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164129}
4130
John Abd-El-Malek8efa11f2019-01-06 00:51:534131namespace {
4132// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024133class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534134 public:
4135 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174136 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534137 : protocol_handler_registry_(protocol_handler_registry) {}
4138 ~ProtocolHandlerThrottle() override = default;
4139
4140 void WillStartRequest(network::ResourceRequest* request,
4141 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294142 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534143 }
4144
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584145 void WillRedirectRequest(
4146 net::RedirectInfo* redirect_info,
4147 const network::mojom::URLResponseHead& response_head,
4148 bool* defer,
4149 std::vector<std::string>* to_be_removed_headers,
4150 net::HttpRequestHeaders* modified_headers,
4151 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294152 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534153 }
4154
4155 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294156 void TranslateUrl(GURL* url) {
4157 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4158 return;
4159 GURL translated_url = protocol_handler_registry_->Translate(*url);
4160 if (!translated_url.is_empty())
4161 *url = translated_url;
4162 }
4163
Clark DuValla411bda2019-08-02 03:09:174164 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534165};
4166} // namespace
4167
Minggang Wangf6840ecf2019-07-29 05:15:024168std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194169ChromeContentBrowserClient::CreateURLLoaderThrottles(
4170 const network::ResourceRequest& request,
4171 content::BrowserContext* browser_context,
4172 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4173 content::NavigationUIData* navigation_ui_data,
4174 int frame_tree_node_id) {
4175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4176
Minggang Wangf6840ecf2019-07-29 05:15:024177 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194178
4179 Profile* profile = Profile::FromBrowserContext(browser_context);
4180
4181 ChromeNavigationUIData* chrome_navigation_ui_data =
4182 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4183
Nico Weberbc5b06f2019-07-26 14:00:134184#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564185 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4186 request.url, *profile->GetPrefs());
4187 if (!matches_enterprise_whitelist) {
Xinghui Lue17b19942020-02-24 21:19:584188 // |url_lookup_service| is used when real time url check is enabled.
4189 safe_browsing::RealTimeUrlLookupService* url_lookup_service =
4190 // |safe_browsing_service_| may be unavailable in tests.
4191 safe_browsing_service_ &&
4192 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
Xinghui Lu8fe39982020-03-02 22:31:384193 profile->GetPrefs(), profile->IsOffTheRecord())
Xinghui Lue17b19942020-02-24 21:19:584194 ? safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
4195 profile)
4196 : nullptr;
Xinghui Lu0abc17b2020-02-20 22:50:194197
Clark DuVall5497288d2019-07-17 00:17:564198 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4199 base::BindOnce(
4200 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534201 base::Unretained(this),
Bettinae83f522c72020-03-12 01:52:334202 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs())),
Xinghui Lua142c102020-03-02 20:50:084203 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584204 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564205 }
Nico Weberbc5b06f2019-07-26 14:00:134206#endif
Clark DuVall5497288d2019-07-17 00:17:564207
dalykba7bbfc2019-12-18 19:59:214208#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4209 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014210 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4211 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214212#endif
4213
Clark DuVallfffa41e2019-06-25 20:27:194214 if (chrome_navigation_ui_data &&
4215 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4216 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4217 chrome_navigation_ui_data->prerender_mode(),
4218 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234219 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194220 }
4221
John Abd-El-Malek4f380d92020-02-19 16:43:364222#if defined(OS_ANDROID)
4223 std::string client_data_header;
John Abd-El-Malekfb9f5462020-02-20 01:18:374224 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4225 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364226 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4227 if (web_contents) {
4228 auto* client_data_header_observer =
4229 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4230 web_contents);
4231 if (client_data_header_observer)
4232 client_data_header = client_data_header_observer->header();
4233 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374234 }
John Abd-El-Malek4f380d92020-02-19 16:43:364235#endif
4236
Clark DuVallfffa41e2019-06-25 20:27:194237 chrome::mojom::DynamicParams dynamic_params = {
4238 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4239 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274240 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4241 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364242#if defined(OS_ANDROID)
Alex Clarke3ebd9772020-02-28 10:50:274243 client_data_header,
John Abd-El-Malek4f380d92020-02-19 16:43:364244#endif
Alex Clarke3ebd9772020-02-28 10:50:274245 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194246
Clark DuValla411bda2019-08-02 03:09:174247 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4248 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214249
Clark DuVall39c2cfc2019-06-25 21:49:284250#if BUILDFLAG(ENABLE_PLUGINS)
4251 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464252 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284253#endif
4254
Robbie McElrath127ad2b2019-07-22 22:38:114255 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404256 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584257 auto signin_throttle =
4258 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114259 if (signin_throttle)
4260 result.push_back(std::move(signin_throttle));
4261
Clark DuVallfffa41e2019-06-25 20:27:194262 return result;
4263}
4264
Ken Rockot6414c4d92017-11-08 19:58:324265void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464266 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324267 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414268#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464269 content::WebContents* web_contents =
4270 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414271#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324272 factories->emplace(
4273 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574274 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464275 web_contents->GetBrowserContext(),
4276 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414277#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4278#if defined(OS_CHROMEOS)
4279 Profile* profile =
4280 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304281 factories->emplace(content::kExternalFileScheme,
4282 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4283 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414284#endif // defined(OS_CHROMEOS)
4285#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324286}
4287
Ting Shao2dc60582019-07-15 04:43:364288void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344289 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4290 content::BrowserContext* browser_context,
4291 NonNetworkURLLoaderFactoryMap* factories) {
4292#if BUILDFLAG(ENABLE_EXTENSIONS)
4293 DCHECK(browser_context);
4294 DCHECK(factories);
4295 factories->emplace(
4296 extensions::kExtensionScheme,
4297 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4298 browser_context));
4299#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4300}
4301
4302void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364303 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4304 content::BrowserContext* browser_context,
4305 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114306#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364307 DCHECK(browser_context);
4308 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364309 factories->emplace(
4310 extensions::kExtensionScheme,
4311 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4312 browser_context));
4313#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364314}
4315
Jay Civelli2578ebe2018-06-05 18:44:314316namespace {
4317
4318// The FileURLLoaderFactory provided to the extension background pages.
4319// Checks with the ChildProcessSecurityPolicy to validate the file access.
4320class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4321 public:
4322 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4323
4324 private:
4325 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274326 void CreateLoaderAndStart(
4327 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4328 int32_t routing_id,
4329 int32_t request_id,
4330 uint32_t options,
4331 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304332 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274333 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4334 override {
Jay Civelli2578ebe2018-06-05 18:44:314335 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4336 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304337 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4338 ->OnComplete(
4339 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314340 return;
4341 }
Yutaka Hiranodf83dca42020-01-07 06:24:554342 content::CreateFileURLLoaderBypassingSecurityChecks(
4343 request, std::move(loader), std::move(client),
4344 /*observer=*/nullptr,
4345 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314346 }
4347
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524348 void Clone(
4349 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4350 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314351 }
4352
4353 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524354 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314355 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4356};
4357
4358} // namespace
4359
Ken Rockot6414c4d92017-11-08 19:58:324360void ChromeContentBrowserClient::
4361 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464362 int render_process_id,
4363 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324364 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414365#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4366 content::RenderFrameHost* frame_host =
4367 RenderFrameHost::FromID(render_process_id, render_frame_id);
4368 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4369#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4370
4371#if defined(OS_CHROMEOS)
4372 if (web_contents) {
4373 Profile* profile =
4374 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304375 factories->emplace(content::kExternalFileScheme,
4376 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4377 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414378 }
4379#endif // defined(OS_CHROMEOS)
4380
Ken Rockot6414c4d92017-11-08 19:58:324381#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464382 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4383 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324384 if (factory)
4385 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234386
4387 // This logic should match
4388 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314389 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234390 return;
Jay Civellic9bbf72d2018-03-24 01:58:314391
4392 Profile* profile =
4393 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4394 InstantService* instant_service =
4395 InstantServiceFactory::GetForProfile(profile);
4396 // The test below matches what's done by ShouldServiceRequestIOThread in
4397 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464398 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314399 factories->emplace(
4400 chrome::kChromeSearchScheme,
4401 content::CreateWebUIURLLoader(
4402 frame_host, chrome::kChromeSearchScheme,
4403 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234404 }
Jay Civellic9bbf72d2018-03-24 01:58:314405
Chris Mumfordbae8a742018-03-01 23:02:234406 extensions::ChromeExtensionWebContentsObserver* web_observer =
4407 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4408 web_contents);
4409
Karan Bhatia91928572018-03-06 01:18:074410 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4411 // to the |web_contents|.
4412 if (!web_observer)
4413 return;
4414
Chris Mumfordbae8a742018-03-01 23:02:234415 const Extension* extension =
4416 web_observer->GetExtensionFromFrame(frame_host, false);
4417 if (!extension)
4418 return;
4419
Sam McNally7414eeb72018-09-03 04:05:304420 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234421 // Support for chrome:// scheme if appropriate.
4422 if ((extension->is_extension() || extension->is_platform_app()) &&
4423 Manifest::IsComponentLocation(extension->location())) {
4424 // Components of chrome that are implemented as extensions or platform apps
4425 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304426 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4427 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4428 }
4429 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4430 (extension->is_platform_app() &&
4431 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234432 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024433 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4434 // URLs. Hosted apps are not allowed because they are served via web servers
4435 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304436 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4437 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024438 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304439 }
4440 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234441 factories->emplace(
4442 content::kChromeUIScheme,
4443 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4444 std::move(allowed_webui_hosts)));
4445 }
Jay Civelli2578ebe2018-06-05 18:44:314446
4447 // Extension with a background page get file access that gets approval from
4448 // ChildProcessSecurityPolicy.
4449 extensions::ExtensionHost* host =
4450 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4451 ->GetBackgroundHostForExtension(extension->id());
4452 if (host) {
4453 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4454 render_process_id));
4455 }
Chris Mumfordbae8a742018-03-01 23:02:234456#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324457}
4458
Ken Rockota0dfaca12018-02-15 07:26:254459bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214460 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254461 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384462 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444463 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264464 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004465 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424466 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184467 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4468 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334469 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084470 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334471 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014472 bool use_proxy = false;
4473
Ken Rockota0dfaca12018-02-15 07:26:254474#if BUILDFLAG(ENABLE_EXTENSIONS)
4475 auto* web_request_api =
4476 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214477 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254478
4479 // NOTE: Some unit test environments do not initialize
4480 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014481 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124482 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384483 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004484 browser_context, frame, render_process_id, type,
4485 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124486 if (bypass_redirect_checks)
4487 *bypass_redirect_checks = use_proxy_for_web_request;
4488 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014489 }
Ken Rockota0dfaca12018-02-15 07:26:254490#endif
Reilly Grant24bf8332018-08-27 21:55:014491
Reilly Grantcc22e602018-09-07 15:25:204492 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444493 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4494 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014495
dalyk0018c16f2020-01-08 20:20:084496#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4497 if (disable_secure_dns) {
4498 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4499 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014500 web_contents &&
4501 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4502 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084503 ->is_captive_portal_window();
4504 }
4505#endif
4506
Reilly Grant24bf8332018-08-27 21:55:014507 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254508}
4509
Jian Lide7b43792018-06-01 23:22:134510std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4511ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4512 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144513 int frame_tree_node_id,
4514 const scoped_refptr<network::SharedURLLoaderFactory>&
4515 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134516 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4517 interceptors;
4518#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234519 interceptors.push_back(
4520 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4521 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134522#endif
Ryan Sturmaf523742019-01-16 00:15:454523
Robert Ogden6946ad42020-01-13 18:01:304524 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4525 interceptors.push_back(
4526 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4527 frame_tree_node_id));
4528 }
4529
Jian Lide7b43792018-06-01 23:22:134530 return interceptors;
4531}
4532
Yutaka Hirano8e0b4d432019-07-04 07:12:384533bool ChromeContentBrowserClient::WillInterceptWebSocket(
4534 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334535#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384536 if (!frame) {
4537 return false;
4538 }
4539 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334540 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4541 frame->GetProcess()->GetBrowserContext());
4542
4543 // NOTE: Some unit test environments do not initialize
4544 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4545 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384546 return false;
Yutaka Hirano36c94952018-05-30 21:33:334547
Yutaka Hirano8e0b4d432019-07-04 07:12:384548 return web_request_api->MayHaveProxies();
4549#else
4550 return false;
4551#endif
4552}
4553
4554void ChromeContentBrowserClient::CreateWebSocket(
4555 content::RenderFrameHost* frame,
4556 WebSocketFactory factory,
4557 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394558 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384559 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404560 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4561 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384562#if BUILDFLAG(ENABLE_EXTENSIONS)
4563 if (!frame) {
4564 return;
4565 }
4566 auto* web_request_api =
4567 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4568 frame->GetProcess()->GetBrowserContext());
4569
4570 DCHECK(web_request_api);
4571 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394572 site_for_cookies.RepresentativeUrl(),
4573 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334574#endif
4575}
4576
Maks Orlovich710d5e32019-07-09 20:16:454577bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464578 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454579 content::BrowserContext* browser_context,
4580 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394581 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404582 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454583 bool is_service_worker,
4584 int process_id,
4585 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034586 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454587 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4588#if BUILDFLAG(ENABLE_EXTENSIONS)
4589 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464590 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454591 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404592 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4593 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454594 return true;
4595 }
4596#endif
4597 return false;
4598}
4599
Matt Menkeae4fdb12018-06-02 06:32:544600void ChromeContentBrowserClient::OnNetworkServiceCreated(
4601 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534602 PrefService* local_state;
4603 if (g_browser_process) {
4604 DCHECK(g_browser_process->local_state());
4605 local_state = g_browser_process->local_state();
4606 } else {
Xi Han85079c22019-04-18 21:43:054607 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4608 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534609 }
4610
4611 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4612 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4613
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494614 // Create SystemNetworkContextManager if it has not been created yet. We need
4615 // to set up global NetworkService state before anything else uses it and this
4616 // is the first opportunity to initialize SystemNetworkContextManager with the
4617 // NetworkService.
4618 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534619 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074620
Min Qin8caab1d2018-10-03 17:28:134621 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544622 network_service);
4623}
4624
Julie Jeongeun Kim5984e992019-09-11 11:00:464625mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254626ChromeContentBrowserClient::CreateNetworkContext(
4627 content::BrowserContext* context,
4628 bool in_memory,
4629 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504630 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454631 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254632}
4633
Robert Sesek34f68f312019-01-14 20:25:114634std::vector<base::FilePath>
4635ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024636 DCHECK(!network_contexts_parent_directory_.empty());
4637 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114638}
4639
Min Qin75ed6df2017-12-01 20:39:154640bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134641 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154642#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4643 // It is OK to load the saved offline copy, in MHTML format.
4644 ChromeNavigationUIData* chrome_navigation_ui_data =
4645 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4646 if (!chrome_navigation_ui_data)
4647 return false;
4648 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4649 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4650 return offline_page_data && offline_page_data->is_offline_page();
4651#else
4652 return false;
4653#endif
4654}
4655
Min Qin30a78a12017-12-06 01:29:134656bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4657 const GURL& url,
4658 const std::string& mime_type) {
4659#if BUILDFLAG(ENABLE_EXTENSIONS)
4660 // Special-case user scripts to get downloaded instead of viewed.
4661 return extensions::UserScript::IsURLUserScript(url, mime_type);
4662#else
4663 return false;
4664#endif
4665}
4666
Donna Wu838ac362018-08-10 10:36:334667void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344668 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044669 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:464670 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:344671 return;
Reilly Grantc31b8192017-12-15 19:54:344672
[email protected]95ebe7c2020-04-08 19:12:454673 CHECK(render_frame_host);
4674 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4675 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344676}
4677
Ovidio Henriquez3d729f62020-02-07 00:43:294678content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4679 if (!bluetooth_delegate_)
4680 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4681 return bluetooth_delegate_.get();
4682}
4683
Reilly Grant0d282322019-01-29 02:42:584684#if !defined(OS_ANDROID)
4685content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4686 if (!serial_delegate_)
4687 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4688 return serial_delegate_.get();
4689}
Matt Reynolds93616f9b2019-06-07 01:28:524690
4691content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4692 if (!hid_delegate_)
4693 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4694 return hid_delegate_.get();
4695}
Reilly Grant0d282322019-01-29 02:42:584696
Balazs Engedya7ff70982018-06-04 18:14:474697std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4698ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334699 content::RenderFrameHost* render_frame_host) {
4700 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4701 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474702}
Nina Satragno8c832df2019-07-29 15:59:394703#endif
Balazs Engedya7ff70982018-06-04 18:14:474704
Jun Cai9409ded2018-01-30 00:19:464705std::unique_ptr<net::ClientCertStore>
4706ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104707 content::BrowserContext* browser_context) {
4708 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464709 ->CreateClientCertStore();
4710}
4711
David Benjamineced01fc2019-02-27 18:29:024712std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394713ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584714 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024715 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034716 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244717 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394718 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034719 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394720 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564721 LoginAuthRequiredCallback auth_required_callback) {
Emily Starkf05b3122020-02-10 19:08:104722 return CreateLoginHandler(
David Benjamineced01fc2019-02-27 18:29:024723 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkf05b3122020-02-10 19:08:104724 std::move(response_headers), std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:394725}
4726
John Abd-El-Maleka67add82018-03-09 18:22:014727bool ChromeContentBrowserClient::HandleExternalProtocol(
4728 const GURL& url,
danakjf4b9e942019-11-29 15:43:044729 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014730 int child_id,
4731 content::NavigationUIData* navigation_data,
4732 bool is_main_frame,
4733 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454734 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454735 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104736 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014737#if BUILDFLAG(ENABLE_EXTENSIONS)
4738 // External protocols are disabled for guests. An exception is made for the
4739 // "mailto" protocol, so that pages that utilize it work properly in a
4740 // WebView.
4741 ChromeNavigationUIData* chrome_data =
4742 static_cast<ChromeNavigationUIData*>(navigation_data);
4743 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4744 (chrome_data &&
4745 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4746 !url.SchemeIs(url::kMailToScheme)) {
4747 return false;
4748 }
4749#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4750
4751#if defined(OS_ANDROID)
4752 // Main frame external protocols are handled by
4753 // InterceptNavigationResourceThrottle.
4754 if (is_main_frame)
4755 return false;
4756#endif // defined(ANDROID)
4757
Emily Stark13b66bdf2019-10-04 17:11:454758 base::PostTask(
4759 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044760 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4761 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014762 return true;
4763}
4764
Jennifer Apacible4f854a82018-04-06 22:22:114765std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284766ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4767 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114768 // Note: content::OverlayWindow::Create() is defined by platform-specific
4769 // implementation in chrome/browser/ui/views. This layering hack, which goes
4770 // through //content and ContentBrowserClient, allows us to work around the
4771 // dependency constraints that disallow directly calling
4772 // chrome/browser/ui/views code either from here or from other code in
4773 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284774 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114775}
4776
Kunihiko Sakamoto19aa7082019-02-25 03:14:434777void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564778 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114779 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564780 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434781 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4782 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564783}
4784
dbeam25472e0c2017-06-23 19:02:314785// Static; handles rewriting Web UI URLs.
4786bool ChromeContentBrowserClient::HandleWebUI(
4787 GURL* url,
4788 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394789 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314790 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394791 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314792 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4793 chrome::kChromeUIHelpHost);
4794 return true; // Return true to update the displayed URL.
4795 }
4796
Hector Carmona566a20b2019-09-13 22:44:424797#if defined(OS_WIN)
4798 // TODO(crbug.com/1003960): Remove when issue is resolved.
4799 if (url->SchemeIs(content::kChromeUIScheme) &&
4800 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4801 url::Replacements<char> replacements;
4802 replacements.SetHost(
4803 chrome::kChromeUIWelcomeHost,
4804 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4805 *url = url->ReplaceComponents(replacements);
4806 return true;
4807 }
4808#endif // defined(OS_WIN)
4809
dbeam25472e0c2017-06-23 19:02:314810 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4811 browser_context, *url)) {
4812 return false;
4813 }
4814
4815#if defined(OS_CHROMEOS)
4816 // Special case : in ChromeOS in Guest mode bookmarks and history are
4817 // disabled for security reasons. New tab page explains the reasons, so
4818 // we redirect user to new tab page.
4819 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4820 if (url->SchemeIs(content::kChromeUIScheme) &&
4821 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4822 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4823 // Rewrite with new tab URL
4824 *url = GURL(chrome::kChromeUINewTabURL);
4825 }
4826 }
4827#endif
4828
4829 return true;
4830}
4831
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064832bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
4833 content::BrowserContext* browser_context,
4834 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:324835 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064836#if defined(OS_ANDROID)
4837 return false;
4838#else
4839 payments::PaymentRequestDisplayManagerFactory::GetInstance()
4840 ->GetForBrowserContext(browser_context)
4841 ->ShowPaymentHandlerWindow(url, std::move(callback));
4842 return true;
4843#endif
4844}
4845
Dan Beam141c48932019-08-22 02:29:394846// static
dbeam25472e0c2017-06-23 19:02:314847bool ChromeContentBrowserClient::HandleWebUIReverse(
4848 GURL* url,
4849 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:424850#if defined(OS_WIN)
4851 // TODO(crbug.com/1003960): Remove when issue is resolved.
4852 // No need to actually reverse-rewrite the URL, but return true to update the
4853 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
4854 if (url->SchemeIs(content::kChromeUIScheme) &&
4855 url->host() == chrome::kChromeUIWelcomeHost) {
4856 return true;
4857 }
4858#endif // defined(OS_WIN)
4859
dbeam25472e0c2017-06-23 19:02:314860 // No need to actually reverse-rewrite the URL, but return true to update the
4861 // displayed URL when rewriting chrome://help to chrome://settings/help.
4862 return url->SchemeIs(content::kChromeUIScheme) &&
4863 url->host() == chrome::kChromeUISettingsHost;
4864}
4865
Alison Maher7f366dc62020-03-03 19:46:004866const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:584867 return ui::NativeTheme::GetInstanceForWeb();
4868}
4869
Clark DuVall5497288d2019-07-17 00:17:564870scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:504871ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:534872 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:354873 DCHECK_CURRENTLY_ON(BrowserThread::IO);
4874
Matt Menke562675cfe2020-01-07 15:50:534875 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:504876 return nullptr;
4877
Yuzhu Shen44094e22017-07-18 22:52:354878 // |safe_browsing_service_| may be unavailable in tests.
4879 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
4880 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:434881 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:354882 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:434883 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:354884 }
4885
Clark DuVall5497288d2019-07-17 00:17:564886 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:354887}
Daniel Vogelheim6008f572018-09-24 14:35:144888
4889base::Optional<std::string>
4890ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:594891 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:184892 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:594893 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
4894 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:144895}
Kunihiko Sakamoto73b803d2018-10-05 09:09:524896
Takashi Toyoshima5af383aa2019-07-22 15:24:224897bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:524898 // We require --user-data-dir flag too so that no dangerous changes are made
4899 // in the user's regular profile.
4900 return base::CommandLine::ForCurrentProcess()->HasSwitch(
4901 switches::kUserDataDir);
4902}
rajendrantfeea8592018-10-19 18:26:064903
4904void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
4905 int32_t network_traffic_annotation_id_hash,
4906 int64_t recv_bytes,
4907 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:034908 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
4909 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
4910 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
4911 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:064912 }
4913}
Ryan Sturmaa05092f2018-10-21 03:56:544914
Ken Rockot4e284d32020-03-06 06:26:494915base::FilePath
4916ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
4917 return g_browser_process->profile_manager()->user_data_dir();
4918}
4919
Ryan Sturmaa05092f2018-10-21 03:56:544920content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
4921 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:394922 content::NavigationHandle* navigation_handle,
4923 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:134924 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
4925 initial_state, navigation_handle, current_navigation_url);
4926
4927 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
4928}
4929
4930content::PreviewsState
4931ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
4932 content::PreviewsState initial_state,
4933 content::NavigationHandle* navigation_handle,
4934 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:544935 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:294936 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:214937
Ryan Sturmaa05092f2018-10-21 03:56:544938 // If this is not a main frame, return the initial state. If there are no
4939 // previews in the state, return the state as is.
4940 if (!navigation_handle->IsInMainFrame() ||
4941 navigation_handle->IsSameDocument()) {
4942 return initial_state;
4943 }
4944
Robert Ogdena994eb42019-02-14 19:15:084945 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:394946 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:084947
Doug Arnettb3b99bc2019-08-09 16:55:564948 // Check if initial state specifies no previews should be considered.
4949 if (initial_state == content::PREVIEWS_OFF)
4950 return initial_state;
4951
Robert Ogdena994eb42019-02-14 19:15:084952 // Do not allow previews on POST navigations since the primary opt-out
4953 // mechanism is to reload the page. Because POST navigations are not
4954 // idempotent, we do not want to show a preview on a POST navigation where
4955 // opting out would cause another navigation, i.e.: a reload.
4956 if (navigation_handle->IsPost())
4957 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:394958
4959 content::WebContents* web_contents = navigation_handle->GetWebContents();
4960 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
4961
Ryan Sturmda2a0e02018-10-25 01:52:214962 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:544963
4964 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
4965 Profile::FromBrowserContext(browser_context));
4966 auto* data_reduction_proxy_settings =
4967 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4968 browser_context);
4969 // If the profile does not support previews or Data Saver, do not turn on
4970 // Previews.
4971 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:354972 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:544973 return content::PREVIEWS_OFF;
4974 }
4975
4976 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:214977 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:544978 // If this tab does not have a PreviewsUITabHelper, no preview should be
4979 // served.
4980 if (!ui_tab_helper)
4981 return content::PREVIEWS_OFF;
4982
4983 DCHECK(!browser_context->IsOffTheRecord());
4984
4985 // Other previews objects should all exist and be initialized if we have made
4986 // it past earlier checks.
4987 previews::PreviewsDeciderImpl* previews_decider_impl =
4988 previews_service->previews_ui_service()->previews_decider_impl();
4989 DCHECK(previews_decider_impl);
4990
Ryan Sturm647d1d92018-11-07 15:41:394991 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:544992 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
4993
Ryan Sturm647d1d92018-11-07 15:41:394994 previews::PreviewsUserData* previews_data =
4995 ui_tab_helper->GetPreviewsUserData(navigation_handle);
4996
4997 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:314998 // previews) and cannot re-evaluate PreviewsState once previews triggering
4999 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375000 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315001 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395002 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375003 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395004 } else {
5005 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5006 navigation_handle, previews_decider_impl->GeneratePageId());
5007 }
5008
5009 DCHECK(previews_data);
5010
Robert Ogden01770b362019-05-22 17:36:435011 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5012 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435013 return content::ALL_SUPPORTED_PREVIEWS;
5014 }
5015
Ryan Sturmaa05092f2018-10-21 03:56:545016 bool is_reload =
5017 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5018
Ryan Sturm647d1d92018-11-07 15:41:395019 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515020 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395021
5022 // For now, treat server previews types as a single decision, and do not
5023 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5024 // header, nor does the plumbing exist to modify the PreviewsState within the
5025 // URLLoader.
Seanac57e9b92019-04-29 19:19:315026 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395027 // Copy the server state that was used before the redirect for the initial
5028 // URL.
Robert Ogden869986f2019-06-20 19:12:055029 previews_state |=
5030 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395031 } else {
Doug Arnetta3dc71582018-11-08 00:25:105032 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215033 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305034 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395035 previews_state |= server_previews_enabled_state;
5036 }
Ryan Sturmaa05092f2018-10-21 03:56:545037 }
5038
Sophie Changa71fa5d2019-11-19 23:53:515039 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545040 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315041 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355042 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5043 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545044
5045 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395046 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545047 return content::PREVIEWS_OFF;
5048 }
5049
5050 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395051 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545052 return content::PREVIEWS_NO_TRANSFORM;
5053 }
5054
5055 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395056 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5057 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545058 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395059 }
5060
5061 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5062 if (delegate) {
5063 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5064 }
Ryan Sturmaa05092f2018-10-21 03:56:545065
5066 // If the allowed previews are limited by the embedder, ensure previews honors
5067 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395068 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5069 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545070 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5071 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5072 previews_state = content::PREVIEWS_OFF;
5073 }
Ryan Sturm647d1d92018-11-07 15:41:395074 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545075 return previews_state;
5076}
5077
5078// static
5079content::PreviewsState
5080ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5081 const GURL& url,
5082 data_reduction_proxy::DataReductionProxyData* drp_data,
5083 previews::PreviewsUserData* previews_user_data,
5084 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055085 content::PreviewsState initial_state,
5086 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545087 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5088 if (!previews::HasEnabledPreviews(initial_state))
5089 return content::PREVIEWS_OFF;
5090
5091 // Check if the server sent a preview directive.
5092 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555093 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545094
Ryan Sturmaa05092f2018-10-21 03:56:545095 // Check the various other client previews types.
5096 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055097 previews_user_data, url, previews_state, previews_decider,
5098 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545099}
5100
5101content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5102 content::PreviewsState initial_state,
5103 content::NavigationHandle* navigation_handle,
5104 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135105 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5106 initial_state, navigation_handle, response_headers);
5107
5108 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5109}
5110
5111content::PreviewsState
5112ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5113 content::PreviewsState initial_state,
5114 content::NavigationHandle* navigation_handle,
5115 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5117 // Only support HTTP and HTTPS.
5118 if (navigation_handle->IsErrorPage() ||
5119 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5120 return content::PREVIEWS_OFF;
5121 }
5122
5123 // If this is not a main frame, return the initial state. If there are no
5124 // previews in the state, return the state as is.
5125 if (!previews::HasEnabledPreviews(initial_state) ||
5126 !navigation_handle->IsInMainFrame() ||
5127 navigation_handle->IsSameDocument()) {
5128 return initial_state;
5129 }
5130
5131 // WebContents that don't have a PreviewsUITabHelper are not supported.
5132 PreviewsUITabHelper* ui_tab_helper =
5133 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5134 if (!ui_tab_helper)
5135 return content::PREVIEWS_OFF;
5136
5137 // If we did not previously create a PreviewsUserData, do not go any further.
5138 previews::PreviewsUserData* previews_user_data =
5139 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5140 if (!previews_user_data)
5141 return content::PREVIEWS_OFF;
5142
5143 PreviewsService* previews_service =
5144 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5145 navigation_handle->GetWebContents()->GetBrowserContext()));
5146
5147 if (!previews_service || !previews_service->previews_ui_service())
5148 return content::PREVIEWS_OFF;
5149
5150// Check if offline previews are being used and set it in the user data.
5151#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5152 offline_pages::OfflinePageTabHelper* tab_helper =
5153 offline_pages::OfflinePageTabHelper::FromWebContents(
5154 navigation_handle->GetWebContents());
5155
Ryan Sturmfc7d92f2019-02-12 02:24:235156 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5157 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5158
5159 // If this is an offline page, but not a preview, then we should not attempt
5160 // any previews or surface the previews UI.
5161 if (is_offline_page && !is_offline_preview)
5162 return content::PREVIEWS_OFF;
5163
5164 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545165#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5166
5167 // Annotate request if no-transform directive found in response headers.
5168 if (response_headers &&
5169 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265170 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545171 }
5172
5173 previews::PreviewsDeciderImpl* previews_decider_impl =
5174 previews_service->previews_ui_service()->previews_decider_impl();
5175 DCHECK(previews_decider_impl);
5176
Clark DuVall9c5a72cc2018-10-25 01:29:215177 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5178 auto* settings =
5179 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5180 navigation_handle->GetWebContents()->GetBrowserContext());
5181 if (settings) {
5182 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5183 // does not yet have all the response information.
5184 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5185 response_headers);
5186 }
Ryan Sturmaa05092f2018-10-21 03:56:545187
5188 // Determine effective PreviewsState for this committed main frame response.
5189 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215190 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055191 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545192
5193 // Double check that we never serve a preview when we have a
5194 // cache-control:no-transform directive.
5195 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5196 !previews::HasEnabledPreviews(committed_state));
5197
Robert Ogdended292c6f2019-05-03 22:44:515198 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545199 previews_user_data->set_committed_previews_state(committed_state);
5200
5201 previews::PreviewsType committed_type =
5202 previews::GetMainFramePreviewsType(committed_state);
5203
5204 // Capture committed previews type, if any, in PreviewsUserData.
5205 // Note: this is for the subset of previews types that are decided upon
5206 // navigation commit. Previews types that are determined prior to
5207 // navigation (such as for offline pages or for redirecting to another
5208 // url), are not set here.
5209 previews_user_data->SetCommittedPreviewsType(committed_type);
5210
5211 // Log the commit decision.
5212 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5213 previews_decider_impl->LogPreviewDecisionMade(
5214 (previews_user_data->cache_control_no_transform_directive()
5215 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5216 : previews::PreviewsEligibilityReason::COMMITTED),
5217 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055218 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055219 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545220
5221 return committed_state;
5222}
Charlie Harrison650e11422018-12-04 00:37:265223
5224void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5225 content::RenderFrameHost* render_frame_host,
5226 blink::mojom::WebFeature feature) {
5227 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5228 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5229 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5230 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315231
5232 // For the SameSite-by-default-cookies related features, log
5233 // the site engagement score for the site whose cookie was blocked. This is to
5234 // gauge the user impact of the cookies being blocked.
5235 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265236}
Yutaka Hirano968d6252018-12-04 05:09:315237
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525238std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315239 return ::GetProduct();
5240}
5241
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525242std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315243 return ::GetUserAgent();
5244}
Sam McNallyd54e23f92019-01-16 04:42:395245
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525246blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175247 return ::GetUserAgentMetadata();
5248}
5249
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525250base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275251 // This icon is available on Android, but adds 19KiB to the APK. Since it
5252 // isn't used on Android we exclude it to avoid bloat.
5253#if !defined(OS_ANDROID)
5254 return base::Optional<gfx::ImageSkia>(
5255 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5256 IDR_PRODUCT_LOGO_256));
5257#else
5258 return base::nullopt;
5259#endif
5260}
5261
Sam McNallyd54e23f92019-01-16 04:42:395262bool ChromeContentBrowserClient::IsBuiltinComponent(
5263 content::BrowserContext* browser_context,
5264 const url::Origin& origin) {
5265#if BUILDFLAG(ENABLE_EXTENSIONS)
5266 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5267 browser_context, origin);
5268#else
5269 return false;
5270#endif
5271}
Oleg Davydov2cc0167b2019-02-05 14:32:485272
5273bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5274 const GURL& url,
5275 content::BrowserContext* context) {
5276 PolicyBlacklistService* service =
5277 PolicyBlacklistFactory::GetForBrowserContext(context);
5278
5279 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5280 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5281 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5282}
Dominic Mazzoni21fb0282019-02-13 18:32:475283
5284ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5285 content::BrowserContext* browser_context) {
5286 Profile* profile = Profile::FromBrowserContext(browser_context);
5287 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5288}
Eric Karld6cd75b2019-03-14 22:01:365289
5290#if defined(OS_ANDROID)
5291content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525292ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335293 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425294 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365295 return WideColorGamutHeuristic::kUseDisplay;
5296 }
Khushal1fc0da52019-10-09 00:38:565297
5298 if (display::Display::HasForceDisplayColorProfile() &&
5299 display::Display::GetForcedDisplayColorProfile() ==
5300 gfx::ColorSpace::CreateDisplayP3D65()) {
5301 return WideColorGamutHeuristic::kUseDisplay;
5302 }
5303
Eric Karld6cd75b2019-03-14 22:01:365304 return WideColorGamutHeuristic::kNone;
5305}
5306#endif
Ehsan Karamad91413d72019-03-22 16:37:485307
5308base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435309ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465310 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485311 base::flat_set<std::string> mime_types;
5312#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465313 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485314 for (const auto& pair : map)
5315 mime_types.insert(pair.first);
5316#endif
5317 return mime_types;
5318}
Yao Xiaod06607b2019-05-02 23:16:365319
5320void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5321 const content::WebContents* web_contents,
5322 const content::RenderFrameHost* frame_host,
5323 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525324 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365325 const ChromeSubresourceFilterClient* client =
5326 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5327 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045328 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365329 if (!user_gesture) {
5330 if (base::FeatureList::IsEnabled(
5331 blink::features::
5332 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5333 download_policy->SetDisallowed(
5334 content::NavigationDownloadType::kAdFrameNoGesture);
5335 } else {
5336 download_policy->SetAllowed(
5337 content::NavigationDownloadType::kAdFrameNoGesture);
5338 }
Yao Xiaod06607b2019-05-02 23:16:365339 }
5340 }
5341}
Jun Cai732a05e32019-05-29 19:34:195342
5343bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5344 content::BrowserContext* browser_context,
5345 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525346 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195347 const HostContentSettingsMap* const content_settings =
5348 HostContentSettingsMapFactory::GetForProfile(
5349 Profile::FromBrowserContext(browser_context));
5350
5351 if (content_settings->GetContentSetting(
5352 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455353 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195354 std::string()) == CONTENT_SETTING_BLOCK) {
5355 return true;
5356 }
5357
5358 return false;
5359}
5360
5361void ChromeContentBrowserClient::BlockBluetoothScanning(
5362 content::BrowserContext* browser_context,
5363 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525364 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195365 HostContentSettingsMap* const content_settings =
5366 HostContentSettingsMapFactory::GetForProfile(
5367 Profile::FromBrowserContext(browser_context));
5368
5369 content_settings->SetContentSettingDefaultScope(
5370 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455371 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195372 CONTENT_SETTING_BLOCK);
5373}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475374
5375bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5376#if defined(OS_ANDROID)
5377 return extra_icu::ModuleProvider::IsModuleInstalled();
5378#endif
5379 return false;
5380}
Guido Urdaneta4030d6a32019-10-17 09:38:165381
5382bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5383 content::BrowserContext* browser_context,
5384 const GURL& url,
5385 const GURL& site_for_cookies,
5386 const base::Optional<url::Origin>& top_frame_origin) {
5387 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5388 return CookieSettingsFactory::GetForProfile(
5389 Profile::FromBrowserContext(browser_context))
5390 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5391}
Sam Goto5cf068e82019-11-04 23:08:445392
5393#if !defined(OS_ANDROID)
5394void ChromeContentBrowserClient::FetchRemoteSms(
5395 content::BrowserContext* browser_context,
5396 const url::Origin& origin,
5397 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5398 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5399}
5400#endif
Roger Tawa03ffdbd2020-01-16 18:12:545401
5402void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5403 content::WebContents* web_contents,
5404 const GURL& url,
5405 const ui::ClipboardFormatType& data_type,
5406 const std::string& data,
5407 IsClipboardPasteAllowedCallback callback) {
5408#if BUILDFLAG(FULL_SAFE_BROWSING)
5409 // Safe browsing does not support images, so accept without checking.
5410 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5411 // types when it is implemented.
5412 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5413 std::move(callback).Run(ClipboardPasteAllowed(true));
5414 return;
5415 }
5416
5417 Profile* profile =
5418 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5419 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
5420 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(profile, url,
5421 &dialog_data)) {
5422 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5423 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5424 web_contents, std::move(dialog_data),
5425 base::BindOnce(
5426 [](IsClipboardPasteAllowedCallback callback,
5427 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5428 const safe_browsing::DeepScanningDialogDelegate::Result&
5429 result) {
5430 std::move(callback).Run(
5431 ClipboardPasteAllowed(result.text_results[0]));
5432 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245433 std::move(callback)),
5434 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545435 } else {
5436 std::move(callback).Run(ClipboardPasteAllowed(true));
5437 }
5438#else
5439 std::move(callback).Run(ClipboardPasteAllowed(true));
5440#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5441}
Lukasz Anforowicz4600ea32020-01-18 02:37:485442
Lukasz Anforowicz1feeba182020-03-16 20:32:025443void ChromeContentBrowserClient::
5444 LogUkmEventForCrossOriginFetchFromContentScript3(
5445 const std::string& isolated_world_host) {
5446#if BUILDFLAG(ENABLE_EXTENSIONS)
5447 const std::string& extension_id = isolated_world_host;
5448 ukm::SourceId source_id =
5449 ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id);
5450 if (source_id != ukm::kInvalidSourceId) {
5451 ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event(
5452 source_id);
5453 ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get());
5454 }
5455#endif
5456}
5457
Lukasz Anforowicz4600ea32020-01-18 02:37:485458#if BUILDFLAG(ENABLE_PLUGINS)
5459bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5460 const url::Origin& embedder_origin,
5461 const content::PepperPluginInfo& plugin_info) {
5462#if BUILDFLAG(ENABLE_PDF)
5463 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5464#if BUILDFLAG(ENABLE_EXTENSIONS)
5465 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5466 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5467 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5468 return true;
5469 }
5470#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5471
5472 // Allow embedding the internal PDF plugin in chrome://print.
5473 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5474 return true;
5475
5476 // Only allow the PDF plugin in the known, trustworthy origins that are
5477 // allowlisted above. See also https://crbug.com/520422 and
5478 // https://crbug.com/1027173.
5479 return false;
5480 }
5481#endif // BUILDFLAG(ENABLE_PDF)
5482
5483 return true;
5484}
5485#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565486
5487#if BUILDFLAG(ENABLE_VR)
5488content::XrIntegrationClient*
5489ChromeContentBrowserClient::GetXrIntegrationClient() {
5490 if (!xr_integration_client_)
5491 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5492 util::PassKey<ChromeContentBrowserClient>());
5493 return xr_integration_client_.get();
5494}
5495#endif // BUILDFLAG(ENABLE_VR)