blob: a483d02adcd01160bb8f111be067e314cc6e333f [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
Chris Hamiltonab4722122020-05-13 18:01:287#include <iterator>
bmcquade5d2d9cf32015-06-19 17:42:288#include <map>
[email protected]7c3228a2011-11-11 21:35:229#include <set>
[email protected]1033acd2012-02-08 08:46:2710#include <utility>
[email protected]7c3228a2011-11-11 21:35:2211#include <vector>
12
brettwf1958912015-10-07 19:43:1213#include "base/base_switches.h"
[email protected]317c58f02011-11-09 02:15:0314#include "base/bind.h"
estark3ba11132015-04-10 01:38:3315#include "base/bind_helpers.h"
[email protected]b80f68432011-05-02 17:22:3016#include "base/command_line.h"
Ken Rockot91c40da82019-08-12 20:07:1117#include "base/compiler_specific.h"
Will Harrisc196ed942019-08-03 03:45:3018#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2419#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0020#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1521#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5822#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2523#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1424#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3325#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3926#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0227#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3728#include "base/stl_util.h"
Aaron Tagliaboschi19ad8d32020-05-12 20:10:4429#include "base/strings/strcat.h"
[email protected]e7463412013-06-10 22:53:4630#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0331#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2832#include "base/strings/string_util.h"
33#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2034#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0335#include "base/system/sys_info.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3236#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4137#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1838#include "build/build_config.h"
Ken Rockot341089f2019-01-11 23:11:5839#include "chrome/app/chrome_content_browser_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4740#include "chrome/browser/accessibility/accessibility_labels_service.h"
41#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
Abigail Kleina81f2e22020-05-04 14:32:4142#include "chrome/browser/accessibility/caption_util.h"
michaeln96f887e22015-04-13 23:58:3143#include "chrome/browser/after_startup_task_utils.h"
Ovidio Henriquez3d729f62020-02-07 00:43:2944#include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h"
[email protected]b8148ac2011-07-13 22:03:2545#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3046#include "chrome/browser/browser_process.h"
msramek1c2b3ca2017-03-14 17:57:5647#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5148#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
[email protected]d5a74be2014-08-08 01:01:2749#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0950#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0851#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2252#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
53#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3054#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
55#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0656#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0857#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4958#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3159#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4560#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0161#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1962#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5363#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5264#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1065#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2766#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2767#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3468#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4269#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
70#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1671#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3672#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3673#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5674#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0475#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0576#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0777#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2378#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1079#include "chrome/browser/net/profile_network_context_service.h"
80#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5481#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0282#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5983#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5684#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0685#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5486#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5187#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5688#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4289#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1190#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4891#include "chrome/browser/plugins/plugin_utils.h"
Robert Ogdenea4ea7392020-01-25 01:44:5392#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3093#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]190e5e22013-07-27 05:59:2394#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4195#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5096#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0797#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:0198#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:1999#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54100#include "chrome/browser/previews/previews_service.h"
101#include "chrome/browser/previews/previews_service_factory.h"
102#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03103#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14104#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32105#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49106#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06107#include "chrome/browser/profiles/renderer_updater.h"
108#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56109#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
110#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44111#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40113#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45114#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31115#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
116#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24117#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43118#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00119#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40120#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35121#include "chrome/browser/safe_browsing/ui_manager.h"
122#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58123#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43124#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44125#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20126#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35127#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40128#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23129#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28130#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02131#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48132#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38133#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32134#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07135#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23136#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10137#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35138#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45139#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52140#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19141#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44142#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38143#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51144#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08145#include "chrome/browser/ui/browser_navigator.h"
146#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43147#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39148#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54149#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28150#include "chrome/browser/ui/login/login_tab_helper.h"
Makoto Shimazuc7502932018-08-15 02:12:56151#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25152#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44153#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58154#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50155#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01156#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45157#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53158#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25159#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59160#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23161#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22162#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01163#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48164#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51165#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14166#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22167#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30168#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02169#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50170#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34171#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37172#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12173#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12174#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22175#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32176#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38177#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28178#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02179#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09180#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47181#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37182#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18183#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30184#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12185#include "components/autofill/core/common/autofill_switches.h"
Clark DuVallf5189252020-04-15 22:33:34186#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53187#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51188#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49189#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44190#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04191#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48192#include "components/cloud_devices/common/cloud_devices_switches.h"
Clark DuVall84a33d612020-04-17 16:01:00193#include "components/content_settings/browser/tab_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16194#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09195#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16196#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52197#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45198#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08199#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03200#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54201#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28202#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43203#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09204#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03205#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24206#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32207#include "components/embedder_support/switches.h"
blundella5e3240a2016-01-05 11:30:43208#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01209#include "components/feature_engagement/public/feature_constants.h"
210#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malekcdb5b522020-05-26 22:41:03211#include "components/google/core/common/google_switches.h"
Alexandre Frechette572755b2019-02-13 22:30:20212#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53213#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16214#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12215#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
216#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
217#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06218#include "components/payments/content/payment_request_display_manager.h"
Chris Hamiltonab4722122020-05-13 18:01:28219#include "components/performance_manager/embedder/performance_manager_registry.h"
Clark DuValla11361ad32020-02-20 22:14:27220#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54221#include "components/permissions/quota_permission_context_impl.h"
Doug Turner9dcaf5962017-12-21 04:38:53222#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54223#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18224#include "components/policy/core/common/policy_service.h"
225#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26226#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54227#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08228#include "components/prefs/pref_service.h"
229#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21230#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54231#include "components/previews/content/previews_decider_impl.h"
232#include "components/previews/content/previews_ui_service.h"
233#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54234#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45235#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43236#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56237#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56238#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13239#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47240#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
241#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
242#include "components/safe_browsing/core/browser/url_checker_delegate.h"
243#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
244#include "components/safe_browsing/core/db/database_manager.h"
245#include "components/safe_browsing/core/features.h"
246#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58247#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Daniel Vogelheim6008f572018-09-24 14:35:14248#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49249#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48250#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49251#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23252#include "components/signin/public/identity_manager/identity_manager.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54253#include "components/site_isolation/preloaded_isolated_origins.h"
csharrisone985ebc2017-04-04 17:05:03254#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17255#include "components/translate/core/common/translate_switches.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02256#include "components/ukm/app_source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21257#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28258#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33259#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46260#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22261#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39262#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33263#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43264#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30265#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38266#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28267#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03268#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31269#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41270#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09271#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03272#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59273#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19274#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31275#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35276#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47277#include "content/public/browser/navigation_handle.h"
278#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11279#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50280#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30281#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33282#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05283#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54284#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34285#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48286#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27287#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13288#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08289#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19290#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21291#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23292#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43293#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18294#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56295#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40296#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02297#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18298#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57299#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23300#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44301#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31302#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05303#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56304#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43305#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59306#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48307#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30308#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28309#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18310#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04311#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31312#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44313#include "media/media_buildflags.h"
314#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12315#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42316#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52317#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08318#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53319#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51320#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58321#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23322#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46323#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57324#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48325#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14326#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38327#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19328#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02329#include "services/metrics/public/cpp/ukm_builders.h"
330#include "services/metrics/public/cpp/ukm_recorder.h"
Takashi Toyoshima128441462019-10-16 04:19:17331#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37332#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50333#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50334#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13335#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05336#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34337#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03338#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06339#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02340#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02341#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02342#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19343#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31344#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17345#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21346#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26347#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18348#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54349#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39350#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08351#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35352#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56353#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21354#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49355#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57356#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45357#include "url/gurl.h"
358#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26359
[email protected]b48c9182011-10-26 18:03:30360#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20361#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14362#include "base/win/win_util.h"
363#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38364#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36365#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18366#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38367#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25368#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38369#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30370#elif defined(OS_CHROMEOS)
Alice Boxhallda2659142020-05-14 06:04:37371#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42372#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30373#include "chrome/app/chrome_crash_reporter_client.h"
Aya ElAttareb5fee12020-05-05 08:56:05374#include "chrome/browser/browser_process.h"
hashimotoa53e7e82016-10-26 06:30:47375#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17376#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30377#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24378#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18379#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08380#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48381#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41382#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32383#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58384#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00385#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
386#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44387#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39388#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31389#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33390#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05391#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Pavol Marko230ea2c92017-12-03 22:35:44392#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34393#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10394#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36395#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27396#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31397#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10398#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21399#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10400#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50401#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05402#include "components/policy/core/common/policy_pref_names.h"
403#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07404#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58405#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50406#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26407#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30408#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09409#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35410#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23411#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45412#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47413#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20414#include "chrome/browser/android/app_hooks.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36415#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36416#include "chrome/browser/android/devtools_manager_delegate_android.h"
417#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
418#include "chrome/browser/android/service_tab_launcher.h"
419#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42420#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09421#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56422#include "chrome/browser/download/android/available_offline_content_provider.h"
423#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23424#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07425#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38426#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11427#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07428#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47429#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36430#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54431#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00432#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36433#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45434#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04435#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45436#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30437#elif defined(OS_POSIX)
438#include "chrome/browser/chrome_browser_main_posix.h"
439#endif
440
tmartinofb341882017-02-10 19:36:53441#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40442#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36443#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54444#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59445#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02446#include "chrome/browser/search/instant_service.h"
447#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46448#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51449#include "chrome/browser/ui/browser.h"
450#include "chrome/browser/ui/browser_finder.h"
451#include "chrome/browser/ui/browser_list.h"
452#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20453#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51454#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39455#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
456#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43457#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27458#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28459#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36460
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33461#if defined(OS_WIN) || defined(OS_MACOSX) || \
462 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52463#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12464#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52465#endif
466
Joshua Perazace68e2f2019-09-23 18:44:24467#if defined(OS_LINUX)
Rohit Rao92f84b6a2020-03-25 14:57:50468#include "components/crash/core/app/crash_switches.h"
469#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24470#endif
471
[email protected]a220b5932013-09-21 03:47:44472#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02473#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02474#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50475#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02476#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13477#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43478#endif
[email protected]b80f68432011-05-02 17:22:30479
Maggie Caia2f03f52019-04-02 02:13:28480// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
481// single navigation throttle to display the intent picker on all platforms.
482#if !defined(OS_ANDROID)
483#if defined(OS_CHROMEOS)
484#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51485#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28486#else
487#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
488#endif
489#endif
490
[email protected]e8b6ca02013-07-10 18:00:51491#if defined(TOOLKIT_VIEWS)
492#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
493#endif
494
estaded3aa0e82016-02-17 22:55:21495#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
496#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51497#endif
498
Mohsen Izadif1958f22019-01-18 20:29:31499#if defined(USE_OZONE)
500#include "ui/ozone/public/ozone_platform.h"
501#endif
502
[email protected]e8b6ca02013-07-10 18:00:51503#if defined(USE_X11)
504#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
505#endif
506
brettwab78fef2016-10-12 02:56:05507#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10508#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38509#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19510#endif
511
Nico Weberaf3b00b2017-09-11 17:58:17512#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55513#include "components/nacl/browser/nacl_browser.h"
514#include "components/nacl/browser/nacl_host_message_filter.h"
515#include "components/nacl/browser/nacl_process_host.h"
516#include "components/nacl/common/nacl_process_type.h"
517#include "components/nacl/common/nacl_switches.h"
518#endif
519
brettw00899e62016-11-12 02:10:17520#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05521#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20522#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27523#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23524#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32525#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51526#include "chrome/browser/extensions/user_script_listener.h"
527#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28528#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49529#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46530#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39531#include "components/guest_view/browser/guest_view_base.h"
532#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25533#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31534#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35535#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32536#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12537#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57538#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48539#include "extensions/browser/guest_view/web_view/web_view_guest.h"
540#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
541#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31542#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27543#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28544#include "extensions/common/extension.h"
545#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13546#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28547#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33548#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28549#include "extensions/common/permissions/permissions_data.h"
550#include "extensions/common/permissions/socket_permission.h"
551#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34552#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25553
brettw4b461082016-11-19 18:55:16554#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55555#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27556#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39557#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55558#endif
559
bauerb8f9c37742017-03-30 15:04:12560#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
561#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
562#endif
563
yilkal240b4f22019-11-27 19:09:06564#if defined(OS_CHROMEOS)
Anatoliy Potapchuk762c40d2020-05-11 15:10:37565#include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06566#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
567#endif // defined(OS_CHROMEOS)
568
thakis678822e2017-04-20 17:20:34569#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38570#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09571#endif
572
weilifabbf7572017-05-22 19:05:16573#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21574#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16575#endif
Lei Zhanga2fa14c2018-05-15 00:05:21576
Xiaohan Wanga4e41842018-06-26 18:45:10577#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49578#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26579#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10580#include "chrome/browser/media/widevine_hardware_caps_win.h"
581#include "third_party/widevine/cdm/widevine_cdm_common.h"
582#endif
583#endif
584
mmenkedb2637ff2017-03-30 23:59:42585#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
586#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
587#endif
588
Nico Weberbc5b06f2019-07-26 14:00:13589#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35590#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32591#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35592#endif
593
Jian Lide7b43792018-06-01 23:22:13594#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54595#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13596#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
597#endif
598
Will Cassella40837ba2019-07-01 21:32:00599#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43600#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
601#endif
602
John Lee0ee748bf2019-12-11 21:35:44603#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
604#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
605#endif
606
Roger Tawa03ffdbd2020-01-16 18:12:54607#if BUILDFLAG(FULL_SAFE_BROWSING)
608#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
609#endif
610
Alexander Cooperc8448702020-03-14 01:39:56611#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23612#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56613#endif
614
[email protected]c7abd422012-09-25 00:20:08615using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39616using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31617using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13618using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59619using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00620using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02621using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11622using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33623using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13624using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05625using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38626using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39627
[email protected]0daaebfe2014-03-15 00:09:05628#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20629using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05630#endif
631
brettw00899e62016-11-12 02:10:17632#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28633using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27634using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28635using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28636using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27637#endif
638
brettw4b461082016-11-19 18:55:16639#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55640using plugins::ChromeContentBrowserClientPluginsPart;
641#endif
642
[email protected]c5dbef02011-05-13 05:06:09643namespace {
644
Will Harris1b9b4152019-08-21 22:33:50645#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30646// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
647// running on Windows 10 1511 and above. See
648// https://blogs.windows.com/blog/tag/code-integrity-guard/.
649const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35650 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50651#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
652 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30653
Colin Blundell9ee731dd2020-01-23 10:42:38654// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
655// parameters.
656void HandleSSLErrorWrapper(
657 content::WebContents* web_contents,
658 int cert_error,
659 const net::SSLInfo& ssl_info,
660 const GURL& request_url,
661 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38662 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
663 Profile* profile =
664 Profile::FromBrowserContext(web_contents->GetBrowserContext());
665
666 // This can happen if GetBrowserContext no longer exists by the time this
667 // gets called (e.g. the SSL error was in a webview that has since been
668 // destroyed); if that's the case we don't need to handle the error (and will
669 // crash if we attempt to).
670 if (!profile)
671 return;
672
Colin Blundell27331f92020-02-05 21:13:01673 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51674
675#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
676 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
677#endif
678
Colin Blundell9ee731dd2020-01-23 10:42:38679 SSLErrorHandler::HandleSSLError(
680 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53681 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51682 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38683 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38684 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
685}
686
lazyboy5d5fede02016-03-10 04:10:14687enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53688 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14689 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53690
691 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14692 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53693
694 // An extension or app tried to load a resource of a different platform app in
695 // a tab.
696 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
697
698 // A non-app and non-extension page tried to load a platform app in a tab.
699 APP_LOADED_IN_TAB_SOURCE_OTHER,
700
lazyboy5d5fede02016-03-10 04:10:14701 APP_LOADED_IN_TAB_SOURCE_MAX
702};
703
Lei Zhang2cfceac2018-11-14 19:36:33704// Cached version of the locale so we can return the locale on the I/O
705// thread.
706std::string& GetIOThreadApplicationLocale() {
707 static base::NoDestructor<std::string> s;
708 return *s;
709}
710
[email protected]f8f93eb2012-09-25 03:06:24711// Returns a copy of the given url with its host set to given host and path set
712// to given path. Other parts of the url will be the same.
713GURL ReplaceURLHostAndPath(const GURL& url,
714 const std::string& host,
715 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05716 url::Replacements<char> replacements;
717 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
718 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24719 return url.ReplaceComponents(replacements);
720}
721
madfbd10852017-01-20 03:15:33722// Handles the rewriting of the new tab page URL based on group policy.
723bool HandleNewTabPageLocationOverride(
724 GURL* url,
725 content::BrowserContext* browser_context) {
726 if (!url->SchemeIs(content::kChromeUIScheme) ||
727 url->host() != chrome::kChromeUINewTabHost)
728 return false;
729
730 Profile* profile = Profile::FromBrowserContext(browser_context);
731 std::string ntp_location =
732 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
733 if (ntp_location.empty())
734 return false;
735
736 *url = GURL(ntp_location);
737 return true;
738}
739
Becca Hughesfe8c32c2018-03-21 13:36:56740#if !defined(OS_ANDROID)
741// Check if the current url is whitelisted based on a list of whitelisted urls.
742bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57743 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56744 // Only check on HTTP and HTTPS pages.
745 if (!current_url.SchemeIsHTTPOrHTTPS())
746 return false;
747
748 for (auto const& value : whitelisted_urls) {
749 ContentSettingsPattern pattern =
750 ContentSettingsPattern::FromString(value.GetString());
751 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
752 continue;
753 if (pattern.Matches(current_url))
754 return true;
755 }
756
757 return false;
758}
759
760// Check if autoplay is allowed by policy configuration.
761bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
762 PrefService* prefs) {
763 DCHECK(prefs);
764
765 // Check if we have globally allowed autoplay by policy.
766 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
767 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
768 return true;
769 }
770
771 if (!contents)
772 return false;
773
774 // Check if the current URL matches a URL pattern on the whitelist.
775 const base::ListValue* autoplay_whitelist =
776 prefs->GetList(prefs::kAutoplayWhitelist);
777 return autoplay_whitelist &&
778 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
779 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
780}
781#endif
782
Joshua Perazaf890e4b2019-01-03 19:19:02783#if defined(OS_ANDROID)
784int GetCrashSignalFD(const base::CommandLine& command_line) {
785 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
786}
787#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03788breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
789 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02790 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52791 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02792 {
793 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31794 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03795 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50796 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02797 crash_handler->StartUploaderThread();
798 return crash_handler;
799 }
800}
801
avi3ef9ec9e2014-12-22 22:50:17802int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24803 if (crash_reporter::IsCrashpadEnabled()) {
804 int fd;
805 pid_t pid;
806 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
807 }
808
[email protected]9de4da52014-05-24 12:26:50809 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39810 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
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("extension");
[email protected]a1733df2012-06-22 11:24:18814 return crash_handler->GetDeathSignalSocket();
815 }
816
817 std::string process_type =
818 command_line.GetSwitchValueASCII(switches::kProcessType);
819
[email protected]779dd282013-10-19 15:57:02820 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31821 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02822 if (!crash_handler)
823 crash_handler = CreateCrashHandlerHost(process_type);
824 return crash_handler->GetDeathSignalSocket();
825 }
[email protected]a1733df2012-06-22 11:24:18826
[email protected]779dd282013-10-19 15:57:02827 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31828 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02829 if (!crash_handler)
830 crash_handler = CreateCrashHandlerHost(process_type);
831 return crash_handler->GetDeathSignalSocket();
832 }
[email protected]a1733df2012-06-22 11:24:18833
[email protected]779dd282013-10-19 15:57:02834 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31835 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02836 if (!crash_handler)
837 crash_handler = CreateCrashHandlerHost(process_type);
838 return crash_handler->GetDeathSignalSocket();
839 }
[email protected]a1733df2012-06-22 11:24:18840
James Cook9207cc12017-10-19 17:08:39841 if (process_type == switches::kUtilityProcess) {
842 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
843 if (!crash_handler)
844 crash_handler = CreateCrashHandlerHost(process_type);
845 return crash_handler->GetDeathSignalSocket();
846 }
847
[email protected]a1733df2012-06-22 11:24:18848 return -1;
849}
Joshua Perazaf890e4b2019-01-03 19:19:02850#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18851
[email protected]eabbfb12013-04-05 23:28:35852void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52853 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33854 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35855}
856
estark3ba11132015-04-10 01:38:33857// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31858// SSLErrorHandler. Uses CertificateReportingService to send reports. The
859// service handles queueing and re-sending of failed reports. Each certificate
860// error creates a new instance of this class.
861class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33862 public:
meacerf43117a2016-12-27 21:02:31863 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12864 content::WebContents* web_contents)
865 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
866 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31867 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33868
869 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55870 void ReportInvalidCertificateChain(
871 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31872 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33873 }
874
875 private:
meacerf43117a2016-12-27 21:02:31876 CertificateReportingService* service_;
877
878 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33879};
880
brettw00899e62016-11-12 02:10:17881#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53882
883AppLoadedInTabSource ClassifyAppLoadedInTabSource(
884 const GURL& opener_url,
885 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58886 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
887 // The forbidden app URL was being opened by a non-extension page (e.g.
888 // http).
889 return APP_LOADED_IN_TAB_SOURCE_OTHER;
890 }
891
892 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53893 // The forbidden app URL was being opened by a different app or extension.
894 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
895 }
Lei Zhang7d0b0f42019-10-12 03:47:58896
897 // This platform app was trying to window.open() one of its own URLs.
898 if (opener_url ==
899 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
900 // Source was the background page.
901 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
902 }
903
904 // Source was a different page inside the app.
905 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53906}
[email protected]9c7656382014-08-08 21:02:30907
Charles Harrison34f67862017-08-22 01:04:17908// Returns true if there is is an extension matching |url| in
909// |opener_render_process_id| with APIPermission::kBackground.
910//
911// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
912// hosted app, even though normal extensions just use the host.
913bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35914 extensions::ProcessMap* process_map,
915 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17916 const GURL& url,
csharrison95f01e922017-04-24 18:52:35917 int opener_render_process_id) {
918 // Note: includes web URLs that are part of an extension's web extent.
919 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17920 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35921 return extension &&
922 extension->permissions_data()->HasAPIPermission(
923 APIPermission::kBackground) &&
924 process_map->Contains(extension->id(), opener_render_process_id);
925}
Kevin Marshall32f99d7e2017-07-11 23:17:46926
csharrison95f01e922017-04-24 18:52:35927#endif
928
Darin Fishere41aab52020-01-29 18:31:23929mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12930 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23931 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
932 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
933 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
934 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12935}
936
Julian Pastarmovb4773b82020-04-21 16:34:14937// Encapculates logic to determine if enterprise policies should be honored.
938// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
939// as a new central class to replace those checks is in the making.
940bool ShouldHonorPolicies() {
941#if defined(OS_WIN)
942 bool is_enterprise_version =
943 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
944 return base::win::IsEnrolledToDomain() ||
945 (base::win::IsDeviceRegisteredWithManagement() &&
946 is_enterprise_version);
947#else // defined(OS_WIN)
948 // TODO(pastarmovj): Replace this with check for MacOS and the new management
949 // service once it is ready.
950 return true;
951#endif // defined(OS_WIN)
952}
953
John Abd-El-Malek92bf3602019-07-31 02:25:48954void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04955 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48956 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45957 bool has_user_gesture,
958 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01959 // If there is no longer a WebContents, the request may have raced with tab
960 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04961 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01962 if (!web_contents)
963 return;
964
965 // Do not launch external requests attached to unswapped prerenders.
966 prerender::PrerenderContents* prerender_contents =
967 prerender::PrerenderContents::FromWebContents(web_contents);
968 if (prerender_contents) {
969 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:01970 return;
971 }
972
Robbie McElrath1294d242019-05-31 20:46:22973 // Do not launch external requests for schemes that have a handler registered.
974 ProtocolHandlerRegistry* protocol_handler_registry =
975 ProtocolHandlerRegistryFactory::GetForBrowserContext(
976 web_contents->GetBrowserContext());
977 if (protocol_handler_registry &&
978 protocol_handler_registry->IsHandledProtocol(url.scheme()))
979 return;
980
John Abd-El-Maleka67add82018-03-09 18:22:01981 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01982 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19983 PolicyBlacklistFactory::GetForBrowserContext(
984 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:14985 if (ShouldHonorPolicies() && service) {
John Abd-El-Maleka67add82018-03-09 18:22:01986 const policy::URLBlacklist::URLBlacklistState url_state =
987 service->GetURLBlacklistState(url);
988 is_whitelisted =
989 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
990 }
991
992 // If the URL is in whitelist, we launch it without asking the user and
993 // without any additional security checks. Since the URL is whitelisted,
994 // we assume it can be executed.
995 if (is_whitelisted) {
996 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
997 } else {
998 ExternalProtocolHandler::LaunchUrl(
999 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1000 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451001 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011002 }
1003}
1004
Yutaka Hirano968d6252018-12-04 05:09:311005std::string GetProduct() {
1006 return version_info::GetProductNameAndVersionForUserAgent();
1007}
1008
Lukasz Anforowicz60d1253d2019-05-08 16:31:371009void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1010 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1011 // For renderer and utility (e.g. NetworkService) processes the switch is the
1012 // only available source, so below the combined (pref/policy + cmdline)
1013 // allowlist of secure origins is injected into |cmdline| for these other
1014 // processes.
1015 std::vector<std::string> allowlist =
1016 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1017 if (!allowlist.empty()) {
1018 cmdline->AppendSwitchASCII(
1019 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1020 base::JoinString(allowlist, ","));
1021 }
1022}
1023
Will Harris1b9b4152019-08-21 22:33:501024#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301025// Returns the full path to |module_name|. Both dev builds (where |module_name|
1026// is in the current executable's directory) and proper installs (where
1027// |module_name| is in a versioned sub-directory of the current executable's
1028// directory) are supported. The identified file is not guaranteed to exist.
1029base::FilePath GetModulePath(base::StringPiece16 module_name) {
1030 base::FilePath exe_dir;
1031 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1032 DCHECK(has_path);
1033
1034 // Look for the module in a versioned sub-directory of the current
1035 // executable's directory and return the path if it can be read. This is the
1036 // expected location of modules for proper installs.
1037 const base::FilePath module_path =
1038 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1039 if (base::PathExists(module_path))
1040 return module_path;
1041
1042 // Otherwise, return the path to the module in the current executable's
1043 // directory. This is the expected location of modules for dev builds.
1044 return exe_dir.Append(module_name);
1045}
Will Harris1b9b4152019-08-21 22:33:501046#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1047 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301048
Lukasz Anforowicz7724d092019-10-03 23:50:211049void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281050 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1051 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211052 if (maybe_throttle)
1053 throttles->push_back(std::move(maybe_throttle));
1054}
1055
Chris Hamiltonab4722122020-05-13 18:01:281056void MaybeAddThrottles(
1057 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1058 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1059 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1060 std::make_move_iterator(additional.end()));
1061}
1062
Evan Stade1e71d6dd2019-10-29 03:04:491063// Returns whether |web_contents| is within a hosted app.
1064bool IsInHostedApp(WebContents* web_contents) {
1065#if BUILDFLAG(ENABLE_EXTENSIONS)
1066 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1067 return (browser &&
1068 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1069#else
1070 return false;
1071#endif
1072}
1073
Lily Chenc2c9e9f2019-12-05 19:55:311074void MaybeRecordSameSiteCookieEngagementHistogram(
1075 content::RenderFrameHost* render_frame_host,
1076 blink::mojom::WebFeature feature) {
1077 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1078 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1079 return;
1080 }
1081
1082 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1083 DCHECK(render_frame_host);
1084
1085 content::BrowserContext* browser_context =
1086 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1087 Profile* profile = Profile::FromBrowserContext(browser_context);
1088 SiteEngagementService* site_engagement_service =
1089 SiteEngagementService::Get(profile);
1090 if (!site_engagement_service)
1091 return;
1092
1093 blink::mojom::EngagementLevel engagement_level =
1094 site_engagement_service->GetEngagementLevel(
1095 render_frame_host->GetLastCommittedURL());
1096 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1097 UMA_HISTOGRAM_ENUMERATION(
1098 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1099 engagement_level);
1100 } else {
1101 UMA_HISTOGRAM_ENUMERATION(
1102 "Net.SameSiteBlockedCookieSiteEngagement."
1103 "CookieInsecureAndSameSiteNone",
1104 engagement_level);
1105 }
1106}
1107
[email protected]9dbfff12011-07-01 19:37:071108} // namespace
[email protected]c5dbef02011-05-13 05:06:091109
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441110// Generate a pseudo-random permutation of the following brand/version pairs:
1111// 1. The base project (i.e. Chromium)
1112// 2. The browser brand, if available
1113// 3. A randomized string containing escaped characters to ensure proper
1114// header parsing, along with an arbitrarily low version to ensure proper
1115// version checking.
1116blink::UserAgentBrandList GenerateBrandVersionList(
1117 int seed,
1118 base::Optional<std::string> brand,
1119 std::string major_version) {
1120 DCHECK_GE(seed, 0);
1121 const int npermutations = 6; // 3!
1122 int permutation = seed % npermutations;
1123
1124 // Pick a stable permutation seeded by major version number. any values here
1125 // and in order should be under three.
1126 const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
1127 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
1128 const std::vector<int> order = orders[permutation];
1129 DCHECK_EQ(6u, orders.size());
1130 DCHECK_EQ(3u, order.size());
1131
1132 const std::vector<std::string> escaped_chars = {"\\", "\"", ";"};
1133 std::string greasey_brand =
1134 base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]],
1135 "A", escaped_chars[order[2]], "Brand"});
1136
1137 blink::UserAgentBrandVersion greasey_bv = {greasey_brand, "99"};
1138 blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version};
1139
1140 blink::UserAgentBrandList greased_brand_version_list(3);
1141
1142 if (brand) {
1143 blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version};
1144
1145 greased_brand_version_list[order[0]] = greasey_bv;
1146 greased_brand_version_list[order[1]] = chromium_bv;
1147 greased_brand_version_list[order[2]] = brand_bv;
1148 } else {
1149 greased_brand_version_list[seed % 2] = greasey_bv;
1150 greased_brand_version_list[(seed + 1) % 2] = chromium_bv;
1151
1152 // If left, the last element would make a blank "" at the end of the header.
1153 greased_brand_version_list.pop_back();
1154 }
1155
1156 return greased_brand_version_list;
1157}
1158
1159const blink::UserAgentBrandList& GetBrandVersionList() {
1160 static const base::NoDestructor<blink::UserAgentBrandList>
1161 greased_brand_version_list([] {
1162 int major_version_number;
1163 std::string major_version = version_info::GetMajorVersionNumber();
1164 base::StringToInt(major_version, &major_version_number);
1165 base::Optional<std::string> brand;
1166#if !BUILDFLAG(CHROMIUM_BRANDING)
1167 brand = version_info::GetProductName();
1168#endif
1169 return GenerateBrandVersionList(major_version_number, brand,
1170 major_version);
1171 }());
1172 return *greased_brand_version_list;
1173}
1174
Yutaka Hirano968d6252018-12-04 05:09:311175std::string GetUserAgent() {
1176 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1177 if (command_line->HasSwitch(switches::kUserAgent)) {
1178 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1179 if (net::HttpUtil::IsValidHeaderValue(ua))
1180 return ua;
1181 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1182 }
1183
John Delaneyac24e572019-04-30 19:47:021184 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1185 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351186 command_line->HasSwitch(switches::kUseMobileUserAgent),
1187 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021188 }
1189
Yutaka Hirano968d6252018-12-04 05:09:311190 std::string product = GetProduct();
1191#if defined(OS_ANDROID)
1192 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1193 product += " Mobile";
1194#endif
1195 return content::BuildUserAgentFromProduct(product);
1196}
1197
Mike West6e4cbb32019-02-13 09:40:171198blink::UserAgentMetadata GetUserAgentMetadata() {
1199 blink::UserAgentMetadata metadata;
Aaron Tagliaboschi9f01b682020-05-05 21:03:171200
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441201 metadata.brand_version_list = GetBrandVersionList();
Mike Weste555be862019-02-20 16:17:301202 metadata.full_version = version_info::GetVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171203 metadata.platform = version_info::GetOSType();
Yoav Weiss4838f1b2020-04-30 21:37:001204 metadata.platform_version =
1205 content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude,
1206 content::IncludeAndroidModel::Exclude);
Aaron Tagliaboschi0585bc932020-05-08 20:03:171207 metadata.architecture = content::GetLowEntropyCpuArchitecture();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361208 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171209
Aaron Tagliaboschibe775e12019-12-09 19:33:041210 metadata.mobile = false;
1211#if defined(OS_ANDROID)
1212 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1213 switches::kUseMobileUserAgent);
1214#endif
1215
Mike West6e4cbb32019-02-13 09:40:171216 return metadata;
1217}
1218
Ran Jia96d43d42018-05-02 17:14:531219ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051220 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311221 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161222#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551223 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401224#endif
[email protected]1deace22013-05-22 06:14:461225
Ahmed Fakhryd70bf37b2018-04-04 17:07:241226#if defined(OS_CHROMEOS)
1227 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1228#endif // defined(OS_CHROMEOS)
1229
John Lee0ee748bf2019-12-11 21:35:441230#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1231 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1232#endif
1233
brettw00899e62016-11-12 02:10:171234#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131235 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271236#endif
bena06f7d62017-04-04 20:48:521237
Sigurdur Asgeirsson70696672019-02-08 16:14:511238 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401239}
1240
1241ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031242 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1243 delete extra_parts_[i];
1244 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401245}
1246
[email protected]bca18382012-06-25 19:15:231247// static
Chris Palmerac7d75642017-11-22 20:12:541248void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1249 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131250 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1251 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541252 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1253 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461254 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541255}
1256
1257// static
[email protected]37ca3fe02013-07-05 15:32:441258void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341259 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251260 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1261 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1262 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281263 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1264 // user policy in addition to the same named ones in Local State (which are
1265 // used for mapping the command-line flags).
1266 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1267 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571268 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401269 registry->RegisterDictionaryPref(
1270 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041271 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101272#if !defined(OS_ANDROID)
1273 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561274 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101275#endif
Takashi Toyoshima128441462019-10-16 04:19:171276 registry->RegisterListPref(prefs::kCorsMitigationList);
1277 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231278}
1279
[email protected]eabbfb12013-04-05 23:28:351280// static
1281void ChromeContentBrowserClient::SetApplicationLocale(
1282 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481283 // The common case is that this function is called early in Chrome startup
1284 // before any threads are created or registered. When there are no threads,
1285 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001286 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331287 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481288 return;
1289 }
1290
1291 // Otherwise we're being called to change the locale. In this case set it on
1292 // the IO thread.
thestig00844cea2015-09-08 21:44:521293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351294
Gabriel Charettee7cdc5cd2020-05-27 23:35:051295 content::GetIOThreadTaskRunner({})->PostTask(
1296 FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351297}
1298
Patrick Monette61dfef92019-05-30 23:06:271299std::unique_ptr<content::BrowserMainParts>
1300ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311301 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271302 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301303 // Construct the Main browser parts based on the OS type.
1304#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051305 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271306 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1307#elif defined(OS_MACOSX)
1308 main_parts =
1309 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1310#elif defined(OS_CHROMEOS)
1311 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1312 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261313#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271314 main_parts =
1315 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141316#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271317 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1318 startup_data_);
[email protected]b48c9182011-10-26 18:03:301319#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271320 main_parts =
1321 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041322#else
[email protected]b48c9182011-10-26 18:03:301323 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271324 main_parts =
1325 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301326#endif
1327
Xi Han9fd44002019-04-30 17:39:361328 bool add_profiles_extra_parts = true;
1329#if defined(OS_ANDROID)
1330 if (startup_data_->HasBuiltProfilePrefService())
1331 add_profiles_extra_parts = false;
1332#endif
1333 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271334 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031335
Xi Han9fd44002019-04-30 17:39:361336 // Construct additional browser parts. Stages are called in the order in
1337 // which they are added.
[email protected]c7480942011-11-08 19:18:271338#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221339#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
estaded3aa0e82016-02-17 22:55:211340 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
1341#else
riajiang7d6ec5c2017-01-25 16:40:331342 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351343#endif
1344#endif
1345
1346#if defined(OS_CHROMEOS)
1347 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331348 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221349#endif
[email protected]dc04be7c2012-03-15 23:57:491350
[email protected]e8b6ca02013-07-10 18:00:511351#if defined(USE_X11)
1352 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241353#endif
1354
Sigurdur Asgeirsson54b72702019-04-12 14:18:541355 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001356
Albert J. Wong59d85acb2017-08-10 00:50:571357 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571358
Sebastien Marchand8c0088102019-10-11 16:47:561359 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1360
Patrick Monette61dfef92019-05-30 23:06:271361 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041362
Zhenyao Mo73144652020-04-06 18:55:051363 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1364 // GpuDataManager initialization could pick up about:flags settings.
1365 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1366
[email protected]50462bf02011-11-21 19:13:311367 return main_parts;
[email protected]f967b722011-09-07 00:58:041368}
1369
michaeln96f887e22015-04-13 23:58:311370void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091371 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021372 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211373 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121374 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291375
Robert Sesek466e43e2019-08-19 22:02:021376 InitNetworkContextsParentDirectory();
1377
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291378 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1379 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311380}
1381
falkenb09d443f2016-04-07 12:36:121382bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1383 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1384}
1385
Gabriel Charettec8cca992017-08-10 18:21:491386void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1387 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1388}
1389
John Abd-El-Malek9d57f9c2019-02-20 18:50:041390bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361391 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041392}
1393
[email protected]e94bbcb2012-09-07 05:33:571394std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191395 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571396 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531397 std::string partition_id;
1398
1399 // The partition ID for webview guest processes is the string value of its
1400 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451401 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531402 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171403#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501404 // The partition ID for extensions with isolated storage is treated similarly
1405 // to the above.
1406 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1407 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1408 partition_id = site.spec();
1409#endif
[email protected]1bc28312012-11-08 08:31:531410
[email protected]056efdc2013-04-06 00:14:531411 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531412 return partition_id;
1413}
1414
1415bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1416 content::BrowserContext* browser_context,
1417 const std::string& partition_id) {
1418 // The default ID is empty and is always valid.
1419 if (partition_id.empty())
1420 return true;
1421
1422 return GURL(partition_id).is_valid();
1423}
1424
1425void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1426 content::BrowserContext* browser_context,
1427 const GURL& site,
[email protected]14acc642012-11-17 12:20:101428 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531429 std::string* partition_domain,
1430 std::string* partition_name,
1431 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101432 // Default to the browser-wide storage partition and override based on |site|
1433 // below.
1434 partition_domain->clear();
1435 partition_name->clear();
1436 *in_memory = false;
1437
brettw00899e62016-11-12 02:10:171438#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451439 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331440 site, partition_domain, partition_name, in_memory);
1441
1442 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101443 // If |can_be_default| is false, the caller is stating that the |site|
1444 // should be parsed as if it had isolated storage. In particular it is
1445 // important to NOT check ExtensionService for the is_storage_isolated()
1446 // attribute because this code path is run during Extension uninstall
1447 // to do cleanup after the Extension has already been unloaded from the
1448 // ExtensionService.
1449 bool is_isolated = !can_be_default;
1450 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341451 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1452 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101453 }
[email protected]1bc28312012-11-08 08:31:531454
[email protected]14acc642012-11-17 12:20:101455 if (is_isolated) {
1456 CHECK(site.has_host());
1457 // For extensions with isolated storage, the the host of the |site| is
1458 // the |partition_domain|. The |in_memory| and |partition_name| are only
1459 // used in guest schemes so they are cleared here.
1460 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531461 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101462 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531463 }
[email protected]1df3d972014-06-11 04:55:181464 success = true;
1465 }
1466#endif
1467
[email protected]14acc642012-11-17 12:20:101468 // Assert that if |can_be_default| is false, the code above must have found a
1469 // non-default partition. If this fails, the caller has a serious logic
1470 // error about which StoragePartition they expect to be in and it is not
1471 // safe to continue.
1472 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441473}
1474
[email protected]38b098f2012-03-14 21:11:571475content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441476ChromeContentBrowserClient::GetWebContentsViewDelegate(
1477 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101478 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321479}
1480
Bo Liu4ade6b1b22017-11-28 02:26:351481bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1482#if defined(OS_ANDROID)
1483 const base::android::ApplicationState app_state =
1484 base::android::ApplicationStatusListener::GetState();
1485 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1486 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1487 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1488#else
1489 return true;
1490#endif
1491}
1492
[email protected]6f2862742013-12-20 07:53:191493void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231494 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301495 int id = host->GetID();
1496 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341497#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491498 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061499#endif
Brett Wilson65f951c2016-11-03 22:06:121500#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401501 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031502#endif
Darin Fisher54cba872020-02-06 21:12:551503 host->AddFilter(new prerender::PrerenderMessageFilter(id));
Darin Fisher8c84328c2019-07-23 02:50:001504
Darin Fisher09aa7222019-08-29 09:27:361505 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001506 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021507
grunell086a4112017-03-02 09:23:041508 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1509 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021510 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121511 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021512 host->SetUserData(
1513 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091514 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021515 audio_debug_recordings_handler));
1516
Nico Weberaf3b00b2017-09-11 17:58:171517#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031518 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1519 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351520#endif
jeremyim364ac1182015-03-03 18:49:431521
Xiaohan Wang9b34281b2017-09-08 23:48:331522#if defined(OS_ANDROID)
1523 // Data cannot be persisted if the profile is off the record.
1524 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061525 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071526
1527 // Register CrashMemoryMetricsCollector to report oom related metrics.
1528 host->SetUserData(
1529 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1530 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331531#endif
1532
Jun Caidb3f93cc2018-07-09 21:54:551533 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061534 RendererUpdaterFactory::GetForProfile(original_profile)
1535 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071536
[email protected]a48ab7112014-08-01 16:48:031537 for (size_t i = 0; i < extra_parts_.size(); ++i)
1538 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141539}
1540
[email protected]3d7474ff2011-07-27 17:47:371541GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571542 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301543 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371544 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521545 if (!profile)
1546 return url;
1547
Marc Treib7d467b792017-12-04 13:31:031548#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291549 // If the input |url| should be assigned to the Instant renderer, make its
1550 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311551 // This needs to happen even if |url| corresponds to an isolated origin; see
1552 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131553 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1554 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031555#endif
[email protected]b3cb3a32013-07-31 01:32:291556
brettw00899e62016-11-12 02:10:171557#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301558 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1559 url);
[email protected]d5a74be2014-08-08 01:01:271560#else
1561 return url;
1562#endif
[email protected]36fb2c7c2011-04-04 15:49:081563}
1564
Alexander Yashkin6aedc6e2018-08-15 08:58:451565bool ChromeContentBrowserClient::
1566 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1567 content::BrowserContext* browser_context,
1568 content::SiteInstance* candidate_site_instance,
1569 bool is_main_frame,
1570 const GURL& candidate_url,
1571 const GURL& destination_url) {
1572 DCHECK(browser_context);
1573 DCHECK(candidate_site_instance);
1574#if BUILDFLAG(ENABLE_EXTENSIONS)
1575 return ChromeContentBrowserClientExtensionsPart::
1576 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1577 browser_context, candidate_site_instance, is_main_frame,
1578 candidate_url, destination_url);
1579#else
1580 return true;
1581#endif
1582}
1583
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521584bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411585#if defined(OS_ANDROID)
1586 return true;
1587#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421588 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411589#else
1590 return false;
1591#endif // defined(OS_ANDROID)
1592}
1593
[email protected]056ad2a2011-07-12 02:13:551594bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441595 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591596 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521597 Profile* profile = Profile::FromBrowserContext(browser_context);
1598 if (!profile)
1599 return false;
1600
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301601 // NTP should use process-per-site. This is a performance optimization to
1602 // reduce process count associated with NTP tabs.
Aaron Colwellabb540b2020-05-05 19:15:591603 if (site_url == GURL(chrome::kChromeUINewTabURL))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301604 return true;
Peter Boström8e9b1632019-08-22 23:12:471605
1606 // The web footer experiment should share its renderer to not effectively
1607 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591608 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471609 return true;
1610
Marc Treib7d467b792017-12-04 13:31:031611#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591612 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521613 return true;
Marc Treib7d467b792017-12-04 13:31:031614#endif
[email protected]c5dec6292013-01-25 04:54:521615
brettw00899e62016-11-12 02:10:171616#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301617 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591618 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301619 return true;
[email protected]d5a74be2014-08-08 01:01:271620#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301621
1622 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1623 // (rather than process-per-site).
1624 return false;
[email protected]056ad2a2011-07-12 02:13:551625}
1626
Lukasz Anforowicz32d27122018-04-09 21:48:331627bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1628 content::BrowserContext* browser_context,
1629 const GURL& site_url) {
1630 Profile* profile = Profile::FromBrowserContext(browser_context);
1631 if (!profile)
1632 return false;
1633
1634#if !defined(OS_ANDROID)
1635 // Instant renderers should not use a spare process, because they require
1636 // passing switches::kInstantProcess to the renderer process when it
1637 // launches. A spare process is launched earlier, before it is known which
1638 // navigation will use it, so it lacks this flag.
1639 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1640 return false;
1641#endif
1642
1643#if BUILDFLAG(ENABLE_EXTENSIONS)
1644 return ChromeContentBrowserClientExtensionsPart::
1645 ShouldUseSpareRenderProcessHost(profile, site_url);
1646#else
1647 return true;
1648#endif
1649}
1650
nickcc0d9142015-10-14 16:27:101651bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421652 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101653 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421654 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171655#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101656 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421657 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101658 return true;
1659 }
1660#endif
1661 return false;
1662}
1663
nick7d0984c2015-08-29 00:13:461664// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1665// origin-lock enforcement, where we don't have a way to efficiently know
1666// effective URLs on the IO thread, and wind up killing processes that e.g.
1667// request cookies for their actual URL. This whole function (and its
1668// ExtensionsPart) should be removed once we add that ability to the IO thread.
1669bool ChromeContentBrowserClient::ShouldLockToOrigin(
1670 content::BrowserContext* browser_context,
1671 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171672#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461673 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1674 browser_context, effective_site_url)) {
1675 return false;
1676 }
1677#endif
1678 return true;
creise5d6d1732015-08-25 19:47:061679}
1680
Nasko Oskov39023672020-05-06 17:31:141681bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1682 base::StringPiece scheme) {
1683 // Note: This method can be called from multiple threads. It is not safe to
1684 // assume it runs only on the UI thread.
1685
1686 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371687 // locked to chrome-search: origin. Locking to chrome-search would kill
1688 // processes upon legitimate requests for cookies from the search engine's
1689 // domain.
Nasko Oskov39023672020-05-06 17:31:141690 if (scheme == chrome::kChromeSearchScheme)
1691 return false;
1692
1693 // All other WebUIs must be locked to origin.
1694 return true;
1695}
1696
Maks Orlovich0e23e312019-07-16 13:13:561697bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021698 base::StringPiece scheme,
1699 bool is_embedded_origin_secure) {
1700 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1701 return true;
Maks Orlovich0e23e312019-07-16 13:13:561702#if BUILDFLAG(ENABLE_EXTENSIONS)
1703 return scheme == extensions::kExtensionScheme;
1704#else
1705 return false;
1706#endif
1707}
1708
Lily Chen0db055b2019-11-15 20:29:021709bool ChromeContentBrowserClient::
1710 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1711 base::StringPiece scheme,
1712 bool is_embedded_origin_secure) {
1713 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1714}
1715
Xiaohan Wang15a07af2020-05-28 23:24:551716// TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle()
1717// implementation. Find a general solution to avoid code duplication.
1718std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess(
1719 content::BrowserContext* browser_context,
1720 const GURL& site_url) {
1721 // By default, use the |site_url| spec as the display name.
1722 std::string name = site_url.spec();
1723
1724#if BUILDFLAG(ENABLE_EXTENSIONS)
1725 // If |site_url| wraps a chrome extension ID, we can display the extension
1726 // name instead, which is more human-readable.
1727 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
1728 const extensions::Extension* extension =
1729 extensions::ExtensionRegistry::Get(browser_context)
1730 ->enabled_extensions()
1731 .GetExtensionOrAppByURL(site_url);
1732 if (extension)
1733 name = extension->name();
1734 }
1735#endif // BUILDFLAG(ENABLE_EXTENSIONS)
1736
1737 return name;
1738}
1739
Lukasz Anforowicz7097890d2019-11-20 21:49:221740void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021741 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591742 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021743 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221744 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071745#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221746 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021747 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071748#endif
1749}
1750
[email protected]73b718f2014-01-27 02:59:461751// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1752// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411753void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1754 std::vector<std::string>* additional_schemes) {
1755 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241756 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351757 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061758}
1759
alexmos94875b3b2017-03-16 22:19:011760void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1761 std::vector<std::string>* additional_schemes) {
1762 GetAdditionalWebUISchemes(additional_schemes);
1763
1764#if BUILDFLAG(ENABLE_EXTENSIONS)
1765 additional_schemes->push_back(extensions::kExtensionScheme);
1766#endif
1767}
1768
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521769bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011770 return webui::LogWebUIUrl(web_ui_url);
1771}
1772
John Abd-El-Malek04bfa8532018-07-12 05:28:221773bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1774 const url::Origin& origin) {
1775 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1776 origin);
1777}
1778
[email protected]46fb9442011-12-09 17:57:471779bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1780 return ProfileIOData::IsHandledURL(url);
1781}
1782
[email protected]c4365fa42013-05-14 01:08:241783bool ChromeContentBrowserClient::CanCommitURL(
1784 content::RenderProcessHost* process_host,
1785 const GURL& url) {
brettw00899e62016-11-12 02:10:171786#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441787 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1788 url);
[email protected]d5a74be2014-08-08 01:01:271789#else
1790 return true;
1791#endif
[email protected]c4365fa42013-05-14 01:08:241792}
1793
rdevlin.cronina32a0902016-11-09 15:50:201794void ChromeContentBrowserClient::OverrideNavigationParams(
1795 SiteInstance* site_instance,
1796 ui::PageTransition* transition,
1797 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581798 content::Referrer* referrer,
1799 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201800 DCHECK(transition);
1801 DCHECK(is_renderer_initiated);
1802 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471803 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1804 // use for making security decisions 99.44% of the time, for detecting the NTP
1805 // it is reliable and the correct way. See http://crbug.com/624410.
1806 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201807 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581808 // Clicks on tiles of the new tab page should be treated as if a user
1809 // clicked on a bookmark. This is consistent with native implementations
1810 // like Android's. This also helps ensure that security features (like
1811 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1812 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201813 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1814 *is_renderer_initiated = false;
1815 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581816 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421817 }
1818}
1819
Charles Reis29e9dd12017-09-28 00:59:151820bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1821 const GURL& url,
1822 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471823 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1824 // use for making security decisions 99.44% of the time, for detecting the NTP
1825 // it is reliable and the correct way. See http://crbug.com/624410.
1826 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1827 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151828}
1829
[email protected]2a5221b2011-09-27 23:07:311830bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301831 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311832 const GURL& site_url) {
1833 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301834 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441835 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521836 // share any host.
1837 if (!profile)
1838 return true;
1839
Marc Treib7895941d2017-11-28 12:37:021840#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141841 // Instant URLs should only be in the instant process and instant process
1842 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521843 InstantService* instant_service =
1844 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141845 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441846 bool is_instant_process =
1847 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141848 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131849 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141850 if (is_instant_process || should_be_in_instant_process)
1851 return is_instant_process && should_be_in_instant_process;
1852 }
Marc Treib7895941d2017-11-28 12:37:021853#endif
[email protected]c5dec6292013-01-25 04:54:521854
brettw00899e62016-11-12 02:10:171855#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131856 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1857 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271858#else
1859 return true;
1860#endif
[email protected]2a5221b2011-09-27 23:07:311861}
1862
[email protected]28c5d0b72014-05-13 08:19:591863bool ChromeContentBrowserClient::MayReuseHost(
1864 content::RenderProcessHost* process_host) {
1865 // If there is currently a prerender in progress for the host provided,
1866 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041867 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591868 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371869 prerender::PrerenderManagerFactory::GetForBrowserContext(
1870 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591871 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491872 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591873 return false;
1874 }
1875
1876 return true;
1877}
1878
[email protected]76411f412012-02-22 18:56:061879bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441880 content::BrowserContext* browser_context,
1881 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061882 // It has to be a valid URL for us to check for an extension.
1883 if (!url.is_valid())
1884 return false;
1885
brettw00899e62016-11-12 02:10:171886#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061887 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131888 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441889 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271890#else
1891 return false;
1892#endif
[email protected]76411f412012-02-22 18:56:061893}
1894
Alex Moshchuk9c9e3882018-11-02 19:57:031895bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1896 content::RenderFrameHost* main_frame) {
1897#if BUILDFLAG(ENABLE_EXTENSIONS)
1898 return ChromeContentBrowserClientExtensionsPart::
1899 ShouldSubframesTryToReuseExistingProcess(main_frame);
1900#else
1901 return true;
1902#endif
1903}
1904
[email protected]6f371442011-11-09 06:45:461905void ChromeContentBrowserClient::SiteInstanceGotProcess(
1906 SiteInstance* site_instance) {
1907 CHECK(site_instance->HasProcess());
1908
Aran Gilmanf010bdd2019-08-28 19:55:441909 Profile* profile =
1910 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521911 if (!profile)
1912 return;
1913
Marc Treib7895941d2017-11-28 12:37:021914#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521915 // Remember the ID of the Instant process to signal the renderer process
1916 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131917 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1918 profile)) {
[email protected]c5dec6292013-01-25 04:54:521919 InstantService* instant_service =
1920 InstantServiceFactory::GetForProfile(profile);
1921 if (instant_service)
1922 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1923 }
Marc Treib7895941d2017-11-28 12:37:021924#endif
[email protected]c5dec6292013-01-25 04:54:521925
[email protected]a48ab7112014-08-01 16:48:031926 for (size_t i = 0; i < extra_parts_.size(); ++i)
1927 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461928}
1929
1930void ChromeContentBrowserClient::SiteInstanceDeleting(
1931 SiteInstance* site_instance) {
1932 if (!site_instance->HasProcess())
1933 return;
1934
[email protected]a48ab7112014-08-01 16:48:031935 for (size_t i = 0; i < extra_parts_.size(); ++i)
1936 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461937}
1938
[email protected]453f5432013-11-26 19:43:001939bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141940 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561941 const GURL& current_effective_url,
1942 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171943#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131944 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561945 ShouldSwapBrowsingInstancesForNavigation(
1946 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271947#else
1948 return false;
1949#endif
[email protected]e3daf3c2011-10-05 21:17:081950}
1951
Nasko Oskovd83b5712018-05-04 04:50:571952bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1953 // TODO(nasko): Consider supporting error page isolation in subframes if
1954 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381955 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571956}
1957
[email protected]3d831992013-07-04 01:13:291958bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1959 return !url.SchemeIs(chrome::kChromeNativeScheme);
1960}
1961
Alex Moshchukd252c192017-07-17 22:03:481962std::vector<url::Origin>
1963ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1964 std::vector<url::Origin> isolated_origin_list;
1965
Alex Moshchuk89352a72017-10-25 20:25:591966// Sign-in process isolation is not needed on Android, see
1967// https://crbug.com/739418.
1968#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381969 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121970 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591971#endif
Alex Moshchukd252c192017-07-17 22:03:481972
Alex Moshchuk81d2a29e2019-07-16 01:14:381973#if BUILDFLAG(ENABLE_EXTENSIONS)
1974 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1975 GetOriginsRequiringDedicatedProcess();
1976 std::move(std::begin(origins_from_extensions),
1977 std::end(origins_from_extensions),
1978 std::back_inserter(isolated_origin_list));
1979#endif
1980
Alex Moshchuk51e1428b2020-04-22 18:00:541981 // Include additional origins preloaded with specific browser configurations,
1982 // if any. For example, this is used on Google Chrome for Android to preload
1983 // a list of important sites to isolate.
1984 auto built_in_origins =
1985 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
1986 std::move(std::begin(built_in_origins), std::end(built_in_origins),
1987 std::back_inserter(isolated_origin_list));
1988
Alex Moshchukd252c192017-07-17 22:03:481989 return isolated_origin_list;
1990}
1991
Lukasz Anforowicz5e201abd2018-03-24 00:41:061992bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341993 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1994}
1995
1996bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371997 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061998}
1999
Alex Moshchuk082b5f82019-03-14 01:34:162000std::vector<std::string>
2001ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
2002 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
2003 return {"Isolate Password Sites"};
2004 else
2005 return {};
2006}
2007
Alex Moshchuke256d562019-04-26 21:43:572008void ChromeContentBrowserClient::PersistIsolatedOrigin(
2009 content::BrowserContext* context,
2010 const url::Origin& origin) {
2011 DCHECK(!context->IsOffTheRecord());
2012 Profile* profile = Profile::FromBrowserContext(context);
2013 ListPrefUpdate update(profile->GetPrefs(),
2014 prefs::kUserTriggeredIsolatedOrigins);
2015 base::ListValue* list = update.Get();
2016 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:362017 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:122018 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:572019}
2020
Ken Rockot314714c2017-11-05 23:36:242021bool ChromeContentBrowserClient::IsFileAccessAllowed(
2022 const base::FilePath& path,
2023 const base::FilePath& absolute_path,
2024 const base::FilePath& profile_path) {
2025 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2026 profile_path);
2027}
2028
[email protected]d2e1a0a2014-06-16 15:49:372029namespace {
2030
2031bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:172032 const base::CommandLine& browser_command_line =
2033 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:352034 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372035 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:352036 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372037 return false;
[email protected]9ef49b42014-08-07 16:44:242038 return true;
[email protected]d2e1a0a2014-06-16 15:49:372039}
2040
bmcquade5d2d9cf32015-06-19 17:42:282041void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2042 const base::CommandLine& browser_command_line,
2043 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522044 // List of field trials that modify the blink-settings command line flag. No
2045 // two field trials in the list should specify the same keys, otherwise one
2046 // field trial may overwrite another. See Source/core/frame/Settings.in in
2047 // Blink for the list of valid keys.
2048 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162049 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2050 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2051 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2052 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522053 };
2054
2055 std::vector<std::string> blink_settings;
2056 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2057 // Each blink-settings field trial should include a forcing_flag group,
2058 // to make sure that clients that specify the blink-settings flag on the
2059 // command line are excluded from the experiment groups. To make
2060 // sure we assign clients that specify this flag to the forcing_flag
2061 // group, we must call GetVariationParams for each field trial first
2062 // (for example, before checking HasSwitch() and returning), since
2063 // GetVariationParams has the side-effect of assigning the client to
2064 // a field trial group.
2065 std::map<std::string, std::string> params;
2066 if (variations::GetVariationParams(field_trial_name, &params)) {
2067 for (const auto& param : params) {
2068 blink_settings.push_back(base::StringPrintf(
2069 "%s=%s", param.first.c_str(), param.second.c_str()));
2070 }
2071 }
2072 }
pmeenan9ac669682015-08-17 14:57:032073
bmcquade9dd54cc2015-06-22 16:56:522074 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282075 return;
2076 }
2077
2078 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2079 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032080 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522081 // blink-settings flag into a group with no params, and we return
2082 // above if no params were specified, so it's an error if we reach
2083 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282084 LOG(WARNING) << "Received field trial params, "
2085 "but blink-settings switch already specified.";
2086 return;
2087 }
2088
bmcquade5d2d9cf32015-06-19 17:42:282089 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262090 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282091}
2092
[email protected]d2e1a0a2014-06-16 15:49:372093} // namespace
2094
[email protected]b80f68432011-05-02 17:22:302095void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172096 base::CommandLine* command_line,
2097 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062098#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352099 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062100 GoogleUpdateSettings::LoadMetricsClientInfo();
2101 if (client_info) {
2102 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2103 client_info->client_id);
2104 }
2105#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022106#if defined(OS_ANDROID)
2107 bool enable_crash_reporter = true;
2108#else
Joshua Perazace68e2f2019-09-23 18:44:242109 bool enable_crash_reporter = false;
2110 if (crash_reporter::IsCrashpadEnabled()) {
2111 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2112 enable_crash_reporter = true;
2113
2114 int fd;
2115 pid_t pid;
2116 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2117 command_line->AppendSwitchASCII(
2118 crash_reporter::switches::kCrashpadHandlerPid,
2119 base::NumberToString(pid));
2120 }
2121 } else {
2122 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2123 }
Joshua Perazaf890e4b2019-01-03 19:19:022124#endif
2125 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512126 std::string switch_value;
dcheng4af48582016-04-19 00:29:352127 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532128 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512129 if (client_info)
2130 switch_value = client_info->client_id;
2131 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252132 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302133 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512134 switch_value);
[email protected]b80f68432011-05-02 17:22:302135 }
Mark Mentovaic67fa64f2015-03-24 14:00:062136#endif
[email protected]b80f68432011-05-02 17:22:302137
[email protected]f1933792011-06-14 00:49:342138 if (logging::DialogsAreSuppressed())
2139 command_line->AppendSwitch(switches::kNoErrorDialogs);
2140
[email protected]b80f68432011-05-02 17:22:302141 std::string process_type =
2142 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172143 const base::CommandLine& browser_command_line =
2144 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322145
[email protected]7c9b6f92013-09-10 18:11:352146 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442147 switches::kUserAgent,
2148 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352149 };
2150 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372151 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322152
fqj15ff3f72015-10-09 19:20:022153 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432154 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312155 };
fqj15ff3f72015-10-09 19:20:022156 command_line->CopySwitchesFrom(browser_command_line,
2157 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372158 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312159
David Van Cleve3df6abb2019-11-26 17:52:512160 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2161 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2162
fqj15ff3f72015-10-09 19:20:022163#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332164 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2165 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522166 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332167 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2168 homedir.value().c_str());
2169#endif
2170
[email protected]718eab62011-10-05 21:16:522171 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032172 content::RenderProcessHost* process =
2173 content::RenderProcessHost::FromID(child_process_id);
2174 Profile* profile =
2175 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442176 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032177 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442178 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2179 process, profile);
[email protected]a48ab7112014-08-01 16:48:032180 }
2181
[email protected]b80f68432011-05-02 17:22:302182#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442183 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2184 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302185 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442186 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2187 login_profile);
[email protected]b80f68432011-05-02 17:22:302188#endif
2189
Aran Gilmanf010bdd2019-08-28 19:55:442190 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222191 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372192 if (process) {
[email protected]a8d851f82011-12-21 00:32:372193 PrefService* prefs = profile->GetPrefs();
2194 // Currently this pref is only registered if applied via a policy.
2195 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2196 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2197 // Turn this policy into a command line switch.
2198 command_line->AppendSwitch(switches::kDisable3DAPIs);
2199 }
[email protected]718eab62011-10-05 21:16:522200
[email protected]1733b782014-06-19 18:51:552201 const base::ListValue* switches =
2202 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2203 if (switches) {
2204 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112205 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552206 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142207 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552208 command_line->AppendSwitch(switch_to_enable);
2209 }
2210 }
2211
Daniel Rubery9eb1e0912020-05-08 17:57:322212#if defined(FULL_SAFE_BROWSING)
[email protected]a8d851f82011-12-21 00:32:372213 // Disable client-side phishing detection in the renderer if it is
Daniel Rubery9eb1e0912020-05-08 17:57:322214 // disabled in the Profile preferences, or by command line flag.
Bettinae83f522c72020-03-12 01:52:332215 if (!safe_browsing::IsSafeBrowsingEnabled(*prefs) ||
Daniel Rubery9eb1e0912020-05-08 17:57:322216 !safe_browsing::ClientSideDetectionServiceFactory::GetForProfile(
2217 profile)) {
[email protected]a8d851f82011-12-21 00:32:372218 command_line->AppendSwitch(
2219 switches::kDisableClientSidePhishingDetection);
2220 }
Daniel Rubery9eb1e0912020-05-08 17:57:322221#endif
[email protected]0045b0f42012-07-26 11:52:082222
vitalybukaa7ae5052014-09-26 04:11:132223 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2224 command_line->AppendSwitch(switches::kDisablePrintPreview);
2225
Marc Treib7895941d2017-11-28 12:37:022226#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522227 InstantService* instant_service =
2228 InstantServiceFactory::GetForProfile(profile);
2229 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542230 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522231 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542232 }
Marc Treib7895941d2017-11-28 12:37:022233#endif
fqjba8749c2015-10-29 15:33:072234
fqj38306f7b2015-11-02 16:59:062235 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542236 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432237 command_line->AppendSwitch(
2238 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542239 }
Daniel Vogelheim976f1c22017-11-22 16:26:032240
Lukasz Anforowicz60d1253d2019-05-08 16:31:372241 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2242
Amr Aboelkherb04cbf32019-04-29 15:17:102243 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2244 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292245 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102246 }
Katie Dillonc25ee5c92019-09-12 17:05:422247
2248 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2249 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2250 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2251 }
Takashi Toyoshima128441462019-10-16 04:19:172252
Mason Freed490f2a22019-11-05 21:41:292253
Daniel Libbyc5bfd91f2020-03-07 03:44:102254 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2255 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2256 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2257 }
2258
Takashi Toyoshima0dab73302019-10-18 01:51:362259 if (!profile->ShouldEnableOutOfBlinkCors()) {
2260 command_line->AppendSwitch(
2261 network::switches::kForceToDisableOutOfBlinkCors);
2262 }
Adrienne Walker297651292020-05-08 00:23:182263
2264 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2265 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2266 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2267 }
[email protected]47c7ec82012-01-18 03:29:212268 }
[email protected]4287a3d2011-06-13 23:56:512269
[email protected]d2e1a0a2014-06-16 15:49:372270 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352271 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042272
Aran Gilmanf010bdd2019-08-28 19:55:442273 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2274 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282275
mdjonesa6b9e172016-09-23 16:24:302276#if defined(OS_ANDROID)
2277 // If the platform is Android, force the distillability service on.
2278 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2279#endif
2280
[email protected]47c7ec82012-01-18 03:29:212281 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512282 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192283 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412284 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302285#if defined(OS_CHROMEOS)
2286 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2287#endif
brettw00899e62016-11-12 02:10:172288#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512289 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272290 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172291 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512292 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272293 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172294 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172295 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282296#endif
estark4b003b332015-02-14 01:07:052297 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512298 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482299 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512300 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502301 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572302 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462303 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302304 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512305 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172306#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242307 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482308 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552309#endif
[email protected]ce304ce2013-02-22 21:54:452310 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342311#if defined(OS_CHROMEOS)
2312 switches::kForceAppMode,
2313#endif
Nico Weberaf3b00b2017-09-11 17:58:172314#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592315 switches::kForcePNaClSubzero,
2316#endif
Marc Treibad33cf942017-08-24 11:19:002317 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032318 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512319 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102320 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322321 embedder_support::kOriginTrialDisabledFeatures,
2322 embedder_support::kOriginTrialDisabledTokens,
2323 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512324 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512325 switches::kPpapiFlashPath,
2326 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032327 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092328 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512329 };
2330
2331 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372332 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172333 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172334#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382335 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442336 extensions::switches::kAllowHTTPBackgroundPage,
2337 extensions::switches::kEnableExperimentalExtensionApis,
2338 extensions::switches::kExtensionsOnChromeURLs,
2339 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382340 };
2341
2342 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372343 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282344#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372345 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132346 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512347 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512348 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502349 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172350#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242351 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582352 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592353 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412354 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552355#endif
[email protected]4287a3d2011-06-13 23:56:512356 switches::kPpapiFlashPath,
2357 switches::kPpapiFlashVersion,
2358 };
2359
2360 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372361 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112362 } else if (process_type == switches::kGpuProcess) {
2363 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2364 // because GPU is expected to be unreliable.
2365 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2366 !command_line->HasSwitch(switches::kDisableBreakpad))
2367 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302368 }
[email protected]6f08af82011-09-15 01:19:032369
Ian Barkley-Yeung550aae052019-07-11 00:11:112370#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302371 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112372 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292373 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112374 };
2375 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2376 base::size(kSwitchNames));
2377 }
2378#endif
2379
wittman832321f52016-10-10 18:18:382380 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442381 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342382
2383#if defined(OS_LINUX)
2384 // Processes may only query perf_event_open with the BPF sandbox disabled.
2385 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2386 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2387 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2388 }
2389#endif
[email protected]b80f68432011-05-02 17:22:302390}
2391
Olivier Yiptong0daa93f2019-08-22 19:40:082392std::string
2393ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2394 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2395}
2396
[email protected]b80f68432011-05-02 17:22:302397std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432398 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332399 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302400 return g_browser_process->GetApplicationLocale();
2401}
2402
[email protected]597a867b2011-11-18 18:31:202403std::string ChromeContentBrowserClient::GetAcceptLangs(
2404 content::BrowserContext* context) {
2405 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202406 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082407}
2408
Dana Fried34d580002019-04-24 20:05:482409gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492410 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482411 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082412}
2413
bengre8a146f2016-03-10 01:20:222414bool ChromeContentBrowserClient::IsDataSaverEnabled(
2415 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382416 if (!browser_context || browser_context->IsOffTheRecord())
2417 return false;
2418
Robert Ogdenc995d4fe2019-03-25 19:18:372419 Profile* profile = Profile::FromBrowserContext(browser_context);
2420 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412421 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2422 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222423}
2424
Kenichi Ishibashi46329872018-07-17 09:43:402425void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2426 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192427 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402428 DCHECK(browser_context);
2429 DCHECK(out_prefs);
2430 renderer_preferences_util::UpdateFromSystemSettings(
2431 out_prefs, Profile::FromBrowserContext(browser_context));
2432}
2433
Clark DuVall5690e742019-07-17 18:26:172434bool ChromeContentBrowserClient::AllowAppCache(
2435 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172436 const GURL& site_for_cookies,
2437 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172438 content::BrowserContext* context) {
2439 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2440 return CookieSettingsFactory::GetForProfile(
2441 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172442 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172443}
2444
Alexander Timin17edc742020-04-23 18:22:182445content::AllowServiceWorkerResult
2446ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072447 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542448 const GURL& site_for_cookies,
2449 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362450 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182451 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522452 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542453 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452454
brettw00899e62016-11-12 02:10:172455#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452456 // Check if this is an extension-related service worker, and, if so, if it's
2457 // allowed (this can return false if, e.g., the extension is disabled).
2458 // If it's not allowed, return immediately. We deliberately do *not* report
2459 // to the TabSpecificContentSettings, since the service worker is blocked
2460 // because of the extension, rather than because of the user's content
2461 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022462 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362463 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182464 return content::AllowServiceWorkerResult::No();
rdevlin.croninf5863da2015-09-10 19:21:452465 }
2466#endif
2467
falken3dbc36e2014-10-10 16:48:072468 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202469
shimazuce8af88122016-10-06 23:49:212470 // Check if JavaScript is allowed.
2471 content_settings::SettingInfo info;
2472 std::unique_ptr<base::Value> value =
2473 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452474 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212475 std::string(), &info);
2476 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2477 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2478
2479 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542480 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2481 scope, site_for_cookies, top_frame_origin);
Alexander Timin17edc742020-04-23 18:22:182482
2483 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2484 !allow_cookies);
falken3dbc36e2014-10-10 16:48:072485}
2486
Alexander Timin17edc742020-04-23 18:22:182487content::AllowServiceWorkerResult
2488ChromeContentBrowserClient::AllowServiceWorkerOnUI(
Matt Falkenhagen7b509e52019-08-15 23:11:412489 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542490 const GURL& site_for_cookies,
2491 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412492 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182493 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412494 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542495 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412496
2497#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022498 // Check if this is an extension-related service worker, and, if so, if it's
2499 // allowed (this can return false if, e.g., the extension is disabled).
2500 // If it's not allowed, return immediately. We deliberately do *not* report
2501 // to the TabSpecificContentSettings, since the service worker is blocked
2502 // because of the extension, rather than because of the user's content
2503 // settings.
2504 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2505 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182506 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022507 }
Matt Falkenhagen7b509e52019-08-15 23:11:412508#endif
2509
2510 Profile* profile = Profile::FromBrowserContext(context);
2511
2512 // Check if JavaScript is allowed.
2513 content_settings::SettingInfo info;
2514 std::unique_ptr<base::Value> value =
2515 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452516 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412517 std::string(), &info);
2518 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2519 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2520
2521 // Check if cookies are allowed.
2522 bool allow_cookies =
2523 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542524 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412525
Alexander Timin17edc742020-04-23 18:22:182526 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2527 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412528}
2529
Jochen Eisinger0ff7645c2017-11-28 08:11:262530bool ChromeContentBrowserClient::AllowSharedWorker(
2531 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542532 const GURL& site_for_cookies,
2533 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262534 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372535 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262536 content::BrowserContext* context,
2537 int render_process_id,
2538 int render_frame_id) {
2539 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2540
2541 // Check if cookies are allowed.
2542 bool allow =
2543 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542544 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2545 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262546
Clark DuVall84a33d612020-04-17 16:01:002547 content_settings::TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372548 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2549 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262550 return allow;
2551}
2552
Patrick Monette6cb099a2019-09-18 19:31:272553bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2554 const std::string& scheme) {
2555#if BUILDFLAG(ENABLE_EXTENSIONS)
2556 // Extensions are allowed to start cross-origin shared workers.
2557 if (scheme == extensions::kExtensionScheme)
2558 return true;
2559#endif
2560
2561 return false;
2562}
2563
Clark DuVallab63d142019-07-23 04:24:362564bool ChromeContentBrowserClient::AllowSignedExchange(
2565 content::BrowserContext* browser_context) {
2566 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2567 Profile* profile = Profile::FromBrowserContext(browser_context);
2568 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2569}
2570
[email protected]f917df22014-07-10 07:45:492571void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352572 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572573 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172574 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572575 base::OnceCallback<void(bool)> callback) {
2576 Profile* profile = Profile::FromBrowserContext(browser_context);
2577 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172578 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352579
brettw00899e62016-11-12 02:10:172580#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572581 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492582#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572583 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492584#endif
2585}
2586
brettw00899e62016-11-12 02:10:172587#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492588void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2589 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172590 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572591 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492592 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572593 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492594 std::map<int, int> process_map;
2595 std::map<int, int>::const_iterator it;
2596 bool has_web_view_guest = false;
2597 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172598 for (const auto& it : render_frames) {
2599 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492600 continue;
2601
Lukasz Anforowicz09060bdf72018-08-23 15:53:172602 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492603
Lukasz Anforowicz09060bdf72018-08-23 15:53:172604 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492605 has_web_view_guest = true;
2606 }
2607 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572608 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492609 return;
2610 }
[email protected]dffb9fc2014-07-16 04:14:022611 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492612 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492613
[email protected]140d6cd92014-08-12 18:26:462614 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572615 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2616 web_view_permission_helper->RequestFileSystemPermission(
2617 url, allow,
2618 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2619 weak_factory_.GetWeakPtr(), url, render_frames,
2620 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492621}
2622#endif
2623
2624void ChromeContentBrowserClient::FileSystemAccessed(
2625 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172626 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572627 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492628 bool allow) {
[email protected]62151052012-02-01 18:40:482629 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172630 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002631 content_settings::TabSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572632 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352633 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572634 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352635}
2636
[email protected]7c5ff9a2012-03-02 07:42:492637bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2638 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572639 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172640 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572641 Profile* profile = Profile::FromBrowserContext(browser_context);
2642 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2643
Christian Dullweber77740152020-05-12 09:54:172644 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492645
2646 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172647 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002648 content_settings::TabSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572649 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492650 }
2651
2652 return allow;
2653}
2654
Ben Kelly6b2e61c2019-03-14 16:06:292655bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2656 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572657 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292658 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572659 Profile* profile = Profile::FromBrowserContext(browser_context);
2660 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172661 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292662
2663 // Record access to CacheStorage for potential display in UI.
2664 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002665 content_settings::TabSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572666 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292667 }
2668
2669 return allow;
2670}
2671
Joshua Bell1ebc8df2019-11-06 00:27:582672bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2673 const GURL& url,
2674 content::BrowserContext* browser_context,
2675 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2676 Profile* profile = Profile::FromBrowserContext(browser_context);
2677 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172678 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582679}
2680
jyasskinc993ce8d2016-03-31 00:38:342681ChromeContentBrowserClient::AllowWebBluetoothResult
2682ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452683 content::BrowserContext* browser_context,
2684 const url::Origin& requesting_origin,
2685 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342686 // TODO(crbug.com/598890): Don't disable if
2687 // base::CommandLine::ForCurrentProcess()->
2688 // HasSwitch(switches::kEnableWebBluetooth) is true.
2689 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272690 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342691 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272692 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342693 // The kill switch is enabled for this permission. Block requests.
2694 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2695 }
2696
jyasskin98bdd3992016-02-26 20:25:452697 const HostContentSettingsMap* const content_settings =
2698 HostContentSettingsMapFactory::GetForProfile(
2699 Profile::FromBrowserContext(browser_context));
2700
csharrisonaec2c542016-10-12 19:40:362701 if (content_settings->GetContentSetting(
2702 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452703 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362704 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342705 return AllowWebBluetoothResult::BLOCK_POLICY;
2706 }
2707 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452708}
2709
beaufort.francois01135bf2016-11-23 14:37:362710std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2711 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2712 "blocklist_additions");
scheib74250322016-04-07 03:32:212713}
2714
John Abd-El-Malek21bca7c2018-10-26 22:13:332715#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522716void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072717 content::BrowserContext* browser_context) {
2718 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2719 if (user_manager) {
2720 const user_manager::User* user =
2721 chromeos::ProfileHelper::Get()->GetUserByProfile(
2722 Profile::FromBrowserContext(browser_context));
2723 if (user && !user->username_hash().empty()) {
2724 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2725 user->username_hash());
2726 }
2727 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332728}
2729#endif
2730
Reilly Grant19aaccd2018-07-16 22:06:372731scoped_refptr<network::SharedURLLoaderFactory>
2732ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2734 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2735
2736 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372737 return nullptr;
2738
Min Qinda0d55b2018-10-12 18:30:052739 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372740 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042741}
2742
Sean Gilhulyda1ee4b2018-11-13 21:56:092743network::mojom::NetworkContext*
2744ChromeContentBrowserClient::GetSystemNetworkContext() {
2745 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2746 DCHECK(g_browser_process->system_network_context_manager());
2747 return g_browser_process->system_network_context_manager()->GetContext();
2748}
2749
Andrew Moylan17329fc2017-09-25 07:43:302750std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2751 return google_apis::GetAPIKey();
2752}
2753
Ke He21ee87f2018-05-30 02:35:322754#if defined(OS_ANDROID)
2755bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2756 // Indicate that Chrome uses the GMS core location provider.
2757 return true;
2758}
2759#endif
2760
Yeolf3dc22ca2019-04-18 17:25:322761scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412762ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542763 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412764}
2765
Mythri Alle0b8de0d2018-10-22 11:06:222766content::GeneratedCodeCacheSettings
2767ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2768 content::BrowserContext* context) {
2769 base::FilePath cache_path;
2770 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2771 // If we pass 0 for size, disk_cache will pick a default size using the
2772 // heuristics based on available disk size. These are implemented in
2773 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162774 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132775 DCHECK(g_browser_process);
2776 PrefService* local_state = g_browser_process->local_state();
2777 if (local_state) {
2778 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2779 base::FilePath disk_cache_dir =
2780 local_state->GetFilePath(prefs::kDiskCacheDir);
2781 if (!disk_cache_dir.empty())
2782 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2783 }
Mythri Ab2486572019-06-13 14:48:162784 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222785}
2786
[email protected]848dd042011-06-04 18:24:032787void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262788 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172789 int cert_error,
2790 const net::SSLInfo& ssl_info,
2791 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232792 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222793 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262794 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262795 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232796 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142797 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022798 // have a context for making the right decision, so block the
2799 // request hard, without an info bar to allow showing the insecure
2800 // content.
estark719dde52016-08-09 03:14:272801 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262802 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022803 return;
2804 }
2805
[email protected]f9034cf2011-07-21 12:43:412806 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572807 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262808 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572809 if (prerender_contents) {
2810 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272811 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262812 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272813 }
[email protected]09667f02014-01-06 15:37:572814 return;
[email protected]f9034cf2011-07-21 12:43:412815 }
2816
Erik Staaba65a6032019-11-27 22:23:262817 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282818 return;
[email protected]848dd042011-06-04 18:24:032819}
2820
Katie D1882617e2020-05-06 20:06:012821#if !defined(OS_ANDROID)
2822bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2823 const GURL main_page_url) {
2824 // Desktop Reader Mode pages should never load resources with certificate
2825 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2826 // on Android: the desktop version has its own security indicator and
2827 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2828 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2829 // pages).
2830 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2831}
2832#endif
2833
Alexander Hendrichbcf2616e2018-05-18 08:21:102834namespace {
2835
Pavol Markob211ab22019-01-23 20:03:042836certificate_matching::CertificatePrincipalPattern
2837ParseCertificatePrincipalPattern(const base::Value* pattern) {
2838 return certificate_matching::CertificatePrincipalPattern::
2839 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2840}
2841
Alexander Hendrichbcf2616e2018-05-18 08:21:102842// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452843// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102844// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2845std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2846 Profile* profile,
2847 const GURL& requesting_url,
2848 net::ClientCertIdentityList& client_certs) {
2849 HostContentSettingsMap* host_content_settings_map =
2850 HostContentSettingsMapFactory::GetForProfile(profile);
2851 std::unique_ptr<base::Value> setting =
2852 host_content_settings_map->GetWebsiteSetting(
2853 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452854 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102855
Pavol Markob211ab22019-01-23 20:03:042856 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102857 return nullptr;
2858
Alexander Hendrichbcf2616e2018-05-18 08:21:102859 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042860 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2861 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102862 // |setting_dict| has the wrong format (e.g. single filter instead of a
2863 // list of filters). This content setting is only provided by
2864 // the |PolicyProvider|, which should always set it to a valid format.
2865 // Therefore, delete the invalid value.
2866 host_content_settings_map->SetWebsiteSettingDefaultScope(
2867 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452868 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042869 return nullptr;
2870 }
2871
2872 for (const base::Value& filter : filters->GetList()) {
2873 DCHECK(filter.is_dict());
2874
2875 auto issuer_pattern = ParseCertificatePrincipalPattern(
2876 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2877 auto subject_pattern = ParseCertificatePrincipalPattern(
2878 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2879 // Use the first certificate that is matched by the filter.
2880 for (auto& client_cert : client_certs) {
2881 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2882 subject_pattern.Matches(client_cert->certificate()->subject())) {
2883 return std::move(client_cert);
2884 }
2885 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102886 }
2887
2888 return nullptr;
2889}
2890
2891} // namespace
2892
Daniel McArdle85735f52019-06-25 03:27:062893base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192894 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402895 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082896 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352897 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022898 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192899 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022900 if (prerender_contents) {
2901 prerender_contents->Destroy(
2902 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062903 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452904 }
2905
[email protected]791879c2013-12-17 07:22:412906 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2907 DCHECK(requesting_url.is_valid())
2908 << "Invalid URL string: https://"
2909 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452910
Pavol Marko230ea2c92017-12-03 22:35:442911 bool may_show_cert_selection = true;
2912
davidben3b8455ae72015-03-11 19:42:192913 Profile* profile =
2914 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442915#if defined(OS_CHROMEOS)
2916 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252917 // On the sign-in profile, never show certificate selection to the user. A
2918 // client certificate is an identifier that can be stable for a long time,
2919 // so only the administrator is allowed to decide which endpoints should see
2920 // it.
2921 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442922
2923 content::StoragePartition* storage_partition =
2924 content::BrowserContext::GetStoragePartition(
2925 profile, web_contents->GetSiteInstance());
2926 chromeos::login::SigninPartitionManager* signin_partition_manager =
2927 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2928 profile);
2929
2930 // On the sign-in profile, only allow client certs in the context of the
2931 // sign-in frame.
2932 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2933 storage_partition)) {
2934 LOG(WARNING)
2935 << "Client cert requested in sign-in profile in wrong context.";
2936 // Continue without client certificate. We do this to mimic the case of no
2937 // client certificate being present in the profile's certificate store.
2938 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062939 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442940 }
2941 VLOG(1) << "Client cert requested in sign-in profile.";
2942 }
2943#endif // defined(OS_CHROMEOS)
2944
Alexander Hendrichbcf2616e2018-05-18 08:21:102945 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2946 AutoSelectCertificate(profile, requesting_url, client_certs);
2947 if (auto_selected_identity) {
2948 // The callback will own |auto_selected_identity| and |delegate|, keeping
2949 // them alive until after ContinueWithCertificate is called.
2950 scoped_refptr<net::X509Certificate> cert =
2951 auto_selected_identity->certificate();
2952 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2953 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582954 base::BindOnce(
2955 &content::ClientCertificateDelegate::ContinueWithCertificate,
2956 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322957 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062958 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452959 }
2960
Pavol Marko230ea2c92017-12-03 22:35:442961 if (!may_show_cert_selection) {
2962 LOG(WARNING) << "No client cert matched by policy and user selection is "
2963 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322964 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442965 // Continue without client certificate. We do this to mimic the case of no
2966 // client certificate being present in the profile's certificate store.
2967 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062968 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442969 }
2970
Daniel McArdle85735f52019-06-25 03:27:062971 return chrome::ShowSSLClientCertificateSelector(
2972 web_contents, cert_request_info, std::move(client_certs),
2973 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452974}
2975
[email protected]dc73a7b2012-03-25 15:27:182976content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562977 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182978}
2979
Adrienne Walker80d95f02020-02-07 22:37:042980content::FeatureObserverClient*
2981ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:242982 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:042983 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:052984}
2985
peterc26c6c62014-12-10 14:13:592986content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022987ChromeContentBrowserClient::GetPlatformNotificationService(
2988 content::BrowserContext* browser_context) {
2989 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2990 Profile* profile = Profile::FromBrowserContext(browser_context);
2991 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042992}
2993
[email protected]9f3fba52011-06-08 20:37:192994bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352995 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352996 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572997 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352998 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032999 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233000 const GURL& target_url,
3001 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213002 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233003 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483004 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233005 bool user_gesture,
3006 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013007 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353008 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3009 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013010
csharrison95f01e922017-04-24 18:52:353011 content::WebContents* web_contents =
3012 content::WebContents::FromRenderFrameHost(opener);
3013 Profile* profile =
3014 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3015 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013016 *no_javascript_access = false;
3017
[email protected]9f3fba52011-06-08 20:37:193018 // If the opener is trying to create a background window but doesn't have
3019 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033020 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173021#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353022 auto* process_map = extensions::ProcessMap::Get(profile);
3023 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173024 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3025 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013026 return false;
3027 }
3028
[email protected]7b54ca02012-03-02 18:06:533029 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3030 // return a recently installed Extension even if this CanCreateWindow call
3031 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013032 // because the permission check above would have caused an early return
3033 // already. We must use the full URL to find hosted apps, though, and not
3034 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553035 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353036 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293037 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013038 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023039#endif
[email protected]190e5e22013-07-27 05:59:233040
3041 return true;
[email protected]9f3fba52011-06-08 20:37:193042 }
[email protected]056efdc2013-04-06 00:14:533043
brettw00899e62016-11-12 02:10:173044#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463045 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353046 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233047 return true;
lazyboy04b75d32016-02-25 03:12:183048 }
3049
nick0fbc3922016-12-16 20:52:073050 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353051 // Intentionally duplicating |registry| code from above because we want to
3052 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3053 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183054 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353055 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143056 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533057 UMA_HISTOGRAM_ENUMERATION(
3058 "Extensions.AppLoadedInTab",
3059 ClassifyAppLoadedInTabSource(opener_url, extension),
3060 APP_LOADED_IN_TAB_SOURCE_MAX);
3061
3062 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163063 return false;
lazyboy5d5fede02016-03-10 04:10:143064 }
lazyboy04b75d32016-02-25 03:12:183065 }
[email protected]5940b0d2014-07-01 00:18:263066#endif
[email protected]190e5e22013-07-27 05:59:233067
Charles Harrisonaf2acd02017-08-18 22:46:023068#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:233069 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:353070 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:583071 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
3072 content_settings, opener_top_level_frame_url, target_url,
3073 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353074 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3075 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583076 return false;
3077 }
3078#endif
3079
Ryan Sturm0ec75df2020-04-23 14:39:153080 DCHECK(!prerender::PrerenderContents::FromWebContents(web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023081
Aaron Colwell9dab1652019-12-09 18:29:493082 BlockedWindowParams blocked_params(
3083 target_url, source_origin, opener->GetSiteInstance(), referrer,
3084 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133085 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:193086 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
3087 &nav_params, nullptr /*=open_url_params*/,
3088 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:193089}
3090
[email protected]c52b2892012-03-07 11:01:023091content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443092ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003093 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513094}
3095
Katie D840d9532018-11-27 06:20:483096content::TtsControllerDelegate*
3097ChromeContentBrowserClient::GetTtsControllerDelegate() {
3098 TtsControllerDelegateImpl* delegate =
3099 TtsControllerDelegateImpl::GetInstance();
3100#if !defined(OS_ANDROID)
3101 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3102 delegate->SetTtsEngineDelegate(tts_extension_engine);
3103#endif
3104 return delegate;
3105}
3106
Katie D4713ee42018-11-30 01:48:273107content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3108#ifdef OS_CHROMEOS
3109 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273110#else
3111 return nullptr;
3112#endif
3113}
3114
[email protected]64d69de42012-02-06 00:19:543115void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443116 RenderViewHost* rvh,
3117 WebPreferences* web_prefs) {
3118 Profile* profile =
3119 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063120 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063121
aelias0df335a2017-03-02 23:43:513122// Fill font preferences. These are not registered on Android
3123// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453124#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193125 FontFamilyCache::FillFontFamilyMap(profile,
3126 prefs::kWebKitStandardFontFamilyMap,
3127 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443128 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193129 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443130 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193131 &web_prefs->serif_font_family_map);
3132 FontFamilyCache::FillFontFamilyMap(profile,
3133 prefs::kWebKitSansSerifFontFamilyMap,
3134 &web_prefs->sans_serif_font_family_map);
3135 FontFamilyCache::FillFontFamilyMap(profile,
3136 prefs::kWebKitCursiveFontFamilyMap,
3137 &web_prefs->cursive_font_family_map);
3138 FontFamilyCache::FillFontFamilyMap(profile,
3139 prefs::kWebKitFantasyFontFamilyMap,
3140 &web_prefs->fantasy_font_family_map);
3141 FontFamilyCache::FillFontFamilyMap(profile,
3142 prefs::kWebKitPictographFontFamilyMap,
3143 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063144
[email protected]64d69de42012-02-06 00:19:543145 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403146 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543147 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403148 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543149 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403150 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543151 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403152 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513153#endif
[email protected]f3986f82012-01-03 20:00:063154
[email protected]ddf72142012-05-22 04:52:403155 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063156
[email protected]64d69de42012-02-06 00:19:543157 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063158 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213159 web_prefs->javascript_can_access_clipboard =
3160 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543161 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063162
[email protected]ddf72142012-05-22 04:52:403163 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543164 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573165
Avi Drissman1aa6cb92019-01-23 15:58:383166 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543167 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573168
[email protected]ddf72142012-05-22 04:52:403169 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543170 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543171 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403172 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063173
Zhenyao Moa3fda9972017-09-16 01:34:403174 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3175 web_prefs->webgl1_enabled = false;
3176 web_prefs->webgl2_enabled = false;
3177 }
[email protected]f3986f82012-01-03 20:00:063178
[email protected]64d69de42012-02-06 00:19:543179 web_prefs->allow_running_insecure_content =
3180 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323181#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053182 web_prefs->font_scale_factor =
3183 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323184 web_prefs->force_enable_zoom =
3185 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493186#endif
Becky Zhoubbfbde32019-02-20 17:07:593187 web_prefs->force_dark_mode_enabled =
3188 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393189
Alice Boxhallda2659142020-05-14 06:04:373190#if defined(OS_CHROMEOS)
3191 web_prefs->always_show_focus =
3192 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
3193#endif
3194
[email protected]af4256d52013-06-04 20:39:073195#if defined(OS_ANDROID)
3196 web_prefs->password_echo_enabled =
3197 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3198#else
[email protected]9d06d88d2012-02-23 22:37:083199 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073200#endif
3201
[email protected]64d69de42012-02-06 00:19:543202 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063203 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543204 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063205 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3206
brettw00899e62016-11-12 02:10:173207#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053208 std::string image_animation_policy =
3209 prefs->GetString(prefs::kAnimationPolicy);
3210 if (image_animation_policy == kAnimationPolicyOnce)
3211 web_prefs->animation_policy =
3212 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3213 else if (image_animation_policy == kAnimationPolicyNone)
3214 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3215 else
3216 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3217#endif
3218
[email protected]f3986f82012-01-03 20:00:063219 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153220 web_prefs->default_encoding =
3221 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543222 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403223 prefs->ClearPref(prefs::kDefaultCharset);
3224 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063225 }
[email protected]64d69de42012-02-06 00:19:543226 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063227
mkwst05544102015-01-10 20:26:163228 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3229 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073230 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163231 web_prefs->strict_mixed_content_checking = true;
3232 web_prefs->strict_powerful_feature_restrictions = true;
3233 }
3234
Robert Ogdencf2872d2019-03-19 18:59:373235 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213236
Tarun Bansal333819e2018-05-15 16:38:423237 web_prefs->data_saver_holdback_web_api_enabled =
3238 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3239 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423240
Jinsuk Kima3d393ce2019-05-27 00:57:423241 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133242 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533243#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423244 auto* delegate = TabAndroid::FromWebContents(contents)
3245 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3246 contents->GetDelegate())
3247 : nullptr;
3248 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133249 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423250 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133251
Mounir Lamouri9c99a1602018-07-05 15:01:443252 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423253 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383254
Alison Maher7f366dc62020-03-03 19:46:003255 web_prefs->preferred_color_scheme =
3256 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3257 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113258 }
Ian Vollick6243dfe02018-03-08 01:08:533259#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533260
Mounir Lamouri6926107f2019-01-31 18:17:433261 // web_app_scope value is platform specific.
3262#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423263 if (delegate)
3264 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433265#elif BUILDFLAG(ENABLE_EXTENSIONS)
3266 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253267 web_prefs->web_app_scope = GURL();
3268 // Set |web_app_scope| based on the app associated with the app window if
3269 // any. Note that the app associated with the window never changes, even
3270 // if the app navigates off scope. This is not a problem because we still
3271 // want to use the scope of the app associated with the window, not the
3272 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433273 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233274 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593275 browser->app_controller()->HasAppId()) {
3276 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3277 const web_app::AppRegistrar& registrar =
3278 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3279 if (registrar.IsLocallyInstalled(app_id))
3280 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433281 }
Mounir Lamouri6926107f2019-01-31 18:17:433282 }
3283#endif
3284
Ian Vollick6243dfe02018-03-08 01:08:533285 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113286 }
zqzhang93e959d12017-03-16 13:10:203287
Tarun Bansal73d67f02018-01-17 05:56:253288 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3289 // Obtain the maximum effective connection type at which the feature is
3290 // enabled.
3291 std::string effective_connection_type_param =
3292 base::GetFieldTrialParamValueByFeature(
3293 features::kLowPriorityIframes,
3294 "max_effective_connection_type_threshold");
3295
3296 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3297 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3298 if (effective_connection_type) {
3299 web_prefs->low_priority_iframes_threshold =
3300 effective_connection_type.value();
3301 }
3302 }
3303
rajendrant0521cee2019-07-29 06:09:263304 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3305 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003306
Scott Little878f7d6702018-05-31 22:09:063307 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3308 const char* param_name =
3309 web_prefs->data_saver_enabled
3310 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3311 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3312 "saver_enabled";
3313
3314 base::StringPairs pairs;
3315 base::SplitStringIntoKeyValuePairs(
3316 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3317 param_name),
3318 ':', ',', &pairs);
3319
3320 for (const auto& pair : pairs) {
3321 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3322 net::GetEffectiveConnectionTypeForName(pair.first);
3323 int value = 0;
3324 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3325 web_prefs->lazy_frame_loading_distance_thresholds_px
3326 [effective_connection_type.value()] = value;
3327 }
3328 }
3329 }
3330
rajendrantd8026342018-08-29 08:08:393331 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3332 const char* param_name =
3333 web_prefs->data_saver_enabled
3334 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3335 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3336 "saver_enabled";
3337
3338 base::StringPairs pairs;
3339 base::SplitStringIntoKeyValuePairs(
3340 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3341 param_name),
3342 ':', ',', &pairs);
3343
3344 for (const auto& pair : pairs) {
3345 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3346 net::GetEffectiveConnectionTypeForName(pair.first);
3347 int value = 0;
3348 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3349 web_prefs->lazy_image_loading_distance_thresholds_px
3350 [effective_connection_type.value()] = value;
3351 }
3352 }
rajendrant3daeae292019-09-20 07:57:543353
3354 pairs.clear();
3355 base::SplitStringIntoKeyValuePairs(
3356 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3357 "lazy_image_first_k_fully_load"),
3358 ':', ',', &pairs);
3359
3360 for (const auto& pair : pairs) {
3361 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3362 net::GetEffectiveConnectionTypeForName(pair.first);
3363 int value = 0;
3364 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3365 web_prefs
3366 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3367 value;
3368 }
3369 }
rajendrantd8026342018-08-29 08:08:393370 }
3371
Tarun Bansald10f17a02018-09-13 00:23:173372 if (base::FeatureList::IsEnabled(
3373 features::kNetworkQualityEstimatorWebHoldback)) {
3374 std::string effective_connection_type_param =
3375 base::GetFieldTrialParamValueByFeature(
3376 features::kNetworkQualityEstimatorWebHoldback,
3377 "web_effective_connection_type_override");
3378
3379 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3380 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3381 DCHECK(effective_connection_type_param.empty() ||
3382 effective_connection_type);
3383 if (effective_connection_type) {
3384 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3385 effective_connection_type.value());
3386 web_prefs->network_quality_estimator_web_holdback =
3387 effective_connection_type.value();
3388 }
3389 }
3390
François Beaufort4f8107d2018-03-05 12:12:103391#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563392 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593393 // If autoplay is allowed by policy then force the no user gesture required
3394 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103395 web_prefs->autoplay_policy =
3396 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553397 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593398 web_prefs->autoplay_policy ==
3399 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553400 // If the autoplay disable settings feature is enabled and the autoplay
3401 // policy is set to using the unified policy then set the default autoplay
3402 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593403 web_prefs->autoplay_policy =
3404 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3405 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3406 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103407 }
Alison Maher7f366dc62020-03-03 19:46:003408
Abigail Kleina81f2e22020-05-04 14:32:413409 auto* native_theme = GetWebTheme();
Alison Maher7f366dc62020-03-03 19:46:003410 switch (native_theme->GetPreferredColorScheme()) {
3411 case ui::NativeTheme::PreferredColorScheme::kDark:
3412 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3413 break;
3414 case ui::NativeTheme::PreferredColorScheme::kLight:
3415 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3416 break;
3417 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3418 web_prefs->preferred_color_scheme =
3419 blink::PreferredColorScheme::kNoPreference;
3420 }
François Beaufort4f8107d2018-03-05 12:12:103421#endif // !defined(OS_ANDROID)
3422
Dave Tapuskac6627e12018-08-30 15:07:193423 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493424
Alison Maher7f366dc62020-03-03 19:46:003425 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3426 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3427 // explicitly uses light (instead of not dark), which is why we don't reset
3428 // back to no-preference. https://crbug.com/965811
3429 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3430 const GURL url = rvh->GetSiteInstance()->GetSiteURL();
3431 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3432#if BUILDFLAG(ENABLE_EXTENSIONS)
3433 if (!force_light) {
3434 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3435 url.host_piece() == extension_misc::kPdfExtensionId;
3436 }
3437#endif
3438 if (force_light)
3439 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3440 }
3441
Abigail Kleina81f2e22020-05-04 14:32:413442 base::Optional<ui::CaptionStyle> style =
3443 captions::GetCaptionStyleFromUserSettings(prefs,
3444 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213445 if (style) {
3446 web_prefs->text_track_background_color = style->background_color;
3447 web_prefs->text_track_text_color = style->text_color;
3448 web_prefs->text_track_text_size = style->text_size;
3449 web_prefs->text_track_text_shadow = style->text_shadow;
3450 web_prefs->text_track_font_family = style->font_family;
3451 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563452 web_prefs->text_track_window_color = style->window_color;
3453 web_prefs->text_track_window_padding = style->window_padding;
3454 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213455 }
Elly Fong-Jonesf92897392019-01-24 16:05:493456
[email protected]a48ab7112014-08-01 16:48:033457 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503458 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363459}
3460
[email protected]b8148ac2011-07-13 22:03:253461void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3462 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033463 for (size_t i = 0; i < extra_parts_.size(); ++i)
3464 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253465
[email protected]b3adbd02011-11-30 22:23:273466 // about: handler. Must come before chrome: handler, since it will
3467 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053468 // actually handle them. Also relies on a preliminary fixup phase.
3469 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253470 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3471 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033472
madfbd10852017-01-20 03:15:333473 // The group policy NTP URL handler must be registered before the other NTP
3474 // URL handlers below.
3475 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3476 BrowserURLHandler::null_handler());
3477
zpengdb4a58e2017-01-10 17:40:323478#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033479 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353480 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033481 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453482#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033483 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133484 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3485 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453486#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033487
[email protected]b8148ac2011-07-13 22:03:253488 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313489 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3490 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253491}
3492
[email protected]650b2d52013-02-10 03:41:453493base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493494 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323495}
3496
[email protected]c9b6eb62011-10-18 20:49:393497std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3498 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3499}
3500
Dominik Röttsches47347832019-03-12 17:45:013501base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3502 base::FilePath user_data_dir;
3503 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3504 DCHECK(!user_data_dir.empty());
3505 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3506}
3507
jmadill57b52d42015-08-21 18:16:133508base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3509 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523510 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133511 DCHECK(!user_data_dir.empty());
3512 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3513}
3514
Khushal7ca0b782018-07-20 05:53:273515base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3516 base::FilePath user_data_dir;
3517 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3518 DCHECK(!user_data_dir.empty());
3519 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3520}
3521
[email protected]b7631cc2012-09-15 05:08:383522void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3523 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163524#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553525 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543526#endif
[email protected]b7631cc2012-09-15 05:08:383527}
3528
[email protected]0c7193742012-11-07 19:05:033529content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443530ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173531#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553532 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033533 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443534 nacl::NaClProcessHost* host =
3535 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3536 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033537 // Found the plugin.
3538 return host->browser_ppapi_host();
3539 }
3540 ++iter;
3541 }
[email protected]a56f8322014-07-16 21:13:553542#endif
Aran Gilmanf010bdd2019-08-28 19:55:443543 return nullptr;
[email protected]0c7193742012-11-07 19:05:033544}
3545
[email protected]38cd8f7f2012-06-15 22:06:073546bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583547 content::BrowserContext* browser_context,
3548 const GURL& url,
[email protected]dda54822013-06-15 01:26:393549 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123550 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163551#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553552 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193553 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403554#else
[email protected]a658d452012-03-02 12:45:293555 return false;
[email protected]93f72062013-05-29 20:29:403556#endif
[email protected]e461da2f2012-02-16 19:06:403557}
3558
adrian.belgund54465ba2016-05-18 10:03:583559bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3560 content::BrowserContext* browser_context,
3561 const GURL& url) {
brettw4b461082016-11-19 18:55:163562#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583563 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3564 browser_context, url);
3565#else
3566 return false;
3567#endif
3568}
3569
adrian.belgun5b341c72016-06-22 22:24:083570std::unique_ptr<content::VpnServiceProxy>
3571ChromeContentBrowserClient::GetVpnServiceProxy(
3572 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173573#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083574 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3575 browser_context);
3576#else
3577 return nullptr;
3578#endif
3579}
3580
Brett Wilson804e83c2017-08-18 22:57:333581std::unique_ptr<ui::SelectFilePolicy>
3582ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3583 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433584}
3585
[email protected]7d9424702013-04-14 13:14:163586void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3587 std::vector<std::string>* additional_allowed_schemes) {
3588 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3589 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483590 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293591 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033592 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3593 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3594 additional_allowed_schemes);
3595 }
[email protected]7d9424702013-04-14 13:14:163596}
3597
falkenad185092016-06-16 06:10:023598void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3599 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043600 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023601}
3602
[email protected]c79859b82014-03-20 22:43:553603void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313604 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033605 for (size_t i = 0; i < extra_parts_.size(); ++i)
3606 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553607}
3608
nzolghadrd87a308d2016-12-07 15:45:563609::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3610 return g_browser_process->rappor_service();
3611}
3612
[email protected]f19bbf62013-07-09 01:22:323613void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313614 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533615 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003616 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3617 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313618#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313619 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313620 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313621 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093622 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093623 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3624 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473625 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093626 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3627 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053628 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3629 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343630 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3631 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473632 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323633 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313634 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003635 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313636#endif
[email protected]445b7db2013-08-02 04:58:273637
[email protected]a48ab7112014-08-01 16:48:033638 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3639 extra_parts_[i]->GetAdditionalFileSystemBackends(
3640 browser_context, storage_partition_path, additional_backends);
3641 }
[email protected]02250952013-04-24 23:52:533642}
3643
jcivellie6f550742017-01-06 19:29:123644#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183645void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173646 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383647 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203648 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123649#if defined(OS_ANDROID)
3650 base::MemoryMappedFile::Region region;
3651 int fd = ui::GetMainAndroidPackFd(&region);
3652 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003653
Samuel Huang31eadf082019-08-28 19:50:433654 // For Android: Native resources for DFMs should only be used by the browser
3655 // process. Their file descriptors and memory mapped file regions are not
3656 // passed to child processes.
3657
jcivellie6f550742017-01-06 19:29:123658 fd = ui::GetCommonResourcesPackFd(&region);
3659 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393660
jcivellie6f550742017-01-06 19:29:123661 fd = ui::GetLocalePackFd(&region);
3662 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383663
zpeng368afac82017-07-17 18:47:453664 // Optional secondary locale .pak file.
3665 fd = ui::GetSecondaryLocalePackFd(&region);
3666 if (fd != -1) {
3667 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3668 }
3669
[email protected]09560f7f2014-06-10 18:40:283670 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523671 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283672 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023673#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383674 int crash_signal_fd = GetCrashSignalFD(command_line);
3675 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133676 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383677 }
jcivellie6f550742017-01-06 19:29:123678}
3679#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303680
[email protected]4a65826d2011-08-25 16:04:013681#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033682base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223683 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033684 // TODO(wfh): Add support for more process types here. crbug.com/499523
3685 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223686 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363687 return base::string16(install_static::GetSandboxSidPrefix()) +
3688 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223689 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033690 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223691 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033692 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223693 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363694 return base::string16(install_static::GetSandboxSidPrefix()) +
3695 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223696 case service_manager::SandboxType::kNoSandbox:
3697 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3698 case service_manager::SandboxType::kXrCompositing:
3699 case service_manager::SandboxType::kNetwork:
3700 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523701 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223702 case service_manager::SandboxType::kAudio:
evliu2e5dbee42020-04-09 23:35:293703 case service_manager::SandboxType::kSpeechRecognition:
Will Harrise705a642020-02-26 20:57:053704 case service_manager::SandboxType::kProxyResolver:
Cliff Smolinsky0aa7ca72020-03-09 21:32:463705 case service_manager::SandboxType::kPdfConversion:
Alex Gough63617352020-03-20 02:34:593706 case service_manager::SandboxType::kSharingService:
Sharon Yangefd8e882020-04-28 20:56:433707 case service_manager::SandboxType::kVideoCapture:
Alex Gough9ab468a6c32019-12-10 19:10:223708 // Should never reach here.
3709 CHECK(0);
wfh182da09c2015-06-24 19:23:033710 return base::string16();
wfh182da09c2015-06-24 19:23:033711 }
wfh182da09c2015-06-24 19:23:033712}
3713
Will Harris956e0ca2019-08-23 20:47:393714bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3715 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503716// Does not work under component build because all the component DLLs would need
3717// to be manually added and maintained. Does not work under ASAN build because
3718// ASAN has not yet fully initialized its instrumentation by the time the CIG
3719// intercepts run.
3720#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393721 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3722 return true;
Will Harrisc196ed942019-08-03 03:45:303723 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3724 return true;
3725
3726 // Only enable signing mitigation if launching from chrome.exe.
3727 base::FilePath exe_path;
3728 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3729 return true;
3730 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3731 return true;
3732
3733 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3734 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093735 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303736 if (result != sandbox::SBOX_ALL_OK)
3737 return false;
3738
Nico Weberc36b0152020-04-18 03:12:463739 // Allow loading Chrome's DLLs.
3740 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303741 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3742 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3743 GetModulePath(dll).value().c_str());
3744 if (result != sandbox::SBOX_ALL_OK)
3745 return false;
3746 }
Will Harris1b9b4152019-08-21 22:33:503747#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303748
3749 return true;
[email protected]34f48682013-03-20 00:30:183750}
Will Harris956e0ca2019-08-23 20:47:393751
3752bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3753 PrefService* local_state = g_browser_process->local_state();
3754 if (local_state &&
3755 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3756 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3757 return false;
3758 return true;
3759}
3760
wfhc91e9672016-01-27 00:14:203761#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013762
Armando Miraglia3a7be232019-11-08 00:33:323763#if defined(OS_WIN) || defined(OS_MACOSX) || \
3764 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3765bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3766 const base::Value* audio_sandbox_enabled_policy_value =
3767 policies.GetValue(policy::key::kAudioSandboxEnabled);
3768 if (audio_sandbox_enabled_policy_value) {
3769 bool force_enable_audio_sandbox;
3770 audio_sandbox_enabled_policy_value->GetAsBoolean(
3771 &force_enable_audio_sandbox);
3772 return force_enable_audio_sandbox;
3773 }
3774
3775 return base::FeatureList::IsEnabled(
3776 service_manager::features::kAudioServiceSandbox);
3777}
3778#endif
3779
Ken Rockotfa5d57112019-05-29 20:57:143780void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123781#if defined(OS_WIN) || defined(OS_MACOSX) || \
3782 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053783 if (startup_data_) {
3784 auto* chrome_feature_list_creator =
3785 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183786 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123787 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053788 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183789 ->GetPolicyService()
3790 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123791 std::string()));
3792
Armando Miraglia3a7be232019-11-08 00:33:323793 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
John Abd-El-Malek27b3ebd22019-02-12 18:59:183794 }
3795#endif
xhwang5e630462015-10-30 03:18:483796}
3797
Ken Rockot8f39a272018-12-21 23:38:353798base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173799ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583800 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583801 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583802 return base::nullopt;
benc70c0e32016-09-22 03:50:373803}
3804
peterbbcccc12015-02-11 22:23:333805void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373806 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333807 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293808 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083809 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373810
3811 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083812
zpengdb4a58e2017-01-10 17:40:323813#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223814 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293815 std::move(callback));
jam1c5a91492016-02-24 20:47:533816#else
cm.sanchi2522bc92017-12-04 08:04:133817 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3818 params.url, params.transition);
3819 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083820
3821 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293822 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333823#endif
mlamourieb40d552015-02-05 00:57:083824}
3825
zhaobinf3704f82017-01-12 07:19:363826content::ControllerPresentationServiceDelegate*
3827ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3828 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463829 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093830 return media_router::PresentationServiceDelegateImpl::
3831 GetOrCreateForWebContents(web_contents);
3832 }
haibinlu9e605a92015-06-06 03:45:093833 return nullptr;
3834}
3835
zhaobinf3704f82017-01-12 07:19:363836content::ReceiverPresentationServiceDelegate*
3837ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3838 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363839 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3840 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3841 // created for offscreen presentations. The WebContents must belong to
3842 // an incognito profile.
3843 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3844 FromWebContents(web_contents)) {
3845 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3846 return impl;
3847 }
3848 }
zhaobinf3704f82017-01-12 07:19:363849 return nullptr;
3850}
3851
horo48d4d3e2015-02-27 03:04:003852void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3853 const GURL& url) {
mathp46284f32015-03-11 13:06:413854 if (url.is_valid()) {
3855 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3856 metric, url);
3857 }
horo48d4d3e2015-02-27 03:04:003858}
3859
Matt Falkenhagen8479b202017-07-14 04:35:313860std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3861 // Don't change these returned strings. They are written (in hashed form) into
3862 // UMA logs. If you add more strings, you must update histograms.xml and get
3863 // histograms review. Only Google domains should be here for privacy purposes.
3864 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3865 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193866 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313867 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193868 if (url.host() == "docs.google.com")
3869 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313870 return std::string();
3871}
3872
avid6d88b912017-01-13 00:16:003873std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473874ChromeContentBrowserClient::CreateThrottlesForNavigation(
3875 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003876 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273877
bmcquadeb4556552017-03-24 22:24:373878 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3879 // that may delay or cancel navigations, so only NavigationThrottles that
3880 // don't delay or cancel navigations (e.g. throttles that are only observing
3881 // callbacks without affecting navigation behavior) should be added before
3882 // MetricsNavigationThrottle.
3883 if (handle->IsInMainFrame()) {
3884 throttles.push_back(
3885 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3886 }
3887
brettw4b461082016-11-19 18:55:163888#if BUILDFLAG(ENABLE_PLUGINS)
Chris Hamiltonab4722122020-05-13 18:01:283889 MaybeAddThrottle(FlashDownloadInterception::MaybeCreateThrottleFor(handle),
3890 &throttles);
trizzofo8ddaeb72016-09-01 23:18:273891#endif
3892
yilkal240b4f22019-11-27 19:09:063893#if defined(OS_CHROMEOS)
3894 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283895 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3896 &throttles);
yilkal240b4f22019-11-27 19:09:063897#endif // defined(OS_CHROMEOS)
3898
mmenkedb2637ff2017-03-30 23:59:423899#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213900 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283901 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
3902 &throttles);
mmenkedb2637ff2017-03-30 23:59:423903#endif
3904
clamy40c9e142015-09-29 11:18:473905#if defined(OS_ANDROID)
3906 // TODO(davidben): This is insufficient to integrate with prerender properly.
3907 // https://crbug.com/370595
3908 prerender::PrerenderContents* prerender_contents =
3909 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3910 if (!prerender_contents && handle->IsInMainFrame()) {
3911 throttles.push_back(
3912 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303913 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473914 }
Min Qin0ab0e162017-11-14 21:57:193915 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043916
3917#if BUILDFLAG(DFMIFY_DEV_UI)
3918 // If the DevUI DFM is already installed, then this is a no-op, except for the
3919 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:283920 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
3921 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:043922#endif // BUILDFLAG(DFMIFY_DEV_UI)
3923
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573924#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473925 if (handle->IsInMainFrame()) {
3926 // Redirect some navigations to apps that have registered matching URL
3927 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:283928 MaybeAddThrottle(
3929 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
3930 &throttles);
clamy40c9e142015-09-29 11:18:473931 }
3932#endif
clamy49678312015-10-22 21:59:003933
3934#if defined(OS_CHROMEOS)
3935 // Check if we need to add merge session throttle. This throttle will postpone
3936 // loading of main frames.
3937 if (handle->IsInMainFrame()) {
3938 // Add interstitial page while merge session process (cookie reconstruction
3939 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3940 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023941 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3942 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003943 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3944 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3945 }
Maggie Caia2f03f52019-04-02 02:13:283946 }
3947#endif
djacobo21e56e02016-07-02 01:14:313948
Maggie Caia2f03f52019-04-02 02:13:283949#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:103950 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283951#if defined(OS_CHROMEOS)
Maggie Caic08b7d42020-05-05 03:51:103952 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3953 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3954 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253955#elif defined(OS_MACOSX)
Maggie Caic08b7d42020-05-05 03:51:103956 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283957#else
Maggie Caic08b7d42020-05-05 03:51:103958 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283959#endif
Maggie Caic08b7d42020-05-05 03:51:103960 if (url_to_apps_throttle)
3961 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003962#endif
3963
brettw00899e62016-11-12 02:10:173964#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003965 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093966 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513967
Chris Hamiltonab4722122020-05-13 18:01:283968 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
3969 ->GetUserScriptListener()
3970 ->CreateNavigationThrottle(handle),
3971 &throttles);
naskob9164c42016-06-07 01:21:353972#endif
3973
bauerb8f9c37742017-03-30 15:04:123974#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213975 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283976 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
3977 &throttles);
bauerb8f9c37742017-03-30 15:04:123978#endif
3979
csharrisone985ebc2017-04-04 17:05:033980 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103981 if (auto* subresource_filter_client =
3982 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3983 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3984 &throttles);
csharrisone985ebc2017-04-04 17:05:033985 }
3986
zhenw6edd49c2017-07-12 05:49:453987#if !defined(OS_ANDROID)
3988 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3989 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:283990 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
3991 MaybeCreateThrottleFor(handle),
3992 &throttles);
zhenw6edd49c2017-07-12 05:49:453993#endif
3994
Nico Weberbc5b06f2019-07-26 14:00:133995#if BUILDFLAG(FULL_SAFE_BROWSING)
Chris Hamiltonab4722122020-05-13 18:01:283996 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
3997 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:093998#endif
3999
Lukasz Anforowicz7724d092019-10-03 23:50:214000 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284001 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
4002 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:274003
Chris Hamiltonab4722122020-05-13 18:01:284004 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
4005 &throttles);
Amber Won6b5edc752017-08-17 19:23:544006
Chris Hamiltonab4722122020-05-13 18:01:284007 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:514008
Jeremy Romanec48d7a2018-03-01 17:35:094009 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534010 handle, handle->GetWebContents()->GetBrowserContext()));
4011
Colin Blundelleaa7377bf2020-01-22 08:49:104012 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
4013 // the relevant extension API whenever an SSL interstitial is shown.
4014 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
4015 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:284016 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4017 handle,
4018 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:384019 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:124020
Emily Starkd6896cd32019-08-21 04:55:544021 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4022
Lukasz Anforowicz7724d092019-10-03 23:50:214023 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284024 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle),
4025 &throttles);
Christopher Thompson4137cec2017-12-19 05:34:234026
Dmitry Gozman57b92ce2017-12-28 22:24:544027#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284028 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4029 &throttles);
4030
4031 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4032 &throttles);
Conley Owensaafcf122018-02-26 18:53:514033
Lukasz Anforowicz7724d092019-10-03 23:50:214034 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284035 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle),
4036 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544037#endif
4038
Carlos IL800e3502020-04-30 16:35:594039 throttles.push_back(
4040 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034041
Mustafa Emre Acer97be4752020-05-13 01:24:434042 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4043 throttles.push_back(
4044 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4045 handle));
4046 }
4047
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334048#if defined(OS_WIN) || defined(OS_MACOSX) || \
4049 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Chris Hamiltonab4722122020-05-13 18:01:284050 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4051 MaybeCreateThrottleFor(handle),
4052 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134053#endif
4054
Anatoliy Potapchuk762c40d2020-05-11 15:10:374055#if defined(OS_CHROMEOS)
4056 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284057 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
4058 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374059#endif
4060
Chris Hamiltonab4722122020-05-13 18:01:284061 auto* performance_manager_registry =
4062 performance_manager::PerformanceManagerRegistry::GetInstance();
4063 if (performance_manager_registry) {
4064 MaybeAddThrottles(
4065 performance_manager_registry->CreateThrottlesForNavigation(handle),
4066 &throttles);
4067 }
4068
dchenge73d8520c2015-12-27 01:19:094069 return throttles;
clamy40c9e142015-09-29 11:18:474070}
4071
clamy1e5574e2016-09-29 16:48:444072std::unique_ptr<content::NavigationUIData>
4073ChromeContentBrowserClient::GetNavigationUIData(
4074 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094075 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444076}
4077
Xiaohan Wanga4e41842018-06-26 18:45:104078void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4079 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104080 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124081 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104082#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264083 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104084 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334085 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104086 }
4087#endif
4088}
4089
[email protected]487974a2014-06-13 16:49:014090content::DevToolsManagerDelegate*
4091ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354092#if defined(OS_ANDROID)
4093 return new DevToolsManagerDelegateAndroid();
4094#else
[email protected]487974a2014-06-13 16:49:014095 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354096#endif
[email protected]487974a2014-06-13 16:49:014097}
4098
Rayan Kanso411e84e2019-02-13 15:27:404099void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4100 content::BrowserContext* browser_context,
4101 int service,
4102 base::Time expiration_time) {
4103 Profile* profile = Profile::FromBrowserContext(browser_context);
4104 DCHECK(profile);
4105
4106 auto* pref_service = profile->GetPrefs();
4107 DCHECK(pref_service);
4108
4109 DictionaryPrefUpdate pref_update(
4110 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4111 base::DictionaryValue* exp_dict = pref_update.Get();
4112
4113 // Convert |expiration_time| to minutes since that is the most granular
4114 // option that returns an int. base::Value does not accept int64.
4115 int expiration_time_minutes =
4116 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4117 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4118}
4119
4120base::flat_map<int, base::Time>
4121ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4122 content::BrowserContext* browser_context) {
4123 Profile* profile = Profile::FromBrowserContext(browser_context);
4124 DCHECK(profile);
4125
4126 auto* pref_service = profile->GetPrefs();
4127 DCHECK(pref_service);
4128
4129 auto* expiration_dict = pref_service->GetDictionary(
4130 prefs::kDevToolsBackgroundServicesExpirationDict);
4131 DCHECK(expiration_dict);
4132
4133 base::flat_map<int, base::Time> expiration_times;
4134 for (const auto& it : *expiration_dict) {
4135 // key.
4136 int service = 0;
4137 bool did_convert = base::StringToInt(it.first, &service);
4138 DCHECK(did_convert);
4139
4140 // value.
4141 DCHECK(it.second->is_int());
4142 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4143 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4144
4145 expiration_times[service] = expiration_time;
4146 }
4147
4148 return expiration_times;
4149}
4150
oysteinec563c582015-02-13 19:19:524151content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524152 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524153}
4154
[email protected]a6868c22013-10-09 02:50:294155bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4156 content::BrowserContext* browser_context,
4157 const GURL& url) {
brettw4b461082016-11-19 18:55:164158#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554159 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194160 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294161#else
4162 return false;
4163#endif
4164}
4165
[email protected]aec5ed52014-06-20 07:51:424166bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4167 content::BrowserContext* browser_context,
4168 const GURL& url) {
brettw4b461082016-11-19 18:55:164169#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554170 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194171 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064172#else
4173 return false;
4174#endif
4175}
4176
mlamourif8c23a2002015-01-27 13:10:104177void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014178 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434179 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524180 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104181
4182 WebContents* web_contents =
4183 WebContents::FromRenderFrameHost(render_frame_host);
4184 DCHECK(web_contents);
4185
mlamourif8c23a2002015-01-27 13:10:104186 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374187 prerender::PrerenderManagerFactory::GetForBrowserContext(
4188 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104189 if (prerender_manager &&
4190 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294191 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104192 }
4193}
4194
Robert Sesek466e43e2019-08-19 22:02:024195void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4196 base::FilePath user_data_dir;
4197 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4198 DCHECK(!user_data_dir.empty());
4199 network_contexts_parent_directory_.push_back(user_data_dir);
4200
4201 base::FilePath cache_dir;
4202 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4203 DCHECK(!cache_dir.empty());
4204 // On some platforms, the cache is a child of the user_data_dir so only
4205 // return the one path.
4206 if (!user_data_dir.IsParent(cache_dir))
4207 network_contexts_parent_directory_.push_back(cache_dir);
4208
4209 // If the cache location has been overridden by a switch or preference,
4210 // include that as well.
4211 if (auto* local_state = g_browser_process->local_state()) {
4212 base::FilePath pref_cache_dir =
4213 local_state->GetFilePath(prefs::kDiskCacheDir);
4214 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4215 network_contexts_parent_directory_.push_back(pref_cache_dir);
4216 }
4217}
4218
[email protected]30335fdf02014-02-26 19:51:274219void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174220 base::CommandLine* to_command_line,
4221 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544222 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274223#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544224 const version_info::Channel kMaxDisableEncryptionChannel =
4225 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274226#else
sdefresne6e883e42015-07-30 08:05:544227 const version_info::Channel kMaxDisableEncryptionChannel =
4228 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274229#endif
4230 if (channel <= kMaxDisableEncryptionChannel) {
4231 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444232 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274233 };
Avi Drissmand251e912018-12-26 15:46:374234 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4235 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274236 }
4237}
bashi933629552016-10-13 23:32:404238
miu54dca6c2016-11-17 10:59:384239#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4240void ChromeContentBrowserClient::CreateMediaRemoter(
4241 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504242 mojo::PendingRemote<media::mojom::RemotingSource> source,
4243 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384244 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504245 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384246}
4247#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464248
Michael Giuffrida6802ffe2017-09-29 03:40:254249base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4250 const base::CommandLine& command_line) {
4251 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164252}
4253
John Abd-El-Malek8efa11f2019-01-06 00:51:534254namespace {
4255// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024256class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534257 public:
4258 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174259 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534260 : protocol_handler_registry_(protocol_handler_registry) {}
4261 ~ProtocolHandlerThrottle() override = default;
4262
4263 void WillStartRequest(network::ResourceRequest* request,
4264 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294265 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534266 }
4267
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584268 void WillRedirectRequest(
4269 net::RedirectInfo* redirect_info,
4270 const network::mojom::URLResponseHead& response_head,
4271 bool* defer,
4272 std::vector<std::string>* to_be_removed_headers,
4273 net::HttpRequestHeaders* modified_headers,
4274 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294275 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534276 }
4277
4278 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294279 void TranslateUrl(GURL* url) {
4280 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4281 return;
4282 GURL translated_url = protocol_handler_registry_->Translate(*url);
4283 if (!translated_url.is_empty())
4284 *url = translated_url;
4285 }
4286
Clark DuValla411bda2019-08-02 03:09:174287 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534288};
4289} // namespace
4290
Minggang Wangf6840ecf2019-07-29 05:15:024291std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194292ChromeContentBrowserClient::CreateURLLoaderThrottles(
4293 const network::ResourceRequest& request,
4294 content::BrowserContext* browser_context,
4295 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4296 content::NavigationUIData* navigation_ui_data,
4297 int frame_tree_node_id) {
4298 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4299
Minggang Wangf6840ecf2019-07-29 05:15:024300 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194301
4302 Profile* profile = Profile::FromBrowserContext(browser_context);
4303
4304 ChromeNavigationUIData* chrome_navigation_ui_data =
4305 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4306
Nico Weberbc5b06f2019-07-26 14:00:134307#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564308 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4309 request.url, *profile->GetPrefs());
4310 if (!matches_enterprise_whitelist) {
Xinghui Lue17b19942020-02-24 21:19:584311 // |url_lookup_service| is used when real time url check is enabled.
4312 safe_browsing::RealTimeUrlLookupService* url_lookup_service =
4313 // |safe_browsing_service_| may be unavailable in tests.
4314 safe_browsing_service_ &&
4315 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
Varun Khaneja24cc123f2020-05-14 21:08:484316 profile->GetPrefs(), profile->IsOffTheRecord(),
4317 g_browser_process->variations_service())
Xinghui Lue17b19942020-02-24 21:19:584318 ? safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
4319 profile)
4320 : nullptr;
Xinghui Lu0abc17b2020-02-20 22:50:194321
Clark DuVall5497288d2019-07-17 00:17:564322 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4323 base::BindOnce(
4324 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534325 base::Unretained(this),
Bettinae83f522c72020-03-12 01:52:334326 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs())),
Xinghui Lua142c102020-03-02 20:50:084327 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584328 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564329 }
Nico Weberbc5b06f2019-07-26 14:00:134330#endif
Clark DuVall5497288d2019-07-17 00:17:564331
dalykba7bbfc2019-12-18 19:59:214332#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4333 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014334 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4335 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214336#endif
4337
Clark DuVallfffa41e2019-06-25 20:27:194338 if (chrome_navigation_ui_data &&
4339 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4340 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4341 chrome_navigation_ui_data->prerender_mode(),
4342 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234343 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194344 }
4345
John Abd-El-Malek4f380d92020-02-19 16:43:364346#if defined(OS_ANDROID)
4347 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234348 bool night_mode_enabled = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374349 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4350 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364351 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4352 if (web_contents) {
4353 auto* client_data_header_observer =
4354 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4355 web_contents);
4356 if (client_data_header_observer)
4357 client_data_header = client_data_header_observer->header();
4358 }
Brandon Wylie21a88ac92020-05-15 02:49:234359
4360 auto* delegate = TabAndroid::FromWebContents(web_contents)
4361 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4362 web_contents->GetDelegate())
4363 : nullptr;
4364 if (delegate) {
4365 night_mode_enabled = delegate->IsNightModeEnabled();
4366 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374367 }
John Abd-El-Malek4f380d92020-02-19 16:43:364368#endif
4369
Clark DuVallfffa41e2019-06-25 20:27:194370 chrome::mojom::DynamicParams dynamic_params = {
4371 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4372 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274373 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4374 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364375#if defined(OS_ANDROID)
Brandon Wylie21a88ac92020-05-15 02:49:234376 client_data_header, night_mode_enabled,
John Abd-El-Malek4f380d92020-02-19 16:43:364377#endif
Alex Clarke3ebd9772020-02-28 10:50:274378 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194379
Clark DuValla411bda2019-08-02 03:09:174380 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4381 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214382
Clark DuVall39c2cfc2019-06-25 21:49:284383#if BUILDFLAG(ENABLE_PLUGINS)
4384 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464385 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284386#endif
4387
Robbie McElrath127ad2b2019-07-22 22:38:114388 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404389 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584390 auto signin_throttle =
4391 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114392 if (signin_throttle)
4393 result.push_back(std::move(signin_throttle));
4394
Clark DuVallfffa41e2019-06-25 20:27:194395 return result;
4396}
4397
Ken Rockot6414c4d92017-11-08 19:58:324398void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464399 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324400 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414401#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464402 content::WebContents* web_contents =
4403 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414404#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324405 factories->emplace(
4406 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574407 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464408 web_contents->GetBrowserContext(),
4409 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414410#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4411#if defined(OS_CHROMEOS)
4412 Profile* profile =
4413 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304414 factories->emplace(content::kExternalFileScheme,
4415 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4416 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414417#endif // defined(OS_CHROMEOS)
4418#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324419}
4420
Ting Shao2dc60582019-07-15 04:43:364421void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344422 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4423 content::BrowserContext* browser_context,
4424 NonNetworkURLLoaderFactoryMap* factories) {
4425#if BUILDFLAG(ENABLE_EXTENSIONS)
4426 DCHECK(browser_context);
4427 DCHECK(factories);
4428 factories->emplace(
4429 extensions::kExtensionScheme,
4430 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4431 browser_context));
4432#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4433}
4434
4435void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364436 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4437 content::BrowserContext* browser_context,
4438 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114439#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364440 DCHECK(browser_context);
4441 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364442 factories->emplace(
4443 extensions::kExtensionScheme,
4444 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4445 browser_context));
4446#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364447}
4448
Jay Civelli2578ebe2018-06-05 18:44:314449namespace {
4450
4451// The FileURLLoaderFactory provided to the extension background pages.
4452// Checks with the ChildProcessSecurityPolicy to validate the file access.
4453class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4454 public:
4455 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4456
4457 private:
4458 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274459 void CreateLoaderAndStart(
4460 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4461 int32_t routing_id,
4462 int32_t request_id,
4463 uint32_t options,
4464 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304465 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274466 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4467 override {
Jay Civelli2578ebe2018-06-05 18:44:314468 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4469 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304470 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4471 ->OnComplete(
4472 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314473 return;
4474 }
Yutaka Hiranodf83dca42020-01-07 06:24:554475 content::CreateFileURLLoaderBypassingSecurityChecks(
4476 request, std::move(loader), std::move(client),
4477 /*observer=*/nullptr,
4478 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314479 }
4480
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524481 void Clone(
4482 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4483 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314484 }
4485
4486 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524487 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314488 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4489};
4490
Aya ElAttareb5fee12020-05-05 08:56:054491#if defined(OS_CHROMEOS)
4492bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4493 PrefService* const local_state = g_browser_process->local_state();
4494 if (!local_state) // Sometimes it's not available in tests.
4495 return false;
4496
4497 const base::ListValue* disabled_system_features_pref =
4498 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4499 if (!disabled_system_features_pref)
4500 return false;
4501
4502 const auto disabled_system_features =
4503 disabled_system_features_pref->GetList();
4504 return base::Contains(disabled_system_features, base::Value(system_feature));
4505}
4506
4507bool IsSystemFeatureURLDisabled(const GURL& url) {
4508 if (!url.SchemeIs(content::kChromeUIScheme))
4509 return false;
4510
4511 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4512 // installation complete successfully.
4513 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4514 url.path() != "/pwa.html" &&
4515 IsSystemFeatureDisabled(policy::SystemFeature::OS_SETTINGS)) {
4516 return true;
4517 }
4518
4519 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
4520 IsSystemFeatureDisabled(policy::SystemFeature::BROWSER_SETTINGS)) {
4521 return true;
4522 }
4523
4524 return false;
4525}
4526#endif
Jay Civelli2578ebe2018-06-05 18:44:314527} // namespace
4528
Ken Rockot6414c4d92017-11-08 19:58:324529void ChromeContentBrowserClient::
4530 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464531 int render_process_id,
4532 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324533 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414534#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4535 content::RenderFrameHost* frame_host =
4536 RenderFrameHost::FromID(render_process_id, render_frame_id);
4537 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4538#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4539
4540#if defined(OS_CHROMEOS)
4541 if (web_contents) {
4542 Profile* profile =
4543 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304544 factories->emplace(content::kExternalFileScheme,
4545 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4546 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414547 }
4548#endif // defined(OS_CHROMEOS)
4549
Ken Rockot6414c4d92017-11-08 19:58:324550#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464551 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4552 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324553 if (factory)
4554 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234555
4556 // This logic should match
4557 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314558 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234559 return;
Jay Civellic9bbf72d2018-03-24 01:58:314560
4561 Profile* profile =
4562 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4563 InstantService* instant_service =
4564 InstantServiceFactory::GetForProfile(profile);
4565 // The test below matches what's done by ShouldServiceRequestIOThread in
4566 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464567 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314568 factories->emplace(
4569 chrome::kChromeSearchScheme,
4570 content::CreateWebUIURLLoader(
4571 frame_host, chrome::kChromeSearchScheme,
4572 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234573 }
Jay Civellic9bbf72d2018-03-24 01:58:314574
Chris Mumfordbae8a742018-03-01 23:02:234575 extensions::ChromeExtensionWebContentsObserver* web_observer =
4576 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4577 web_contents);
4578
Karan Bhatia91928572018-03-06 01:18:074579 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4580 // to the |web_contents|.
4581 if (!web_observer)
4582 return;
4583
Chris Mumfordbae8a742018-03-01 23:02:234584 const Extension* extension =
4585 web_observer->GetExtensionFromFrame(frame_host, false);
4586 if (!extension)
4587 return;
4588
Sam McNally7414eeb72018-09-03 04:05:304589 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234590 // Support for chrome:// scheme if appropriate.
4591 if ((extension->is_extension() || extension->is_platform_app()) &&
4592 Manifest::IsComponentLocation(extension->location())) {
4593 // Components of chrome that are implemented as extensions or platform apps
4594 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304595 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4596 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4597 }
4598 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4599 (extension->is_platform_app() &&
4600 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234601 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024602 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4603 // URLs. Hosted apps are not allowed because they are served via web servers
4604 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304605 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4606 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024607 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304608 }
4609 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234610 factories->emplace(
4611 content::kChromeUIScheme,
4612 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4613 std::move(allowed_webui_hosts)));
4614 }
Jay Civelli2578ebe2018-06-05 18:44:314615
4616 // Extension with a background page get file access that gets approval from
4617 // ChildProcessSecurityPolicy.
4618 extensions::ExtensionHost* host =
4619 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4620 ->GetBackgroundHostForExtension(extension->id());
4621 if (host) {
4622 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4623 render_process_id));
4624 }
Chris Mumfordbae8a742018-03-01 23:02:234625#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324626}
4627
Ken Rockota0dfaca12018-02-15 07:26:254628bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214629 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254630 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384631 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444632 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264633 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004634 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424635 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184636 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4637 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334638 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084639 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334640 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014641 bool use_proxy = false;
4642
Ken Rockota0dfaca12018-02-15 07:26:254643#if BUILDFLAG(ENABLE_EXTENSIONS)
4644 auto* web_request_api =
4645 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214646 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254647
4648 // NOTE: Some unit test environments do not initialize
4649 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014650 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124651 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384652 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004653 browser_context, frame, render_process_id, type,
4654 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124655 if (bypass_redirect_checks)
4656 *bypass_redirect_checks = use_proxy_for_web_request;
4657 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014658 }
Ken Rockota0dfaca12018-02-15 07:26:254659#endif
Reilly Grant24bf8332018-08-27 21:55:014660
Reilly Grantcc22e602018-09-07 15:25:204661 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444662 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4663 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014664
dalyk0018c16f2020-01-08 20:20:084665#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4666 if (disable_secure_dns) {
4667 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4668 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014669 web_contents &&
4670 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4671 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084672 ->is_captive_portal_window();
4673 }
4674#endif
4675
Reilly Grant24bf8332018-08-27 21:55:014676 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254677}
4678
Jian Lide7b43792018-06-01 23:22:134679std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4680ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4681 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144682 int frame_tree_node_id,
4683 const scoped_refptr<network::SharedURLLoaderFactory>&
4684 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134685 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4686 interceptors;
4687#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234688 interceptors.push_back(
4689 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4690 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134691#endif
Ryan Sturmaf523742019-01-16 00:15:454692
Robert Ogden6946ad42020-01-13 18:01:304693 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4694 interceptors.push_back(
4695 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4696 frame_tree_node_id));
4697 }
4698
Jian Lide7b43792018-06-01 23:22:134699 return interceptors;
4700}
4701
Yutaka Hirano8e0b4d432019-07-04 07:12:384702bool ChromeContentBrowserClient::WillInterceptWebSocket(
4703 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334704#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384705 if (!frame) {
4706 return false;
4707 }
4708 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334709 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4710 frame->GetProcess()->GetBrowserContext());
4711
4712 // NOTE: Some unit test environments do not initialize
4713 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4714 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384715 return false;
Yutaka Hirano36c94952018-05-30 21:33:334716
Yutaka Hirano8e0b4d432019-07-04 07:12:384717 return web_request_api->MayHaveProxies();
4718#else
4719 return false;
4720#endif
4721}
4722
4723void ChromeContentBrowserClient::CreateWebSocket(
4724 content::RenderFrameHost* frame,
4725 WebSocketFactory factory,
4726 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394727 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384728 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404729 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4730 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384731#if BUILDFLAG(ENABLE_EXTENSIONS)
4732 if (!frame) {
4733 return;
4734 }
4735 auto* web_request_api =
4736 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4737 frame->GetProcess()->GetBrowserContext());
4738
4739 DCHECK(web_request_api);
4740 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394741 site_for_cookies.RepresentativeUrl(),
4742 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334743#endif
4744}
4745
Maks Orlovich710d5e32019-07-09 20:16:454746bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464747 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454748 content::BrowserContext* browser_context,
4749 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394750 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404751 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454752 bool is_service_worker,
4753 int process_id,
4754 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034755 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454756 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4757#if BUILDFLAG(ENABLE_EXTENSIONS)
4758 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464759 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454760 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404761 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4762 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454763 return true;
4764 }
4765#endif
4766 return false;
4767}
4768
Matt Menkeae4fdb12018-06-02 06:32:544769void ChromeContentBrowserClient::OnNetworkServiceCreated(
4770 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534771 PrefService* local_state;
4772 if (g_browser_process) {
4773 DCHECK(g_browser_process->local_state());
4774 local_state = g_browser_process->local_state();
4775 } else {
Xi Han85079c22019-04-18 21:43:054776 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4777 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534778 }
4779
4780 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4781 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4782
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494783 // Create SystemNetworkContextManager if it has not been created yet. We need
4784 // to set up global NetworkService state before anything else uses it and this
4785 // is the first opportunity to initialize SystemNetworkContextManager with the
4786 // NetworkService.
4787 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534788 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074789
Min Qin8caab1d2018-10-03 17:28:134790 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544791 network_service);
4792}
4793
Matthew Denton8888ae52020-05-14 08:20:024794void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:254795 content::BrowserContext* context,
4796 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:024797 const base::FilePath& relative_partition_path,
4798 network::mojom::NetworkContextParams* network_context_params,
4799 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504800 Profile* profile = Profile::FromBrowserContext(context);
Matthew Denton8888ae52020-05-14 08:20:024801 profile->ConfigureNetworkContextParams(in_memory, relative_partition_path,
4802 network_context_params,
4803 cert_verifier_creation_params);
Ken Rockota0dfaca12018-02-15 07:26:254804}
4805
Robert Sesek34f68f312019-01-14 20:25:114806std::vector<base::FilePath>
4807ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024808 DCHECK(!network_contexts_parent_directory_.empty());
4809 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114810}
4811
Min Qin75ed6df2017-12-01 20:39:154812bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134813 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154814#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4815 // It is OK to load the saved offline copy, in MHTML format.
4816 ChromeNavigationUIData* chrome_navigation_ui_data =
4817 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4818 if (!chrome_navigation_ui_data)
4819 return false;
4820 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4821 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4822 return offline_page_data && offline_page_data->is_offline_page();
4823#else
4824 return false;
4825#endif
4826}
4827
Min Qin30a78a12017-12-06 01:29:134828bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4829 const GURL& url,
4830 const std::string& mime_type) {
4831#if BUILDFLAG(ENABLE_EXTENSIONS)
4832 // Special-case user scripts to get downloaded instead of viewed.
4833 return extensions::UserScript::IsURLUserScript(url, mime_type);
4834#else
4835 return false;
4836#endif
4837}
4838
Donna Wu838ac362018-08-10 10:36:334839void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344840 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044841 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:464842 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:344843 return;
4844
[email protected]95ebe7c2020-04-08 19:12:454845 CHECK(render_frame_host);
4846 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4847 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344848}
4849
Ovidio Henriquez3d729f62020-02-07 00:43:294850content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4851 if (!bluetooth_delegate_)
4852 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4853 return bluetooth_delegate_.get();
4854}
4855
Reilly Grant0d282322019-01-29 02:42:584856#if !defined(OS_ANDROID)
4857content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4858 if (!serial_delegate_)
4859 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4860 return serial_delegate_.get();
4861}
Matt Reynolds93616f9b2019-06-07 01:28:524862
4863content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4864 if (!hid_delegate_)
4865 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4866 return hid_delegate_.get();
4867}
Reilly Grant0d282322019-01-29 02:42:584868
Balazs Engedya7ff70982018-06-04 18:14:474869std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4870ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334871 content::RenderFrameHost* render_frame_host) {
4872 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4873 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474874}
Nina Satragno8c832df2019-07-29 15:59:394875#endif
Balazs Engedya7ff70982018-06-04 18:14:474876
Jun Cai9409ded2018-01-30 00:19:464877std::unique_ptr<net::ClientCertStore>
4878ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104879 content::BrowserContext* browser_context) {
4880 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464881 ->CreateClientCertStore();
4882}
4883
David Benjamineced01fc2019-02-27 18:29:024884std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394885ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584886 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024887 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034888 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244889 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394890 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034891 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394892 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564893 LoginAuthRequiredCallback auth_required_callback) {
Emily Stark63c884f2020-05-12 03:55:284894 // For subresources, create a LoginHandler directly, which may show a login
4895 // prompt to the user. Main frame resources go through LoginTabHelper, which
4896 // manages a more complicated flow to avoid confusion about which website is
4897 // showing the prompt.
4898 if (is_request_for_main_frame) {
4899 LoginTabHelper::CreateForWebContents(web_contents);
4900 return LoginTabHelper::FromWebContents(web_contents)
4901 ->CreateAndStartMainFrameLoginDelegate(
4902 auth_info, web_contents, request_id, url, response_headers,
4903 std::move(auth_required_callback));
4904 }
4905 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
4906 auth_info, web_contents, std::move(auth_required_callback));
4907 login_handler->StartSubresource(request_id, url, response_headers);
4908 return login_handler;
Jun Caibc561f412018-02-28 18:41:394909}
4910
John Abd-El-Maleka67add82018-03-09 18:22:014911bool ChromeContentBrowserClient::HandleExternalProtocol(
4912 const GURL& url,
danakjf4b9e942019-11-29 15:43:044913 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014914 int child_id,
4915 content::NavigationUIData* navigation_data,
4916 bool is_main_frame,
4917 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454918 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454919 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104920 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014921#if BUILDFLAG(ENABLE_EXTENSIONS)
4922 // External protocols are disabled for guests. An exception is made for the
4923 // "mailto" protocol, so that pages that utilize it work properly in a
4924 // WebView.
4925 ChromeNavigationUIData* chrome_data =
4926 static_cast<ChromeNavigationUIData*>(navigation_data);
4927 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4928 (chrome_data &&
4929 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4930 !url.SchemeIs(url::kMailToScheme)) {
4931 return false;
4932 }
4933#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4934
4935#if defined(OS_ANDROID)
4936 // Main frame external protocols are handled by
4937 // InterceptNavigationResourceThrottle.
4938 if (is_main_frame)
4939 return false;
4940#endif // defined(ANDROID)
4941
Gabriel Charettee7cdc5cd2020-05-27 23:35:054942 content::GetUIThreadTaskRunner({})->PostTask(
4943 FROM_HERE,
danakjf4b9e942019-11-29 15:43:044944 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4945 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014946 return true;
4947}
4948
Jennifer Apacible4f854a82018-04-06 22:22:114949std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284950ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4951 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114952 // Note: content::OverlayWindow::Create() is defined by platform-specific
4953 // implementation in chrome/browser/ui/views. This layering hack, which goes
4954 // through //content and ContentBrowserClient, allows us to work around the
4955 // dependency constraints that disallow directly calling
4956 // chrome/browser/ui/views code either from here or from other code in
4957 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284958 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114959}
4960
Kunihiko Sakamoto19aa7082019-02-25 03:14:434961void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564962 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114963 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564964 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434965 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4966 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564967}
4968
dbeam25472e0c2017-06-23 19:02:314969// Static; handles rewriting Web UI URLs.
4970bool ChromeContentBrowserClient::HandleWebUI(
4971 GURL* url,
4972 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394973 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314974 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394975 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314976 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4977 chrome::kChromeUIHelpHost);
4978 return true; // Return true to update the displayed URL.
4979 }
4980
Hector Carmona566a20b2019-09-13 22:44:424981#if defined(OS_WIN)
4982 // TODO(crbug.com/1003960): Remove when issue is resolved.
4983 if (url->SchemeIs(content::kChromeUIScheme) &&
4984 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4985 url::Replacements<char> replacements;
4986 replacements.SetHost(
4987 chrome::kChromeUIWelcomeHost,
4988 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4989 *url = url->ReplaceComponents(replacements);
4990 return true;
4991 }
4992#endif // defined(OS_WIN)
4993
dbeam25472e0c2017-06-23 19:02:314994 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4995 browser_context, *url)) {
4996 return false;
4997 }
4998
4999#if defined(OS_CHROMEOS)
5000 // Special case : in ChromeOS in Guest mode bookmarks and history are
5001 // disabled for security reasons. New tab page explains the reasons, so
5002 // we redirect user to new tab page.
5003 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5004 if (url->SchemeIs(content::kChromeUIScheme) &&
5005 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5006 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5007 // Rewrite with new tab URL
5008 *url = GURL(chrome::kChromeUINewTabURL);
5009 }
5010 }
Aya ElAttareb5fee12020-05-05 08:56:055011
5012 if (IsSystemFeatureURLDisabled(*url)) {
5013 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
5014 return true;
5015 }
5016
dbeam25472e0c2017-06-23 19:02:315017#endif
5018
5019 return true;
5020}
5021
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065022bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5023 content::BrowserContext* browser_context,
5024 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325025 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065026#if defined(OS_ANDROID)
5027 return false;
5028#else
5029 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5030 ->GetForBrowserContext(browser_context)
5031 ->ShowPaymentHandlerWindow(url, std::move(callback));
5032 return true;
5033#endif
5034}
5035
Dan Beam141c48932019-08-22 02:29:395036// static
dbeam25472e0c2017-06-23 19:02:315037bool ChromeContentBrowserClient::HandleWebUIReverse(
5038 GURL* url,
5039 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425040#if defined(OS_WIN)
5041 // TODO(crbug.com/1003960): Remove when issue is resolved.
5042 // No need to actually reverse-rewrite the URL, but return true to update the
5043 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5044 if (url->SchemeIs(content::kChromeUIScheme) &&
5045 url->host() == chrome::kChromeUIWelcomeHost) {
5046 return true;
5047 }
5048#endif // defined(OS_WIN)
5049
dbeam25472e0c2017-06-23 19:02:315050 // No need to actually reverse-rewrite the URL, but return true to update the
5051 // displayed URL when rewriting chrome://help to chrome://settings/help.
5052 return url->SchemeIs(content::kChromeUIScheme) &&
5053 url->host() == chrome::kChromeUISettingsHost;
5054}
5055
Alison Maher7f366dc62020-03-03 19:46:005056const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585057 return ui::NativeTheme::GetInstanceForWeb();
5058}
5059
Clark DuVall5497288d2019-07-17 00:17:565060scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505061ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:535062 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:355063 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5064
Matt Menke562675cfe2020-01-07 15:50:535065 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:505066 return nullptr;
5067
Yuzhu Shen44094e22017-07-18 22:52:355068 // |safe_browsing_service_| may be unavailable in tests.
5069 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5070 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435071 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355072 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435073 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355074 }
5075
Clark DuVall5497288d2019-07-17 00:17:565076 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355077}
Daniel Vogelheim6008f572018-09-24 14:35:145078
5079base::Optional<std::string>
5080ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595081 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185082 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595083 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5084 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145085}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525086
Takashi Toyoshima5af383aa2019-07-22 15:24:225087bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525088 // We require --user-data-dir flag too so that no dangerous changes are made
5089 // in the user's regular profile.
5090 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5091 switches::kUserDataDir);
5092}
rajendrantfeea8592018-10-19 18:26:065093
5094void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5095 int32_t network_traffic_annotation_id_hash,
5096 int64_t recv_bytes,
5097 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035098 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5099 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5100 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5101 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065102 }
5103}
Ryan Sturmaa05092f2018-10-21 03:56:545104
Ken Rockot4e284d32020-03-06 06:26:495105base::FilePath
5106ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
5107 return g_browser_process->profile_manager()->user_data_dir();
5108}
5109
Ryan Sturmaa05092f2018-10-21 03:56:545110content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5111 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395112 content::NavigationHandle* navigation_handle,
5113 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135114 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5115 initial_state, navigation_handle, current_navigation_url);
5116
5117 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5118}
5119
5120content::PreviewsState
5121ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5122 content::PreviewsState initial_state,
5123 content::NavigationHandle* navigation_handle,
5124 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545125 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295126 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215127
Ryan Sturmaa05092f2018-10-21 03:56:545128 // If this is not a main frame, return the initial state. If there are no
5129 // previews in the state, return the state as is.
5130 if (!navigation_handle->IsInMainFrame() ||
5131 navigation_handle->IsSameDocument()) {
5132 return initial_state;
5133 }
5134
Robert Ogdena994eb42019-02-14 19:15:085135 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395136 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085137
Doug Arnettb3b99bc2019-08-09 16:55:565138 // Check if initial state specifies no previews should be considered.
5139 if (initial_state == content::PREVIEWS_OFF)
5140 return initial_state;
5141
Robert Ogdena994eb42019-02-14 19:15:085142 // Do not allow previews on POST navigations since the primary opt-out
5143 // mechanism is to reload the page. Because POST navigations are not
5144 // idempotent, we do not want to show a preview on a POST navigation where
5145 // opting out would cause another navigation, i.e.: a reload.
5146 if (navigation_handle->IsPost())
5147 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395148
5149 content::WebContents* web_contents = navigation_handle->GetWebContents();
5150 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5151
Ryan Sturmda2a0e02018-10-25 01:52:215152 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545153
5154 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5155 Profile::FromBrowserContext(browser_context));
5156 auto* data_reduction_proxy_settings =
5157 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5158 browser_context);
5159 // If the profile does not support previews or Data Saver, do not turn on
5160 // Previews.
5161 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355162 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545163 return content::PREVIEWS_OFF;
5164 }
5165
5166 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215167 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545168 // If this tab does not have a PreviewsUITabHelper, no preview should be
5169 // served.
5170 if (!ui_tab_helper)
5171 return content::PREVIEWS_OFF;
5172
5173 DCHECK(!browser_context->IsOffTheRecord());
5174
5175 // Other previews objects should all exist and be initialized if we have made
5176 // it past earlier checks.
5177 previews::PreviewsDeciderImpl* previews_decider_impl =
5178 previews_service->previews_ui_service()->previews_decider_impl();
5179 DCHECK(previews_decider_impl);
5180
Ryan Sturm647d1d92018-11-07 15:41:395181 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545182 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5183
Ryan Sturm647d1d92018-11-07 15:41:395184 previews::PreviewsUserData* previews_data =
5185 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5186
5187 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315188 // previews) and cannot re-evaluate PreviewsState once previews triggering
5189 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375190 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315191 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395192 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375193 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395194 } else {
5195 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5196 navigation_handle, previews_decider_impl->GeneratePageId());
5197 }
5198
5199 DCHECK(previews_data);
5200
Robert Ogden01770b362019-05-22 17:36:435201 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5202 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435203 return content::ALL_SUPPORTED_PREVIEWS;
5204 }
5205
Ryan Sturmaa05092f2018-10-21 03:56:545206 bool is_reload =
5207 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5208
Ryan Sturm647d1d92018-11-07 15:41:395209 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515210 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395211
5212 // For now, treat server previews types as a single decision, and do not
5213 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5214 // header, nor does the plumbing exist to modify the PreviewsState within the
5215 // URLLoader.
Seanac57e9b92019-04-29 19:19:315216 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395217 // Copy the server state that was used before the redirect for the initial
5218 // URL.
Robert Ogden869986f2019-06-20 19:12:055219 previews_state |=
5220 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395221 } else {
Doug Arnetta3dc71582018-11-08 00:25:105222 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215223 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305224 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395225 previews_state |= server_previews_enabled_state;
5226 }
Ryan Sturmaa05092f2018-10-21 03:56:545227 }
5228
Sophie Changa71fa5d2019-11-19 23:53:515229 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545230 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315231 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355232 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5233 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545234
5235 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395236 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545237 return content::PREVIEWS_OFF;
5238 }
5239
5240 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395241 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545242 return content::PREVIEWS_NO_TRANSFORM;
5243 }
5244
5245 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395246 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5247 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545248 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395249 }
5250
5251 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5252 if (delegate) {
5253 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5254 }
Ryan Sturmaa05092f2018-10-21 03:56:545255
5256 // If the allowed previews are limited by the embedder, ensure previews honors
5257 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395258 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5259 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545260 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5261 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5262 previews_state = content::PREVIEWS_OFF;
5263 }
Ryan Sturm647d1d92018-11-07 15:41:395264 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545265 return previews_state;
5266}
5267
5268// static
5269content::PreviewsState
5270ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5271 const GURL& url,
5272 data_reduction_proxy::DataReductionProxyData* drp_data,
5273 previews::PreviewsUserData* previews_user_data,
5274 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055275 content::PreviewsState initial_state,
5276 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545277 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5278 if (!previews::HasEnabledPreviews(initial_state))
5279 return content::PREVIEWS_OFF;
5280
5281 // Check if the server sent a preview directive.
5282 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555283 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545284
Ryan Sturmaa05092f2018-10-21 03:56:545285 // Check the various other client previews types.
5286 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055287 previews_user_data, url, previews_state, previews_decider,
5288 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545289}
5290
5291content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5292 content::PreviewsState initial_state,
5293 content::NavigationHandle* navigation_handle,
5294 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135295 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5296 initial_state, navigation_handle, response_headers);
5297
5298 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5299}
5300
5301content::PreviewsState
5302ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5303 content::PreviewsState initial_state,
5304 content::NavigationHandle* navigation_handle,
5305 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545306 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arthursonzogni90bb0922020-05-28 09:22:235307 DCHECK(!navigation_handle->HasCommitted());
5308
Ryan Sturmaa05092f2018-10-21 03:56:545309 // Only support HTTP and HTTPS.
arthursonzogni90bb0922020-05-28 09:22:235310 if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS())
Ryan Sturmaa05092f2018-10-21 03:56:545311 return content::PREVIEWS_OFF;
Ryan Sturmaa05092f2018-10-21 03:56:545312
5313 // If this is not a main frame, return the initial state. If there are no
5314 // previews in the state, return the state as is.
5315 if (!previews::HasEnabledPreviews(initial_state) ||
5316 !navigation_handle->IsInMainFrame() ||
5317 navigation_handle->IsSameDocument()) {
5318 return initial_state;
5319 }
5320
5321 // WebContents that don't have a PreviewsUITabHelper are not supported.
5322 PreviewsUITabHelper* ui_tab_helper =
5323 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5324 if (!ui_tab_helper)
5325 return content::PREVIEWS_OFF;
5326
5327 // If we did not previously create a PreviewsUserData, do not go any further.
5328 previews::PreviewsUserData* previews_user_data =
5329 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5330 if (!previews_user_data)
5331 return content::PREVIEWS_OFF;
5332
5333 PreviewsService* previews_service =
5334 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5335 navigation_handle->GetWebContents()->GetBrowserContext()));
5336
5337 if (!previews_service || !previews_service->previews_ui_service())
5338 return content::PREVIEWS_OFF;
5339
5340// Check if offline previews are being used and set it in the user data.
5341#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5342 offline_pages::OfflinePageTabHelper* tab_helper =
5343 offline_pages::OfflinePageTabHelper::FromWebContents(
5344 navigation_handle->GetWebContents());
5345
Ryan Sturmfc7d92f2019-02-12 02:24:235346 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5347 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5348
5349 // If this is an offline page, but not a preview, then we should not attempt
5350 // any previews or surface the previews UI.
5351 if (is_offline_page && !is_offline_preview)
5352 return content::PREVIEWS_OFF;
5353
5354 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545355#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5356
5357 // Annotate request if no-transform directive found in response headers.
5358 if (response_headers &&
5359 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265360 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545361 }
5362
5363 previews::PreviewsDeciderImpl* previews_decider_impl =
5364 previews_service->previews_ui_service()->previews_decider_impl();
5365 DCHECK(previews_decider_impl);
5366
Clark DuVall9c5a72cc2018-10-25 01:29:215367 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5368 auto* settings =
5369 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5370 navigation_handle->GetWebContents()->GetBrowserContext());
5371 if (settings) {
5372 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5373 // does not yet have all the response information.
5374 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5375 response_headers);
5376 }
Ryan Sturmaa05092f2018-10-21 03:56:545377
5378 // Determine effective PreviewsState for this committed main frame response.
5379 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215380 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055381 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545382
5383 // Double check that we never serve a preview when we have a
5384 // cache-control:no-transform directive.
5385 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5386 !previews::HasEnabledPreviews(committed_state));
5387
Robert Ogdended292c6f2019-05-03 22:44:515388 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545389 previews_user_data->set_committed_previews_state(committed_state);
5390
5391 previews::PreviewsType committed_type =
5392 previews::GetMainFramePreviewsType(committed_state);
5393
5394 // Capture committed previews type, if any, in PreviewsUserData.
5395 // Note: this is for the subset of previews types that are decided upon
5396 // navigation commit. Previews types that are determined prior to
5397 // navigation (such as for offline pages or for redirecting to another
5398 // url), are not set here.
5399 previews_user_data->SetCommittedPreviewsType(committed_type);
5400
5401 // Log the commit decision.
5402 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5403 previews_decider_impl->LogPreviewDecisionMade(
5404 (previews_user_data->cache_control_no_transform_directive()
5405 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5406 : previews::PreviewsEligibilityReason::COMMITTED),
5407 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055408 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055409 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545410
5411 return committed_state;
5412}
Charlie Harrison650e11422018-12-04 00:37:265413
5414void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5415 content::RenderFrameHost* render_frame_host,
5416 blink::mojom::WebFeature feature) {
5417 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5418 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5419 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5420 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315421
5422 // For the SameSite-by-default-cookies related features, log
5423 // the site engagement score for the site whose cookie was blocked. This is to
5424 // gauge the user impact of the cookies being blocked.
5425 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265426}
Yutaka Hirano968d6252018-12-04 05:09:315427
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525428std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315429 return ::GetProduct();
5430}
5431
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525432std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315433 return ::GetUserAgent();
5434}
Sam McNallyd54e23f92019-01-16 04:42:395435
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525436blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175437 return ::GetUserAgentMetadata();
5438}
5439
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525440base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275441 // This icon is available on Android, but adds 19KiB to the APK. Since it
5442 // isn't used on Android we exclude it to avoid bloat.
5443#if !defined(OS_ANDROID)
5444 return base::Optional<gfx::ImageSkia>(
5445 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5446 IDR_PRODUCT_LOGO_256));
5447#else
5448 return base::nullopt;
5449#endif
5450}
5451
Sam McNallyd54e23f92019-01-16 04:42:395452bool ChromeContentBrowserClient::IsBuiltinComponent(
5453 content::BrowserContext* browser_context,
5454 const url::Origin& origin) {
5455#if BUILDFLAG(ENABLE_EXTENSIONS)
5456 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5457 browser_context, origin);
5458#else
5459 return false;
5460#endif
5461}
Oleg Davydov2cc0167b2019-02-05 14:32:485462
5463bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5464 const GURL& url,
5465 content::BrowserContext* context) {
5466 PolicyBlacklistService* service =
5467 PolicyBlacklistFactory::GetForBrowserContext(context);
5468
5469 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5470 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5471 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5472}
Dominic Mazzoni21fb0282019-02-13 18:32:475473
5474ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5475 content::BrowserContext* browser_context) {
5476 Profile* profile = Profile::FromBrowserContext(browser_context);
5477 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5478}
Eric Karld6cd75b2019-03-14 22:01:365479
5480#if defined(OS_ANDROID)
5481content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525482ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335483 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425484 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365485 return WideColorGamutHeuristic::kUseDisplay;
5486 }
Khushal1fc0da52019-10-09 00:38:565487
5488 if (display::Display::HasForceDisplayColorProfile() &&
5489 display::Display::GetForcedDisplayColorProfile() ==
5490 gfx::ColorSpace::CreateDisplayP3D65()) {
5491 return WideColorGamutHeuristic::kUseDisplay;
5492 }
5493
Eric Karld6cd75b2019-03-14 22:01:365494 return WideColorGamutHeuristic::kNone;
5495}
5496#endif
Ehsan Karamad91413d72019-03-22 16:37:485497
5498base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435499ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465500 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485501 base::flat_set<std::string> mime_types;
5502#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465503 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485504 for (const auto& pair : map)
5505 mime_types.insert(pair.first);
5506#endif
5507 return mime_types;
5508}
Yao Xiaod06607b2019-05-02 23:16:365509
5510void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5511 const content::WebContents* web_contents,
5512 const content::RenderFrameHost* frame_host,
5513 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525514 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365515 const ChromeSubresourceFilterClient* client =
5516 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5517 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045518 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365519 if (!user_gesture) {
5520 if (base::FeatureList::IsEnabled(
5521 blink::features::
5522 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5523 download_policy->SetDisallowed(
5524 content::NavigationDownloadType::kAdFrameNoGesture);
5525 } else {
5526 download_policy->SetAllowed(
5527 content::NavigationDownloadType::kAdFrameNoGesture);
5528 }
Yao Xiaod06607b2019-05-02 23:16:365529 }
5530 }
5531}
Jun Cai732a05e32019-05-29 19:34:195532
5533bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5534 content::BrowserContext* browser_context,
5535 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525536 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195537 const HostContentSettingsMap* const content_settings =
5538 HostContentSettingsMapFactory::GetForProfile(
5539 Profile::FromBrowserContext(browser_context));
5540
5541 if (content_settings->GetContentSetting(
5542 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455543 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195544 std::string()) == CONTENT_SETTING_BLOCK) {
5545 return true;
5546 }
5547
5548 return false;
5549}
5550
5551void ChromeContentBrowserClient::BlockBluetoothScanning(
5552 content::BrowserContext* browser_context,
5553 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525554 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195555 HostContentSettingsMap* const content_settings =
5556 HostContentSettingsMapFactory::GetForProfile(
5557 Profile::FromBrowserContext(browser_context));
5558
5559 content_settings->SetContentSettingDefaultScope(
5560 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455561 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195562 CONTENT_SETTING_BLOCK);
5563}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475564
5565bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5566#if defined(OS_ANDROID)
5567 return extra_icu::ModuleProvider::IsModuleInstalled();
5568#endif
5569 return false;
5570}
Guido Urdaneta4030d6a32019-10-17 09:38:165571
5572bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5573 content::BrowserContext* browser_context,
5574 const GURL& url,
5575 const GURL& site_for_cookies,
5576 const base::Optional<url::Origin>& top_frame_origin) {
5577 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5578 return CookieSettingsFactory::GetForProfile(
5579 Profile::FromBrowserContext(browser_context))
5580 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5581}
Sam Goto5cf068e82019-11-04 23:08:445582
5583#if !defined(OS_ANDROID)
5584void ChromeContentBrowserClient::FetchRemoteSms(
5585 content::BrowserContext* browser_context,
5586 const url::Origin& origin,
5587 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5588 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5589}
5590#endif
Roger Tawa03ffdbd2020-01-16 18:12:545591
5592void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5593 content::WebContents* web_contents,
5594 const GURL& url,
5595 const ui::ClipboardFormatType& data_type,
5596 const std::string& data,
5597 IsClipboardPasteAllowedCallback callback) {
5598#if BUILDFLAG(FULL_SAFE_BROWSING)
5599 // Safe browsing does not support images, so accept without checking.
5600 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5601 // types when it is implemented.
5602 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5603 std::move(callback).Run(ClipboardPasteAllowed(true));
5604 return;
5605 }
5606
5607 Profile* profile =
5608 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5609 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265610 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(
5611 profile, url, &dialog_data,
5612 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545613 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5614 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5615 web_contents, std::move(dialog_data),
5616 base::BindOnce(
5617 [](IsClipboardPasteAllowedCallback callback,
5618 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5619 const safe_browsing::DeepScanningDialogDelegate::Result&
5620 result) {
5621 std::move(callback).Run(
5622 ClipboardPasteAllowed(result.text_results[0]));
5623 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245624 std::move(callback)),
5625 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545626 } else {
5627 std::move(callback).Run(ClipboardPasteAllowed(true));
5628 }
5629#else
5630 std::move(callback).Run(ClipboardPasteAllowed(true));
5631#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5632}
Lukasz Anforowicz4600ea32020-01-18 02:37:485633
Lukasz Anforowicz1feeba182020-03-16 20:32:025634void ChromeContentBrowserClient::
5635 LogUkmEventForCrossOriginFetchFromContentScript3(
5636 const std::string& isolated_world_host) {
5637#if BUILDFLAG(ENABLE_EXTENSIONS)
5638 const std::string& extension_id = isolated_world_host;
5639 ukm::SourceId source_id =
5640 ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id);
5641 if (source_id != ukm::kInvalidSourceId) {
5642 ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event(
5643 source_id);
5644 ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get());
5645 }
5646#endif
5647}
5648
Lukasz Anforowicz4600ea32020-01-18 02:37:485649#if BUILDFLAG(ENABLE_PLUGINS)
5650bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5651 const url::Origin& embedder_origin,
5652 const content::PepperPluginInfo& plugin_info) {
5653#if BUILDFLAG(ENABLE_PDF)
5654 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5655#if BUILDFLAG(ENABLE_EXTENSIONS)
5656 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5657 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5658 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5659 return true;
5660 }
5661#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5662
5663 // Allow embedding the internal PDF plugin in chrome://print.
5664 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5665 return true;
5666
5667 // Only allow the PDF plugin in the known, trustworthy origins that are
5668 // allowlisted above. See also https://crbug.com/520422 and
5669 // https://crbug.com/1027173.
5670 return false;
5671 }
5672#endif // BUILDFLAG(ENABLE_PDF)
5673
5674 return true;
5675}
5676#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565677
5678#if BUILDFLAG(ENABLE_VR)
5679content::XrIntegrationClient*
5680ChromeContentBrowserClient::GetXrIntegrationClient() {
5681 if (!xr_integration_client_)
5682 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5683 util::PassKey<ChromeContentBrowserClient>());
5684 return xr_integration_client_.get();
5685}
5686#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185687
5688bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5689 content::BrowserContext* browser_context) {
5690 auto* profile = Profile::FromBrowserContext(browser_context);
5691 auto* prefs = profile->GetPrefs();
5692
5693 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5694 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5695 return false;
5696 }
5697 if (base::FeatureList::IsEnabled(
5698 blink::features::kAppCacheRequireOriginTrial)) {
5699 return true;
5700 }
5701
5702 return false;
5703}