blob: d21354516d08367889aeb18727ef9a2f022ae5fd [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"
Eric Seckler8652dcd52018-09-20 10:42:2836#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3237#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4138#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1839#include "build/build_config.h"
Ken Rockot341089f2019-01-11 23:11:5840#include "chrome/app/chrome_content_browser_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4741#include "chrome/browser/accessibility/accessibility_labels_service.h"
42#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
Abigail Kleina81f2e22020-05-04 14:32:4143#include "chrome/browser/accessibility/caption_util.h"
michaeln96f887e22015-04-13 23:58:3144#include "chrome/browser/after_startup_task_utils.h"
Ovidio Henriquez3d729f62020-02-07 00:43:2945#include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h"
[email protected]b8148ac2011-07-13 22:03:2546#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3047#include "chrome/browser/browser_process.h"
msramek1c2b3ca2017-03-14 17:57:5648#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5149#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
[email protected]d5a74be2014-08-08 01:01:2750#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0951#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0852#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2253#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
54#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3055#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
56#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0657#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0858#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4959#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3160#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4561#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0162#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1963#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5364#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5265#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1066#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2767#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2768#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3469#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4270#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
71#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1672#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3673#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3674#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5675#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0476#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0577#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0778#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2379#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1080#include "chrome/browser/net/profile_network_context_service.h"
81#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5482#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0283#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5984#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5685#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0686#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5487#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5188#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5689#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4290#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1191#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4892#include "chrome/browser/plugins/plugin_utils.h"
Robert Ogdenea4ea7392020-01-25 01:44:5393#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3094#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]190e5e22013-07-27 05:59:2395#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4196#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5097#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0798#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:0199#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:19100#include "chrome/browser/previews/previews_content_util.h"
Ryan Sturmaa05092f2018-10-21 03:56:54101#include "chrome/browser/previews/previews_service.h"
102#include "chrome/browser/previews/previews_service_factory.h"
103#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03104#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14105#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32106#include "chrome/browser/profiles/profile_io_data.h"
Ken Rockot4e284d32020-03-06 06:26:49107#include "chrome/browser/profiles/profile_manager.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06108#include "chrome/browser/profiles/renderer_updater.h"
109#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56110#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
111#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44112#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38113#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40114#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45115#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31116#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
117#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:24118#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
Mustafa Emre Acer97be4752020-05-13 01:24:43119#include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h"
Carlos IL4ee307e2018-12-22 03:19:00120#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40121#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35122#include "chrome/browser/safe_browsing/ui_manager.h"
123#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58124#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43125#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44126#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20127#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35128#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40129#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23130#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28131#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02132#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48133#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38134#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32135#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07136#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23137#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10138#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35139#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45140#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52141#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19142#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44143#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38144#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51145#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08146#include "chrome/browser/ui/browser_navigator.h"
147#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43148#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39149#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54150#include "chrome/browser/ui/login/login_navigation_throttle.h"
Emily Stark63c884f2020-05-12 03:55:28151#include "chrome/browser/ui/login/login_tab_helper.h"
Makoto Shimazuc7502932018-08-15 02:12:56152#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25153#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44154#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58155#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50156#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01157#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45158#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53159#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25160#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59161#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23162#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22163#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01164#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48165#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51166#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14167#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22168#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30169#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02170#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50171#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34172#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37173#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12174#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12175#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22176#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32177#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38178#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28179#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02180#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09181#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47182#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37183#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18184#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30185#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12186#include "components/autofill/core/common/autofill_switches.h"
Clark DuVallf5189252020-04-15 22:33:34187#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53188#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51189#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49190#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44191#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04192#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48193#include "components/cloud_devices/common/cloud_devices_switches.h"
Clark DuVall84a33d612020-04-17 16:01:00194#include "components/content_settings/browser/tab_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16195#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09196#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16197#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52198#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45199#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08200#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03201#include "components/content_settings/core/common/pref_names.h"
Ryan Sturmaa05092f2018-10-21 03:56:54202#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28203#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43204#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09205#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
wychene55687342015-11-13 20:17:03206#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24207#include "components/dom_distiller/core/url_constants.h"
Clark DuVall3d4e89b92020-04-03 23:07:32208#include "components/embedder_support/switches.h"
blundella5e3240a2016-01-05 11:30:43209#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01210#include "components/feature_engagement/public/feature_constants.h"
211#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malekcdb5b522020-05-26 22:41:03212#include "components/google/core/common/google_switches.h"
Alexandre Frechette572755b2019-02-13 22:30:20213#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53214#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16215#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12216#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
217#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
218#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06219#include "components/payments/content/payment_request_display_manager.h"
Chris Hamiltonab4722122020-05-13 18:01:28220#include "components/performance_manager/embedder/performance_manager_registry.h"
Clark DuValla11361ad32020-02-20 22:14:27221#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54222#include "components/permissions/quota_permission_context_impl.h"
Doug Turner9dcaf5962017-12-21 04:38:53223#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54224#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18225#include "components/policy/core/common/policy_service.h"
226#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26227#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54228#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08229#include "components/prefs/pref_service.h"
230#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21231#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54232#include "components/previews/content/previews_decider_impl.h"
233#include "components/previews/content/previews_ui_service.h"
234#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54235#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45236#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43237#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56238#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56239#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13240#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47241#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
242#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
243#include "components/safe_browsing/core/browser/url_checker_delegate.h"
244#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
245#include "components/safe_browsing/core/db/database_manager.h"
246#include "components/safe_browsing/core/features.h"
247#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58248#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Daniel Vogelheim6008f572018-09-24 14:35:14249#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49250#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48251#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49252#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23253#include "components/signin/public/identity_manager/identity_manager.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54254#include "components/site_isolation/preloaded_isolated_origins.h"
csharrisone985ebc2017-04-04 17:05:03255#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17256#include "components/translate/core/common/translate_switches.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02257#include "components/ukm/app_source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21258#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28259#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33260#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46261#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22262#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39263#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33264#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43265#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30266#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38267#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28268#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03269#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31270#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41271#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09272#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03273#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59274#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19275#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31276#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35277#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47278#include "content/public/browser/navigation_handle.h"
279#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11280#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50281#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30282#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33283#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05284#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54285#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34286#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48287#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27288#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13289#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08290#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19291#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21292#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23293#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43294#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18295#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56296#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40297#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02298#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18299#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57300#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23301#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44302#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31303#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05304#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56305#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43306#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59307#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48308#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30309#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28310#include "gpu/config/gpu_switches.h"
Alexander Timin17edc742020-04-23 18:22:18311#include "ipc/ipc_message.h"
grunell086a4112017-03-02 09:23:04312#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31313#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44314#include "media/media_buildflags.h"
315#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12316#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42317#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52318#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08319#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53320#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51321#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58322#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23323#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46324#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57325#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48326#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14327#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38328#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19329#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02330#include "services/metrics/public/cpp/ukm_builders.h"
331#include "services/metrics/public/cpp/ukm_recorder.h"
Takashi Toyoshima128441462019-10-16 04:19:17332#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37333#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50334#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50335#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13336#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05337#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34338#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03339#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06340#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02341#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02342#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02343#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19344#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31345#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17346#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21347#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26348#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18349#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54350#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39351#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08352#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35353#include "ui/base/ui_base_features.h"
Khushal1fc0da52019-10-09 00:38:56354#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21355#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49356#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57357#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45358#include "url/gurl.h"
359#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26360
[email protected]b48c9182011-10-26 18:03:30361#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20362#include "base/strings/string_tokenizer.h"
Julian Pastarmovb4773b82020-04-21 16:34:14363#include "base/win/win_util.h"
364#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38365#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36366#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18367#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38368#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25369#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38370#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30371#elif defined(OS_CHROMEOS)
Alice Boxhallda2659142020-05-14 06:04:37372#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xiafc9f38132019-08-02 00:51:42373#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30374#include "chrome/app/chrome_crash_reporter_client.h"
Aya ElAttareb5fee12020-05-05 08:56:05375#include "chrome/browser/browser_process.h"
hashimotoa53e7e82016-10-26 06:30:47376#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17377#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30378#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24379#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18380#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08381#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48382#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41383#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32384#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58385#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00386#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
387#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44388#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39389#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31390#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33391#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Aya ElAttareb5fee12020-05-05 08:56:05392#include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h"
Pavol Marko230ea2c92017-12-03 22:35:44393#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34394#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10395#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36396#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27397#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31398#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10399#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21400#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10401#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50402#include "components/crash/core/app/breakpad_linux.h"
Aya ElAttareb5fee12020-05-05 08:56:05403#include "components/policy/core/common/policy_pref_names.h"
404#include "components/prefs/pref_service.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07405#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58406#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50407#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26408#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30409#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09410#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35411#include "base/android/application_status_listener.h"
Brandon Wylie21a88ac92020-05-15 02:49:23412#include "base/feature_list.h"
Samuel Huange63048d2019-09-03 20:35:45413#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47414#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20415#include "chrome/browser/android/app_hooks.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36416#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36417#include "chrome/browser/android/devtools_manager_delegate_android.h"
418#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
419#include "chrome/browser/android/service_tab_launcher.h"
420#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42421#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09422#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56423#include "chrome/browser/download/android/available_offline_content_provider.h"
424#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Brandon Wylie21a88ac92020-05-15 02:49:23425#include "chrome/browser/flags/android/chrome_feature_list.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07426#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38427#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11428#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07429#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47430#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36431#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54432#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00433#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36434#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45435#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04436#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45437#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30438#elif defined(OS_POSIX)
439#include "chrome/browser/chrome_browser_main_posix.h"
440#endif
441
tmartinofb341882017-02-10 19:36:53442#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40443#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36444#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54445#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59446#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02447#include "chrome/browser/search/instant_service.h"
448#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46449#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51450#include "chrome/browser/ui/browser.h"
451#include "chrome/browser/ui/browser_finder.h"
452#include "chrome/browser/ui/browser_list.h"
453#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20454#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51455#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39456#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
457#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43458#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27459#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28460#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36461
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33462#if defined(OS_WIN) || defined(OS_MACOSX) || \
463 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52464#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12465#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52466#endif
467
Joshua Perazace68e2f2019-09-23 18:44:24468#if defined(OS_LINUX)
Rohit Rao92f84b6a2020-03-25 14:57:50469#include "components/crash/core/app/crash_switches.h"
470#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24471#endif
472
[email protected]a220b5932013-09-21 03:47:44473#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02474#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02475#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50476#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02477#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13478#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43479#endif
[email protected]b80f68432011-05-02 17:22:30480
Maggie Caia2f03f52019-04-02 02:13:28481// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
482// single navigation throttle to display the intent picker on all platforms.
483#if !defined(OS_ANDROID)
484#if defined(OS_CHROMEOS)
485#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51486#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28487#else
488#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
489#endif
490#endif
491
[email protected]e8b6ca02013-07-10 18:00:51492#if defined(TOOLKIT_VIEWS)
493#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
494#endif
495
estaded3aa0e82016-02-17 22:55:21496#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
497#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51498#endif
499
Mohsen Izadif1958f22019-01-18 20:29:31500#if defined(USE_OZONE)
501#include "ui/ozone/public/ozone_platform.h"
502#endif
503
[email protected]e8b6ca02013-07-10 18:00:51504#if defined(USE_X11)
505#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
506#endif
507
brettwab78fef2016-10-12 02:56:05508#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10509#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38510#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19511#endif
512
Nico Weberaf3b00b2017-09-11 17:58:17513#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55514#include "components/nacl/browser/nacl_browser.h"
515#include "components/nacl/browser/nacl_host_message_filter.h"
516#include "components/nacl/browser/nacl_process_host.h"
517#include "components/nacl/common/nacl_process_type.h"
518#include "components/nacl/common/nacl_switches.h"
519#endif
520
brettw00899e62016-11-12 02:10:17521#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05522#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20523#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27524#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23525#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32526#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51527#include "chrome/browser/extensions/user_script_listener.h"
528#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28529#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49530#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46531#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39532#include "components/guest_view/browser/guest_view_base.h"
533#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25534#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31535#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35536#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32537#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12538#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57539#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48540#include "extensions/browser/guest_view/web_view/web_view_guest.h"
541#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
542#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31543#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27544#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28545#include "extensions/common/extension.h"
546#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13547#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28548#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33549#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28550#include "extensions/common/permissions/permissions_data.h"
551#include "extensions/common/permissions/socket_permission.h"
552#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34553#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25554
brettw4b461082016-11-19 18:55:16555#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55556#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27557#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39558#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55559#endif
560
bauerb8f9c37742017-03-30 15:04:12561#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
562#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
563#endif
564
yilkal240b4f22019-11-27 19:09:06565#if defined(OS_CHROMEOS)
Anatoliy Potapchuk762c40d2020-05-11 15:10:37566#include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h"
yilkal240b4f22019-11-27 19:09:06567#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
568#endif // defined(OS_CHROMEOS)
569
thakis678822e2017-04-20 17:20:34570#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38571#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09572#endif
573
weilifabbf7572017-05-22 19:05:16574#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21575#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16576#endif
Lei Zhanga2fa14c2018-05-15 00:05:21577
Xiaohan Wanga4e41842018-06-26 18:45:10578#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49579#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26580#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10581#include "chrome/browser/media/widevine_hardware_caps_win.h"
582#include "third_party/widevine/cdm/widevine_cdm_common.h"
583#endif
584#endif
585
mmenkedb2637ff2017-03-30 23:59:42586#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
587#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
588#endif
589
Nico Weberbc5b06f2019-07-26 14:00:13590#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35591#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Daniel Rubery9eb1e0912020-05-08 17:57:32592#include "chrome/browser/safe_browsing/client_side_detection_service_factory.h"
Daniel Ruberya1611e32019-04-24 21:38:35593#endif
594
Jian Lide7b43792018-06-01 23:22:13595#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54596#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13597#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
598#endif
599
Will Cassella40837ba2019-07-01 21:32:00600#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43601#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
602#endif
603
John Lee0ee748bf2019-12-11 21:35:44604#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
605#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
606#endif
607
Roger Tawa03ffdbd2020-01-16 18:12:54608#if BUILDFLAG(FULL_SAFE_BROWSING)
609#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
610#endif
611
Alexander Cooperc8448702020-03-14 01:39:56612#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23613#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56614#endif
615
[email protected]c7abd422012-09-25 00:20:08616using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39617using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31618using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13619using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59620using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00621using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02622using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11623using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33624using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13625using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05626using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38627using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39628
[email protected]0daaebfe2014-03-15 00:09:05629#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20630using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05631#endif
632
brettw00899e62016-11-12 02:10:17633#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28634using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27635using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28636using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28637using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27638#endif
639
brettw4b461082016-11-19 18:55:16640#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55641using plugins::ChromeContentBrowserClientPluginsPart;
642#endif
643
[email protected]c5dbef02011-05-13 05:06:09644namespace {
645
Will Harris1b9b4152019-08-21 22:33:50646#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30647// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
648// running on Windows 10 1511 and above. See
649// https://blogs.windows.com/blog/tag/code-integrity-guard/.
650const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35651 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50652#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
653 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30654
Colin Blundell9ee731dd2020-01-23 10:42:38655// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
656// parameters.
657void HandleSSLErrorWrapper(
658 content::WebContents* web_contents,
659 int cert_error,
660 const net::SSLInfo& ssl_info,
661 const GURL& request_url,
662 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38663 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
664 Profile* profile =
665 Profile::FromBrowserContext(web_contents->GetBrowserContext());
666
667 // This can happen if GetBrowserContext no longer exists by the time this
668 // gets called (e.g. the SSL error was in a webview that has since been
669 // destroyed); if that's the case we don't need to handle the error (and will
670 // crash if we attempt to).
671 if (!profile)
672 return;
673
Colin Blundell27331f92020-02-05 21:13:01674 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51675
676#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
677 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
678#endif
679
Colin Blundell9ee731dd2020-01-23 10:42:38680 SSLErrorHandler::HandleSSLError(
681 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53682 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51683 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38684 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38685 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
686}
687
lazyboy5d5fede02016-03-10 04:10:14688enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53689 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14690 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53691
692 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14693 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53694
695 // An extension or app tried to load a resource of a different platform app in
696 // a tab.
697 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
698
699 // A non-app and non-extension page tried to load a platform app in a tab.
700 APP_LOADED_IN_TAB_SOURCE_OTHER,
701
lazyboy5d5fede02016-03-10 04:10:14702 APP_LOADED_IN_TAB_SOURCE_MAX
703};
704
Lei Zhang2cfceac2018-11-14 19:36:33705// Cached version of the locale so we can return the locale on the I/O
706// thread.
707std::string& GetIOThreadApplicationLocale() {
708 static base::NoDestructor<std::string> s;
709 return *s;
710}
711
[email protected]f8f93eb2012-09-25 03:06:24712// Returns a copy of the given url with its host set to given host and path set
713// to given path. Other parts of the url will be the same.
714GURL ReplaceURLHostAndPath(const GURL& url,
715 const std::string& host,
716 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05717 url::Replacements<char> replacements;
718 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
719 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24720 return url.ReplaceComponents(replacements);
721}
722
madfbd10852017-01-20 03:15:33723// Handles the rewriting of the new tab page URL based on group policy.
724bool HandleNewTabPageLocationOverride(
725 GURL* url,
726 content::BrowserContext* browser_context) {
727 if (!url->SchemeIs(content::kChromeUIScheme) ||
728 url->host() != chrome::kChromeUINewTabHost)
729 return false;
730
731 Profile* profile = Profile::FromBrowserContext(browser_context);
732 std::string ntp_location =
733 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
734 if (ntp_location.empty())
735 return false;
736
737 *url = GURL(ntp_location);
738 return true;
739}
740
Becca Hughesfe8c32c2018-03-21 13:36:56741#if !defined(OS_ANDROID)
742// Check if the current url is whitelisted based on a list of whitelisted urls.
743bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57744 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56745 // Only check on HTTP and HTTPS pages.
746 if (!current_url.SchemeIsHTTPOrHTTPS())
747 return false;
748
749 for (auto const& value : whitelisted_urls) {
750 ContentSettingsPattern pattern =
751 ContentSettingsPattern::FromString(value.GetString());
752 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
753 continue;
754 if (pattern.Matches(current_url))
755 return true;
756 }
757
758 return false;
759}
760
761// Check if autoplay is allowed by policy configuration.
762bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
763 PrefService* prefs) {
764 DCHECK(prefs);
765
766 // Check if we have globally allowed autoplay by policy.
767 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
768 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
769 return true;
770 }
771
772 if (!contents)
773 return false;
774
775 // Check if the current URL matches a URL pattern on the whitelist.
776 const base::ListValue* autoplay_whitelist =
777 prefs->GetList(prefs::kAutoplayWhitelist);
778 return autoplay_whitelist &&
779 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
780 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
781}
782#endif
783
Joshua Perazaf890e4b2019-01-03 19:19:02784#if defined(OS_ANDROID)
785int GetCrashSignalFD(const base::CommandLine& command_line) {
786 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
787}
788#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03789breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
790 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02791 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52792 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02793 {
794 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31795 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03796 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50797 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02798 crash_handler->StartUploaderThread();
799 return crash_handler;
800 }
801}
802
avi3ef9ec9e2014-12-22 22:50:17803int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24804 if (crash_reporter::IsCrashpadEnabled()) {
805 int fd;
806 pid_t pid;
807 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
808 }
809
[email protected]9de4da52014-05-24 12:26:50810 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39811 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31812 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02813 if (!crash_handler)
814 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18815 return crash_handler->GetDeathSignalSocket();
816 }
817
818 std::string process_type =
819 command_line.GetSwitchValueASCII(switches::kProcessType);
820
[email protected]779dd282013-10-19 15:57:02821 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31822 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02823 if (!crash_handler)
824 crash_handler = CreateCrashHandlerHost(process_type);
825 return crash_handler->GetDeathSignalSocket();
826 }
[email protected]a1733df2012-06-22 11:24:18827
[email protected]779dd282013-10-19 15:57:02828 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31829 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02830 if (!crash_handler)
831 crash_handler = CreateCrashHandlerHost(process_type);
832 return crash_handler->GetDeathSignalSocket();
833 }
[email protected]a1733df2012-06-22 11:24:18834
[email protected]779dd282013-10-19 15:57:02835 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31836 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02837 if (!crash_handler)
838 crash_handler = CreateCrashHandlerHost(process_type);
839 return crash_handler->GetDeathSignalSocket();
840 }
[email protected]a1733df2012-06-22 11:24:18841
James Cook9207cc12017-10-19 17:08:39842 if (process_type == switches::kUtilityProcess) {
843 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
844 if (!crash_handler)
845 crash_handler = CreateCrashHandlerHost(process_type);
846 return crash_handler->GetDeathSignalSocket();
847 }
848
[email protected]a1733df2012-06-22 11:24:18849 return -1;
850}
Joshua Perazaf890e4b2019-01-03 19:19:02851#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18852
[email protected]eabbfb12013-04-05 23:28:35853void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52854 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33855 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35856}
857
estark3ba11132015-04-10 01:38:33858// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31859// SSLErrorHandler. Uses CertificateReportingService to send reports. The
860// service handles queueing and re-sending of failed reports. Each certificate
861// error creates a new instance of this class.
862class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33863 public:
meacerf43117a2016-12-27 21:02:31864 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12865 content::WebContents* web_contents)
866 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
867 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31868 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33869
870 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55871 void ReportInvalidCertificateChain(
872 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31873 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33874 }
875
876 private:
meacerf43117a2016-12-27 21:02:31877 CertificateReportingService* service_;
878
879 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33880};
881
brettw00899e62016-11-12 02:10:17882#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53883
884AppLoadedInTabSource ClassifyAppLoadedInTabSource(
885 const GURL& opener_url,
886 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58887 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
888 // The forbidden app URL was being opened by a non-extension page (e.g.
889 // http).
890 return APP_LOADED_IN_TAB_SOURCE_OTHER;
891 }
892
893 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53894 // The forbidden app URL was being opened by a different app or extension.
895 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
896 }
Lei Zhang7d0b0f42019-10-12 03:47:58897
898 // This platform app was trying to window.open() one of its own URLs.
899 if (opener_url ==
900 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
901 // Source was the background page.
902 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
903 }
904
905 // Source was a different page inside the app.
906 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53907}
[email protected]9c7656382014-08-08 21:02:30908
Charles Harrison34f67862017-08-22 01:04:17909// Returns true if there is is an extension matching |url| in
910// |opener_render_process_id| with APIPermission::kBackground.
911//
912// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
913// hosted app, even though normal extensions just use the host.
914bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35915 extensions::ProcessMap* process_map,
916 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17917 const GURL& url,
csharrison95f01e922017-04-24 18:52:35918 int opener_render_process_id) {
919 // Note: includes web URLs that are part of an extension's web extent.
920 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17921 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35922 return extension &&
923 extension->permissions_data()->HasAPIPermission(
924 APIPermission::kBackground) &&
925 process_map->Contains(extension->id(), opener_render_process_id);
926}
Kevin Marshall32f99d7e2017-07-11 23:17:46927
csharrison95f01e922017-04-24 18:52:35928#endif
929
Darin Fishere41aab52020-01-29 18:31:23930mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12931 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23932 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
933 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
934 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
935 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12936}
937
Julian Pastarmovb4773b82020-04-21 16:34:14938// Encapculates logic to determine if enterprise policies should be honored.
939// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
940// as a new central class to replace those checks is in the making.
941bool ShouldHonorPolicies() {
942#if defined(OS_WIN)
943 bool is_enterprise_version =
944 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
945 return base::win::IsEnrolledToDomain() ||
946 (base::win::IsDeviceRegisteredWithManagement() &&
947 is_enterprise_version);
948#else // defined(OS_WIN)
949 // TODO(pastarmovj): Replace this with check for MacOS and the new management
950 // service once it is ready.
951 return true;
952#endif // defined(OS_WIN)
953}
954
John Abd-El-Malek92bf3602019-07-31 02:25:48955void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04956 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48957 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45958 bool has_user_gesture,
959 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01960 // If there is no longer a WebContents, the request may have raced with tab
961 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04962 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01963 if (!web_contents)
964 return;
965
966 // Do not launch external requests attached to unswapped prerenders.
967 prerender::PrerenderContents* prerender_contents =
968 prerender::PrerenderContents::FromWebContents(web_contents);
969 if (prerender_contents) {
970 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:01971 return;
972 }
973
Robbie McElrath1294d242019-05-31 20:46:22974 // Do not launch external requests for schemes that have a handler registered.
975 ProtocolHandlerRegistry* protocol_handler_registry =
976 ProtocolHandlerRegistryFactory::GetForBrowserContext(
977 web_contents->GetBrowserContext());
978 if (protocol_handler_registry &&
979 protocol_handler_registry->IsHandledProtocol(url.scheme()))
980 return;
981
John Abd-El-Maleka67add82018-03-09 18:22:01982 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01983 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19984 PolicyBlacklistFactory::GetForBrowserContext(
985 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:14986 if (ShouldHonorPolicies() && service) {
John Abd-El-Maleka67add82018-03-09 18:22:01987 const policy::URLBlacklist::URLBlacklistState url_state =
988 service->GetURLBlacklistState(url);
989 is_whitelisted =
990 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
991 }
992
993 // If the URL is in whitelist, we launch it without asking the user and
994 // without any additional security checks. Since the URL is whitelisted,
995 // we assume it can be executed.
996 if (is_whitelisted) {
997 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
998 } else {
999 ExternalProtocolHandler::LaunchUrl(
1000 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1001 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:451002 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:011003 }
1004}
1005
Yutaka Hirano968d6252018-12-04 05:09:311006std::string GetProduct() {
1007 return version_info::GetProductNameAndVersionForUserAgent();
1008}
1009
Lukasz Anforowicz60d1253d2019-05-08 16:31:371010void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1011 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1012 // For renderer and utility (e.g. NetworkService) processes the switch is the
1013 // only available source, so below the combined (pref/policy + cmdline)
1014 // allowlist of secure origins is injected into |cmdline| for these other
1015 // processes.
1016 std::vector<std::string> allowlist =
1017 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1018 if (!allowlist.empty()) {
1019 cmdline->AppendSwitchASCII(
1020 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1021 base::JoinString(allowlist, ","));
1022 }
1023}
1024
Will Harris1b9b4152019-08-21 22:33:501025#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301026// Returns the full path to |module_name|. Both dev builds (where |module_name|
1027// is in the current executable's directory) and proper installs (where
1028// |module_name| is in a versioned sub-directory of the current executable's
1029// directory) are supported. The identified file is not guaranteed to exist.
1030base::FilePath GetModulePath(base::StringPiece16 module_name) {
1031 base::FilePath exe_dir;
1032 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1033 DCHECK(has_path);
1034
1035 // Look for the module in a versioned sub-directory of the current
1036 // executable's directory and return the path if it can be read. This is the
1037 // expected location of modules for proper installs.
1038 const base::FilePath module_path =
1039 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1040 if (base::PathExists(module_path))
1041 return module_path;
1042
1043 // Otherwise, return the path to the module in the current executable's
1044 // directory. This is the expected location of modules for dev builds.
1045 return exe_dir.Append(module_name);
1046}
Will Harris1b9b4152019-08-21 22:33:501047#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1048 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301049
Lukasz Anforowicz7724d092019-10-03 23:50:211050void MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:281051 std::unique_ptr<content::NavigationThrottle> maybe_throttle,
1052 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
Lukasz Anforowicz7724d092019-10-03 23:50:211053 if (maybe_throttle)
1054 throttles->push_back(std::move(maybe_throttle));
1055}
1056
Chris Hamiltonab4722122020-05-13 18:01:281057void MaybeAddThrottles(
1058 std::vector<std::unique_ptr<content::NavigationThrottle>> additional,
1059 std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) {
1060 combined->insert(combined->end(), std::make_move_iterator(additional.begin()),
1061 std::make_move_iterator(additional.end()));
1062}
1063
Evan Stade1e71d6dd2019-10-29 03:04:491064// Returns whether |web_contents| is within a hosted app.
1065bool IsInHostedApp(WebContents* web_contents) {
1066#if BUILDFLAG(ENABLE_EXTENSIONS)
1067 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1068 return (browser &&
1069 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1070#else
1071 return false;
1072#endif
1073}
1074
Lily Chenc2c9e9f2019-12-05 19:55:311075void MaybeRecordSameSiteCookieEngagementHistogram(
1076 content::RenderFrameHost* render_frame_host,
1077 blink::mojom::WebFeature feature) {
1078 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1079 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1080 return;
1081 }
1082
1083 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1084 DCHECK(render_frame_host);
1085
1086 content::BrowserContext* browser_context =
1087 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1088 Profile* profile = Profile::FromBrowserContext(browser_context);
1089 SiteEngagementService* site_engagement_service =
1090 SiteEngagementService::Get(profile);
1091 if (!site_engagement_service)
1092 return;
1093
1094 blink::mojom::EngagementLevel engagement_level =
1095 site_engagement_service->GetEngagementLevel(
1096 render_frame_host->GetLastCommittedURL());
1097 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1098 UMA_HISTOGRAM_ENUMERATION(
1099 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1100 engagement_level);
1101 } else {
1102 UMA_HISTOGRAM_ENUMERATION(
1103 "Net.SameSiteBlockedCookieSiteEngagement."
1104 "CookieInsecureAndSameSiteNone",
1105 engagement_level);
1106 }
1107}
1108
[email protected]9dbfff12011-07-01 19:37:071109} // namespace
[email protected]c5dbef02011-05-13 05:06:091110
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441111// Generate a pseudo-random permutation of the following brand/version pairs:
1112// 1. The base project (i.e. Chromium)
1113// 2. The browser brand, if available
1114// 3. A randomized string containing escaped characters to ensure proper
1115// header parsing, along with an arbitrarily low version to ensure proper
1116// version checking.
1117blink::UserAgentBrandList GenerateBrandVersionList(
1118 int seed,
1119 base::Optional<std::string> brand,
1120 std::string major_version) {
1121 DCHECK_GE(seed, 0);
1122 const int npermutations = 6; // 3!
1123 int permutation = seed % npermutations;
1124
1125 // Pick a stable permutation seeded by major version number. any values here
1126 // and in order should be under three.
1127 const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
1128 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
1129 const std::vector<int> order = orders[permutation];
1130 DCHECK_EQ(6u, orders.size());
1131 DCHECK_EQ(3u, order.size());
1132
1133 const std::vector<std::string> escaped_chars = {"\\", "\"", ";"};
1134 std::string greasey_brand =
1135 base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]],
1136 "A", escaped_chars[order[2]], "Brand"});
1137
1138 blink::UserAgentBrandVersion greasey_bv = {greasey_brand, "99"};
1139 blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version};
1140
1141 blink::UserAgentBrandList greased_brand_version_list(3);
1142
1143 if (brand) {
1144 blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version};
1145
1146 greased_brand_version_list[order[0]] = greasey_bv;
1147 greased_brand_version_list[order[1]] = chromium_bv;
1148 greased_brand_version_list[order[2]] = brand_bv;
1149 } else {
1150 greased_brand_version_list[seed % 2] = greasey_bv;
1151 greased_brand_version_list[(seed + 1) % 2] = chromium_bv;
1152
1153 // If left, the last element would make a blank "" at the end of the header.
1154 greased_brand_version_list.pop_back();
1155 }
1156
1157 return greased_brand_version_list;
1158}
1159
1160const blink::UserAgentBrandList& GetBrandVersionList() {
1161 static const base::NoDestructor<blink::UserAgentBrandList>
1162 greased_brand_version_list([] {
1163 int major_version_number;
1164 std::string major_version = version_info::GetMajorVersionNumber();
1165 base::StringToInt(major_version, &major_version_number);
1166 base::Optional<std::string> brand;
1167#if !BUILDFLAG(CHROMIUM_BRANDING)
1168 brand = version_info::GetProductName();
1169#endif
1170 return GenerateBrandVersionList(major_version_number, brand,
1171 major_version);
1172 }());
1173 return *greased_brand_version_list;
1174}
1175
Yutaka Hirano968d6252018-12-04 05:09:311176std::string GetUserAgent() {
1177 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1178 if (command_line->HasSwitch(switches::kUserAgent)) {
1179 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1180 if (net::HttpUtil::IsValidHeaderValue(ua))
1181 return ua;
1182 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1183 }
1184
John Delaneyac24e572019-04-30 19:47:021185 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1186 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351187 command_line->HasSwitch(switches::kUseMobileUserAgent),
1188 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021189 }
1190
Yutaka Hirano968d6252018-12-04 05:09:311191 std::string product = GetProduct();
1192#if defined(OS_ANDROID)
1193 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1194 product += " Mobile";
1195#endif
1196 return content::BuildUserAgentFromProduct(product);
1197}
1198
Mike West6e4cbb32019-02-13 09:40:171199blink::UserAgentMetadata GetUserAgentMetadata() {
1200 blink::UserAgentMetadata metadata;
Aaron Tagliaboschi9f01b682020-05-05 21:03:171201
Aaron Tagliaboschi19ad8d32020-05-12 20:10:441202 metadata.brand_version_list = GetBrandVersionList();
Mike Weste555be862019-02-20 16:17:301203 metadata.full_version = version_info::GetVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171204 metadata.platform = version_info::GetOSType();
Yoav Weiss4838f1b2020-04-30 21:37:001205 metadata.platform_version =
1206 content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude,
1207 content::IncludeAndroidModel::Exclude);
Aaron Tagliaboschi0585bc932020-05-08 20:03:171208 metadata.architecture = content::GetLowEntropyCpuArchitecture();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361209 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171210
Aaron Tagliaboschibe775e12019-12-09 19:33:041211 metadata.mobile = false;
1212#if defined(OS_ANDROID)
1213 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1214 switches::kUseMobileUserAgent);
1215#endif
1216
Mike West6e4cbb32019-02-13 09:40:171217 return metadata;
1218}
1219
Ran Jia96d43d42018-05-02 17:14:531220ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051221 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311222 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161223#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551224 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401225#endif
[email protected]1deace22013-05-22 06:14:461226
Ahmed Fakhryd70bf37b2018-04-04 17:07:241227#if defined(OS_CHROMEOS)
1228 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1229#endif // defined(OS_CHROMEOS)
1230
John Lee0ee748bf2019-12-11 21:35:441231#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1232 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1233#endif
1234
brettw00899e62016-11-12 02:10:171235#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131236 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271237#endif
bena06f7d62017-04-04 20:48:521238
Sigurdur Asgeirsson70696672019-02-08 16:14:511239 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401240}
1241
1242ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031243 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1244 delete extra_parts_[i];
1245 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401246}
1247
[email protected]bca18382012-06-25 19:15:231248// static
Chris Palmerac7d75642017-11-22 20:12:541249void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1250 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131251 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1252 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541253 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1254 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461255 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541256}
1257
1258// static
[email protected]37ca3fe02013-07-05 15:32:441259void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341260 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251261 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1262 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1263 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281264 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1265 // user policy in addition to the same named ones in Local State (which are
1266 // used for mapping the command-line flags).
1267 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1268 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571269 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401270 registry->RegisterDictionaryPref(
1271 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041272 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101273#if !defined(OS_ANDROID)
1274 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561275 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101276#endif
Takashi Toyoshima128441462019-10-16 04:19:171277 registry->RegisterListPref(prefs::kCorsMitigationList);
1278 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231279}
1280
[email protected]eabbfb12013-04-05 23:28:351281// static
1282void ChromeContentBrowserClient::SetApplicationLocale(
1283 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481284 // The common case is that this function is called early in Chrome startup
1285 // before any threads are created or registered. When there are no threads,
1286 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001287 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331288 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481289 return;
1290 }
1291
1292 // Otherwise we're being called to change the locale. In this case set it on
1293 // the IO thread.
thestig00844cea2015-09-08 21:44:521294 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351295
Sami Kyostila5e1306d2019-08-14 11:01:291296 base::PostTask(FROM_HERE, {BrowserThread::IO},
1297 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351298}
1299
Patrick Monette61dfef92019-05-30 23:06:271300std::unique_ptr<content::BrowserMainParts>
1301ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311302 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271303 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301304 // Construct the Main browser parts based on the OS type.
1305#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051306 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271307 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1308#elif defined(OS_MACOSX)
1309 main_parts =
1310 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1311#elif defined(OS_CHROMEOS)
1312 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1313 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261314#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271315 main_parts =
1316 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141317#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271318 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1319 startup_data_);
[email protected]b48c9182011-10-26 18:03:301320#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271321 main_parts =
1322 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041323#else
[email protected]b48c9182011-10-26 18:03:301324 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271325 main_parts =
1326 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301327#endif
1328
Xi Han9fd44002019-04-30 17:39:361329 bool add_profiles_extra_parts = true;
1330#if defined(OS_ANDROID)
1331 if (startup_data_->HasBuiltProfilePrefService())
1332 add_profiles_extra_parts = false;
1333#endif
1334 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271335 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031336
Xi Han9fd44002019-04-30 17:39:361337 // Construct additional browser parts. Stages are called in the order in
1338 // which they are added.
[email protected]c7480942011-11-08 19:18:271339#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221340#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
estaded3aa0e82016-02-17 22:55:211341 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
1342#else
riajiang7d6ec5c2017-01-25 16:40:331343 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351344#endif
1345#endif
1346
1347#if defined(OS_CHROMEOS)
1348 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331349 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221350#endif
[email protected]dc04be7c2012-03-15 23:57:491351
[email protected]e8b6ca02013-07-10 18:00:511352#if defined(USE_X11)
1353 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241354#endif
1355
Sigurdur Asgeirsson54b72702019-04-12 14:18:541356 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001357
Albert J. Wong59d85acb2017-08-10 00:50:571358 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571359
Sebastien Marchand8c0088102019-10-11 16:47:561360 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1361
Patrick Monette61dfef92019-05-30 23:06:271362 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041363
Zhenyao Mo73144652020-04-06 18:55:051364 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1365 // GpuDataManager initialization could pick up about:flags settings.
1366 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1367
[email protected]50462bf02011-11-21 19:13:311368 return main_parts;
[email protected]f967b722011-09-07 00:58:041369}
1370
michaeln96f887e22015-04-13 23:58:311371void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091372 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021373 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211374 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121375 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291376
Robert Sesek466e43e2019-08-19 22:02:021377 InitNetworkContextsParentDirectory();
1378
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291379 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1380 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311381}
1382
falkenb09d443f2016-04-07 12:36:121383bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1384 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1385}
1386
Gabriel Charettec8cca992017-08-10 18:21:491387void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1388 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1389}
1390
John Abd-El-Malek9d57f9c2019-02-20 18:50:041391bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361392 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041393}
1394
[email protected]e94bbcb2012-09-07 05:33:571395std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191396 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571397 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531398 std::string partition_id;
1399
1400 // The partition ID for webview guest processes is the string value of its
1401 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451402 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531403 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171404#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501405 // The partition ID for extensions with isolated storage is treated similarly
1406 // to the above.
1407 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1408 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1409 partition_id = site.spec();
1410#endif
[email protected]1bc28312012-11-08 08:31:531411
[email protected]056efdc2013-04-06 00:14:531412 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531413 return partition_id;
1414}
1415
1416bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1417 content::BrowserContext* browser_context,
1418 const std::string& partition_id) {
1419 // The default ID is empty and is always valid.
1420 if (partition_id.empty())
1421 return true;
1422
1423 return GURL(partition_id).is_valid();
1424}
1425
1426void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1427 content::BrowserContext* browser_context,
1428 const GURL& site,
[email protected]14acc642012-11-17 12:20:101429 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531430 std::string* partition_domain,
1431 std::string* partition_name,
1432 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101433 // Default to the browser-wide storage partition and override based on |site|
1434 // below.
1435 partition_domain->clear();
1436 partition_name->clear();
1437 *in_memory = false;
1438
brettw00899e62016-11-12 02:10:171439#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451440 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331441 site, partition_domain, partition_name, in_memory);
1442
1443 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101444 // If |can_be_default| is false, the caller is stating that the |site|
1445 // should be parsed as if it had isolated storage. In particular it is
1446 // important to NOT check ExtensionService for the is_storage_isolated()
1447 // attribute because this code path is run during Extension uninstall
1448 // to do cleanup after the Extension has already been unloaded from the
1449 // ExtensionService.
1450 bool is_isolated = !can_be_default;
1451 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341452 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1453 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101454 }
[email protected]1bc28312012-11-08 08:31:531455
[email protected]14acc642012-11-17 12:20:101456 if (is_isolated) {
1457 CHECK(site.has_host());
1458 // For extensions with isolated storage, the the host of the |site| is
1459 // the |partition_domain|. The |in_memory| and |partition_name| are only
1460 // used in guest schemes so they are cleared here.
1461 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531462 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101463 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531464 }
[email protected]1df3d972014-06-11 04:55:181465 success = true;
1466 }
1467#endif
1468
[email protected]14acc642012-11-17 12:20:101469 // Assert that if |can_be_default| is false, the code above must have found a
1470 // non-default partition. If this fails, the caller has a serious logic
1471 // error about which StoragePartition they expect to be in and it is not
1472 // safe to continue.
1473 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441474}
1475
[email protected]38b098f2012-03-14 21:11:571476content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441477ChromeContentBrowserClient::GetWebContentsViewDelegate(
1478 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101479 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321480}
1481
Bo Liu4ade6b1b22017-11-28 02:26:351482bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1483#if defined(OS_ANDROID)
1484 const base::android::ApplicationState app_state =
1485 base::android::ApplicationStatusListener::GetState();
1486 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1487 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1488 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1489#else
1490 return true;
1491#endif
1492}
1493
[email protected]6f2862742013-12-20 07:53:191494void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231495 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301496 int id = host->GetID();
1497 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341498#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491499 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061500#endif
Brett Wilson65f951c2016-11-03 22:06:121501#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401502 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031503#endif
Darin Fisher54cba872020-02-06 21:12:551504 host->AddFilter(new prerender::PrerenderMessageFilter(id));
Darin Fisher8c84328c2019-07-23 02:50:001505
Darin Fisher09aa7222019-08-29 09:27:361506 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001507 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021508
grunell086a4112017-03-02 09:23:041509 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1510 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021511 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121512 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021513 host->SetUserData(
1514 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091515 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021516 audio_debug_recordings_handler));
1517
Nico Weberaf3b00b2017-09-11 17:58:171518#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031519 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1520 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351521#endif
jeremyim364ac1182015-03-03 18:49:431522
Xiaohan Wang9b34281b2017-09-08 23:48:331523#if defined(OS_ANDROID)
1524 // Data cannot be persisted if the profile is off the record.
1525 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061526 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071527
1528 // Register CrashMemoryMetricsCollector to report oom related metrics.
1529 host->SetUserData(
1530 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1531 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331532#endif
1533
Jun Caidb3f93cc2018-07-09 21:54:551534 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061535 RendererUpdaterFactory::GetForProfile(original_profile)
1536 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071537
[email protected]a48ab7112014-08-01 16:48:031538 for (size_t i = 0; i < extra_parts_.size(); ++i)
1539 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141540}
1541
[email protected]3d7474ff2011-07-27 17:47:371542GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571543 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301544 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371545 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521546 if (!profile)
1547 return url;
1548
Marc Treib7d467b792017-12-04 13:31:031549#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291550 // If the input |url| should be assigned to the Instant renderer, make its
1551 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311552 // This needs to happen even if |url| corresponds to an isolated origin; see
1553 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131554 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1555 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031556#endif
[email protected]b3cb3a32013-07-31 01:32:291557
brettw00899e62016-11-12 02:10:171558#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301559 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1560 url);
[email protected]d5a74be2014-08-08 01:01:271561#else
1562 return url;
1563#endif
[email protected]36fb2c7c2011-04-04 15:49:081564}
1565
Alexander Yashkin6aedc6e2018-08-15 08:58:451566bool ChromeContentBrowserClient::
1567 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1568 content::BrowserContext* browser_context,
1569 content::SiteInstance* candidate_site_instance,
1570 bool is_main_frame,
1571 const GURL& candidate_url,
1572 const GURL& destination_url) {
1573 DCHECK(browser_context);
1574 DCHECK(candidate_site_instance);
1575#if BUILDFLAG(ENABLE_EXTENSIONS)
1576 return ChromeContentBrowserClientExtensionsPart::
1577 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1578 browser_context, candidate_site_instance, is_main_frame,
1579 candidate_url, destination_url);
1580#else
1581 return true;
1582#endif
1583}
1584
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521585bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411586#if defined(OS_ANDROID)
1587 return true;
1588#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421589 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411590#else
1591 return false;
1592#endif // defined(OS_ANDROID)
1593}
1594
[email protected]056ad2a2011-07-12 02:13:551595bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441596 content::BrowserContext* browser_context,
Aaron Colwellabb540b2020-05-05 19:15:591597 const GURL& site_url) {
[email protected]c5dec6292013-01-25 04:54:521598 Profile* profile = Profile::FromBrowserContext(browser_context);
1599 if (!profile)
1600 return false;
1601
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301602 // NTP should use process-per-site. This is a performance optimization to
1603 // reduce process count associated with NTP tabs.
Aaron Colwellabb540b2020-05-05 19:15:591604 if (site_url == GURL(chrome::kChromeUINewTabURL))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301605 return true;
Peter Boström8e9b1632019-08-22 23:12:471606
1607 // The web footer experiment should share its renderer to not effectively
1608 // instantiate one per window. See https://crbug.com/993502.
Aaron Colwellabb540b2020-05-05 19:15:591609 if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
Peter Boström8e9b1632019-08-22 23:12:471610 return true;
1611
Marc Treib7d467b792017-12-04 13:31:031612#if !defined(OS_ANDROID)
Aaron Colwellabb540b2020-05-05 19:15:591613 if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile))
[email protected]c5dec6292013-01-25 04:54:521614 return true;
Marc Treib7d467b792017-12-04 13:31:031615#endif
[email protected]c5dec6292013-01-25 04:54:521616
brettw00899e62016-11-12 02:10:171617#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301618 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
Aaron Colwellabb540b2020-05-05 19:15:591619 profile, site_url))
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301620 return true;
[email protected]d5a74be2014-08-08 01:01:271621#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301622
1623 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1624 // (rather than process-per-site).
1625 return false;
[email protected]056ad2a2011-07-12 02:13:551626}
1627
Lukasz Anforowicz32d27122018-04-09 21:48:331628bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1629 content::BrowserContext* browser_context,
1630 const GURL& site_url) {
1631 Profile* profile = Profile::FromBrowserContext(browser_context);
1632 if (!profile)
1633 return false;
1634
1635#if !defined(OS_ANDROID)
1636 // Instant renderers should not use a spare process, because they require
1637 // passing switches::kInstantProcess to the renderer process when it
1638 // launches. A spare process is launched earlier, before it is known which
1639 // navigation will use it, so it lacks this flag.
1640 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1641 return false;
1642#endif
1643
1644#if BUILDFLAG(ENABLE_EXTENSIONS)
1645 return ChromeContentBrowserClientExtensionsPart::
1646 ShouldUseSpareRenderProcessHost(profile, site_url);
1647#else
1648 return true;
1649#endif
1650}
1651
nickcc0d9142015-10-14 16:27:101652bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421653 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101654 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421655 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171656#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101657 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421658 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101659 return true;
1660 }
1661#endif
1662 return false;
1663}
1664
nick7d0984c2015-08-29 00:13:461665// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1666// origin-lock enforcement, where we don't have a way to efficiently know
1667// effective URLs on the IO thread, and wind up killing processes that e.g.
1668// request cookies for their actual URL. This whole function (and its
1669// ExtensionsPart) should be removed once we add that ability to the IO thread.
1670bool ChromeContentBrowserClient::ShouldLockToOrigin(
1671 content::BrowserContext* browser_context,
1672 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171673#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461674 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1675 browser_context, effective_site_url)) {
1676 return false;
1677 }
1678#endif
1679 return true;
creise5d6d1732015-08-25 19:47:061680}
1681
Nasko Oskov39023672020-05-06 17:31:141682bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock(
1683 base::StringPiece scheme) {
1684 // Note: This method can be called from multiple threads. It is not safe to
1685 // assume it runs only on the UI thread.
1686
1687 // chrome-search: documents commit only in the NTP instant process and are not
Alex Moshchuk7de38462020-05-20 00:05:371688 // locked to chrome-search: origin. Locking to chrome-search would kill
1689 // processes upon legitimate requests for cookies from the search engine's
1690 // domain.
Nasko Oskov39023672020-05-06 17:31:141691 if (scheme == chrome::kChromeSearchScheme)
1692 return false;
1693
1694 // All other WebUIs must be locked to origin.
1695 return true;
1696}
1697
Maks Orlovich0e23e312019-07-16 13:13:561698bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021699 base::StringPiece scheme,
1700 bool is_embedded_origin_secure) {
1701 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1702 return true;
Maks Orlovich0e23e312019-07-16 13:13:561703#if BUILDFLAG(ENABLE_EXTENSIONS)
1704 return scheme == extensions::kExtensionScheme;
1705#else
1706 return false;
1707#endif
1708}
1709
Lily Chen0db055b2019-11-15 20:29:021710bool ChromeContentBrowserClient::
1711 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1712 base::StringPiece scheme,
1713 bool is_embedded_origin_secure) {
1714 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1715}
1716
Lukasz Anforowicz7097890d2019-11-20 21:49:221717void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021718 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591719 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021720 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221721 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071722#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221723 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021724 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071725#endif
1726}
1727
[email protected]73b718f2014-01-27 02:59:461728// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1729// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411730void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1731 std::vector<std::string>* additional_schemes) {
1732 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241733 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351734 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061735}
1736
alexmos94875b3b2017-03-16 22:19:011737void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1738 std::vector<std::string>* additional_schemes) {
1739 GetAdditionalWebUISchemes(additional_schemes);
1740
1741#if BUILDFLAG(ENABLE_EXTENSIONS)
1742 additional_schemes->push_back(extensions::kExtensionScheme);
1743#endif
1744}
1745
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521746bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011747 return webui::LogWebUIUrl(web_ui_url);
1748}
1749
John Abd-El-Malek04bfa8532018-07-12 05:28:221750bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1751 const url::Origin& origin) {
1752 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1753 origin);
1754}
1755
[email protected]46fb9442011-12-09 17:57:471756bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1757 return ProfileIOData::IsHandledURL(url);
1758}
1759
[email protected]c4365fa42013-05-14 01:08:241760bool ChromeContentBrowserClient::CanCommitURL(
1761 content::RenderProcessHost* process_host,
1762 const GURL& url) {
brettw00899e62016-11-12 02:10:171763#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441764 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1765 url);
[email protected]d5a74be2014-08-08 01:01:271766#else
1767 return true;
1768#endif
[email protected]c4365fa42013-05-14 01:08:241769}
1770
rdevlin.cronina32a0902016-11-09 15:50:201771void ChromeContentBrowserClient::OverrideNavigationParams(
1772 SiteInstance* site_instance,
1773 ui::PageTransition* transition,
1774 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581775 content::Referrer* referrer,
1776 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201777 DCHECK(transition);
1778 DCHECK(is_renderer_initiated);
1779 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471780 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1781 // use for making security decisions 99.44% of the time, for detecting the NTP
1782 // it is reliable and the correct way. See http://crbug.com/624410.
1783 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201784 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581785 // Clicks on tiles of the new tab page should be treated as if a user
1786 // clicked on a bookmark. This is consistent with native implementations
1787 // like Android's. This also helps ensure that security features (like
1788 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1789 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201790 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1791 *is_renderer_initiated = false;
1792 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581793 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421794 }
1795}
1796
Charles Reis29e9dd12017-09-28 00:59:151797bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1798 const GURL& url,
1799 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471800 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1801 // use for making security decisions 99.44% of the time, for detecting the NTP
1802 // it is reliable and the correct way. See http://crbug.com/624410.
1803 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1804 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151805}
1806
[email protected]2a5221b2011-09-27 23:07:311807bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301808 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311809 const GURL& site_url) {
1810 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301811 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441812 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521813 // share any host.
1814 if (!profile)
1815 return true;
1816
Marc Treib7895941d2017-11-28 12:37:021817#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141818 // Instant URLs should only be in the instant process and instant process
1819 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521820 InstantService* instant_service =
1821 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141822 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441823 bool is_instant_process =
1824 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141825 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131826 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141827 if (is_instant_process || should_be_in_instant_process)
1828 return is_instant_process && should_be_in_instant_process;
1829 }
Marc Treib7895941d2017-11-28 12:37:021830#endif
[email protected]c5dec6292013-01-25 04:54:521831
brettw00899e62016-11-12 02:10:171832#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131833 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1834 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271835#else
1836 return true;
1837#endif
[email protected]2a5221b2011-09-27 23:07:311838}
1839
[email protected]28c5d0b72014-05-13 08:19:591840bool ChromeContentBrowserClient::MayReuseHost(
1841 content::RenderProcessHost* process_host) {
1842 // If there is currently a prerender in progress for the host provided,
1843 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041844 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591845 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371846 prerender::PrerenderManagerFactory::GetForBrowserContext(
1847 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591848 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491849 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591850 return false;
1851 }
1852
1853 return true;
1854}
1855
[email protected]76411f412012-02-22 18:56:061856bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441857 content::BrowserContext* browser_context,
1858 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061859 // It has to be a valid URL for us to check for an extension.
1860 if (!url.is_valid())
1861 return false;
1862
brettw00899e62016-11-12 02:10:171863#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061864 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131865 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441866 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271867#else
1868 return false;
1869#endif
[email protected]76411f412012-02-22 18:56:061870}
1871
Alex Moshchuk9c9e3882018-11-02 19:57:031872bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1873 content::RenderFrameHost* main_frame) {
1874#if BUILDFLAG(ENABLE_EXTENSIONS)
1875 return ChromeContentBrowserClientExtensionsPart::
1876 ShouldSubframesTryToReuseExistingProcess(main_frame);
1877#else
1878 return true;
1879#endif
1880}
1881
[email protected]6f371442011-11-09 06:45:461882void ChromeContentBrowserClient::SiteInstanceGotProcess(
1883 SiteInstance* site_instance) {
1884 CHECK(site_instance->HasProcess());
1885
Aran Gilmanf010bdd2019-08-28 19:55:441886 Profile* profile =
1887 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521888 if (!profile)
1889 return;
1890
Marc Treib7895941d2017-11-28 12:37:021891#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521892 // Remember the ID of the Instant process to signal the renderer process
1893 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131894 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1895 profile)) {
[email protected]c5dec6292013-01-25 04:54:521896 InstantService* instant_service =
1897 InstantServiceFactory::GetForProfile(profile);
1898 if (instant_service)
1899 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1900 }
Marc Treib7895941d2017-11-28 12:37:021901#endif
[email protected]c5dec6292013-01-25 04:54:521902
[email protected]a48ab7112014-08-01 16:48:031903 for (size_t i = 0; i < extra_parts_.size(); ++i)
1904 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461905}
1906
1907void ChromeContentBrowserClient::SiteInstanceDeleting(
1908 SiteInstance* site_instance) {
1909 if (!site_instance->HasProcess())
1910 return;
1911
[email protected]a48ab7112014-08-01 16:48:031912 for (size_t i = 0; i < extra_parts_.size(); ++i)
1913 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461914}
1915
[email protected]453f5432013-11-26 19:43:001916bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141917 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561918 const GURL& current_effective_url,
1919 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171920#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131921 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561922 ShouldSwapBrowsingInstancesForNavigation(
1923 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271924#else
1925 return false;
1926#endif
[email protected]e3daf3c2011-10-05 21:17:081927}
1928
Nasko Oskovd83b5712018-05-04 04:50:571929bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1930 // TODO(nasko): Consider supporting error page isolation in subframes if
1931 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381932 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571933}
1934
[email protected]3d831992013-07-04 01:13:291935bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1936 return !url.SchemeIs(chrome::kChromeNativeScheme);
1937}
1938
Alex Moshchukd252c192017-07-17 22:03:481939std::vector<url::Origin>
1940ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1941 std::vector<url::Origin> isolated_origin_list;
1942
Alex Moshchuk89352a72017-10-25 20:25:591943// Sign-in process isolation is not needed on Android, see
1944// https://crbug.com/739418.
1945#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381946 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121947 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591948#endif
Alex Moshchukd252c192017-07-17 22:03:481949
Alex Moshchuk81d2a29e2019-07-16 01:14:381950#if BUILDFLAG(ENABLE_EXTENSIONS)
1951 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1952 GetOriginsRequiringDedicatedProcess();
1953 std::move(std::begin(origins_from_extensions),
1954 std::end(origins_from_extensions),
1955 std::back_inserter(isolated_origin_list));
1956#endif
1957
Alex Moshchuk51e1428b2020-04-22 18:00:541958 // Include additional origins preloaded with specific browser configurations,
1959 // if any. For example, this is used on Google Chrome for Android to preload
1960 // a list of important sites to isolate.
1961 auto built_in_origins =
1962 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
1963 std::move(std::begin(built_in_origins), std::end(built_in_origins),
1964 std::back_inserter(isolated_origin_list));
1965
Alex Moshchukd252c192017-07-17 22:03:481966 return isolated_origin_list;
1967}
1968
Lukasz Anforowicz5e201abd2018-03-24 00:41:061969bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341970 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1971}
1972
1973bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371974 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061975}
1976
Alex Moshchuk082b5f82019-03-14 01:34:161977std::vector<std::string>
1978ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1979 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1980 return {"Isolate Password Sites"};
1981 else
1982 return {};
1983}
1984
Alex Moshchuke256d562019-04-26 21:43:571985void ChromeContentBrowserClient::PersistIsolatedOrigin(
1986 content::BrowserContext* context,
1987 const url::Origin& origin) {
1988 DCHECK(!context->IsOffTheRecord());
1989 Profile* profile = Profile::FromBrowserContext(context);
1990 ListPrefUpdate update(profile->GetPrefs(),
1991 prefs::kUserTriggeredIsolatedOrigins);
1992 base::ListValue* list = update.Get();
1993 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361994 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121995 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571996}
1997
Ken Rockot314714c2017-11-05 23:36:241998bool ChromeContentBrowserClient::IsFileAccessAllowed(
1999 const base::FilePath& path,
2000 const base::FilePath& absolute_path,
2001 const base::FilePath& profile_path) {
2002 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
2003 profile_path);
2004}
2005
[email protected]d2e1a0a2014-06-16 15:49:372006namespace {
2007
2008bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:172009 const base::CommandLine& browser_command_line =
2010 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:352011 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372012 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:352013 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372014 return false;
[email protected]9ef49b42014-08-07 16:44:242015 return true;
[email protected]d2e1a0a2014-06-16 15:49:372016}
2017
bmcquade5d2d9cf32015-06-19 17:42:282018void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2019 const base::CommandLine& browser_command_line,
2020 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522021 // List of field trials that modify the blink-settings command line flag. No
2022 // two field trials in the list should specify the same keys, otherwise one
2023 // field trial may overwrite another. See Source/core/frame/Settings.in in
2024 // Blink for the list of valid keys.
2025 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162026 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2027 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2028 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2029 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522030 };
2031
2032 std::vector<std::string> blink_settings;
2033 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2034 // Each blink-settings field trial should include a forcing_flag group,
2035 // to make sure that clients that specify the blink-settings flag on the
2036 // command line are excluded from the experiment groups. To make
2037 // sure we assign clients that specify this flag to the forcing_flag
2038 // group, we must call GetVariationParams for each field trial first
2039 // (for example, before checking HasSwitch() and returning), since
2040 // GetVariationParams has the side-effect of assigning the client to
2041 // a field trial group.
2042 std::map<std::string, std::string> params;
2043 if (variations::GetVariationParams(field_trial_name, &params)) {
2044 for (const auto& param : params) {
2045 blink_settings.push_back(base::StringPrintf(
2046 "%s=%s", param.first.c_str(), param.second.c_str()));
2047 }
2048 }
2049 }
pmeenan9ac669682015-08-17 14:57:032050
bmcquade9dd54cc2015-06-22 16:56:522051 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282052 return;
2053 }
2054
2055 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2056 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032057 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522058 // blink-settings flag into a group with no params, and we return
2059 // above if no params were specified, so it's an error if we reach
2060 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282061 LOG(WARNING) << "Received field trial params, "
2062 "but blink-settings switch already specified.";
2063 return;
2064 }
2065
bmcquade5d2d9cf32015-06-19 17:42:282066 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262067 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282068}
2069
[email protected]d2e1a0a2014-06-16 15:49:372070} // namespace
2071
[email protected]b80f68432011-05-02 17:22:302072void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172073 base::CommandLine* command_line,
2074 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062075#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352076 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062077 GoogleUpdateSettings::LoadMetricsClientInfo();
2078 if (client_info) {
2079 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2080 client_info->client_id);
2081 }
2082#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022083#if defined(OS_ANDROID)
2084 bool enable_crash_reporter = true;
2085#else
Joshua Perazace68e2f2019-09-23 18:44:242086 bool enable_crash_reporter = false;
2087 if (crash_reporter::IsCrashpadEnabled()) {
2088 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2089 enable_crash_reporter = true;
2090
2091 int fd;
2092 pid_t pid;
2093 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2094 command_line->AppendSwitchASCII(
2095 crash_reporter::switches::kCrashpadHandlerPid,
2096 base::NumberToString(pid));
2097 }
2098 } else {
2099 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2100 }
Joshua Perazaf890e4b2019-01-03 19:19:022101#endif
2102 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512103 std::string switch_value;
dcheng4af48582016-04-19 00:29:352104 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532105 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512106 if (client_info)
2107 switch_value = client_info->client_id;
2108 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252109 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302110 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512111 switch_value);
[email protected]b80f68432011-05-02 17:22:302112 }
Mark Mentovaic67fa64f2015-03-24 14:00:062113#endif
[email protected]b80f68432011-05-02 17:22:302114
[email protected]f1933792011-06-14 00:49:342115 if (logging::DialogsAreSuppressed())
2116 command_line->AppendSwitch(switches::kNoErrorDialogs);
2117
[email protected]b80f68432011-05-02 17:22:302118 std::string process_type =
2119 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172120 const base::CommandLine& browser_command_line =
2121 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322122
[email protected]7c9b6f92013-09-10 18:11:352123 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442124 switches::kUserAgent,
2125 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352126 };
2127 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372128 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322129
fqj15ff3f72015-10-09 19:20:022130 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432131 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312132 };
fqj15ff3f72015-10-09 19:20:022133 command_line->CopySwitchesFrom(browser_command_line,
2134 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372135 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312136
David Van Cleve3df6abb2019-11-26 17:52:512137 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2138 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2139
fqj15ff3f72015-10-09 19:20:022140#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332141 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2142 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522143 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332144 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2145 homedir.value().c_str());
2146#endif
2147
[email protected]718eab62011-10-05 21:16:522148 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032149 content::RenderProcessHost* process =
2150 content::RenderProcessHost::FromID(child_process_id);
2151 Profile* profile =
2152 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442153 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032154 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442155 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2156 process, profile);
[email protected]a48ab7112014-08-01 16:48:032157 }
2158
[email protected]b80f68432011-05-02 17:22:302159#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442160 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2161 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302162 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442163 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2164 login_profile);
[email protected]b80f68432011-05-02 17:22:302165#endif
2166
Aran Gilmanf010bdd2019-08-28 19:55:442167 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222168 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372169 if (process) {
[email protected]a8d851f82011-12-21 00:32:372170 PrefService* prefs = profile->GetPrefs();
2171 // Currently this pref is only registered if applied via a policy.
2172 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2173 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2174 // Turn this policy into a command line switch.
2175 command_line->AppendSwitch(switches::kDisable3DAPIs);
2176 }
[email protected]718eab62011-10-05 21:16:522177
[email protected]1733b782014-06-19 18:51:552178 const base::ListValue* switches =
2179 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2180 if (switches) {
2181 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112182 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552183 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142184 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552185 command_line->AppendSwitch(switch_to_enable);
2186 }
2187 }
2188
Daniel Rubery9eb1e0912020-05-08 17:57:322189#if defined(FULL_SAFE_BROWSING)
[email protected]a8d851f82011-12-21 00:32:372190 // Disable client-side phishing detection in the renderer if it is
Daniel Rubery9eb1e0912020-05-08 17:57:322191 // disabled in the Profile preferences, or by command line flag.
Bettinae83f522c72020-03-12 01:52:332192 if (!safe_browsing::IsSafeBrowsingEnabled(*prefs) ||
Daniel Rubery9eb1e0912020-05-08 17:57:322193 !safe_browsing::ClientSideDetectionServiceFactory::GetForProfile(
2194 profile)) {
[email protected]a8d851f82011-12-21 00:32:372195 command_line->AppendSwitch(
2196 switches::kDisableClientSidePhishingDetection);
2197 }
Daniel Rubery9eb1e0912020-05-08 17:57:322198#endif
[email protected]0045b0f42012-07-26 11:52:082199
vitalybukaa7ae5052014-09-26 04:11:132200 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2201 command_line->AppendSwitch(switches::kDisablePrintPreview);
2202
Marc Treib7895941d2017-11-28 12:37:022203#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522204 InstantService* instant_service =
2205 InstantServiceFactory::GetForProfile(profile);
2206 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542207 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522208 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542209 }
Marc Treib7895941d2017-11-28 12:37:022210#endif
fqjba8749c2015-10-29 15:33:072211
fqj38306f7b2015-11-02 16:59:062212 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542213 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432214 command_line->AppendSwitch(
2215 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542216 }
Daniel Vogelheim976f1c22017-11-22 16:26:032217
Lukasz Anforowicz60d1253d2019-05-08 16:31:372218 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2219
Amr Aboelkherb04cbf32019-04-29 15:17:102220 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2221 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292222 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102223 }
Katie Dillonc25ee5c92019-09-12 17:05:422224
2225 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2226 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2227 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2228 }
Takashi Toyoshima128441462019-10-16 04:19:172229
Mason Freed490f2a22019-11-05 21:41:292230
Daniel Libbyc5bfd91f2020-03-07 03:44:102231 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2232 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2233 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2234 }
2235
Takashi Toyoshima0dab73302019-10-18 01:51:362236 if (!profile->ShouldEnableOutOfBlinkCors()) {
2237 command_line->AppendSwitch(
2238 network::switches::kForceToDisableOutOfBlinkCors);
2239 }
Adrienne Walker297651292020-05-08 00:23:182240
2241 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
2242 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
2243 command_line->AppendSwitch(switches::kAppCacheForceEnabled);
2244 }
[email protected]47c7ec82012-01-18 03:29:212245 }
[email protected]4287a3d2011-06-13 23:56:512246
[email protected]d2e1a0a2014-06-16 15:49:372247 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352248 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042249
Aran Gilmanf010bdd2019-08-28 19:55:442250 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2251 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282252
mdjonesa6b9e172016-09-23 16:24:302253#if defined(OS_ANDROID)
2254 // If the platform is Android, force the distillability service on.
2255 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2256#endif
2257
[email protected]47c7ec82012-01-18 03:29:212258 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512259 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192260 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412261 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302262#if defined(OS_CHROMEOS)
2263 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2264#endif
brettw00899e62016-11-12 02:10:172265#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512266 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272267 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172268 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512269 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272270 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172271 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172272 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282273#endif
estark4b003b332015-02-14 01:07:052274 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512275 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482276 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512277 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502278 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572279 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462280 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302281 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512282 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172283#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242284 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482285 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552286#endif
[email protected]ce304ce2013-02-22 21:54:452287 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342288#if defined(OS_CHROMEOS)
2289 switches::kForceAppMode,
2290#endif
Nico Weberaf3b00b2017-09-11 17:58:172291#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592292 switches::kForcePNaClSubzero,
2293#endif
Marc Treibad33cf942017-08-24 11:19:002294 switches::kForceUIDirection,
John Abd-El-Malekcdb5b522020-05-26 22:41:032295 switches::kIgnoreGooglePortNumbers,
erikcorryb251cb92014-09-25 23:48:512296 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102297 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322298 embedder_support::kOriginTrialDisabledFeatures,
2299 embedder_support::kOriginTrialDisabledTokens,
2300 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512301 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512302 switches::kPpapiFlashPath,
2303 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032304 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092305 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512306 };
2307
2308 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372309 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172310 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172311#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382312 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442313 extensions::switches::kAllowHTTPBackgroundPage,
2314 extensions::switches::kEnableExperimentalExtensionApis,
2315 extensions::switches::kExtensionsOnChromeURLs,
2316 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382317 };
2318
2319 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372320 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282321#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372322 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132323 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512324 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512325 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502326 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172327#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242328 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582329 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592330 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412331 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552332#endif
[email protected]4287a3d2011-06-13 23:56:512333 switches::kPpapiFlashPath,
2334 switches::kPpapiFlashVersion,
2335 };
2336
2337 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372338 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112339 } else if (process_type == switches::kGpuProcess) {
2340 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2341 // because GPU is expected to be unreliable.
2342 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2343 !command_line->HasSwitch(switches::kDisableBreakpad))
2344 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302345 }
[email protected]6f08af82011-09-15 01:19:032346
Ian Barkley-Yeung550aae052019-07-11 00:11:112347#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302348 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112349 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292350 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112351 };
2352 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2353 base::size(kSwitchNames));
2354 }
2355#endif
2356
wittman832321f52016-10-10 18:18:382357 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442358 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342359
2360#if defined(OS_LINUX)
2361 // Processes may only query perf_event_open with the BPF sandbox disabled.
2362 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2363 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2364 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2365 }
2366#endif
[email protected]b80f68432011-05-02 17:22:302367}
2368
Olivier Yiptong0daa93f2019-08-22 19:40:082369std::string
2370ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2371 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2372}
2373
[email protected]b80f68432011-05-02 17:22:302374std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432375 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332376 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302377 return g_browser_process->GetApplicationLocale();
2378}
2379
[email protected]597a867b2011-11-18 18:31:202380std::string ChromeContentBrowserClient::GetAcceptLangs(
2381 content::BrowserContext* context) {
2382 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202383 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082384}
2385
Dana Fried34d580002019-04-24 20:05:482386gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492387 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482388 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082389}
2390
bengre8a146f2016-03-10 01:20:222391bool ChromeContentBrowserClient::IsDataSaverEnabled(
2392 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382393 if (!browser_context || browser_context->IsOffTheRecord())
2394 return false;
2395
Robert Ogdenc995d4fe2019-03-25 19:18:372396 Profile* profile = Profile::FromBrowserContext(browser_context);
2397 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412398 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2399 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222400}
2401
Kenichi Ishibashi46329872018-07-17 09:43:402402void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2403 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192404 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402405 DCHECK(browser_context);
2406 DCHECK(out_prefs);
2407 renderer_preferences_util::UpdateFromSystemSettings(
2408 out_prefs, Profile::FromBrowserContext(browser_context));
2409}
2410
Clark DuVall5690e742019-07-17 18:26:172411bool ChromeContentBrowserClient::AllowAppCache(
2412 const GURL& manifest_url,
Christian Dullweber77740152020-05-12 09:54:172413 const GURL& site_for_cookies,
2414 const base::Optional<url::Origin>& top_frame_origin,
Clark DuVall5690e742019-07-17 18:26:172415 content::BrowserContext* context) {
2416 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2417 return CookieSettingsFactory::GetForProfile(
2418 Profile::FromBrowserContext(context))
Christian Dullweber77740152020-05-12 09:54:172419 ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin);
Clark DuVall5690e742019-07-17 18:26:172420}
2421
Alexander Timin17edc742020-04-23 18:22:182422content::AllowServiceWorkerResult
2423ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072424 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542425 const GURL& site_for_cookies,
2426 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362427 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182428 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522429 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542430 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452431
brettw00899e62016-11-12 02:10:172432#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452433 // Check if this is an extension-related service worker, and, if so, if it's
2434 // allowed (this can return false if, e.g., the extension is disabled).
2435 // If it's not allowed, return immediately. We deliberately do *not* report
2436 // to the TabSpecificContentSettings, since the service worker is blocked
2437 // because of the extension, rather than because of the user's content
2438 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022439 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362440 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182441 return content::AllowServiceWorkerResult::No();
rdevlin.croninf5863da2015-09-10 19:21:452442 }
2443#endif
2444
falken3dbc36e2014-10-10 16:48:072445 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202446
shimazuce8af88122016-10-06 23:49:212447 // Check if JavaScript is allowed.
2448 content_settings::SettingInfo info;
2449 std::unique_ptr<base::Value> value =
2450 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452451 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212452 std::string(), &info);
2453 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2454 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2455
2456 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542457 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2458 scope, site_for_cookies, top_frame_origin);
Alexander Timin17edc742020-04-23 18:22:182459
2460 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2461 !allow_cookies);
falken3dbc36e2014-10-10 16:48:072462}
2463
Alexander Timin17edc742020-04-23 18:22:182464content::AllowServiceWorkerResult
2465ChromeContentBrowserClient::AllowServiceWorkerOnUI(
Matt Falkenhagen7b509e52019-08-15 23:11:412466 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542467 const GURL& site_for_cookies,
2468 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412469 const GURL& script_url,
Alexander Timin17edc742020-04-23 18:22:182470 content::BrowserContext* context) {
Matt Falkenhagen7b509e52019-08-15 23:11:412471 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542472 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412473
2474#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022475 // Check if this is an extension-related service worker, and, if so, if it's
2476 // allowed (this can return false if, e.g., the extension is disabled).
2477 // If it's not allowed, return immediately. We deliberately do *not* report
2478 // to the TabSpecificContentSettings, since the service worker is blocked
2479 // because of the extension, rather than because of the user's content
2480 // settings.
2481 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2482 scope, first_party_url, script_url, context)) {
Alexander Timin17edc742020-04-23 18:22:182483 return content::AllowServiceWorkerResult::No();
Matt Falkenhagena59e1cce2019-08-22 23:45:022484 }
Matt Falkenhagen7b509e52019-08-15 23:11:412485#endif
2486
2487 Profile* profile = Profile::FromBrowserContext(context);
2488
2489 // Check if JavaScript is allowed.
2490 content_settings::SettingInfo info;
2491 std::unique_ptr<base::Value> value =
2492 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452493 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412494 std::string(), &info);
2495 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2496 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2497
2498 // Check if cookies are allowed.
2499 bool allow_cookies =
2500 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542501 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412502
Alexander Timin17edc742020-04-23 18:22:182503 return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript,
2504 !allow_cookies);
Matt Falkenhagen7b509e52019-08-15 23:11:412505}
2506
Jochen Eisinger0ff7645c2017-11-28 08:11:262507bool ChromeContentBrowserClient::AllowSharedWorker(
2508 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542509 const GURL& site_for_cookies,
2510 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262511 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372512 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262513 content::BrowserContext* context,
2514 int render_process_id,
2515 int render_frame_id) {
2516 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2517
2518 // Check if cookies are allowed.
2519 bool allow =
2520 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542521 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2522 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262523
Clark DuVall84a33d612020-04-17 16:01:002524 content_settings::TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372525 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2526 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262527 return allow;
2528}
2529
Patrick Monette6cb099a2019-09-18 19:31:272530bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2531 const std::string& scheme) {
2532#if BUILDFLAG(ENABLE_EXTENSIONS)
2533 // Extensions are allowed to start cross-origin shared workers.
2534 if (scheme == extensions::kExtensionScheme)
2535 return true;
2536#endif
2537
2538 return false;
2539}
2540
Clark DuVallab63d142019-07-23 04:24:362541bool ChromeContentBrowserClient::AllowSignedExchange(
2542 content::BrowserContext* browser_context) {
2543 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2544 Profile* profile = Profile::FromBrowserContext(browser_context);
2545 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2546}
2547
[email protected]f917df22014-07-10 07:45:492548void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352549 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572550 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172551 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572552 base::OnceCallback<void(bool)> callback) {
2553 Profile* profile = Profile::FromBrowserContext(browser_context);
2554 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172555 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]5c5a88e2011-11-12 00:45:352556
brettw00899e62016-11-12 02:10:172557#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572558 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492559#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572560 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492561#endif
2562}
2563
brettw00899e62016-11-12 02:10:172564#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492565void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2566 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172567 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572568 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492569 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572570 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492571 std::map<int, int> process_map;
2572 std::map<int, int>::const_iterator it;
2573 bool has_web_view_guest = false;
2574 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172575 for (const auto& it : render_frames) {
2576 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492577 continue;
2578
Lukasz Anforowicz09060bdf72018-08-23 15:53:172579 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492580
Lukasz Anforowicz09060bdf72018-08-23 15:53:172581 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492582 has_web_view_guest = true;
2583 }
2584 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572585 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492586 return;
2587 }
[email protected]dffb9fc2014-07-16 04:14:022588 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492589 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492590
[email protected]140d6cd92014-08-12 18:26:462591 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572592 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2593 web_view_permission_helper->RequestFileSystemPermission(
2594 url, allow,
2595 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2596 weak_factory_.GetWeakPtr(), url, render_frames,
2597 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492598}
2599#endif
2600
2601void ChromeContentBrowserClient::FileSystemAccessed(
2602 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172603 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572604 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492605 bool allow) {
[email protected]62151052012-02-01 18:40:482606 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172607 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002608 content_settings::TabSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572609 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352610 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572611 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352612}
2613
[email protected]7c5ff9a2012-03-02 07:42:492614bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2615 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572616 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172617 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572618 Profile* profile = Profile::FromBrowserContext(browser_context);
2619 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2620
Christian Dullweber77740152020-05-12 09:54:172621 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
[email protected]7c5ff9a2012-03-02 07:42:492622
2623 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172624 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002625 content_settings::TabSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572626 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492627 }
2628
2629 return allow;
2630}
2631
Ben Kelly6b2e61c2019-03-14 16:06:292632bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2633 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572634 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292635 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572636 Profile* profile = Profile::FromBrowserContext(browser_context);
2637 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172638 bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Ben Kelly6b2e61c2019-03-14 16:06:292639
2640 // Record access to CacheStorage for potential display in UI.
2641 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002642 content_settings::TabSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572643 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292644 }
2645
2646 return allow;
2647}
2648
Joshua Bell1ebc8df2019-11-06 00:27:582649bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2650 const GURL& url,
2651 content::BrowserContext* browser_context,
2652 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2653 Profile* profile = Profile::FromBrowserContext(browser_context);
2654 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Christian Dullweber77740152020-05-12 09:54:172655 return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt);
Joshua Bell1ebc8df2019-11-06 00:27:582656}
2657
jyasskinc993ce8d2016-03-31 00:38:342658ChromeContentBrowserClient::AllowWebBluetoothResult
2659ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452660 content::BrowserContext* browser_context,
2661 const url::Origin& requesting_origin,
2662 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342663 // TODO(crbug.com/598890): Don't disable if
2664 // base::CommandLine::ForCurrentProcess()->
2665 // HasSwitch(switches::kEnableWebBluetooth) is true.
2666 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272667 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342668 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272669 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342670 // The kill switch is enabled for this permission. Block requests.
2671 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2672 }
2673
jyasskin98bdd3992016-02-26 20:25:452674 const HostContentSettingsMap* const content_settings =
2675 HostContentSettingsMapFactory::GetForProfile(
2676 Profile::FromBrowserContext(browser_context));
2677
csharrisonaec2c542016-10-12 19:40:362678 if (content_settings->GetContentSetting(
2679 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452680 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362681 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342682 return AllowWebBluetoothResult::BLOCK_POLICY;
2683 }
2684 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452685}
2686
beaufort.francois01135bf2016-11-23 14:37:362687std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2688 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2689 "blocklist_additions");
scheib74250322016-04-07 03:32:212690}
2691
John Abd-El-Malek21bca7c2018-10-26 22:13:332692#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522693void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072694 content::BrowserContext* browser_context) {
2695 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2696 if (user_manager) {
2697 const user_manager::User* user =
2698 chromeos::ProfileHelper::Get()->GetUserByProfile(
2699 Profile::FromBrowserContext(browser_context));
2700 if (user && !user->username_hash().empty()) {
2701 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2702 user->username_hash());
2703 }
2704 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332705}
2706#endif
2707
Reilly Grant19aaccd2018-07-16 22:06:372708scoped_refptr<network::SharedURLLoaderFactory>
2709ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2711 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2712
2713 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372714 return nullptr;
2715
Min Qinda0d55b2018-10-12 18:30:052716 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372717 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042718}
2719
Sean Gilhulyda1ee4b2018-11-13 21:56:092720network::mojom::NetworkContext*
2721ChromeContentBrowserClient::GetSystemNetworkContext() {
2722 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2723 DCHECK(g_browser_process->system_network_context_manager());
2724 return g_browser_process->system_network_context_manager()->GetContext();
2725}
2726
Andrew Moylan17329fc2017-09-25 07:43:302727std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2728 return google_apis::GetAPIKey();
2729}
2730
Ke He21ee87f2018-05-30 02:35:322731#if defined(OS_ANDROID)
2732bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2733 // Indicate that Chrome uses the GMS core location provider.
2734 return true;
2735}
2736#endif
2737
Yeolf3dc22ca2019-04-18 17:25:322738scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412739ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542740 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412741}
2742
Mythri Alle0b8de0d2018-10-22 11:06:222743content::GeneratedCodeCacheSettings
2744ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2745 content::BrowserContext* context) {
2746 base::FilePath cache_path;
2747 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2748 // If we pass 0 for size, disk_cache will pick a default size using the
2749 // heuristics based on available disk size. These are implemented in
2750 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162751 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132752 DCHECK(g_browser_process);
2753 PrefService* local_state = g_browser_process->local_state();
2754 if (local_state) {
2755 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2756 base::FilePath disk_cache_dir =
2757 local_state->GetFilePath(prefs::kDiskCacheDir);
2758 if (!disk_cache_dir.empty())
2759 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2760 }
Mythri Ab2486572019-06-13 14:48:162761 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222762}
2763
[email protected]848dd042011-06-04 18:24:032764void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262765 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172766 int cert_error,
2767 const net::SSLInfo& ssl_info,
2768 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232769 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222770 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262771 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262772 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232773 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142774 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022775 // have a context for making the right decision, so block the
2776 // request hard, without an info bar to allow showing the insecure
2777 // content.
estark719dde52016-08-09 03:14:272778 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262779 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022780 return;
2781 }
2782
[email protected]f9034cf2011-07-21 12:43:412783 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572784 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262785 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572786 if (prerender_contents) {
2787 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272788 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262789 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272790 }
[email protected]09667f02014-01-06 15:37:572791 return;
[email protected]f9034cf2011-07-21 12:43:412792 }
2793
Erik Staaba65a6032019-11-27 22:23:262794 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282795 return;
[email protected]848dd042011-06-04 18:24:032796}
2797
Katie D1882617e2020-05-06 20:06:012798#if !defined(OS_ANDROID)
2799bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError(
2800 const GURL main_page_url) {
2801 // Desktop Reader Mode pages should never load resources with certificate
2802 // errors. Desktop Reader Mode is more strict about security than Reader Mode
2803 // on Android: the desktop version has its own security indicator and
2804 // is not downgraded to a WARNING, whereas Android will show "Not secure"
2805 // in the omnibox (for low-end devices which show the omnibox on Reader Mode
2806 // pages).
2807 return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme);
2808}
2809#endif
2810
Alexander Hendrichbcf2616e2018-05-18 08:21:102811namespace {
2812
Pavol Markob211ab22019-01-23 20:03:042813certificate_matching::CertificatePrincipalPattern
2814ParseCertificatePrincipalPattern(const base::Value* pattern) {
2815 return certificate_matching::CertificatePrincipalPattern::
2816 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2817}
2818
Alexander Hendrichbcf2616e2018-05-18 08:21:102819// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452820// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102821// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2822std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2823 Profile* profile,
2824 const GURL& requesting_url,
2825 net::ClientCertIdentityList& client_certs) {
2826 HostContentSettingsMap* host_content_settings_map =
2827 HostContentSettingsMapFactory::GetForProfile(profile);
2828 std::unique_ptr<base::Value> setting =
2829 host_content_settings_map->GetWebsiteSetting(
2830 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452831 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102832
Pavol Markob211ab22019-01-23 20:03:042833 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102834 return nullptr;
2835
Alexander Hendrichbcf2616e2018-05-18 08:21:102836 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042837 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2838 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102839 // |setting_dict| has the wrong format (e.g. single filter instead of a
2840 // list of filters). This content setting is only provided by
2841 // the |PolicyProvider|, which should always set it to a valid format.
2842 // Therefore, delete the invalid value.
2843 host_content_settings_map->SetWebsiteSettingDefaultScope(
2844 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452845 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042846 return nullptr;
2847 }
2848
2849 for (const base::Value& filter : filters->GetList()) {
2850 DCHECK(filter.is_dict());
2851
2852 auto issuer_pattern = ParseCertificatePrincipalPattern(
2853 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2854 auto subject_pattern = ParseCertificatePrincipalPattern(
2855 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2856 // Use the first certificate that is matched by the filter.
2857 for (auto& client_cert : client_certs) {
2858 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2859 subject_pattern.Matches(client_cert->certificate()->subject())) {
2860 return std::move(client_cert);
2861 }
2862 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102863 }
2864
2865 return nullptr;
2866}
2867
2868} // namespace
2869
Daniel McArdle85735f52019-06-25 03:27:062870base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192871 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402872 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082873 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352874 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022875 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192876 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022877 if (prerender_contents) {
2878 prerender_contents->Destroy(
2879 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062880 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452881 }
2882
[email protected]791879c2013-12-17 07:22:412883 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2884 DCHECK(requesting_url.is_valid())
2885 << "Invalid URL string: https://"
2886 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452887
Pavol Marko230ea2c92017-12-03 22:35:442888 bool may_show_cert_selection = true;
2889
davidben3b8455ae72015-03-11 19:42:192890 Profile* profile =
2891 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442892#if defined(OS_CHROMEOS)
2893 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252894 // On the sign-in profile, never show certificate selection to the user. A
2895 // client certificate is an identifier that can be stable for a long time,
2896 // so only the administrator is allowed to decide which endpoints should see
2897 // it.
2898 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442899
2900 content::StoragePartition* storage_partition =
2901 content::BrowserContext::GetStoragePartition(
2902 profile, web_contents->GetSiteInstance());
2903 chromeos::login::SigninPartitionManager* signin_partition_manager =
2904 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2905 profile);
2906
2907 // On the sign-in profile, only allow client certs in the context of the
2908 // sign-in frame.
2909 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2910 storage_partition)) {
2911 LOG(WARNING)
2912 << "Client cert requested in sign-in profile in wrong context.";
2913 // Continue without client certificate. We do this to mimic the case of no
2914 // client certificate being present in the profile's certificate store.
2915 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062916 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442917 }
2918 VLOG(1) << "Client cert requested in sign-in profile.";
2919 }
2920#endif // defined(OS_CHROMEOS)
2921
Alexander Hendrichbcf2616e2018-05-18 08:21:102922 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2923 AutoSelectCertificate(profile, requesting_url, client_certs);
2924 if (auto_selected_identity) {
2925 // The callback will own |auto_selected_identity| and |delegate|, keeping
2926 // them alive until after ContinueWithCertificate is called.
2927 scoped_refptr<net::X509Certificate> cert =
2928 auto_selected_identity->certificate();
2929 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2930 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582931 base::BindOnce(
2932 &content::ClientCertificateDelegate::ContinueWithCertificate,
2933 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322934 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062935 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452936 }
2937
Pavol Marko230ea2c92017-12-03 22:35:442938 if (!may_show_cert_selection) {
2939 LOG(WARNING) << "No client cert matched by policy and user selection is "
2940 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322941 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442942 // Continue without client certificate. We do this to mimic the case of no
2943 // client certificate being present in the profile's certificate store.
2944 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062945 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442946 }
2947
Daniel McArdle85735f52019-06-25 03:27:062948 return chrome::ShowSSLClientCertificateSelector(
2949 web_contents, cert_request_info, std::move(client_certs),
2950 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452951}
2952
[email protected]dc73a7b2012-03-25 15:27:182953content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562954 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182955}
2956
Adrienne Walker80d95f02020-02-07 22:37:042957content::FeatureObserverClient*
2958ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:242959 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:042960 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:052961}
2962
peterc26c6c62014-12-10 14:13:592963content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022964ChromeContentBrowserClient::GetPlatformNotificationService(
2965 content::BrowserContext* browser_context) {
2966 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2967 Profile* profile = Profile::FromBrowserContext(browser_context);
2968 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042969}
2970
[email protected]9f3fba52011-06-08 20:37:192971bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352972 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352973 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572974 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352975 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032976 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232977 const GURL& target_url,
2978 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212979 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232980 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482981 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232982 bool user_gesture,
2983 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012984 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352985 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2986 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012987
csharrison95f01e922017-04-24 18:52:352988 content::WebContents* web_contents =
2989 content::WebContents::FromRenderFrameHost(opener);
2990 Profile* profile =
2991 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2992 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012993 *no_javascript_access = false;
2994
[email protected]9f3fba52011-06-08 20:37:192995 // If the opener is trying to create a background window but doesn't have
2996 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032997 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172998#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352999 auto* process_map = extensions::ProcessMap::Get(profile);
3000 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173001 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3002 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013003 return false;
3004 }
3005
[email protected]7b54ca02012-03-02 18:06:533006 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3007 // return a recently installed Extension even if this CanCreateWindow call
3008 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013009 // because the permission check above would have caused an early return
3010 // already. We must use the full URL to find hosted apps, though, and not
3011 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553012 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353013 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293014 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013015 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023016#endif
[email protected]190e5e22013-07-27 05:59:233017
3018 return true;
[email protected]9f3fba52011-06-08 20:37:193019 }
[email protected]056efdc2013-04-06 00:14:533020
brettw00899e62016-11-12 02:10:173021#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463022 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353023 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233024 return true;
lazyboy04b75d32016-02-25 03:12:183025 }
3026
nick0fbc3922016-12-16 20:52:073027 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353028 // Intentionally duplicating |registry| code from above because we want to
3029 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3030 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183031 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353032 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143033 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533034 UMA_HISTOGRAM_ENUMERATION(
3035 "Extensions.AppLoadedInTab",
3036 ClassifyAppLoadedInTabSource(opener_url, extension),
3037 APP_LOADED_IN_TAB_SOURCE_MAX);
3038
3039 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163040 return false;
lazyboy5d5fede02016-03-10 04:10:143041 }
lazyboy04b75d32016-02-25 03:12:183042 }
[email protected]5940b0d2014-07-01 00:18:263043#endif
[email protected]190e5e22013-07-27 05:59:233044
Charles Harrisonaf2acd02017-08-18 22:46:023045#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:233046 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:353047 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:583048 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
3049 content_settings, opener_top_level_frame_url, target_url,
3050 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353051 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3052 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583053 return false;
3054 }
3055#endif
3056
Ryan Sturm0ec75df2020-04-23 14:39:153057 DCHECK(!prerender::PrerenderContents::FromWebContents(web_contents));
Charles Harrisonaf2acd02017-08-18 22:46:023058
Aaron Colwell9dab1652019-12-09 18:29:493059 BlockedWindowParams blocked_params(
3060 target_url, source_origin, opener->GetSiteInstance(), referrer,
3061 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133062 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:193063 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
3064 &nav_params, nullptr /*=open_url_params*/,
3065 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:193066}
3067
[email protected]c52b2892012-03-07 11:01:023068content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443069ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003070 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513071}
3072
Katie D840d9532018-11-27 06:20:483073content::TtsControllerDelegate*
3074ChromeContentBrowserClient::GetTtsControllerDelegate() {
3075 TtsControllerDelegateImpl* delegate =
3076 TtsControllerDelegateImpl::GetInstance();
3077#if !defined(OS_ANDROID)
3078 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3079 delegate->SetTtsEngineDelegate(tts_extension_engine);
3080#endif
3081 return delegate;
3082}
3083
Katie D4713ee42018-11-30 01:48:273084content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3085#ifdef OS_CHROMEOS
3086 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273087#else
3088 return nullptr;
3089#endif
3090}
3091
[email protected]64d69de42012-02-06 00:19:543092void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443093 RenderViewHost* rvh,
3094 WebPreferences* web_prefs) {
3095 Profile* profile =
3096 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063097 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063098
aelias0df335a2017-03-02 23:43:513099// Fill font preferences. These are not registered on Android
3100// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453101#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193102 FontFamilyCache::FillFontFamilyMap(profile,
3103 prefs::kWebKitStandardFontFamilyMap,
3104 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443105 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193106 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443107 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193108 &web_prefs->serif_font_family_map);
3109 FontFamilyCache::FillFontFamilyMap(profile,
3110 prefs::kWebKitSansSerifFontFamilyMap,
3111 &web_prefs->sans_serif_font_family_map);
3112 FontFamilyCache::FillFontFamilyMap(profile,
3113 prefs::kWebKitCursiveFontFamilyMap,
3114 &web_prefs->cursive_font_family_map);
3115 FontFamilyCache::FillFontFamilyMap(profile,
3116 prefs::kWebKitFantasyFontFamilyMap,
3117 &web_prefs->fantasy_font_family_map);
3118 FontFamilyCache::FillFontFamilyMap(profile,
3119 prefs::kWebKitPictographFontFamilyMap,
3120 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063121
[email protected]64d69de42012-02-06 00:19:543122 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403123 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543124 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403125 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543126 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403127 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543128 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403129 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513130#endif
[email protected]f3986f82012-01-03 20:00:063131
[email protected]ddf72142012-05-22 04:52:403132 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063133
[email protected]64d69de42012-02-06 00:19:543134 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063135 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213136 web_prefs->javascript_can_access_clipboard =
3137 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543138 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063139
[email protected]ddf72142012-05-22 04:52:403140 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543141 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573142
Avi Drissman1aa6cb92019-01-23 15:58:383143 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543144 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573145
[email protected]ddf72142012-05-22 04:52:403146 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543147 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543148 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403149 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063150
Zhenyao Moa3fda9972017-09-16 01:34:403151 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3152 web_prefs->webgl1_enabled = false;
3153 web_prefs->webgl2_enabled = false;
3154 }
[email protected]f3986f82012-01-03 20:00:063155
[email protected]64d69de42012-02-06 00:19:543156 web_prefs->allow_running_insecure_content =
3157 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323158#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053159 web_prefs->font_scale_factor =
3160 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323161 web_prefs->force_enable_zoom =
3162 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493163#endif
Becky Zhoubbfbde32019-02-20 17:07:593164 web_prefs->force_dark_mode_enabled =
3165 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393166
Alice Boxhallda2659142020-05-14 06:04:373167#if defined(OS_CHROMEOS)
3168 web_prefs->always_show_focus =
3169 prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled);
3170#endif
3171
[email protected]af4256d52013-06-04 20:39:073172#if defined(OS_ANDROID)
3173 web_prefs->password_echo_enabled =
3174 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3175#else
[email protected]9d06d88d2012-02-23 22:37:083176 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073177#endif
3178
[email protected]64d69de42012-02-06 00:19:543179 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063180 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543181 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063182 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3183
brettw00899e62016-11-12 02:10:173184#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053185 std::string image_animation_policy =
3186 prefs->GetString(prefs::kAnimationPolicy);
3187 if (image_animation_policy == kAnimationPolicyOnce)
3188 web_prefs->animation_policy =
3189 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3190 else if (image_animation_policy == kAnimationPolicyNone)
3191 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3192 else
3193 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3194#endif
3195
[email protected]f3986f82012-01-03 20:00:063196 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153197 web_prefs->default_encoding =
3198 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543199 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403200 prefs->ClearPref(prefs::kDefaultCharset);
3201 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063202 }
[email protected]64d69de42012-02-06 00:19:543203 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063204
mkwst05544102015-01-10 20:26:163205 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3206 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073207 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163208 web_prefs->strict_mixed_content_checking = true;
3209 web_prefs->strict_powerful_feature_restrictions = true;
3210 }
3211
Robert Ogdencf2872d2019-03-19 18:59:373212 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213213
Tarun Bansal333819e2018-05-15 16:38:423214 web_prefs->data_saver_holdback_web_api_enabled =
3215 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3216 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423217
Jinsuk Kima3d393ce2019-05-27 00:57:423218 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133219 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533220#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423221 auto* delegate = TabAndroid::FromWebContents(contents)
3222 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3223 contents->GetDelegate())
3224 : nullptr;
3225 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133226 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423227 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133228
Mounir Lamouri9c99a1602018-07-05 15:01:443229 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423230 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383231
Alison Maher7f366dc62020-03-03 19:46:003232 web_prefs->preferred_color_scheme =
3233 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3234 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113235 }
Ian Vollick6243dfe02018-03-08 01:08:533236#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533237
Mounir Lamouri6926107f2019-01-31 18:17:433238 // web_app_scope value is platform specific.
3239#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423240 if (delegate)
3241 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433242#elif BUILDFLAG(ENABLE_EXTENSIONS)
3243 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253244 web_prefs->web_app_scope = GURL();
3245 // Set |web_app_scope| based on the app associated with the app window if
3246 // any. Note that the app associated with the window never changes, even
3247 // if the app navigates off scope. This is not a problem because we still
3248 // want to use the scope of the app associated with the window, not the
3249 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433250 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233251 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593252 browser->app_controller()->HasAppId()) {
3253 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3254 const web_app::AppRegistrar& registrar =
3255 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3256 if (registrar.IsLocallyInstalled(app_id))
3257 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433258 }
Mounir Lamouri6926107f2019-01-31 18:17:433259 }
3260#endif
3261
Ian Vollick6243dfe02018-03-08 01:08:533262 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113263 }
zqzhang93e959d12017-03-16 13:10:203264
Tarun Bansal73d67f02018-01-17 05:56:253265 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3266 // Obtain the maximum effective connection type at which the feature is
3267 // enabled.
3268 std::string effective_connection_type_param =
3269 base::GetFieldTrialParamValueByFeature(
3270 features::kLowPriorityIframes,
3271 "max_effective_connection_type_threshold");
3272
3273 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3274 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3275 if (effective_connection_type) {
3276 web_prefs->low_priority_iframes_threshold =
3277 effective_connection_type.value();
3278 }
3279 }
3280
rajendrant0521cee2019-07-29 06:09:263281 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3282 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003283
Scott Little878f7d6702018-05-31 22:09:063284 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3285 const char* param_name =
3286 web_prefs->data_saver_enabled
3287 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3288 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3289 "saver_enabled";
3290
3291 base::StringPairs pairs;
3292 base::SplitStringIntoKeyValuePairs(
3293 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3294 param_name),
3295 ':', ',', &pairs);
3296
3297 for (const auto& pair : pairs) {
3298 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3299 net::GetEffectiveConnectionTypeForName(pair.first);
3300 int value = 0;
3301 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3302 web_prefs->lazy_frame_loading_distance_thresholds_px
3303 [effective_connection_type.value()] = value;
3304 }
3305 }
3306 }
3307
rajendrantd8026342018-08-29 08:08:393308 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3309 const char* param_name =
3310 web_prefs->data_saver_enabled
3311 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3312 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3313 "saver_enabled";
3314
3315 base::StringPairs pairs;
3316 base::SplitStringIntoKeyValuePairs(
3317 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3318 param_name),
3319 ':', ',', &pairs);
3320
3321 for (const auto& pair : pairs) {
3322 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3323 net::GetEffectiveConnectionTypeForName(pair.first);
3324 int value = 0;
3325 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3326 web_prefs->lazy_image_loading_distance_thresholds_px
3327 [effective_connection_type.value()] = value;
3328 }
3329 }
rajendrant3daeae292019-09-20 07:57:543330
3331 pairs.clear();
3332 base::SplitStringIntoKeyValuePairs(
3333 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3334 "lazy_image_first_k_fully_load"),
3335 ':', ',', &pairs);
3336
3337 for (const auto& pair : pairs) {
3338 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3339 net::GetEffectiveConnectionTypeForName(pair.first);
3340 int value = 0;
3341 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3342 web_prefs
3343 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3344 value;
3345 }
3346 }
rajendrantd8026342018-08-29 08:08:393347 }
3348
Tarun Bansald10f17a02018-09-13 00:23:173349 if (base::FeatureList::IsEnabled(
3350 features::kNetworkQualityEstimatorWebHoldback)) {
3351 std::string effective_connection_type_param =
3352 base::GetFieldTrialParamValueByFeature(
3353 features::kNetworkQualityEstimatorWebHoldback,
3354 "web_effective_connection_type_override");
3355
3356 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3357 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3358 DCHECK(effective_connection_type_param.empty() ||
3359 effective_connection_type);
3360 if (effective_connection_type) {
3361 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3362 effective_connection_type.value());
3363 web_prefs->network_quality_estimator_web_holdback =
3364 effective_connection_type.value();
3365 }
3366 }
3367
François Beaufort4f8107d2018-03-05 12:12:103368#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563369 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593370 // If autoplay is allowed by policy then force the no user gesture required
3371 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103372 web_prefs->autoplay_policy =
3373 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553374 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593375 web_prefs->autoplay_policy ==
3376 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553377 // If the autoplay disable settings feature is enabled and the autoplay
3378 // policy is set to using the unified policy then set the default autoplay
3379 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593380 web_prefs->autoplay_policy =
3381 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3382 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3383 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103384 }
Alison Maher7f366dc62020-03-03 19:46:003385
Abigail Kleina81f2e22020-05-04 14:32:413386 auto* native_theme = GetWebTheme();
Alison Maher7f366dc62020-03-03 19:46:003387 switch (native_theme->GetPreferredColorScheme()) {
3388 case ui::NativeTheme::PreferredColorScheme::kDark:
3389 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3390 break;
3391 case ui::NativeTheme::PreferredColorScheme::kLight:
3392 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3393 break;
3394 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3395 web_prefs->preferred_color_scheme =
3396 blink::PreferredColorScheme::kNoPreference;
3397 }
François Beaufort4f8107d2018-03-05 12:12:103398#endif // !defined(OS_ANDROID)
3399
Dave Tapuskac6627e12018-08-30 15:07:193400 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493401
Alison Maher7f366dc62020-03-03 19:46:003402 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3403 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3404 // explicitly uses light (instead of not dark), which is why we don't reset
3405 // back to no-preference. https://crbug.com/965811
3406 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3407 const GURL url = rvh->GetSiteInstance()->GetSiteURL();
3408 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3409#if BUILDFLAG(ENABLE_EXTENSIONS)
3410 if (!force_light) {
3411 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3412 url.host_piece() == extension_misc::kPdfExtensionId;
3413 }
3414#endif
3415 if (force_light)
3416 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3417 }
3418
Abigail Kleina81f2e22020-05-04 14:32:413419 base::Optional<ui::CaptionStyle> style =
3420 captions::GetCaptionStyleFromUserSettings(prefs,
3421 true /* record_metrics */);
Evan Liu7cdbf8872019-06-19 16:47:213422 if (style) {
3423 web_prefs->text_track_background_color = style->background_color;
3424 web_prefs->text_track_text_color = style->text_color;
3425 web_prefs->text_track_text_size = style->text_size;
3426 web_prefs->text_track_text_shadow = style->text_shadow;
3427 web_prefs->text_track_font_family = style->font_family;
3428 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563429 web_prefs->text_track_window_color = style->window_color;
3430 web_prefs->text_track_window_padding = style->window_padding;
3431 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213432 }
Elly Fong-Jonesf92897392019-01-24 16:05:493433
[email protected]a48ab7112014-08-01 16:48:033434 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503435 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363436}
3437
[email protected]b8148ac2011-07-13 22:03:253438void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3439 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033440 for (size_t i = 0; i < extra_parts_.size(); ++i)
3441 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253442
[email protected]b3adbd02011-11-30 22:23:273443 // about: handler. Must come before chrome: handler, since it will
3444 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053445 // actually handle them. Also relies on a preliminary fixup phase.
3446 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253447 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3448 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033449
madfbd10852017-01-20 03:15:333450 // The group policy NTP URL handler must be registered before the other NTP
3451 // URL handlers below.
3452 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3453 BrowserURLHandler::null_handler());
3454
zpengdb4a58e2017-01-10 17:40:323455#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033456 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353457 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033458 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453459#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033460 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133461 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3462 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453463#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033464
[email protected]b8148ac2011-07-13 22:03:253465 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313466 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3467 &ChromeContentBrowserClient::HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:253468}
3469
[email protected]650b2d52013-02-10 03:41:453470base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493471 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323472}
3473
[email protected]c9b6eb62011-10-18 20:49:393474std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3475 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3476}
3477
Dominik Röttsches47347832019-03-12 17:45:013478base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3479 base::FilePath user_data_dir;
3480 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3481 DCHECK(!user_data_dir.empty());
3482 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3483}
3484
jmadill57b52d42015-08-21 18:16:133485base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3486 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523487 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133488 DCHECK(!user_data_dir.empty());
3489 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3490}
3491
Khushal7ca0b782018-07-20 05:53:273492base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3493 base::FilePath user_data_dir;
3494 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3495 DCHECK(!user_data_dir.empty());
3496 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3497}
3498
[email protected]b7631cc2012-09-15 05:08:383499void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3500 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163501#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553502 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543503#endif
[email protected]b7631cc2012-09-15 05:08:383504}
3505
[email protected]0c7193742012-11-07 19:05:033506content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443507ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173508#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553509 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033510 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443511 nacl::NaClProcessHost* host =
3512 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3513 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033514 // Found the plugin.
3515 return host->browser_ppapi_host();
3516 }
3517 ++iter;
3518 }
[email protected]a56f8322014-07-16 21:13:553519#endif
Aran Gilmanf010bdd2019-08-28 19:55:443520 return nullptr;
[email protected]0c7193742012-11-07 19:05:033521}
3522
[email protected]38cd8f7f2012-06-15 22:06:073523bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583524 content::BrowserContext* browser_context,
3525 const GURL& url,
[email protected]dda54822013-06-15 01:26:393526 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123527 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163528#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553529 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193530 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403531#else
[email protected]a658d452012-03-02 12:45:293532 return false;
[email protected]93f72062013-05-29 20:29:403533#endif
[email protected]e461da2f2012-02-16 19:06:403534}
3535
adrian.belgund54465ba2016-05-18 10:03:583536bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3537 content::BrowserContext* browser_context,
3538 const GURL& url) {
brettw4b461082016-11-19 18:55:163539#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583540 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3541 browser_context, url);
3542#else
3543 return false;
3544#endif
3545}
3546
adrian.belgun5b341c72016-06-22 22:24:083547std::unique_ptr<content::VpnServiceProxy>
3548ChromeContentBrowserClient::GetVpnServiceProxy(
3549 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173550#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083551 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3552 browser_context);
3553#else
3554 return nullptr;
3555#endif
3556}
3557
Brett Wilson804e83c2017-08-18 22:57:333558std::unique_ptr<ui::SelectFilePolicy>
3559ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3560 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433561}
3562
[email protected]7d9424702013-04-14 13:14:163563void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3564 std::vector<std::string>* additional_allowed_schemes) {
3565 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3566 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483567 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293568 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033569 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3570 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3571 additional_allowed_schemes);
3572 }
[email protected]7d9424702013-04-14 13:14:163573}
3574
falkenad185092016-06-16 06:10:023575void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3576 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043577 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023578}
3579
[email protected]c79859b82014-03-20 22:43:553580void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313581 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033582 for (size_t i = 0; i < extra_parts_.size(); ++i)
3583 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553584}
3585
nzolghadrd87a308d2016-12-07 15:45:563586::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3587 return g_browser_process->rappor_service();
3588}
3589
[email protected]f19bbf62013-07-09 01:22:323590void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313591 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533592 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003593 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3594 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313595#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313596 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313597 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313598 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093599 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093600 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3601 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473602 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093603 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3604 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053605 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3606 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343607 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3608 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473609 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323610 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313611 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003612 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313613#endif
[email protected]445b7db2013-08-02 04:58:273614
[email protected]a48ab7112014-08-01 16:48:033615 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3616 extra_parts_[i]->GetAdditionalFileSystemBackends(
3617 browser_context, storage_partition_path, additional_backends);
3618 }
[email protected]02250952013-04-24 23:52:533619}
3620
jcivellie6f550742017-01-06 19:29:123621#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183622void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173623 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383624 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203625 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123626#if defined(OS_ANDROID)
3627 base::MemoryMappedFile::Region region;
3628 int fd = ui::GetMainAndroidPackFd(&region);
3629 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003630
Samuel Huang31eadf082019-08-28 19:50:433631 // For Android: Native resources for DFMs should only be used by the browser
3632 // process. Their file descriptors and memory mapped file regions are not
3633 // passed to child processes.
3634
jcivellie6f550742017-01-06 19:29:123635 fd = ui::GetCommonResourcesPackFd(&region);
3636 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393637
jcivellie6f550742017-01-06 19:29:123638 fd = ui::GetLocalePackFd(&region);
3639 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383640
zpeng368afac82017-07-17 18:47:453641 // Optional secondary locale .pak file.
3642 fd = ui::GetSecondaryLocalePackFd(&region);
3643 if (fd != -1) {
3644 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3645 }
3646
[email protected]09560f7f2014-06-10 18:40:283647 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523648 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283649 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023650#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383651 int crash_signal_fd = GetCrashSignalFD(command_line);
3652 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133653 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383654 }
jcivellie6f550742017-01-06 19:29:123655}
3656#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303657
[email protected]4a65826d2011-08-25 16:04:013658#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033659base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223660 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033661 // TODO(wfh): Add support for more process types here. crbug.com/499523
3662 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223663 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363664 return base::string16(install_static::GetSandboxSidPrefix()) +
3665 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223666 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033667 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223668 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033669 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223670 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363671 return base::string16(install_static::GetSandboxSidPrefix()) +
3672 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223673 case service_manager::SandboxType::kNoSandbox:
3674 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3675 case service_manager::SandboxType::kXrCompositing:
3676 case service_manager::SandboxType::kNetwork:
3677 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523678 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223679 case service_manager::SandboxType::kAudio:
evliu2e5dbee42020-04-09 23:35:293680 case service_manager::SandboxType::kSpeechRecognition:
Will Harrise705a642020-02-26 20:57:053681 case service_manager::SandboxType::kProxyResolver:
Cliff Smolinsky0aa7ca72020-03-09 21:32:463682 case service_manager::SandboxType::kPdfConversion:
Alex Gough63617352020-03-20 02:34:593683 case service_manager::SandboxType::kSharingService:
Sharon Yangefd8e882020-04-28 20:56:433684 case service_manager::SandboxType::kVideoCapture:
Alex Gough9ab468a6c32019-12-10 19:10:223685 // Should never reach here.
3686 CHECK(0);
wfh182da09c2015-06-24 19:23:033687 return base::string16();
wfh182da09c2015-06-24 19:23:033688 }
wfh182da09c2015-06-24 19:23:033689}
3690
Will Harris956e0ca2019-08-23 20:47:393691bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3692 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503693// Does not work under component build because all the component DLLs would need
3694// to be manually added and maintained. Does not work under ASAN build because
3695// ASAN has not yet fully initialized its instrumentation by the time the CIG
3696// intercepts run.
3697#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393698 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3699 return true;
Will Harrisc196ed942019-08-03 03:45:303700 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3701 return true;
3702
3703 // Only enable signing mitigation if launching from chrome.exe.
3704 base::FilePath exe_path;
3705 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3706 return true;
3707 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3708 return true;
3709
3710 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3711 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093712 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303713 if (result != sandbox::SBOX_ALL_OK)
3714 return false;
3715
Nico Weberc36b0152020-04-18 03:12:463716 // Allow loading Chrome's DLLs.
3717 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303718 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3719 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3720 GetModulePath(dll).value().c_str());
3721 if (result != sandbox::SBOX_ALL_OK)
3722 return false;
3723 }
Will Harris1b9b4152019-08-21 22:33:503724#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303725
3726 return true;
[email protected]34f48682013-03-20 00:30:183727}
Will Harris956e0ca2019-08-23 20:47:393728
3729bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3730 PrefService* local_state = g_browser_process->local_state();
3731 if (local_state &&
3732 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3733 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3734 return false;
3735 return true;
3736}
3737
wfhc91e9672016-01-27 00:14:203738#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013739
Armando Miraglia3a7be232019-11-08 00:33:323740#if defined(OS_WIN) || defined(OS_MACOSX) || \
3741 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3742bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3743 const base::Value* audio_sandbox_enabled_policy_value =
3744 policies.GetValue(policy::key::kAudioSandboxEnabled);
3745 if (audio_sandbox_enabled_policy_value) {
3746 bool force_enable_audio_sandbox;
3747 audio_sandbox_enabled_policy_value->GetAsBoolean(
3748 &force_enable_audio_sandbox);
3749 return force_enable_audio_sandbox;
3750 }
3751
3752 return base::FeatureList::IsEnabled(
3753 service_manager::features::kAudioServiceSandbox);
3754}
3755#endif
3756
Ken Rockotfa5d57112019-05-29 20:57:143757void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123758#if defined(OS_WIN) || defined(OS_MACOSX) || \
3759 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053760 if (startup_data_) {
3761 auto* chrome_feature_list_creator =
3762 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183763 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123764 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053765 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183766 ->GetPolicyService()
3767 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123768 std::string()));
3769
Armando Miraglia3a7be232019-11-08 00:33:323770 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
John Abd-El-Malek27b3ebd22019-02-12 18:59:183771 }
3772#endif
xhwang5e630462015-10-30 03:18:483773}
3774
Ken Rockot8f39a272018-12-21 23:38:353775base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173776ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583777 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583778 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583779 return base::nullopt;
benc70c0e32016-09-22 03:50:373780}
3781
peterbbcccc12015-02-11 22:23:333782void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373783 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333784 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293785 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083786 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373787
3788 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083789
zpengdb4a58e2017-01-10 17:40:323790#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223791 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293792 std::move(callback));
jam1c5a91492016-02-24 20:47:533793#else
cm.sanchi2522bc92017-12-04 08:04:133794 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3795 params.url, params.transition);
3796 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083797
3798 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293799 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333800#endif
mlamourieb40d552015-02-05 00:57:083801}
3802
zhaobinf3704f82017-01-12 07:19:363803content::ControllerPresentationServiceDelegate*
3804ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3805 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463806 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093807 return media_router::PresentationServiceDelegateImpl::
3808 GetOrCreateForWebContents(web_contents);
3809 }
haibinlu9e605a92015-06-06 03:45:093810 return nullptr;
3811}
3812
zhaobinf3704f82017-01-12 07:19:363813content::ReceiverPresentationServiceDelegate*
3814ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3815 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363816 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3817 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3818 // created for offscreen presentations. The WebContents must belong to
3819 // an incognito profile.
3820 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3821 FromWebContents(web_contents)) {
3822 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3823 return impl;
3824 }
3825 }
zhaobinf3704f82017-01-12 07:19:363826 return nullptr;
3827}
3828
horo48d4d3e2015-02-27 03:04:003829void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3830 const GURL& url) {
mathp46284f32015-03-11 13:06:413831 if (url.is_valid()) {
3832 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3833 metric, url);
3834 }
horo48d4d3e2015-02-27 03:04:003835}
3836
Matt Falkenhagen8479b202017-07-14 04:35:313837std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3838 // Don't change these returned strings. They are written (in hashed form) into
3839 // UMA logs. If you add more strings, you must update histograms.xml and get
3840 // histograms review. Only Google domains should be here for privacy purposes.
3841 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3842 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193843 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313844 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193845 if (url.host() == "docs.google.com")
3846 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313847 return std::string();
3848}
3849
avid6d88b912017-01-13 00:16:003850std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473851ChromeContentBrowserClient::CreateThrottlesForNavigation(
3852 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003853 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273854
bmcquadeb4556552017-03-24 22:24:373855 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3856 // that may delay or cancel navigations, so only NavigationThrottles that
3857 // don't delay or cancel navigations (e.g. throttles that are only observing
3858 // callbacks without affecting navigation behavior) should be added before
3859 // MetricsNavigationThrottle.
3860 if (handle->IsInMainFrame()) {
3861 throttles.push_back(
3862 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3863 }
3864
brettw4b461082016-11-19 18:55:163865#if BUILDFLAG(ENABLE_PLUGINS)
Chris Hamiltonab4722122020-05-13 18:01:283866 MaybeAddThrottle(FlashDownloadInterception::MaybeCreateThrottleFor(handle),
3867 &throttles);
trizzofo8ddaeb72016-09-01 23:18:273868#endif
3869
yilkal240b4f22019-11-27 19:09:063870#if defined(OS_CHROMEOS)
3871 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283872 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle),
3873 &throttles);
yilkal240b4f22019-11-27 19:09:063874#endif // defined(OS_CHROMEOS)
3875
mmenkedb2637ff2017-03-30 23:59:423876#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213877 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283878 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle),
3879 &throttles);
mmenkedb2637ff2017-03-30 23:59:423880#endif
3881
clamy40c9e142015-09-29 11:18:473882#if defined(OS_ANDROID)
3883 // TODO(davidben): This is insufficient to integrate with prerender properly.
3884 // https://crbug.com/370595
3885 prerender::PrerenderContents* prerender_contents =
3886 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3887 if (!prerender_contents && handle->IsInMainFrame()) {
3888 throttles.push_back(
3889 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303890 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473891 }
Min Qin0ab0e162017-11-14 21:57:193892 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043893
3894#if BUILDFLAG(DFMIFY_DEV_UI)
3895 // If the DevUI DFM is already installed, then this is a no-op, except for the
3896 // side effect of ensuring that the DevUI DFM is loaded.
Chris Hamiltonab4722122020-05-13 18:01:283897 MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle),
3898 &throttles);
Samuel Huang3a1ce1c32019-10-16 17:34:043899#endif // BUILDFLAG(DFMIFY_DEV_UI)
3900
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573901#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473902 if (handle->IsInMainFrame()) {
3903 // Redirect some navigations to apps that have registered matching URL
3904 // handlers ('url_handlers' in the manifest).
Chris Hamiltonab4722122020-05-13 18:01:283905 MaybeAddThrottle(
3906 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle),
3907 &throttles);
clamy40c9e142015-09-29 11:18:473908 }
3909#endif
clamy49678312015-10-22 21:59:003910
3911#if defined(OS_CHROMEOS)
3912 // Check if we need to add merge session throttle. This throttle will postpone
3913 // loading of main frames.
3914 if (handle->IsInMainFrame()) {
3915 // Add interstitial page while merge session process (cookie reconstruction
3916 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3917 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023918 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3919 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003920 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3921 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3922 }
Maggie Caia2f03f52019-04-02 02:13:283923 }
3924#endif
djacobo21e56e02016-07-02 01:14:313925
Maggie Caia2f03f52019-04-02 02:13:283926#if !defined(OS_ANDROID)
Maggie Caic08b7d42020-05-05 03:51:103927 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283928#if defined(OS_CHROMEOS)
Maggie Caic08b7d42020-05-05 03:51:103929 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3930 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3931 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253932#elif defined(OS_MACOSX)
Maggie Caic08b7d42020-05-05 03:51:103933 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283934#else
Maggie Caic08b7d42020-05-05 03:51:103935 apps::AppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283936#endif
Maggie Caic08b7d42020-05-05 03:51:103937 if (url_to_apps_throttle)
3938 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003939#endif
3940
brettw00899e62016-11-12 02:10:173941#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003942 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093943 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513944
Chris Hamiltonab4722122020-05-13 18:01:283945 MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get()
3946 ->GetUserScriptListener()
3947 ->CreateNavigationThrottle(handle),
3948 &throttles);
naskob9164c42016-06-07 01:21:353949#endif
3950
bauerb8f9c37742017-03-30 15:04:123951#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213952 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283953 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle),
3954 &throttles);
bauerb8f9c37742017-03-30 15:04:123955#endif
3956
csharrisone985ebc2017-04-04 17:05:033957 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103958 if (auto* subresource_filter_client =
3959 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3960 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3961 &throttles);
csharrisone985ebc2017-04-04 17:05:033962 }
3963
zhenw6edd49c2017-07-12 05:49:453964#if !defined(OS_ANDROID)
3965 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3966 // enabled on non-Android platforms.
Chris Hamiltonab4722122020-05-13 18:01:283967 MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle::
3968 MaybeCreateThrottleFor(handle),
3969 &throttles);
zhenw6edd49c2017-07-12 05:49:453970#endif
3971
Nico Weberbc5b06f2019-07-26 14:00:133972#if BUILDFLAG(FULL_SAFE_BROWSING)
Chris Hamiltonab4722122020-05-13 18:01:283973 MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle),
3974 &throttles);
Jialiu Linbdbb81d2017-10-11 21:29:093975#endif
3976
Lukasz Anforowicz7724d092019-10-03 23:50:213977 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:283978 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle),
3979 &throttles);
Joe DeBlasio6e8409a2019-02-20 23:08:273980
Chris Hamiltonab4722122020-05-13 18:01:283981 MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle),
3982 &throttles);
Amber Won6b5edc752017-08-17 19:23:543983
Chris Hamiltonab4722122020-05-13 18:01:283984 MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles);
Charles Harrison6dd11d282017-10-03 06:14:513985
Jeremy Romanec48d7a2018-03-01 17:35:093986 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533987 handle, handle->GetWebContents()->GetBrowserContext()));
3988
Colin Blundelleaa7377bf2020-01-22 08:49:103989 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
3990 // the relevant extension API whenever an SSL interstitial is shown.
3991 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
3992 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:283993 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3994 handle,
3995 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:383996 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123997
Emily Starkd6896cd32019-08-21 04:55:543998 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3999
Lukasz Anforowicz7724d092019-10-03 23:50:214000 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284001 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle),
4002 &throttles);
Christopher Thompson4137cec2017-12-19 05:34:234003
Dmitry Gozman57b92ce2017-12-28 22:24:544004#if !defined(OS_ANDROID)
Chris Hamiltonab4722122020-05-13 18:01:284005 MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle),
4006 &throttles);
4007
4008 MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle),
4009 &throttles);
Conley Owensaafcf122018-02-26 18:53:514010
Lukasz Anforowicz7724d092019-10-03 23:50:214011 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284012 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle),
4013 &throttles);
Dmitry Gozman57b92ce2017-12-28 22:24:544014#endif
4015
Carlos IL800e3502020-04-30 16:35:594016 throttles.push_back(
4017 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle));
Robert Ogdenafd250b2018-07-25 22:21:034018
Mustafa Emre Acer97be4752020-05-13 01:24:434019 if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) {
4020 throttles.push_back(
4021 std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>(
4022 handle));
4023 }
4024
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334025#if defined(OS_WIN) || defined(OS_MACOSX) || \
4026 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Chris Hamiltonab4722122020-05-13 18:01:284027 MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle::
4028 MaybeCreateThrottleFor(handle),
4029 &throttles);
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134030#endif
4031
Anatoliy Potapchuk762c40d2020-05-11 15:10:374032#if defined(OS_CHROMEOS)
4033 MaybeAddThrottle(
Chris Hamiltonab4722122020-05-13 18:01:284034 chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle),
4035 &throttles);
Anatoliy Potapchuk762c40d2020-05-11 15:10:374036#endif
4037
Chris Hamiltonab4722122020-05-13 18:01:284038 auto* performance_manager_registry =
4039 performance_manager::PerformanceManagerRegistry::GetInstance();
4040 if (performance_manager_registry) {
4041 MaybeAddThrottles(
4042 performance_manager_registry->CreateThrottlesForNavigation(handle),
4043 &throttles);
4044 }
4045
dchenge73d8520c2015-12-27 01:19:094046 return throttles;
clamy40c9e142015-09-29 11:18:474047}
4048
clamy1e5574e2016-09-29 16:48:444049std::unique_ptr<content::NavigationUIData>
4050ChromeContentBrowserClient::GetNavigationUIData(
4051 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094052 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444053}
4054
Xiaohan Wanga4e41842018-06-26 18:45:104055void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4056 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104057 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124058 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104059#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264060 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104061 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334062 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104063 }
4064#endif
4065}
4066
[email protected]487974a2014-06-13 16:49:014067content::DevToolsManagerDelegate*
4068ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354069#if defined(OS_ANDROID)
4070 return new DevToolsManagerDelegateAndroid();
4071#else
[email protected]487974a2014-06-13 16:49:014072 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354073#endif
[email protected]487974a2014-06-13 16:49:014074}
4075
Rayan Kanso411e84e2019-02-13 15:27:404076void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4077 content::BrowserContext* browser_context,
4078 int service,
4079 base::Time expiration_time) {
4080 Profile* profile = Profile::FromBrowserContext(browser_context);
4081 DCHECK(profile);
4082
4083 auto* pref_service = profile->GetPrefs();
4084 DCHECK(pref_service);
4085
4086 DictionaryPrefUpdate pref_update(
4087 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4088 base::DictionaryValue* exp_dict = pref_update.Get();
4089
4090 // Convert |expiration_time| to minutes since that is the most granular
4091 // option that returns an int. base::Value does not accept int64.
4092 int expiration_time_minutes =
4093 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4094 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4095}
4096
4097base::flat_map<int, base::Time>
4098ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4099 content::BrowserContext* browser_context) {
4100 Profile* profile = Profile::FromBrowserContext(browser_context);
4101 DCHECK(profile);
4102
4103 auto* pref_service = profile->GetPrefs();
4104 DCHECK(pref_service);
4105
4106 auto* expiration_dict = pref_service->GetDictionary(
4107 prefs::kDevToolsBackgroundServicesExpirationDict);
4108 DCHECK(expiration_dict);
4109
4110 base::flat_map<int, base::Time> expiration_times;
4111 for (const auto& it : *expiration_dict) {
4112 // key.
4113 int service = 0;
4114 bool did_convert = base::StringToInt(it.first, &service);
4115 DCHECK(did_convert);
4116
4117 // value.
4118 DCHECK(it.second->is_int());
4119 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4120 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4121
4122 expiration_times[service] = expiration_time;
4123 }
4124
4125 return expiration_times;
4126}
4127
oysteinec563c582015-02-13 19:19:524128content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524129 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524130}
4131
[email protected]a6868c22013-10-09 02:50:294132bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4133 content::BrowserContext* browser_context,
4134 const GURL& url) {
brettw4b461082016-11-19 18:55:164135#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554136 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194137 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294138#else
4139 return false;
4140#endif
4141}
4142
[email protected]aec5ed52014-06-20 07:51:424143bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4144 content::BrowserContext* browser_context,
4145 const GURL& url) {
brettw4b461082016-11-19 18:55:164146#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554147 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194148 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064149#else
4150 return false;
4151#endif
4152}
4153
mlamourif8c23a2002015-01-27 13:10:104154void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014155 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434156 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524157 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104158
4159 WebContents* web_contents =
4160 WebContents::FromRenderFrameHost(render_frame_host);
4161 DCHECK(web_contents);
4162
mlamourif8c23a2002015-01-27 13:10:104163 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374164 prerender::PrerenderManagerFactory::GetForBrowserContext(
4165 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104166 if (prerender_manager &&
4167 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294168 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104169 }
4170}
4171
Robert Sesek466e43e2019-08-19 22:02:024172void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4173 base::FilePath user_data_dir;
4174 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4175 DCHECK(!user_data_dir.empty());
4176 network_contexts_parent_directory_.push_back(user_data_dir);
4177
4178 base::FilePath cache_dir;
4179 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4180 DCHECK(!cache_dir.empty());
4181 // On some platforms, the cache is a child of the user_data_dir so only
4182 // return the one path.
4183 if (!user_data_dir.IsParent(cache_dir))
4184 network_contexts_parent_directory_.push_back(cache_dir);
4185
4186 // If the cache location has been overridden by a switch or preference,
4187 // include that as well.
4188 if (auto* local_state = g_browser_process->local_state()) {
4189 base::FilePath pref_cache_dir =
4190 local_state->GetFilePath(prefs::kDiskCacheDir);
4191 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4192 network_contexts_parent_directory_.push_back(pref_cache_dir);
4193 }
4194}
4195
[email protected]30335fdf02014-02-26 19:51:274196void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174197 base::CommandLine* to_command_line,
4198 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544199 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274200#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544201 const version_info::Channel kMaxDisableEncryptionChannel =
4202 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274203#else
sdefresne6e883e42015-07-30 08:05:544204 const version_info::Channel kMaxDisableEncryptionChannel =
4205 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274206#endif
4207 if (channel <= kMaxDisableEncryptionChannel) {
4208 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444209 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274210 };
Avi Drissmand251e912018-12-26 15:46:374211 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4212 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274213 }
4214}
bashi933629552016-10-13 23:32:404215
miu54dca6c2016-11-17 10:59:384216#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4217void ChromeContentBrowserClient::CreateMediaRemoter(
4218 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504219 mojo::PendingRemote<media::mojom::RemotingSource> source,
4220 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384221 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504222 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384223}
4224#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464225
Michael Giuffrida6802ffe2017-09-29 03:40:254226base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4227 const base::CommandLine& command_line) {
4228 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164229}
4230
John Abd-El-Malek8efa11f2019-01-06 00:51:534231namespace {
4232// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024233class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534234 public:
4235 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174236 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534237 : protocol_handler_registry_(protocol_handler_registry) {}
4238 ~ProtocolHandlerThrottle() override = default;
4239
4240 void WillStartRequest(network::ResourceRequest* request,
4241 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294242 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534243 }
4244
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:584245 void WillRedirectRequest(
4246 net::RedirectInfo* redirect_info,
4247 const network::mojom::URLResponseHead& response_head,
4248 bool* defer,
4249 std::vector<std::string>* to_be_removed_headers,
4250 net::HttpRequestHeaders* modified_headers,
4251 net::HttpRequestHeaders* modified_cors_exempt_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294252 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534253 }
4254
4255 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294256 void TranslateUrl(GURL* url) {
4257 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4258 return;
4259 GURL translated_url = protocol_handler_registry_->Translate(*url);
4260 if (!translated_url.is_empty())
4261 *url = translated_url;
4262 }
4263
Clark DuValla411bda2019-08-02 03:09:174264 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534265};
4266} // namespace
4267
Minggang Wangf6840ecf2019-07-29 05:15:024268std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194269ChromeContentBrowserClient::CreateURLLoaderThrottles(
4270 const network::ResourceRequest& request,
4271 content::BrowserContext* browser_context,
4272 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4273 content::NavigationUIData* navigation_ui_data,
4274 int frame_tree_node_id) {
4275 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4276
Minggang Wangf6840ecf2019-07-29 05:15:024277 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194278
4279 Profile* profile = Profile::FromBrowserContext(browser_context);
4280
4281 ChromeNavigationUIData* chrome_navigation_ui_data =
4282 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4283
Nico Weberbc5b06f2019-07-26 14:00:134284#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564285 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4286 request.url, *profile->GetPrefs());
4287 if (!matches_enterprise_whitelist) {
Xinghui Lue17b19942020-02-24 21:19:584288 // |url_lookup_service| is used when real time url check is enabled.
4289 safe_browsing::RealTimeUrlLookupService* url_lookup_service =
4290 // |safe_browsing_service_| may be unavailable in tests.
4291 safe_browsing_service_ &&
4292 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
Varun Khaneja24cc123f2020-05-14 21:08:484293 profile->GetPrefs(), profile->IsOffTheRecord(),
4294 g_browser_process->variations_service())
Xinghui Lue17b19942020-02-24 21:19:584295 ? safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
4296 profile)
4297 : nullptr;
Xinghui Lu0abc17b2020-02-20 22:50:194298
Clark DuVall5497288d2019-07-17 00:17:564299 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4300 base::BindOnce(
4301 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534302 base::Unretained(this),
Bettinae83f522c72020-03-12 01:52:334303 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs())),
Xinghui Lua142c102020-03-02 20:50:084304 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584305 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564306 }
Nico Weberbc5b06f2019-07-26 14:00:134307#endif
Clark DuVall5497288d2019-07-17 00:17:564308
dalykba7bbfc2019-12-18 19:59:214309#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4310 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014311 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4312 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214313#endif
4314
Clark DuVallfffa41e2019-06-25 20:27:194315 if (chrome_navigation_ui_data &&
4316 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4317 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4318 chrome_navigation_ui_data->prerender_mode(),
4319 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234320 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194321 }
4322
John Abd-El-Malek4f380d92020-02-19 16:43:364323#if defined(OS_ANDROID)
4324 std::string client_data_header;
Brandon Wylie21a88ac92020-05-15 02:49:234325 bool night_mode_enabled = false;
John Abd-El-Malekfb9f5462020-02-20 01:18:374326 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4327 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364328 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4329 if (web_contents) {
4330 auto* client_data_header_observer =
4331 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4332 web_contents);
4333 if (client_data_header_observer)
4334 client_data_header = client_data_header_observer->header();
4335 }
Brandon Wylie21a88ac92020-05-15 02:49:234336
4337 auto* delegate = TabAndroid::FromWebContents(web_contents)
4338 ? static_cast<android::TabWebContentsDelegateAndroid*>(
4339 web_contents->GetDelegate())
4340 : nullptr;
4341 if (delegate) {
4342 night_mode_enabled = delegate->IsNightModeEnabled();
4343 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374344 }
John Abd-El-Malek4f380d92020-02-19 16:43:364345#endif
4346
Clark DuVallfffa41e2019-06-25 20:27:194347 chrome::mojom::DynamicParams dynamic_params = {
4348 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4349 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274350 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4351 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364352#if defined(OS_ANDROID)
Brandon Wylie21a88ac92020-05-15 02:49:234353 client_data_header, night_mode_enabled,
John Abd-El-Malek4f380d92020-02-19 16:43:364354#endif
Alex Clarke3ebd9772020-02-28 10:50:274355 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194356
Clark DuValla411bda2019-08-02 03:09:174357 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4358 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214359
Clark DuVall39c2cfc2019-06-25 21:49:284360#if BUILDFLAG(ENABLE_PLUGINS)
4361 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464362 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284363#endif
4364
Robbie McElrath127ad2b2019-07-22 22:38:114365 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404366 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584367 auto signin_throttle =
4368 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114369 if (signin_throttle)
4370 result.push_back(std::move(signin_throttle));
4371
Clark DuVallfffa41e2019-06-25 20:27:194372 return result;
4373}
4374
Ken Rockot6414c4d92017-11-08 19:58:324375void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464376 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324377 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414378#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464379 content::WebContents* web_contents =
4380 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414381#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324382 factories->emplace(
4383 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574384 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464385 web_contents->GetBrowserContext(),
4386 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414387#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4388#if defined(OS_CHROMEOS)
4389 Profile* profile =
4390 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304391 factories->emplace(content::kExternalFileScheme,
4392 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4393 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414394#endif // defined(OS_CHROMEOS)
4395#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324396}
4397
Ting Shao2dc60582019-07-15 04:43:364398void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344399 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4400 content::BrowserContext* browser_context,
4401 NonNetworkURLLoaderFactoryMap* factories) {
4402#if BUILDFLAG(ENABLE_EXTENSIONS)
4403 DCHECK(browser_context);
4404 DCHECK(factories);
4405 factories->emplace(
4406 extensions::kExtensionScheme,
4407 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4408 browser_context));
4409#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4410}
4411
4412void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364413 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4414 content::BrowserContext* browser_context,
4415 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114416#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364417 DCHECK(browser_context);
4418 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364419 factories->emplace(
4420 extensions::kExtensionScheme,
4421 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4422 browser_context));
4423#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364424}
4425
Jay Civelli2578ebe2018-06-05 18:44:314426namespace {
4427
4428// The FileURLLoaderFactory provided to the extension background pages.
4429// Checks with the ChildProcessSecurityPolicy to validate the file access.
4430class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4431 public:
4432 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4433
4434 private:
4435 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274436 void CreateLoaderAndStart(
4437 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4438 int32_t routing_id,
4439 int32_t request_id,
4440 uint32_t options,
4441 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304442 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274443 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4444 override {
Jay Civelli2578ebe2018-06-05 18:44:314445 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4446 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304447 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4448 ->OnComplete(
4449 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314450 return;
4451 }
Yutaka Hiranodf83dca42020-01-07 06:24:554452 content::CreateFileURLLoaderBypassingSecurityChecks(
4453 request, std::move(loader), std::move(client),
4454 /*observer=*/nullptr,
4455 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314456 }
4457
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524458 void Clone(
4459 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4460 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314461 }
4462
4463 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524464 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314465 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4466};
4467
Aya ElAttareb5fee12020-05-05 08:56:054468#if defined(OS_CHROMEOS)
4469bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) {
4470 PrefService* const local_state = g_browser_process->local_state();
4471 if (!local_state) // Sometimes it's not available in tests.
4472 return false;
4473
4474 const base::ListValue* disabled_system_features_pref =
4475 local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList);
4476 if (!disabled_system_features_pref)
4477 return false;
4478
4479 const auto disabled_system_features =
4480 disabled_system_features_pref->GetList();
4481 return base::Contains(disabled_system_features, base::Value(system_feature));
4482}
4483
4484bool IsSystemFeatureURLDisabled(const GURL& url) {
4485 if (!url.SchemeIs(content::kChromeUIScheme))
4486 return false;
4487
4488 // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app
4489 // installation complete successfully.
4490 if (url.DomainIs(chrome::kChromeUIOSSettingsHost) &&
4491 url.path() != "/pwa.html" &&
4492 IsSystemFeatureDisabled(policy::SystemFeature::OS_SETTINGS)) {
4493 return true;
4494 }
4495
4496 if (url.DomainIs(chrome::kChromeUISettingsHost) &&
4497 IsSystemFeatureDisabled(policy::SystemFeature::BROWSER_SETTINGS)) {
4498 return true;
4499 }
4500
4501 return false;
4502}
4503#endif
Jay Civelli2578ebe2018-06-05 18:44:314504} // namespace
4505
Ken Rockot6414c4d92017-11-08 19:58:324506void ChromeContentBrowserClient::
4507 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464508 int render_process_id,
4509 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324510 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414511#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4512 content::RenderFrameHost* frame_host =
4513 RenderFrameHost::FromID(render_process_id, render_frame_id);
4514 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4515#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4516
4517#if defined(OS_CHROMEOS)
4518 if (web_contents) {
4519 Profile* profile =
4520 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304521 factories->emplace(content::kExternalFileScheme,
4522 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4523 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414524 }
4525#endif // defined(OS_CHROMEOS)
4526
Ken Rockot6414c4d92017-11-08 19:58:324527#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464528 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4529 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324530 if (factory)
4531 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234532
4533 // This logic should match
4534 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314535 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234536 return;
Jay Civellic9bbf72d2018-03-24 01:58:314537
4538 Profile* profile =
4539 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4540 InstantService* instant_service =
4541 InstantServiceFactory::GetForProfile(profile);
4542 // The test below matches what's done by ShouldServiceRequestIOThread in
4543 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464544 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314545 factories->emplace(
4546 chrome::kChromeSearchScheme,
4547 content::CreateWebUIURLLoader(
4548 frame_host, chrome::kChromeSearchScheme,
4549 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234550 }
Jay Civellic9bbf72d2018-03-24 01:58:314551
Chris Mumfordbae8a742018-03-01 23:02:234552 extensions::ChromeExtensionWebContentsObserver* web_observer =
4553 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4554 web_contents);
4555
Karan Bhatia91928572018-03-06 01:18:074556 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4557 // to the |web_contents|.
4558 if (!web_observer)
4559 return;
4560
Chris Mumfordbae8a742018-03-01 23:02:234561 const Extension* extension =
4562 web_observer->GetExtensionFromFrame(frame_host, false);
4563 if (!extension)
4564 return;
4565
Sam McNally7414eeb72018-09-03 04:05:304566 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234567 // Support for chrome:// scheme if appropriate.
4568 if ((extension->is_extension() || extension->is_platform_app()) &&
4569 Manifest::IsComponentLocation(extension->location())) {
4570 // Components of chrome that are implemented as extensions or platform apps
4571 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304572 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4573 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4574 }
4575 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4576 (extension->is_platform_app() &&
4577 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234578 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024579 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4580 // URLs. Hosted apps are not allowed because they are served via web servers
4581 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304582 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4583 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024584 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304585 }
4586 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234587 factories->emplace(
4588 content::kChromeUIScheme,
4589 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4590 std::move(allowed_webui_hosts)));
4591 }
Jay Civelli2578ebe2018-06-05 18:44:314592
4593 // Extension with a background page get file access that gets approval from
4594 // ChildProcessSecurityPolicy.
4595 extensions::ExtensionHost* host =
4596 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4597 ->GetBackgroundHostForExtension(extension->id());
4598 if (host) {
4599 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4600 render_process_id));
4601 }
Chris Mumfordbae8a742018-03-01 23:02:234602#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324603}
4604
Ken Rockota0dfaca12018-02-15 07:26:254605bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214606 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254607 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384608 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444609 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264610 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004611 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424612 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184613 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4614 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334615 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084616 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334617 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014618 bool use_proxy = false;
4619
Ken Rockota0dfaca12018-02-15 07:26:254620#if BUILDFLAG(ENABLE_EXTENSIONS)
4621 auto* web_request_api =
4622 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214623 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254624
4625 // NOTE: Some unit test environments do not initialize
4626 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014627 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124628 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384629 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004630 browser_context, frame, render_process_id, type,
4631 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124632 if (bypass_redirect_checks)
4633 *bypass_redirect_checks = use_proxy_for_web_request;
4634 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014635 }
Ken Rockota0dfaca12018-02-15 07:26:254636#endif
Reilly Grant24bf8332018-08-27 21:55:014637
Reilly Grantcc22e602018-09-07 15:25:204638 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444639 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4640 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014641
dalyk0018c16f2020-01-08 20:20:084642#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4643 if (disable_secure_dns) {
4644 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4645 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014646 web_contents &&
4647 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4648 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084649 ->is_captive_portal_window();
4650 }
4651#endif
4652
Reilly Grant24bf8332018-08-27 21:55:014653 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254654}
4655
Jian Lide7b43792018-06-01 23:22:134656std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4657ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4658 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144659 int frame_tree_node_id,
4660 const scoped_refptr<network::SharedURLLoaderFactory>&
4661 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134662 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4663 interceptors;
4664#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234665 interceptors.push_back(
4666 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4667 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134668#endif
Ryan Sturmaf523742019-01-16 00:15:454669
Robert Ogden6946ad42020-01-13 18:01:304670 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4671 interceptors.push_back(
4672 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4673 frame_tree_node_id));
4674 }
4675
Jian Lide7b43792018-06-01 23:22:134676 return interceptors;
4677}
4678
Yutaka Hirano8e0b4d432019-07-04 07:12:384679bool ChromeContentBrowserClient::WillInterceptWebSocket(
4680 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334681#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384682 if (!frame) {
4683 return false;
4684 }
4685 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334686 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4687 frame->GetProcess()->GetBrowserContext());
4688
4689 // NOTE: Some unit test environments do not initialize
4690 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4691 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384692 return false;
Yutaka Hirano36c94952018-05-30 21:33:334693
Yutaka Hirano8e0b4d432019-07-04 07:12:384694 return web_request_api->MayHaveProxies();
4695#else
4696 return false;
4697#endif
4698}
4699
4700void ChromeContentBrowserClient::CreateWebSocket(
4701 content::RenderFrameHost* frame,
4702 WebSocketFactory factory,
4703 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394704 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384705 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404706 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4707 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384708#if BUILDFLAG(ENABLE_EXTENSIONS)
4709 if (!frame) {
4710 return;
4711 }
4712 auto* web_request_api =
4713 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4714 frame->GetProcess()->GetBrowserContext());
4715
4716 DCHECK(web_request_api);
4717 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394718 site_for_cookies.RepresentativeUrl(),
4719 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334720#endif
4721}
4722
Maks Orlovich710d5e32019-07-09 20:16:454723bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464724 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454725 content::BrowserContext* browser_context,
4726 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394727 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404728 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454729 bool is_service_worker,
4730 int process_id,
4731 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034732 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454733 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4734#if BUILDFLAG(ENABLE_EXTENSIONS)
4735 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464736 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454737 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404738 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4739 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454740 return true;
4741 }
4742#endif
4743 return false;
4744}
4745
Matt Menkeae4fdb12018-06-02 06:32:544746void ChromeContentBrowserClient::OnNetworkServiceCreated(
4747 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534748 PrefService* local_state;
4749 if (g_browser_process) {
4750 DCHECK(g_browser_process->local_state());
4751 local_state = g_browser_process->local_state();
4752 } else {
Xi Han85079c22019-04-18 21:43:054753 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4754 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534755 }
4756
4757 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4758 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4759
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494760 // Create SystemNetworkContextManager if it has not been created yet. We need
4761 // to set up global NetworkService state before anything else uses it and this
4762 // is the first opportunity to initialize SystemNetworkContextManager with the
4763 // NetworkService.
4764 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534765 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074766
Min Qin8caab1d2018-10-03 17:28:134767 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544768 network_service);
4769}
4770
Matthew Denton8888ae52020-05-14 08:20:024771void ChromeContentBrowserClient::ConfigureNetworkContextParams(
Ken Rockota0dfaca12018-02-15 07:26:254772 content::BrowserContext* context,
4773 bool in_memory,
Matthew Denton8888ae52020-05-14 08:20:024774 const base::FilePath& relative_partition_path,
4775 network::mojom::NetworkContextParams* network_context_params,
4776 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504777 Profile* profile = Profile::FromBrowserContext(context);
Matthew Denton8888ae52020-05-14 08:20:024778 profile->ConfigureNetworkContextParams(in_memory, relative_partition_path,
4779 network_context_params,
4780 cert_verifier_creation_params);
Ken Rockota0dfaca12018-02-15 07:26:254781}
4782
Robert Sesek34f68f312019-01-14 20:25:114783std::vector<base::FilePath>
4784ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024785 DCHECK(!network_contexts_parent_directory_.empty());
4786 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114787}
4788
Min Qin75ed6df2017-12-01 20:39:154789bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134790 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154791#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4792 // It is OK to load the saved offline copy, in MHTML format.
4793 ChromeNavigationUIData* chrome_navigation_ui_data =
4794 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4795 if (!chrome_navigation_ui_data)
4796 return false;
4797 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4798 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4799 return offline_page_data && offline_page_data->is_offline_page();
4800#else
4801 return false;
4802#endif
4803}
4804
Min Qin30a78a12017-12-06 01:29:134805bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4806 const GURL& url,
4807 const std::string& mime_type) {
4808#if BUILDFLAG(ENABLE_EXTENSIONS)
4809 // Special-case user scripts to get downloaded instead of viewed.
4810 return extensions::UserScript::IsURLUserScript(url, mime_type);
4811#else
4812 return false;
4813#endif
4814}
4815
Donna Wu838ac362018-08-10 10:36:334816void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344817 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044818 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant27b2a3c2020-04-28 23:52:464819 if (!base::FeatureList::IsEnabled(features::kWebUsb))
Reilly Grantc31b8192017-12-15 19:54:344820 return;
4821
[email protected]95ebe7c2020-04-08 19:12:454822 CHECK(render_frame_host);
4823 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4824 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344825}
4826
Ovidio Henriquez3d729f62020-02-07 00:43:294827content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4828 if (!bluetooth_delegate_)
4829 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4830 return bluetooth_delegate_.get();
4831}
4832
Reilly Grant0d282322019-01-29 02:42:584833#if !defined(OS_ANDROID)
4834content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4835 if (!serial_delegate_)
4836 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4837 return serial_delegate_.get();
4838}
Matt Reynolds93616f9b2019-06-07 01:28:524839
4840content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4841 if (!hid_delegate_)
4842 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4843 return hid_delegate_.get();
4844}
Reilly Grant0d282322019-01-29 02:42:584845
Balazs Engedya7ff70982018-06-04 18:14:474846std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4847ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334848 content::RenderFrameHost* render_frame_host) {
4849 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4850 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474851}
Nina Satragno8c832df2019-07-29 15:59:394852#endif
Balazs Engedya7ff70982018-06-04 18:14:474853
Jun Cai9409ded2018-01-30 00:19:464854std::unique_ptr<net::ClientCertStore>
4855ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104856 content::BrowserContext* browser_context) {
4857 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464858 ->CreateClientCertStore();
4859}
4860
David Benjamineced01fc2019-02-27 18:29:024861std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394862ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584863 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024864 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034865 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244866 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394867 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034868 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394869 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564870 LoginAuthRequiredCallback auth_required_callback) {
Emily Stark63c884f2020-05-12 03:55:284871 // For subresources, create a LoginHandler directly, which may show a login
4872 // prompt to the user. Main frame resources go through LoginTabHelper, which
4873 // manages a more complicated flow to avoid confusion about which website is
4874 // showing the prompt.
4875 if (is_request_for_main_frame) {
4876 LoginTabHelper::CreateForWebContents(web_contents);
4877 return LoginTabHelper::FromWebContents(web_contents)
4878 ->CreateAndStartMainFrameLoginDelegate(
4879 auth_info, web_contents, request_id, url, response_headers,
4880 std::move(auth_required_callback));
4881 }
4882 std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create(
4883 auth_info, web_contents, std::move(auth_required_callback));
4884 login_handler->StartSubresource(request_id, url, response_headers);
4885 return login_handler;
Jun Caibc561f412018-02-28 18:41:394886}
4887
John Abd-El-Maleka67add82018-03-09 18:22:014888bool ChromeContentBrowserClient::HandleExternalProtocol(
4889 const GURL& url,
danakjf4b9e942019-11-29 15:43:044890 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014891 int child_id,
4892 content::NavigationUIData* navigation_data,
4893 bool is_main_frame,
4894 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454895 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454896 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104897 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014898#if BUILDFLAG(ENABLE_EXTENSIONS)
4899 // External protocols are disabled for guests. An exception is made for the
4900 // "mailto" protocol, so that pages that utilize it work properly in a
4901 // WebView.
4902 ChromeNavigationUIData* chrome_data =
4903 static_cast<ChromeNavigationUIData*>(navigation_data);
4904 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4905 (chrome_data &&
4906 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4907 !url.SchemeIs(url::kMailToScheme)) {
4908 return false;
4909 }
4910#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4911
4912#if defined(OS_ANDROID)
4913 // Main frame external protocols are handled by
4914 // InterceptNavigationResourceThrottle.
4915 if (is_main_frame)
4916 return false;
4917#endif // defined(ANDROID)
4918
Emily Stark13b66bdf2019-10-04 17:11:454919 base::PostTask(
4920 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044921 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4922 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014923 return true;
4924}
4925
Jennifer Apacible4f854a82018-04-06 22:22:114926std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284927ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4928 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114929 // Note: content::OverlayWindow::Create() is defined by platform-specific
4930 // implementation in chrome/browser/ui/views. This layering hack, which goes
4931 // through //content and ContentBrowserClient, allows us to work around the
4932 // dependency constraints that disallow directly calling
4933 // chrome/browser/ui/views code either from here or from other code in
4934 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284935 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114936}
4937
Kunihiko Sakamoto19aa7082019-02-25 03:14:434938void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564939 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114940 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564941 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434942 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4943 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564944}
4945
dbeam25472e0c2017-06-23 19:02:314946// Static; handles rewriting Web UI URLs.
4947bool ChromeContentBrowserClient::HandleWebUI(
4948 GURL* url,
4949 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394950 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314951 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394952 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314953 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4954 chrome::kChromeUIHelpHost);
4955 return true; // Return true to update the displayed URL.
4956 }
4957
Hector Carmona566a20b2019-09-13 22:44:424958#if defined(OS_WIN)
4959 // TODO(crbug.com/1003960): Remove when issue is resolved.
4960 if (url->SchemeIs(content::kChromeUIScheme) &&
4961 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4962 url::Replacements<char> replacements;
4963 replacements.SetHost(
4964 chrome::kChromeUIWelcomeHost,
4965 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4966 *url = url->ReplaceComponents(replacements);
4967 return true;
4968 }
4969#endif // defined(OS_WIN)
4970
dbeam25472e0c2017-06-23 19:02:314971 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4972 browser_context, *url)) {
4973 return false;
4974 }
4975
4976#if defined(OS_CHROMEOS)
4977 // Special case : in ChromeOS in Guest mode bookmarks and history are
4978 // disabled for security reasons. New tab page explains the reasons, so
4979 // we redirect user to new tab page.
4980 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4981 if (url->SchemeIs(content::kChromeUIScheme) &&
4982 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4983 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4984 // Rewrite with new tab URL
4985 *url = GURL(chrome::kChromeUINewTabURL);
4986 }
4987 }
Aya ElAttareb5fee12020-05-05 08:56:054988
4989 if (IsSystemFeatureURLDisabled(*url)) {
4990 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, "");
4991 return true;
4992 }
4993
dbeam25472e0c2017-06-23 19:02:314994#endif
4995
4996 return true;
4997}
4998
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064999bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5000 content::BrowserContext* browser_context,
5001 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325002 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065003#if defined(OS_ANDROID)
5004 return false;
5005#else
5006 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5007 ->GetForBrowserContext(browser_context)
5008 ->ShowPaymentHandlerWindow(url, std::move(callback));
5009 return true;
5010#endif
5011}
5012
Dan Beam141c48932019-08-22 02:29:395013// static
dbeam25472e0c2017-06-23 19:02:315014bool ChromeContentBrowserClient::HandleWebUIReverse(
5015 GURL* url,
5016 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425017#if defined(OS_WIN)
5018 // TODO(crbug.com/1003960): Remove when issue is resolved.
5019 // No need to actually reverse-rewrite the URL, but return true to update the
5020 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5021 if (url->SchemeIs(content::kChromeUIScheme) &&
5022 url->host() == chrome::kChromeUIWelcomeHost) {
5023 return true;
5024 }
5025#endif // defined(OS_WIN)
5026
dbeam25472e0c2017-06-23 19:02:315027 // No need to actually reverse-rewrite the URL, but return true to update the
5028 // displayed URL when rewriting chrome://help to chrome://settings/help.
5029 return url->SchemeIs(content::kChromeUIScheme) &&
5030 url->host() == chrome::kChromeUISettingsHost;
5031}
5032
Alison Maher7f366dc62020-03-03 19:46:005033const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:585034 return ui::NativeTheme::GetInstanceForWeb();
5035}
5036
Clark DuVall5497288d2019-07-17 00:17:565037scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505038ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:535039 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:355040 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5041
Matt Menke562675cfe2020-01-07 15:50:535042 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:505043 return nullptr;
5044
Yuzhu Shen44094e22017-07-18 22:52:355045 // |safe_browsing_service_| may be unavailable in tests.
5046 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5047 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435048 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355049 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435050 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355051 }
5052
Clark DuVall5497288d2019-07-17 00:17:565053 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355054}
Daniel Vogelheim6008f572018-09-24 14:35:145055
5056base::Optional<std::string>
5057ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:595058 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185059 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:595060 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5061 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145062}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525063
Takashi Toyoshima5af383aa2019-07-22 15:24:225064bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525065 // We require --user-data-dir flag too so that no dangerous changes are made
5066 // in the user's regular profile.
5067 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5068 switches::kUserDataDir);
5069}
rajendrantfeea8592018-10-19 18:26:065070
5071void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5072 int32_t network_traffic_annotation_id_hash,
5073 int64_t recv_bytes,
5074 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035075 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5076 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5077 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5078 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065079 }
5080}
Ryan Sturmaa05092f2018-10-21 03:56:545081
Ken Rockot4e284d32020-03-06 06:26:495082base::FilePath
5083ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
5084 return g_browser_process->profile_manager()->user_data_dir();
5085}
5086
Ryan Sturmaa05092f2018-10-21 03:56:545087content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5088 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395089 content::NavigationHandle* navigation_handle,
5090 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135091 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5092 initial_state, navigation_handle, current_navigation_url);
5093
5094 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5095}
5096
5097content::PreviewsState
5098ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5099 content::PreviewsState initial_state,
5100 content::NavigationHandle* navigation_handle,
5101 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295103 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215104
Ryan Sturmaa05092f2018-10-21 03:56:545105 // If this is not a main frame, return the initial state. If there are no
5106 // previews in the state, return the state as is.
5107 if (!navigation_handle->IsInMainFrame() ||
5108 navigation_handle->IsSameDocument()) {
5109 return initial_state;
5110 }
5111
Robert Ogdena994eb42019-02-14 19:15:085112 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395113 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085114
Doug Arnettb3b99bc2019-08-09 16:55:565115 // Check if initial state specifies no previews should be considered.
5116 if (initial_state == content::PREVIEWS_OFF)
5117 return initial_state;
5118
Robert Ogdena994eb42019-02-14 19:15:085119 // Do not allow previews on POST navigations since the primary opt-out
5120 // mechanism is to reload the page. Because POST navigations are not
5121 // idempotent, we do not want to show a preview on a POST navigation where
5122 // opting out would cause another navigation, i.e.: a reload.
5123 if (navigation_handle->IsPost())
5124 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395125
5126 content::WebContents* web_contents = navigation_handle->GetWebContents();
5127 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5128
Ryan Sturmda2a0e02018-10-25 01:52:215129 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545130
5131 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5132 Profile::FromBrowserContext(browser_context));
5133 auto* data_reduction_proxy_settings =
5134 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5135 browser_context);
5136 // If the profile does not support previews or Data Saver, do not turn on
5137 // Previews.
5138 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355139 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545140 return content::PREVIEWS_OFF;
5141 }
5142
5143 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215144 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545145 // If this tab does not have a PreviewsUITabHelper, no preview should be
5146 // served.
5147 if (!ui_tab_helper)
5148 return content::PREVIEWS_OFF;
5149
5150 DCHECK(!browser_context->IsOffTheRecord());
5151
5152 // Other previews objects should all exist and be initialized if we have made
5153 // it past earlier checks.
5154 previews::PreviewsDeciderImpl* previews_decider_impl =
5155 previews_service->previews_ui_service()->previews_decider_impl();
5156 DCHECK(previews_decider_impl);
5157
Ryan Sturm647d1d92018-11-07 15:41:395158 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545159 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5160
Ryan Sturm647d1d92018-11-07 15:41:395161 previews::PreviewsUserData* previews_data =
5162 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5163
5164 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315165 // previews) and cannot re-evaluate PreviewsState once previews triggering
5166 // logic has already been run, so they should not change. Assume that
Robert Ogden54892d02020-04-28 22:36:375167 // previews triggering logic has run when PreviewsUserData already exists.
Seanac57e9b92019-04-29 19:19:315168 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395169 if (previews_data) {
Robert Ogden54892d02020-04-28 22:36:375170 previews_triggering_logic_already_ran = true;
Ryan Sturm647d1d92018-11-07 15:41:395171 } else {
5172 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5173 navigation_handle, previews_decider_impl->GeneratePageId());
5174 }
5175
5176 DCHECK(previews_data);
5177
Robert Ogden01770b362019-05-22 17:36:435178 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5179 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435180 return content::ALL_SUPPORTED_PREVIEWS;
5181 }
5182
Ryan Sturmaa05092f2018-10-21 03:56:545183 bool is_reload =
5184 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5185
Ryan Sturm647d1d92018-11-07 15:41:395186 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515187 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395188
5189 // For now, treat server previews types as a single decision, and do not
5190 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5191 // header, nor does the plumbing exist to modify the PreviewsState within the
5192 // URLLoader.
Seanac57e9b92019-04-29 19:19:315193 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395194 // Copy the server state that was used before the redirect for the initial
5195 // URL.
Robert Ogden869986f2019-06-20 19:12:055196 previews_state |=
5197 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395198 } else {
Doug Arnetta3dc71582018-11-08 00:25:105199 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215200 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305201 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395202 previews_state |= server_previews_enabled_state;
5203 }
Ryan Sturmaa05092f2018-10-21 03:56:545204 }
5205
Sophie Changa71fa5d2019-11-19 23:53:515206 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545207 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315208 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355209 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5210 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545211
5212 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395213 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545214 return content::PREVIEWS_OFF;
5215 }
5216
5217 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395218 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545219 return content::PREVIEWS_NO_TRANSFORM;
5220 }
5221
5222 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395223 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5224 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545225 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395226 }
5227
5228 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5229 if (delegate) {
5230 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5231 }
Ryan Sturmaa05092f2018-10-21 03:56:545232
5233 // If the allowed previews are limited by the embedder, ensure previews honors
5234 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395235 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5236 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545237 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5238 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5239 previews_state = content::PREVIEWS_OFF;
5240 }
Ryan Sturm647d1d92018-11-07 15:41:395241 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545242 return previews_state;
5243}
5244
5245// static
5246content::PreviewsState
5247ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5248 const GURL& url,
5249 data_reduction_proxy::DataReductionProxyData* drp_data,
5250 previews::PreviewsUserData* previews_user_data,
5251 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055252 content::PreviewsState initial_state,
5253 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545254 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5255 if (!previews::HasEnabledPreviews(initial_state))
5256 return content::PREVIEWS_OFF;
5257
5258 // Check if the server sent a preview directive.
5259 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555260 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545261
Ryan Sturmaa05092f2018-10-21 03:56:545262 // Check the various other client previews types.
5263 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055264 previews_user_data, url, previews_state, previews_decider,
5265 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545266}
5267
5268content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5269 content::PreviewsState initial_state,
5270 content::NavigationHandle* navigation_handle,
5271 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135272 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5273 initial_state, navigation_handle, response_headers);
5274
5275 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5276}
5277
5278content::PreviewsState
5279ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5280 content::PreviewsState initial_state,
5281 content::NavigationHandle* navigation_handle,
5282 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545283 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5284 // Only support HTTP and HTTPS.
5285 if (navigation_handle->IsErrorPage() ||
5286 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5287 return content::PREVIEWS_OFF;
5288 }
5289
5290 // If this is not a main frame, return the initial state. If there are no
5291 // previews in the state, return the state as is.
5292 if (!previews::HasEnabledPreviews(initial_state) ||
5293 !navigation_handle->IsInMainFrame() ||
5294 navigation_handle->IsSameDocument()) {
5295 return initial_state;
5296 }
5297
5298 // WebContents that don't have a PreviewsUITabHelper are not supported.
5299 PreviewsUITabHelper* ui_tab_helper =
5300 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5301 if (!ui_tab_helper)
5302 return content::PREVIEWS_OFF;
5303
5304 // If we did not previously create a PreviewsUserData, do not go any further.
5305 previews::PreviewsUserData* previews_user_data =
5306 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5307 if (!previews_user_data)
5308 return content::PREVIEWS_OFF;
5309
5310 PreviewsService* previews_service =
5311 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5312 navigation_handle->GetWebContents()->GetBrowserContext()));
5313
5314 if (!previews_service || !previews_service->previews_ui_service())
5315 return content::PREVIEWS_OFF;
5316
5317// Check if offline previews are being used and set it in the user data.
5318#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5319 offline_pages::OfflinePageTabHelper* tab_helper =
5320 offline_pages::OfflinePageTabHelper::FromWebContents(
5321 navigation_handle->GetWebContents());
5322
Ryan Sturmfc7d92f2019-02-12 02:24:235323 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5324 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5325
5326 // If this is an offline page, but not a preview, then we should not attempt
5327 // any previews or surface the previews UI.
5328 if (is_offline_page && !is_offline_preview)
5329 return content::PREVIEWS_OFF;
5330
5331 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545332#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5333
5334 // Annotate request if no-transform directive found in response headers.
5335 if (response_headers &&
5336 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265337 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545338 }
5339
5340 previews::PreviewsDeciderImpl* previews_decider_impl =
5341 previews_service->previews_ui_service()->previews_decider_impl();
5342 DCHECK(previews_decider_impl);
5343
Clark DuVall9c5a72cc2018-10-25 01:29:215344 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5345 auto* settings =
5346 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5347 navigation_handle->GetWebContents()->GetBrowserContext());
5348 if (settings) {
5349 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5350 // does not yet have all the response information.
5351 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5352 response_headers);
5353 }
Ryan Sturmaa05092f2018-10-21 03:56:545354
5355 // Determine effective PreviewsState for this committed main frame response.
5356 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215357 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055358 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545359
5360 // Double check that we never serve a preview when we have a
5361 // cache-control:no-transform directive.
5362 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5363 !previews::HasEnabledPreviews(committed_state));
5364
Robert Ogdended292c6f2019-05-03 22:44:515365 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545366 previews_user_data->set_committed_previews_state(committed_state);
5367
5368 previews::PreviewsType committed_type =
5369 previews::GetMainFramePreviewsType(committed_state);
5370
5371 // Capture committed previews type, if any, in PreviewsUserData.
5372 // Note: this is for the subset of previews types that are decided upon
5373 // navigation commit. Previews types that are determined prior to
5374 // navigation (such as for offline pages or for redirecting to another
5375 // url), are not set here.
5376 previews_user_data->SetCommittedPreviewsType(committed_type);
5377
5378 // Log the commit decision.
5379 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5380 previews_decider_impl->LogPreviewDecisionMade(
5381 (previews_user_data->cache_control_no_transform_directive()
5382 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5383 : previews::PreviewsEligibilityReason::COMMITTED),
5384 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055385 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055386 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545387
5388 return committed_state;
5389}
Charlie Harrison650e11422018-12-04 00:37:265390
5391void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5392 content::RenderFrameHost* render_frame_host,
5393 blink::mojom::WebFeature feature) {
5394 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5395 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5396 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5397 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315398
5399 // For the SameSite-by-default-cookies related features, log
5400 // the site engagement score for the site whose cookie was blocked. This is to
5401 // gauge the user impact of the cookies being blocked.
5402 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265403}
Yutaka Hirano968d6252018-12-04 05:09:315404
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525405std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315406 return ::GetProduct();
5407}
5408
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525409std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315410 return ::GetUserAgent();
5411}
Sam McNallyd54e23f92019-01-16 04:42:395412
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525413blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175414 return ::GetUserAgentMetadata();
5415}
5416
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525417base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275418 // This icon is available on Android, but adds 19KiB to the APK. Since it
5419 // isn't used on Android we exclude it to avoid bloat.
5420#if !defined(OS_ANDROID)
5421 return base::Optional<gfx::ImageSkia>(
5422 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5423 IDR_PRODUCT_LOGO_256));
5424#else
5425 return base::nullopt;
5426#endif
5427}
5428
Sam McNallyd54e23f92019-01-16 04:42:395429bool ChromeContentBrowserClient::IsBuiltinComponent(
5430 content::BrowserContext* browser_context,
5431 const url::Origin& origin) {
5432#if BUILDFLAG(ENABLE_EXTENSIONS)
5433 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5434 browser_context, origin);
5435#else
5436 return false;
5437#endif
5438}
Oleg Davydov2cc0167b2019-02-05 14:32:485439
5440bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5441 const GURL& url,
5442 content::BrowserContext* context) {
5443 PolicyBlacklistService* service =
5444 PolicyBlacklistFactory::GetForBrowserContext(context);
5445
5446 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5447 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5448 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5449}
Dominic Mazzoni21fb0282019-02-13 18:32:475450
5451ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5452 content::BrowserContext* browser_context) {
5453 Profile* profile = Profile::FromBrowserContext(browser_context);
5454 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5455}
Eric Karld6cd75b2019-03-14 22:01:365456
5457#if defined(OS_ANDROID)
5458content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525459ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335460 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425461 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365462 return WideColorGamutHeuristic::kUseDisplay;
5463 }
Khushal1fc0da52019-10-09 00:38:565464
5465 if (display::Display::HasForceDisplayColorProfile() &&
5466 display::Display::GetForcedDisplayColorProfile() ==
5467 gfx::ColorSpace::CreateDisplayP3D65()) {
5468 return WideColorGamutHeuristic::kUseDisplay;
5469 }
5470
Eric Karld6cd75b2019-03-14 22:01:365471 return WideColorGamutHeuristic::kNone;
5472}
5473#endif
Ehsan Karamad91413d72019-03-22 16:37:485474
5475base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435476ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465477 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485478 base::flat_set<std::string> mime_types;
5479#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465480 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485481 for (const auto& pair : map)
5482 mime_types.insert(pair.first);
5483#endif
5484 return mime_types;
5485}
Yao Xiaod06607b2019-05-02 23:16:365486
5487void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5488 const content::WebContents* web_contents,
5489 const content::RenderFrameHost* frame_host,
5490 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525491 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365492 const ChromeSubresourceFilterClient* client =
5493 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5494 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045495 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365496 if (!user_gesture) {
5497 if (base::FeatureList::IsEnabled(
5498 blink::features::
5499 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5500 download_policy->SetDisallowed(
5501 content::NavigationDownloadType::kAdFrameNoGesture);
5502 } else {
5503 download_policy->SetAllowed(
5504 content::NavigationDownloadType::kAdFrameNoGesture);
5505 }
Yao Xiaod06607b2019-05-02 23:16:365506 }
5507 }
5508}
Jun Cai732a05e32019-05-29 19:34:195509
5510bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5511 content::BrowserContext* browser_context,
5512 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525513 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195514 const HostContentSettingsMap* const content_settings =
5515 HostContentSettingsMapFactory::GetForProfile(
5516 Profile::FromBrowserContext(browser_context));
5517
5518 if (content_settings->GetContentSetting(
5519 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455520 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195521 std::string()) == CONTENT_SETTING_BLOCK) {
5522 return true;
5523 }
5524
5525 return false;
5526}
5527
5528void ChromeContentBrowserClient::BlockBluetoothScanning(
5529 content::BrowserContext* browser_context,
5530 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525531 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195532 HostContentSettingsMap* const content_settings =
5533 HostContentSettingsMapFactory::GetForProfile(
5534 Profile::FromBrowserContext(browser_context));
5535
5536 content_settings->SetContentSettingDefaultScope(
5537 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455538 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195539 CONTENT_SETTING_BLOCK);
5540}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475541
5542bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5543#if defined(OS_ANDROID)
5544 return extra_icu::ModuleProvider::IsModuleInstalled();
5545#endif
5546 return false;
5547}
Guido Urdaneta4030d6a32019-10-17 09:38:165548
5549bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5550 content::BrowserContext* browser_context,
5551 const GURL& url,
5552 const GURL& site_for_cookies,
5553 const base::Optional<url::Origin>& top_frame_origin) {
5554 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5555 return CookieSettingsFactory::GetForProfile(
5556 Profile::FromBrowserContext(browser_context))
5557 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5558}
Sam Goto5cf068e82019-11-04 23:08:445559
5560#if !defined(OS_ANDROID)
5561void ChromeContentBrowserClient::FetchRemoteSms(
5562 content::BrowserContext* browser_context,
5563 const url::Origin& origin,
5564 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5565 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5566}
5567#endif
Roger Tawa03ffdbd2020-01-16 18:12:545568
5569void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5570 content::WebContents* web_contents,
5571 const GURL& url,
5572 const ui::ClipboardFormatType& data_type,
5573 const std::string& data,
5574 IsClipboardPasteAllowedCallback callback) {
5575#if BUILDFLAG(FULL_SAFE_BROWSING)
5576 // Safe browsing does not support images, so accept without checking.
5577 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5578 // types when it is implemented.
5579 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5580 std::move(callback).Run(ClipboardPasteAllowed(true));
5581 return;
5582 }
5583
5584 Profile* profile =
5585 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5586 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
Dominique Fauteux-Chapleauc08c8c962020-05-07 18:46:265587 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(
5588 profile, url, &dialog_data,
5589 enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) {
Roger Tawa03ffdbd2020-01-16 18:12:545590 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5591 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5592 web_contents, std::move(dialog_data),
5593 base::BindOnce(
5594 [](IsClipboardPasteAllowedCallback callback,
5595 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5596 const safe_browsing::DeepScanningDialogDelegate::Result&
5597 result) {
5598 std::move(callback).Run(
5599 ClipboardPasteAllowed(result.text_results[0]));
5600 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245601 std::move(callback)),
5602 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545603 } else {
5604 std::move(callback).Run(ClipboardPasteAllowed(true));
5605 }
5606#else
5607 std::move(callback).Run(ClipboardPasteAllowed(true));
5608#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5609}
Lukasz Anforowicz4600ea32020-01-18 02:37:485610
Lukasz Anforowicz1feeba182020-03-16 20:32:025611void ChromeContentBrowserClient::
5612 LogUkmEventForCrossOriginFetchFromContentScript3(
5613 const std::string& isolated_world_host) {
5614#if BUILDFLAG(ENABLE_EXTENSIONS)
5615 const std::string& extension_id = isolated_world_host;
5616 ukm::SourceId source_id =
5617 ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id);
5618 if (source_id != ukm::kInvalidSourceId) {
5619 ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event(
5620 source_id);
5621 ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get());
5622 }
5623#endif
5624}
5625
Lukasz Anforowicz4600ea32020-01-18 02:37:485626#if BUILDFLAG(ENABLE_PLUGINS)
5627bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5628 const url::Origin& embedder_origin,
5629 const content::PepperPluginInfo& plugin_info) {
5630#if BUILDFLAG(ENABLE_PDF)
5631 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5632#if BUILDFLAG(ENABLE_EXTENSIONS)
5633 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5634 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5635 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5636 return true;
5637 }
5638#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5639
5640 // Allow embedding the internal PDF plugin in chrome://print.
5641 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5642 return true;
5643
5644 // Only allow the PDF plugin in the known, trustworthy origins that are
5645 // allowlisted above. See also https://crbug.com/520422 and
5646 // https://crbug.com/1027173.
5647 return false;
5648 }
5649#endif // BUILDFLAG(ENABLE_PDF)
5650
5651 return true;
5652}
5653#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565654
5655#if BUILDFLAG(ENABLE_VR)
5656content::XrIntegrationClient*
5657ChromeContentBrowserClient::GetXrIntegrationClient() {
5658 if (!xr_integration_client_)
5659 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5660 util::PassKey<ChromeContentBrowserClient>());
5661 return xr_integration_client_.get();
5662}
5663#endif // BUILDFLAG(ENABLE_VR)
Adrienne Walker297651292020-05-08 00:23:185664
5665bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
5666 content::BrowserContext* browser_context) {
5667 auto* profile = Profile::FromBrowserContext(browser_context);
5668 auto* prefs = profile->GetPrefs();
5669
5670 if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) &&
5671 prefs->GetBoolean(prefs::kAppCacheForceEnabled)) {
5672 return false;
5673 }
5674 if (base::FeatureList::IsEnabled(
5675 blink::features::kAppCacheRequireOriginTrial)) {
5676 return true;
5677 }
5678
5679 return false;
5680}