blob: 8d5f199419689516673a92cb6ad3e99c3124754f [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
bmcquade5d2d9cf32015-06-19 17:42:287#include <map>
[email protected]7c3228a2011-11-11 21:35:228#include <set>
[email protected]1033acd2012-02-08 08:46:279#include <utility>
[email protected]7c3228a2011-11-11 21:35:2210#include <vector>
11
brettwf1958912015-10-07 19:43:1212#include "base/base_switches.h"
[email protected]317c58f02011-11-09 02:15:0313#include "base/bind.h"
estark3ba11132015-04-10 01:38:3314#include "base/bind_helpers.h"
[email protected]b80f68432011-05-02 17:22:3015#include "base/command_line.h"
Ken Rockot91c40da82019-08-12 20:07:1116#include "base/compiler_specific.h"
Will Harrisc196ed942019-08-03 03:45:3017#include "base/files/file_util.h"
morritad95714f2014-10-01 02:37:2418#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0019#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1520#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5821#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2522#include "base/metrics/field_trial_params.h"
evliuedcbb87d2019-11-22 19:49:4123#include "base/metrics/histogram_functions.h"
lazyboy5d5fede02016-03-10 04:10:1424#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3325#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3926#include "base/path_service.h"
Gabriel Charettee926fc12019-12-16 19:00:0227#include "base/sequenced_task_runner.h"
Avi Drissmand251e912018-12-26 15:46:3728#include "base/stl_util.h"
[email protected]e7463412013-06-10 22:53:4629#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0330#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2831#include "base/strings/string_util.h"
32#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2033#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0334#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2835#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3236#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4137#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1838#include "build/build_config.h"
Ken Rockot341089f2019-01-11 23:11:5839#include "chrome/app/chrome_content_browser_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4740#include "chrome/browser/accessibility/accessibility_labels_service.h"
41#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
michaeln96f887e22015-04-13 23:58:3142#include "chrome/browser/after_startup_task_utils.h"
Ovidio Henriquez3d729f62020-02-07 00:43:2943#include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h"
[email protected]b8148ac2011-07-13 22:03:2544#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3045#include "chrome/browser/browser_process.h"
msramek1c2b3ca2017-03-14 17:57:5646#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
Colin Blundell111b61c02020-01-24 11:53:5147#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
[email protected]d5a74be2014-08-08 01:01:2748#include "chrome/browser/chrome_content_browser_client_parts.h"
drogerb1716972015-06-30 09:04:0949#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0850#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Robbie McElrath1294d242019-05-31 20:46:2251#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
52#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3053#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
54#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0655#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0856#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4957#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3158#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4559#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0160#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1961#include "chrome/browser/font_family_cache.h"
Peng Huang71d398ed2020-02-28 01:30:5362#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5263#include "chrome/browser/hid/chrome_hid_delegate.h"
Colin Blundelleaa7377bf2020-01-22 08:49:1064#include "chrome/browser/interstitials/enterprise_util.h"
Avi Drissmand30927342018-05-22 15:04:2765#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2766#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3467#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4268#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
69#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1670#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3671#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3672#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
Sebastien Marchand8c0088102019-10-11 16:47:5673#include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h"
[email protected]95132f52013-04-12 02:19:0474#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0575#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0776#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
John Abd-El-Malek7577f262019-06-10 21:23:2377#include "chrome/browser/net/chrome_network_delegate.h"
David Benjaminf6a34092019-11-07 19:55:1078#include "chrome/browser/net/profile_network_context_service.h"
79#include "chrome/browser/net/profile_network_context_service_factory.h"
Matt Menkeae4fdb12018-06-02 06:32:5480#include "chrome/browser/net/system_network_context_manager.h"
Richard Knolld0eae962019-04-04 12:34:0281#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5982#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5683#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0684#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5485#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5186#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5687#include "chrome/browser/permissions/attestation_permission_request.h"
[email protected]0609b17f2011-05-31 20:13:4288#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1189#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4890#include "chrome/browser/plugins/plugin_utils.h"
Robert Ogdenea4ea7392020-01-25 01:44:5391#include "chrome/browser/prerender/isolated/isolated_prerender_features.h"
Robert Ogden6946ad42020-01-13 18:01:3092#include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h"
[email protected]190e5e22013-07-27 05:59:2393#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4194#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5095#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0796#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:0197#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:1998#include "chrome/browser/previews/previews_content_util.h"
Robert Ogden0f4d88682019-09-24 22:27:5299#include "chrome/browser/previews/previews_lite_page_redirect_decider.h"
100#include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.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"
Carlos IL4ee307e2018-12-22 03:19:00119#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40120#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35121#include "chrome/browser/safe_browsing/ui_manager.h"
122#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
Xinghui Lue17b19942020-02-24 21:19:58123#include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:43124#include "chrome/browser/search/search.h"
Sam Goto5cf068e82019-11-04 23:08:44125#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20126#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35127#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40128#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23129#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28130#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02131#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48132#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Colin Blundell13e92ec2020-01-27 09:47:38133#include "chrome/browser/ssl/chrome_security_blocking_page_factory.h"
Joe DeBlasio9b996292019-01-31 05:09:32134#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07135#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
Christopher Thompson4137cec2017-12-19 05:34:23136#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10137#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35138#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45139#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52140#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19141#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44142#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38143#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51144#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08145#include "chrome/browser/ui/browser_navigator.h"
146#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43147#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39148#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54149#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56150#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25151#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44152#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58153#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50154#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01155#include "chrome/browser/ui/webui/log_web_ui_url.h"
[email protected]95ebe7c2020-04-08 19:12:45156#include "chrome/browser/usb/frame_usb_services.h"
Ian Vollick6243dfe02018-03-08 01:08:53157#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25158#include "chrome/browser/web_applications/components/app_registrar.h"
Alan Cutter1797f46a2020-02-12 02:48:59159#include "chrome/browser/web_applications/components/web_app_provider_base.h"
Scott Violet6200d332018-02-23 21:29:23160#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22161#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01162#include "chrome/common/chrome_constants.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48163#include "chrome/common/chrome_content_client.h"
chrisha927d8fe2017-01-18 23:09:51164#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14165#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22166#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30167#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02168#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50169#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34170#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37171#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12172#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19173#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12174#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22175#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32176#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38177#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28178#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02179#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09180#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47181#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37182#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18183#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30184#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12185#include "components/autofill/core/common/autofill_switches.h"
Clark DuVallf5189252020-04-15 22:33:34186#include "components/browsing_data/content/browsing_data_helper.h"
msramek1c8e19d2017-01-04 20:04:53187#include "components/browsing_data/core/browsing_data_utils.h"
Colin Blundell111b61c02020-01-24 11:53:51188#include "components/captive_portal/content/captive_portal_service.h"
Colin Blundell7cf3fe32020-01-23 09:52:49189#include "components/captive_portal/core/buildflags.h"
[email protected]649b57272014-05-09 14:54:44190#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04191#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48192#include "components/cloud_devices/common/cloud_devices_switches.h"
Clark DuVall84a33d612020-04-17 16:01:00193#include "components/content_settings/browser/tab_specific_content_settings.h"
mukai8eaec822014-10-25 17:53:16194#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09195#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16196#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52197#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45198#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08199#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03200#include "components/content_settings/core/common/pref_names.h"
Clark DuVall0e901722019-08-14 23:31:37201#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.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-Malek9cf3d7f02018-07-27 02:40:39212#include "components/google/core/common/google_util.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"
Clark DuValla11361ad32020-02-20 22:14:27220#include "components/permissions/permission_context_base.h"
Scott Violet93893782020-03-27 16:23:54221#include "components/permissions/quota_permission_context_impl.h"
Doug Turner9dcaf5962017-12-21 04:38:53222#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54223#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18224#include "components/policy/core/common/policy_service.h"
225#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26226#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54227#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08228#include "components/prefs/pref_service.h"
229#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21230#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54231#include "components/previews/content/previews_decider_impl.h"
232#include "components/previews/content/previews_ui_service.h"
233#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54234#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45235#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43236#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56237#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56238#include "components/rappor/rappor_service_impl.h"
Nico Weberbc5b06f2019-07-26 14:00:13239#include "components/safe_browsing/buildflags.h"
Ali Jumafb3dc1f2020-01-07 17:33:47240#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
241#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
242#include "components/safe_browsing/core/browser/url_checker_delegate.h"
243#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
244#include "components/safe_browsing/core/db/database_manager.h"
245#include "components/safe_browsing/core/features.h"
246#include "components/safe_browsing/core/realtime/policy_engine.h"
Xinghui Lue17b19942020-02-24 21:19:58247#include "components/safe_browsing/core/realtime/url_lookup_service.h"
Daniel Vogelheim6008f572018-09-24 14:35:14248#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49249#include "components/security_interstitials/content/ssl_cert_reporter.h"
Colin Blundell5eb994b2020-01-28 11:50:48250#include "components/security_interstitials/content/ssl_error_handler.h"
Evan Stade1e71d6dd2019-10-29 03:04:49251#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23252#include "components/signin/public/identity_manager/identity_manager.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54253#include "components/site_isolation/preloaded_isolated_origins.h"
csharrisone985ebc2017-04-04 17:05:03254#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17255#include "components/translate/core/common/translate_switches.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02256#include "components/ukm/app_source_url_recorder.h"
rsleevi24f64dc22015-08-07 21:39:21257#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28258#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33259#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46260#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22261#include "components/version_info/version_info.h"
Chris Blumef59fc6282020-02-21 00:18:39262#include "components/viz/common/features.h"
Chris Blume7f752e32020-02-14 22:22:33263#include "components/viz/common/viz_utils.h"
[email protected]e0ada9c2012-03-20 03:54:43264#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30265#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38266#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28267#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03268#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31269#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41270#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09271#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03272#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59273#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19274#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31275#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35276#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47277#include "content/public/browser/navigation_handle.h"
278#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11279#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50280#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30281#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33282#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05283#include "content/public/browser/resource_context.h"
Alex Moshchuk51e1428b2020-04-22 18:00:54284#include "content/public/browser/site_isolation_policy.h"
jam608f2992016-03-31 16:35:34285#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48286#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27287#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13288#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08289#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19290#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21291#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23292#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43293#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18294#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56295#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40296#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02297#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18298#include "content/public/common/network_service_util.h"
ben51bb6c62016-11-17 20:15:57299#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23300#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44301#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31302#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05303#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56304#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43305#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59306#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48307#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30308#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28309#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04310#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31311#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44312#include "media/media_buildflags.h"
313#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12314#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42315#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52316#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08317#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53318#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51319#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58320#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23321#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46322#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57323#include "net/ssl/ssl_cert_request_info.h"
Lukasz Anforowicz4600ea32020-01-18 02:37:48324#include "pdf/buildflags.h"
Scott Violet02e38b92018-03-27 23:42:14325#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38326#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19327#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz1feeba182020-03-16 20:32:02328#include "services/metrics/public/cpp/ukm_builders.h"
329#include "services/metrics/public/cpp/ukm_recorder.h"
Takashi Toyoshima128441462019-10-16 04:19:17330#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37331#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50332#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50333#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13334#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05335#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34336#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03337#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06338#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02339#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02340#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02341#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19342#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31343#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17344#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21345#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26346#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18347#include "ui/base/buildflags.h"
Roger Tawa03ffdbd2020-01-16 18:12:54348#include "ui/base/clipboard/clipboard_format_type.h"
[email protected]c9b6eb62011-10-18 20:49:39349#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08350#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35351#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21352#include "ui/base/ui_base_switches.h"
Khushal1fc0da52019-10-09 00:38:56353#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21354#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49355#include "ui/native_theme/caption_style.h"
356#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)
Xiyuan Xiafc9f38132019-08-02 00:51:42372#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30373#include "chrome/app/chrome_crash_reporter_client.h"
hashimotoa53e7e82016-10-26 06:30:47374#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17375#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30376#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24377#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18378#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08379#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48380#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41381#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32382#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58383#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00384#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
385#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44386#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39387#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31388#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33389#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44390#include "chrome/browser/chromeos/profiles/profile_helper.h"
Anand K. Mistry7694c362020-03-17 23:33:34391#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
[email protected]c94ac692013-07-27 00:50:10392#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36393#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27394#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31395#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10396#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21397#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10398#include "chromeos/constants/chromeos_switches.h"
Rohit Rao92f84b6a2020-03-25 14:57:50399#include "components/crash/core/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07400#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58401#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50402#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26403#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30404#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09405#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35406#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45407#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47408#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20409#include "chrome/browser/android/app_hooks.h"
John Abd-El-Malek4f380d92020-02-19 16:43:36410#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
Scott Violetef765b92017-06-09 21:26:36411#include "chrome/browser/android/devtools_manager_delegate_android.h"
412#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
413#include "chrome/browser/android/service_tab_launcher.h"
414#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42415#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09416#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56417#include "chrome/browser/download/android/available_offline_content_provider.h"
418#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07419#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38420#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11421#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07422#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47423#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36424#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54425#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00426#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36427#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45428#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04429#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45430#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30431#elif defined(OS_POSIX)
432#include "chrome/browser/chrome_browser_main_posix.h"
433#endif
434
tmartinofb341882017-02-10 19:36:53435#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40436#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36437#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54438#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59439#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02440#include "chrome/browser/search/instant_service.h"
441#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46442#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51443#include "chrome/browser/ui/browser.h"
444#include "chrome/browser/ui/browser_finder.h"
445#include "chrome/browser/ui/browser_list.h"
446#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20447#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51448#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39449#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
450#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43451#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27452#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28453#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36454
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33455#if defined(OS_WIN) || defined(OS_MACOSX) || \
456 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52457#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12458#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52459#endif
460
Joshua Perazace68e2f2019-09-23 18:44:24461#if defined(OS_LINUX)
Rohit Rao92f84b6a2020-03-25 14:57:50462#include "components/crash/core/app/crash_switches.h"
463#include "components/crash/core/app/crashpad.h"
Joshua Perazace68e2f2019-09-23 18:44:24464#endif
465
[email protected]a220b5932013-09-21 03:47:44466#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02467#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02468#include "base/debug/leak_annotations.h"
Rohit Rao92f84b6a2020-03-25 14:57:50469#include "components/crash/core/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02470#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13471#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43472#endif
[email protected]b80f68432011-05-02 17:22:30473
Maggie Caia2f03f52019-04-02 02:13:28474// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
475// single navigation throttle to display the intent picker on all platforms.
476#if !defined(OS_ANDROID)
477#if defined(OS_CHROMEOS)
478#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51479#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28480#else
481#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
482#endif
483#endif
484
[email protected]e8b6ca02013-07-10 18:00:51485#if defined(TOOLKIT_VIEWS)
486#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
487#endif
488
estaded3aa0e82016-02-17 22:55:21489#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
490#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
[email protected]e8b6ca02013-07-10 18:00:51491#endif
492
Mohsen Izadif1958f22019-01-18 20:29:31493#if defined(USE_OZONE)
494#include "ui/ozone/public/ozone_platform.h"
495#endif
496
[email protected]e8b6ca02013-07-10 18:00:51497#if defined(USE_X11)
498#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
499#endif
500
brettwab78fef2016-10-12 02:56:05501#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
Colin Blundellca2b20e2020-01-28 10:07:10502#include "components/captive_portal/content/captive_portal_tab_helper.h"
Colin Blundell11999f372020-01-28 14:17:38503#include "components/captive_portal/content/captive_portal_url_loader_throttle.h"
[email protected]7a2a6d802014-06-06 13:39:19504#endif
505
Nico Weberaf3b00b2017-09-11 17:58:17506#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55507#include "components/nacl/browser/nacl_browser.h"
508#include "components/nacl/browser/nacl_host_message_filter.h"
509#include "components/nacl/browser/nacl_process_host.h"
510#include "components/nacl/common/nacl_process_type.h"
511#include "components/nacl/common/nacl_switches.h"
512#endif
513
brettw00899e62016-11-12 02:10:17514#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05515#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20516#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27517#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23518#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32519#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51520#include "chrome/browser/extensions/user_script_listener.h"
521#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28522#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49523#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46524#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39525#include "components/guest_view/browser/guest_view_base.h"
526#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25527#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31528#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35529#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32530#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12531#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57532#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48533#include "extensions/browser/guest_view/web_view/web_view_guest.h"
534#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
535#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31536#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27537#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28538#include "extensions/common/extension.h"
539#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13540#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28541#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33542#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28543#include "extensions/common/permissions/permissions_data.h"
544#include "extensions/common/permissions/socket_permission.h"
545#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34546#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25547
brettw4b461082016-11-19 18:55:16548#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55549#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27550#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39551#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55552#endif
553
bauerb8f9c37742017-03-30 15:04:12554#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
555#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
556#endif
557
yilkal240b4f22019-11-27 19:09:06558#if defined(OS_CHROMEOS)
559#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
560#endif // defined(OS_CHROMEOS)
561
thakis678822e2017-04-20 17:20:34562#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38563#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09564#endif
565
weilifabbf7572017-05-22 19:05:16566#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21567#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16568#endif
Lei Zhanga2fa14c2018-05-15 00:05:21569
Xiaohan Wanga4e41842018-06-26 18:45:10570#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49571#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26572#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10573#include "chrome/browser/media/widevine_hardware_caps_win.h"
574#include "third_party/widevine/cdm/widevine_cdm_common.h"
575#endif
576#endif
577
mmenkedb2637ff2017-03-30 23:59:42578#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
579#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
580#endif
581
Nico Weberbc5b06f2019-07-26 14:00:13582#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35583#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
584#endif
585
Jian Lide7b43792018-06-01 23:22:13586#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54587#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13588#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
589#endif
590
Will Cassella40837ba2019-07-01 21:32:00591#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43592#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
593#endif
594
John Lee0ee748bf2019-12-11 21:35:44595#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
596#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
597#endif
598
Roger Tawa03ffdbd2020-01-16 18:12:54599#if BUILDFLAG(FULL_SAFE_BROWSING)
600#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
601#endif
602
Alexander Cooperc8448702020-03-14 01:39:56603#if BUILDFLAG(ENABLE_VR)
Alexander Cooperf4b3013d2020-03-23 18:47:23604#include "chrome/browser/vr/chrome_xr_integration_client.h"
Alexander Cooperc8448702020-03-14 01:39:56605#endif
606
[email protected]c7abd422012-09-25 00:20:08607using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39608using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31609using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13610using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59611using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00612using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02613using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11614using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33615using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13616using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05617using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38618using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39619
[email protected]0daaebfe2014-03-15 00:09:05620#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20621using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05622#endif
623
brettw00899e62016-11-12 02:10:17624#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28625using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27626using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28627using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28628using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27629#endif
630
brettw4b461082016-11-19 18:55:16631#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55632using plugins::ChromeContentBrowserClientPluginsPart;
633#endif
634
[email protected]c5dbef02011-05-13 05:06:09635namespace {
636
Will Harris1b9b4152019-08-21 22:33:50637#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30638// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
639// running on Windows 10 1511 and above. See
640// https://blogs.windows.com/blog/tag/code-integrity-guard/.
641const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35642 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50643#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
644 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30645
Colin Blundell9ee731dd2020-01-23 10:42:38646// Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level
647// parameters.
648void HandleSSLErrorWrapper(
649 content::WebContents* web_contents,
650 int cert_error,
651 const net::SSLInfo& ssl_info,
652 const GURL& request_url,
653 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
Colin Blundell9ee731dd2020-01-23 10:42:38654 SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) {
655 Profile* profile =
656 Profile::FromBrowserContext(web_contents->GetBrowserContext());
657
658 // This can happen if GetBrowserContext no longer exists by the time this
659 // gets called (e.g. the SSL error was in a webview that has since been
660 // destroyed); if that's the case we don't need to handle the error (and will
661 // crash if we attempt to).
662 if (!profile)
663 return;
664
Colin Blundell27331f92020-02-05 21:13:01665 captive_portal::CaptivePortalService* captive_portal_service = nullptr;
Colin Blundell111b61c02020-01-24 11:53:51666
667#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
668 captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile);
669#endif
670
Colin Blundell9ee731dd2020-01-23 10:42:38671 SSLErrorHandler::HandleSSLError(
672 web_contents, cert_error, ssl_info, request_url,
Colin Blundella3fc1222020-01-23 11:41:53673 std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback),
Colin Blundell111b61c02020-01-24 11:53:51674 g_browser_process->network_time_tracker(), captive_portal_service,
Colin Blundell13e92ec2020-01-27 09:47:38675 std::make_unique<ChromeSecurityBlockingPageFactory>(),
Colin Blundell9ee731dd2020-01-23 10:42:38676 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed));
677}
678
lazyboy5d5fede02016-03-10 04:10:14679enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53680 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14681 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53682
683 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14684 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53685
686 // An extension or app tried to load a resource of a different platform app in
687 // a tab.
688 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
689
690 // A non-app and non-extension page tried to load a platform app in a tab.
691 APP_LOADED_IN_TAB_SOURCE_OTHER,
692
lazyboy5d5fede02016-03-10 04:10:14693 APP_LOADED_IN_TAB_SOURCE_MAX
694};
695
Lei Zhang2cfceac2018-11-14 19:36:33696// Cached version of the locale so we can return the locale on the I/O
697// thread.
698std::string& GetIOThreadApplicationLocale() {
699 static base::NoDestructor<std::string> s;
700 return *s;
701}
702
[email protected]f8f93eb2012-09-25 03:06:24703// Returns a copy of the given url with its host set to given host and path set
704// to given path. Other parts of the url will be the same.
705GURL ReplaceURLHostAndPath(const GURL& url,
706 const std::string& host,
707 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05708 url::Replacements<char> replacements;
709 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
710 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24711 return url.ReplaceComponents(replacements);
712}
713
madfbd10852017-01-20 03:15:33714// Handles the rewriting of the new tab page URL based on group policy.
715bool HandleNewTabPageLocationOverride(
716 GURL* url,
717 content::BrowserContext* browser_context) {
718 if (!url->SchemeIs(content::kChromeUIScheme) ||
719 url->host() != chrome::kChromeUINewTabHost)
720 return false;
721
722 Profile* profile = Profile::FromBrowserContext(browser_context);
723 std::string ntp_location =
724 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
725 if (ntp_location.empty())
726 return false;
727
728 *url = GURL(ntp_location);
729 return true;
730}
731
Becca Hughesfe8c32c2018-03-21 13:36:56732#if !defined(OS_ANDROID)
733// Check if the current url is whitelisted based on a list of whitelisted urls.
734bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57735 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56736 // Only check on HTTP and HTTPS pages.
737 if (!current_url.SchemeIsHTTPOrHTTPS())
738 return false;
739
740 for (auto const& value : whitelisted_urls) {
741 ContentSettingsPattern pattern =
742 ContentSettingsPattern::FromString(value.GetString());
743 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
744 continue;
745 if (pattern.Matches(current_url))
746 return true;
747 }
748
749 return false;
750}
751
752// Check if autoplay is allowed by policy configuration.
753bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
754 PrefService* prefs) {
755 DCHECK(prefs);
756
757 // Check if we have globally allowed autoplay by policy.
758 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
759 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
760 return true;
761 }
762
763 if (!contents)
764 return false;
765
766 // Check if the current URL matches a URL pattern on the whitelist.
767 const base::ListValue* autoplay_whitelist =
768 prefs->GetList(prefs::kAutoplayWhitelist);
769 return autoplay_whitelist &&
770 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
771 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
772}
773#endif
774
Joshua Perazaf890e4b2019-01-03 19:19:02775#if defined(OS_ANDROID)
776int GetCrashSignalFD(const base::CommandLine& command_line) {
777 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
778}
779#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03780breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
781 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02782 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52783 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02784 {
785 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31786 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03787 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50788 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02789 crash_handler->StartUploaderThread();
790 return crash_handler;
791 }
792}
793
avi3ef9ec9e2014-12-22 22:50:17794int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24795 if (crash_reporter::IsCrashpadEnabled()) {
796 int fd;
797 pid_t pid;
798 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
799 }
800
[email protected]9de4da52014-05-24 12:26:50801 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39802 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31803 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02804 if (!crash_handler)
805 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18806 return crash_handler->GetDeathSignalSocket();
807 }
808
809 std::string process_type =
810 command_line.GetSwitchValueASCII(switches::kProcessType);
811
[email protected]779dd282013-10-19 15:57:02812 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31813 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02814 if (!crash_handler)
815 crash_handler = CreateCrashHandlerHost(process_type);
816 return crash_handler->GetDeathSignalSocket();
817 }
[email protected]a1733df2012-06-22 11:24:18818
[email protected]779dd282013-10-19 15:57:02819 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31820 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02821 if (!crash_handler)
822 crash_handler = CreateCrashHandlerHost(process_type);
823 return crash_handler->GetDeathSignalSocket();
824 }
[email protected]a1733df2012-06-22 11:24:18825
[email protected]779dd282013-10-19 15:57:02826 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31827 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02828 if (!crash_handler)
829 crash_handler = CreateCrashHandlerHost(process_type);
830 return crash_handler->GetDeathSignalSocket();
831 }
[email protected]a1733df2012-06-22 11:24:18832
James Cook9207cc12017-10-19 17:08:39833 if (process_type == switches::kUtilityProcess) {
834 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
835 if (!crash_handler)
836 crash_handler = CreateCrashHandlerHost(process_type);
837 return crash_handler->GetDeathSignalSocket();
838 }
839
[email protected]a1733df2012-06-22 11:24:18840 return -1;
841}
Joshua Perazaf890e4b2019-01-03 19:19:02842#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18843
[email protected]eabbfb12013-04-05 23:28:35844void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52845 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33846 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35847}
848
estark3ba11132015-04-10 01:38:33849// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31850// SSLErrorHandler. Uses CertificateReportingService to send reports. The
851// service handles queueing and re-sending of failed reports. Each certificate
852// error creates a new instance of this class.
853class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33854 public:
meacerf43117a2016-12-27 21:02:31855 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12856 content::WebContents* web_contents)
857 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
858 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31859 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33860
861 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55862 void ReportInvalidCertificateChain(
863 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31864 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33865 }
866
867 private:
meacerf43117a2016-12-27 21:02:31868 CertificateReportingService* service_;
869
870 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33871};
872
brettw00899e62016-11-12 02:10:17873#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53874
875AppLoadedInTabSource ClassifyAppLoadedInTabSource(
876 const GURL& opener_url,
877 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58878 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
879 // The forbidden app URL was being opened by a non-extension page (e.g.
880 // http).
881 return APP_LOADED_IN_TAB_SOURCE_OTHER;
882 }
883
884 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53885 // The forbidden app URL was being opened by a different app or extension.
886 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
887 }
Lei Zhang7d0b0f42019-10-12 03:47:58888
889 // This platform app was trying to window.open() one of its own URLs.
890 if (opener_url ==
891 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
892 // Source was the background page.
893 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
894 }
895
896 // Source was a different page inside the app.
897 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53898}
[email protected]9c7656382014-08-08 21:02:30899
Charles Harrison34f67862017-08-22 01:04:17900// Returns true if there is is an extension matching |url| in
901// |opener_render_process_id| with APIPermission::kBackground.
902//
903// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
904// hosted app, even though normal extensions just use the host.
905bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35906 extensions::ProcessMap* process_map,
907 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17908 const GURL& url,
csharrison95f01e922017-04-24 18:52:35909 int opener_render_process_id) {
910 // Note: includes web URLs that are part of an extension's web extent.
911 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17912 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35913 return extension &&
914 extension->permissions_data()->HasAPIPermission(
915 APIPermission::kBackground) &&
916 process_map->Contains(extension->id(), opener_render_process_id);
917}
Kevin Marshall32f99d7e2017-07-11 23:17:46918
csharrison95f01e922017-04-24 18:52:35919#endif
920
Darin Fishere41aab52020-01-29 18:31:23921mojo::PendingRemote<chrome::mojom::PrerenderCanceler> GetPrerenderCanceler(
John Abd-El-Malekd2377982018-01-08 22:23:12922 const base::Callback<content::WebContents*()>& wc_getter) {
Darin Fishere41aab52020-01-29 18:31:23923 mojo::PendingRemote<chrome::mojom::PrerenderCanceler> canceler;
924 prerender::PrerenderContents::FromWebContents(wc_getter.Run())
925 ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver());
926 return canceler;
John Abd-El-Malekd2377982018-01-08 22:23:12927}
928
Julian Pastarmovb4773b82020-04-21 16:34:14929// Encapculates logic to determine if enterprise policies should be honored.
930// This is a copy of the code in policy_loader_win.cc but it's ok to duplicate
931// as a new central class to replace those checks is in the making.
932bool ShouldHonorPolicies() {
933#if defined(OS_WIN)
934 bool is_enterprise_version =
935 base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME;
936 return base::win::IsEnrolledToDomain() ||
937 (base::win::IsDeviceRegisteredWithManagement() &&
938 is_enterprise_version);
939#else // defined(OS_WIN)
940 // TODO(pastarmovj): Replace this with check for MacOS and the new management
941 // service once it is ready.
942 return true;
943#endif // defined(OS_WIN)
944}
945
John Abd-El-Malek92bf3602019-07-31 02:25:48946void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04947 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48948 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45949 bool has_user_gesture,
950 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01951 // If there is no longer a WebContents, the request may have raced with tab
952 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04953 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01954 if (!web_contents)
955 return;
956
957 // Do not launch external requests attached to unswapped prerenders.
958 prerender::PrerenderContents* prerender_contents =
959 prerender::PrerenderContents::FromWebContents(web_contents);
960 if (prerender_contents) {
961 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
John Abd-El-Maleka67add82018-03-09 18:22:01962 return;
963 }
964
Robbie McElrath1294d242019-05-31 20:46:22965 // Do not launch external requests for schemes that have a handler registered.
966 ProtocolHandlerRegistry* protocol_handler_registry =
967 ProtocolHandlerRegistryFactory::GetForBrowserContext(
968 web_contents->GetBrowserContext());
969 if (protocol_handler_registry &&
970 protocol_handler_registry->IsHandledProtocol(url.scheme()))
971 return;
972
John Abd-El-Maleka67add82018-03-09 18:22:01973 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01974 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19975 PolicyBlacklistFactory::GetForBrowserContext(
976 web_contents->GetBrowserContext());
Julian Pastarmovb4773b82020-04-21 16:34:14977 if (ShouldHonorPolicies() && service) {
John Abd-El-Maleka67add82018-03-09 18:22:01978 const policy::URLBlacklist::URLBlacklistState url_state =
979 service->GetURLBlacklistState(url);
980 is_whitelisted =
981 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
982 }
983
984 // If the URL is in whitelist, we launch it without asking the user and
985 // without any additional security checks. Since the URL is whitelisted,
986 // we assume it can be executed.
987 if (is_whitelisted) {
988 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
989 } else {
990 ExternalProtocolHandler::LaunchUrl(
991 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
992 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45993 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:01994 }
995}
996
Yutaka Hirano968d6252018-12-04 05:09:31997std::string GetProduct() {
998 return version_info::GetProductNameAndVersionForUserAgent();
999}
1000
Lukasz Anforowicz60d1253d2019-05-08 16:31:371001void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1002 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1003 // For renderer and utility (e.g. NetworkService) processes the switch is the
1004 // only available source, so below the combined (pref/policy + cmdline)
1005 // allowlist of secure origins is injected into |cmdline| for these other
1006 // processes.
1007 std::vector<std::string> allowlist =
1008 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1009 if (!allowlist.empty()) {
1010 cmdline->AppendSwitchASCII(
1011 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1012 base::JoinString(allowlist, ","));
1013 }
1014}
1015
Will Harris1b9b4152019-08-21 22:33:501016#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301017// Returns the full path to |module_name|. Both dev builds (where |module_name|
1018// is in the current executable's directory) and proper installs (where
1019// |module_name| is in a versioned sub-directory of the current executable's
1020// directory) are supported. The identified file is not guaranteed to exist.
1021base::FilePath GetModulePath(base::StringPiece16 module_name) {
1022 base::FilePath exe_dir;
1023 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1024 DCHECK(has_path);
1025
1026 // Look for the module in a versioned sub-directory of the current
1027 // executable's directory and return the path if it can be read. This is the
1028 // expected location of modules for proper installs.
1029 const base::FilePath module_path =
1030 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1031 if (base::PathExists(module_path))
1032 return module_path;
1033
1034 // Otherwise, return the path to the module in the current executable's
1035 // directory. This is the expected location of modules for dev builds.
1036 return exe_dir.Append(module_name);
1037}
Will Harris1b9b4152019-08-21 22:33:501038#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1039 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301040
Lukasz Anforowicz7724d092019-10-03 23:50:211041void MaybeAddThrottle(
1042 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles,
1043 std::unique_ptr<content::NavigationThrottle> maybe_throttle) {
1044 if (maybe_throttle)
1045 throttles->push_back(std::move(maybe_throttle));
1046}
1047
Evan Stade1e71d6dd2019-10-29 03:04:491048// Returns whether |web_contents| is within a hosted app.
1049bool IsInHostedApp(WebContents* web_contents) {
1050#if BUILDFLAG(ENABLE_EXTENSIONS)
1051 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1052 return (browser &&
1053 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1054#else
1055 return false;
1056#endif
1057}
1058
Lily Chenc2c9e9f2019-12-05 19:55:311059void MaybeRecordSameSiteCookieEngagementHistogram(
1060 content::RenderFrameHost* render_frame_host,
1061 blink::mojom::WebFeature feature) {
1062 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1063 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1064 return;
1065 }
1066
1067 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1068 DCHECK(render_frame_host);
1069
1070 content::BrowserContext* browser_context =
1071 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1072 Profile* profile = Profile::FromBrowserContext(browser_context);
1073 SiteEngagementService* site_engagement_service =
1074 SiteEngagementService::Get(profile);
1075 if (!site_engagement_service)
1076 return;
1077
1078 blink::mojom::EngagementLevel engagement_level =
1079 site_engagement_service->GetEngagementLevel(
1080 render_frame_host->GetLastCommittedURL());
1081 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1082 UMA_HISTOGRAM_ENUMERATION(
1083 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1084 engagement_level);
1085 } else {
1086 UMA_HISTOGRAM_ENUMERATION(
1087 "Net.SameSiteBlockedCookieSiteEngagement."
1088 "CookieInsecureAndSameSiteNone",
1089 engagement_level);
1090 }
1091}
1092
[email protected]9dbfff12011-07-01 19:37:071093} // namespace
[email protected]c5dbef02011-05-13 05:06:091094
Yutaka Hirano968d6252018-12-04 05:09:311095std::string GetUserAgent() {
1096 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1097 if (command_line->HasSwitch(switches::kUserAgent)) {
1098 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1099 if (net::HttpUtil::IsValidHeaderValue(ua))
1100 return ua;
1101 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1102 }
1103
John Delaneyac24e572019-04-30 19:47:021104 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1105 return content::GetFrozenUserAgent(
Maks Orlovich449df8f2020-04-02 21:21:351106 command_line->HasSwitch(switches::kUseMobileUserAgent),
1107 version_info::GetMajorVersionNumber());
John Delaneyac24e572019-04-30 19:47:021108 }
1109
Yutaka Hirano968d6252018-12-04 05:09:311110 std::string product = GetProduct();
1111#if defined(OS_ANDROID)
1112 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1113 product += " Mobile";
1114#endif
1115 return content::BuildUserAgentFromProduct(product);
1116}
1117
Mike West6e4cbb32019-02-13 09:40:171118blink::UserAgentMetadata GetUserAgentMetadata() {
1119 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171120 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301121 metadata.full_version = version_info::GetVersionNumber();
1122 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171123 metadata.platform = version_info::GetOSType();
Yoav Weiss1aeefa82020-03-06 12:02:171124 metadata.platform_version = content::GetOSVersion(false);
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361125 metadata.architecture = content::BuildCpuInfo();
1126 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171127
Aaron Tagliaboschibe775e12019-12-09 19:33:041128 metadata.mobile = false;
1129#if defined(OS_ANDROID)
1130 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1131 switches::kUseMobileUserAgent);
1132#endif
1133
Mike West6e4cbb32019-02-13 09:40:171134 return metadata;
1135}
1136
Ran Jia96d43d42018-05-02 17:14:531137ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051138 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311139 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161140#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:551141 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401142#endif
[email protected]1deace22013-05-22 06:14:461143
Ahmed Fakhryd70bf37b2018-04-04 17:07:241144#if defined(OS_CHROMEOS)
1145 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1146#endif // defined(OS_CHROMEOS)
1147
John Lee0ee748bf2019-12-11 21:35:441148#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1149 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1150#endif
1151
brettw00899e62016-11-12 02:10:171152#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131153 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271154#endif
bena06f7d62017-04-04 20:48:521155
Sigurdur Asgeirsson70696672019-02-08 16:14:511156 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401157}
1158
1159ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031160 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1161 delete extra_parts_[i];
1162 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401163}
1164
[email protected]bca18382012-06-25 19:15:231165// static
Chris Palmerac7d75642017-11-22 20:12:541166void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1167 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131168 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1169 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541170 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1171 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461172 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541173}
1174
1175// static
[email protected]37ca3fe02013-07-05 15:32:441176void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341177 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251178 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1179 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1180 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281181 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1182 // user policy in addition to the same named ones in Local State (which are
1183 // used for mapping the command-line flags).
1184 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1185 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571186 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401187 registry->RegisterDictionaryPref(
1188 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041189 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101190#if !defined(OS_ANDROID)
1191 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561192 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101193#endif
Takashi Toyoshima128441462019-10-16 04:19:171194 registry->RegisterListPref(prefs::kCorsMitigationList);
1195 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231196}
1197
[email protected]eabbfb12013-04-05 23:28:351198// static
1199void ChromeContentBrowserClient::SetApplicationLocale(
1200 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481201 // The common case is that this function is called early in Chrome startup
1202 // before any threads are created or registered. When there are no threads,
1203 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001204 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331205 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481206 return;
1207 }
1208
1209 // Otherwise we're being called to change the locale. In this case set it on
1210 // the IO thread.
thestig00844cea2015-09-08 21:44:521211 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351212
Sami Kyostila5e1306d2019-08-14 11:01:291213 base::PostTask(FROM_HERE, {BrowserThread::IO},
1214 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351215}
1216
Patrick Monette61dfef92019-05-30 23:06:271217std::unique_ptr<content::BrowserMainParts>
1218ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311219 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271220 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301221 // Construct the Main browser parts based on the OS type.
1222#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051223 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271224 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1225#elif defined(OS_MACOSX)
1226 main_parts =
1227 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1228#elif defined(OS_CHROMEOS)
1229 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1230 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261231#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271232 main_parts =
1233 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141234#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271235 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1236 startup_data_);
[email protected]b48c9182011-10-26 18:03:301237#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271238 main_parts =
1239 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041240#else
[email protected]b48c9182011-10-26 18:03:301241 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271242 main_parts =
1243 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301244#endif
1245
Xi Han9fd44002019-04-30 17:39:361246 bool add_profiles_extra_parts = true;
1247#if defined(OS_ANDROID)
1248 if (startup_data_->HasBuiltProfilePrefService())
1249 add_profiles_extra_parts = false;
1250#endif
1251 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271252 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031253
Xi Han9fd44002019-04-30 17:39:361254 // Construct additional browser parts. Stages are called in the order in
1255 // which they are added.
[email protected]c7480942011-11-08 19:18:271256#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221257#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
estaded3aa0e82016-02-17 22:55:211258 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
1259#else
riajiang7d6ec5c2017-01-25 16:40:331260 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351261#endif
1262#endif
1263
1264#if defined(OS_CHROMEOS)
1265 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331266 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221267#endif
[email protected]dc04be7c2012-03-15 23:57:491268
[email protected]e8b6ca02013-07-10 18:00:511269#if defined(USE_X11)
1270 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241271#endif
1272
Sigurdur Asgeirsson54b72702019-04-12 14:18:541273 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001274
Albert J. Wong59d85acb2017-08-10 00:50:571275 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571276
Sebastien Marchand8c0088102019-10-11 16:47:561277 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1278
Patrick Monette61dfef92019-05-30 23:06:271279 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041280
Zhenyao Mo73144652020-04-06 18:55:051281 // Always add ChromeBrowserMainExtraPartsGpu last to make sure
1282 // GpuDataManager initialization could pick up about:flags settings.
1283 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1284
[email protected]50462bf02011-11-21 19:13:311285 return main_parts;
[email protected]f967b722011-09-07 00:58:041286}
1287
michaeln96f887e22015-04-13 23:58:311288void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091289 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021290 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211291 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121292 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291293
Robert Sesek466e43e2019-08-19 22:02:021294 InitNetworkContextsParentDirectory();
1295
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1297 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311298}
1299
falkenb09d443f2016-04-07 12:36:121300bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1301 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1302}
1303
Gabriel Charettec8cca992017-08-10 18:21:491304void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1305 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1306}
1307
John Abd-El-Malek9d57f9c2019-02-20 18:50:041308bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361309 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041310}
1311
[email protected]e94bbcb2012-09-07 05:33:571312std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191313 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571314 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531315 std::string partition_id;
1316
1317 // The partition ID for webview guest processes is the string value of its
1318 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451319 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531320 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171321#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501322 // The partition ID for extensions with isolated storage is treated similarly
1323 // to the above.
1324 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1325 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1326 partition_id = site.spec();
1327#endif
[email protected]1bc28312012-11-08 08:31:531328
[email protected]056efdc2013-04-06 00:14:531329 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531330 return partition_id;
1331}
1332
1333bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1334 content::BrowserContext* browser_context,
1335 const std::string& partition_id) {
1336 // The default ID is empty and is always valid.
1337 if (partition_id.empty())
1338 return true;
1339
1340 return GURL(partition_id).is_valid();
1341}
1342
1343void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1344 content::BrowserContext* browser_context,
1345 const GURL& site,
[email protected]14acc642012-11-17 12:20:101346 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531347 std::string* partition_domain,
1348 std::string* partition_name,
1349 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101350 // Default to the browser-wide storage partition and override based on |site|
1351 // below.
1352 partition_domain->clear();
1353 partition_name->clear();
1354 *in_memory = false;
1355
brettw00899e62016-11-12 02:10:171356#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451357 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331358 site, partition_domain, partition_name, in_memory);
1359
1360 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101361 // If |can_be_default| is false, the caller is stating that the |site|
1362 // should be parsed as if it had isolated storage. In particular it is
1363 // important to NOT check ExtensionService for the is_storage_isolated()
1364 // attribute because this code path is run during Extension uninstall
1365 // to do cleanup after the Extension has already been unloaded from the
1366 // ExtensionService.
1367 bool is_isolated = !can_be_default;
1368 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341369 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1370 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101371 }
[email protected]1bc28312012-11-08 08:31:531372
[email protected]14acc642012-11-17 12:20:101373 if (is_isolated) {
1374 CHECK(site.has_host());
1375 // For extensions with isolated storage, the the host of the |site| is
1376 // the |partition_domain|. The |in_memory| and |partition_name| are only
1377 // used in guest schemes so they are cleared here.
1378 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531379 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101380 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531381 }
[email protected]1df3d972014-06-11 04:55:181382 success = true;
1383 }
1384#endif
1385
[email protected]14acc642012-11-17 12:20:101386 // Assert that if |can_be_default| is false, the code above must have found a
1387 // non-default partition. If this fails, the caller has a serious logic
1388 // error about which StoragePartition they expect to be in and it is not
1389 // safe to continue.
1390 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441391}
1392
[email protected]38b098f2012-03-14 21:11:571393content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441394ChromeContentBrowserClient::GetWebContentsViewDelegate(
1395 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101396 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321397}
1398
Bo Liu4ade6b1b22017-11-28 02:26:351399bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1400#if defined(OS_ANDROID)
1401 const base::android::ApplicationState app_state =
1402 base::android::ApplicationStatusListener::GetState();
1403 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1404 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1405 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1406#else
1407 return true;
1408#endif
1409}
1410
[email protected]6f2862742013-12-20 07:53:191411void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231412 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301413 int id = host->GetID();
1414 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341415#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491416 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061417#endif
Brett Wilson65f951c2016-11-03 22:06:121418#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401419 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031420#endif
Darin Fisher54cba872020-02-06 21:12:551421 host->AddFilter(new prerender::PrerenderMessageFilter(id));
Darin Fisher8c84328c2019-07-23 02:50:001422
Darin Fisher09aa7222019-08-29 09:27:361423 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001424 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021425
grunell086a4112017-03-02 09:23:041426 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1427 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021428 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121429 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021430 host->SetUserData(
1431 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091432 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021433 audio_debug_recordings_handler));
1434
Nico Weberaf3b00b2017-09-11 17:58:171435#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031436 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1437 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351438#endif
jeremyim364ac1182015-03-03 18:49:431439
Xiaohan Wang9b34281b2017-09-08 23:48:331440#if defined(OS_ANDROID)
1441 // Data cannot be persisted if the profile is off the record.
1442 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061443 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071444
1445 // Register CrashMemoryMetricsCollector to report oom related metrics.
1446 host->SetUserData(
1447 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1448 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331449#endif
1450
Jun Caidb3f93cc2018-07-09 21:54:551451 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061452 RendererUpdaterFactory::GetForProfile(original_profile)
1453 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071454
[email protected]a48ab7112014-08-01 16:48:031455 for (size_t i = 0; i < extra_parts_.size(); ++i)
1456 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141457}
1458
[email protected]3d7474ff2011-07-27 17:47:371459GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571460 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301461 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371462 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521463 if (!profile)
1464 return url;
1465
Marc Treib7d467b792017-12-04 13:31:031466#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291467 // If the input |url| should be assigned to the Instant renderer, make its
1468 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311469 // This needs to happen even if |url| corresponds to an isolated origin; see
1470 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131471 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1472 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031473#endif
[email protected]b3cb3a32013-07-31 01:32:291474
brettw00899e62016-11-12 02:10:171475#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301476 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1477 url);
[email protected]d5a74be2014-08-08 01:01:271478#else
1479 return url;
1480#endif
[email protected]36fb2c7c2011-04-04 15:49:081481}
1482
Alexander Yashkin6aedc6e2018-08-15 08:58:451483bool ChromeContentBrowserClient::
1484 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1485 content::BrowserContext* browser_context,
1486 content::SiteInstance* candidate_site_instance,
1487 bool is_main_frame,
1488 const GURL& candidate_url,
1489 const GURL& destination_url) {
1490 DCHECK(browser_context);
1491 DCHECK(candidate_site_instance);
1492#if BUILDFLAG(ENABLE_EXTENSIONS)
1493 return ChromeContentBrowserClientExtensionsPart::
1494 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1495 browser_context, candidate_site_instance, is_main_frame,
1496 candidate_url, destination_url);
1497#else
1498 return true;
1499#endif
1500}
1501
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521502bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411503#if defined(OS_ANDROID)
1504 return true;
1505#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421506 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411507#else
1508 return false;
1509#endif // defined(OS_ANDROID)
1510}
1511
[email protected]056ad2a2011-07-12 02:13:551512bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441513 content::BrowserContext* browser_context,
1514 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521515 Profile* profile = Profile::FromBrowserContext(browser_context);
1516 if (!profile)
1517 return false;
1518
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301519 // NTP should use process-per-site. This is a performance optimization to
1520 // reduce process count associated with NTP tabs.
1521 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1522 return true;
Peter Boström8e9b1632019-08-22 23:12:471523
1524 // The web footer experiment should share its renderer to not effectively
1525 // instantiate one per window. See https://crbug.com/993502.
1526 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1527 return true;
1528
Marc Treib7d467b792017-12-04 13:31:031529#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131530 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521531 return true;
Marc Treib7d467b792017-12-04 13:31:031532#endif
[email protected]c5dec6292013-01-25 04:54:521533
brettw00899e62016-11-12 02:10:171534#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301535 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1536 profile, effective_url))
1537 return true;
[email protected]d5a74be2014-08-08 01:01:271538#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301539
1540 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1541 // (rather than process-per-site).
1542 return false;
[email protected]056ad2a2011-07-12 02:13:551543}
1544
Lukasz Anforowicz32d27122018-04-09 21:48:331545bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1546 content::BrowserContext* browser_context,
1547 const GURL& site_url) {
1548 Profile* profile = Profile::FromBrowserContext(browser_context);
1549 if (!profile)
1550 return false;
1551
1552#if !defined(OS_ANDROID)
1553 // Instant renderers should not use a spare process, because they require
1554 // passing switches::kInstantProcess to the renderer process when it
1555 // launches. A spare process is launched earlier, before it is known which
1556 // navigation will use it, so it lacks this flag.
1557 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1558 return false;
1559#endif
1560
1561#if BUILDFLAG(ENABLE_EXTENSIONS)
1562 return ChromeContentBrowserClientExtensionsPart::
1563 ShouldUseSpareRenderProcessHost(profile, site_url);
1564#else
1565 return true;
1566#endif
1567}
1568
nickcc0d9142015-10-14 16:27:101569bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421570 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101571 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421572 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171573#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101574 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421575 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101576 return true;
1577 }
1578#endif
1579 return false;
1580}
1581
nick7d0984c2015-08-29 00:13:461582// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1583// origin-lock enforcement, where we don't have a way to efficiently know
1584// effective URLs on the IO thread, and wind up killing processes that e.g.
1585// request cookies for their actual URL. This whole function (and its
1586// ExtensionsPart) should be removed once we add that ability to the IO thread.
1587bool ChromeContentBrowserClient::ShouldLockToOrigin(
1588 content::BrowserContext* browser_context,
1589 const GURL& effective_site_url) {
1590 // Origin lock to the search scheme would kill processes upon legitimate
1591 // requests for cookies from the search engine's domain.
1592 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1593 return false;
1594
brettw00899e62016-11-12 02:10:171595#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461596 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1597 browser_context, effective_site_url)) {
1598 return false;
1599 }
1600#endif
1601 return true;
creise5d6d1732015-08-25 19:47:061602}
1603
Maks Orlovich0e23e312019-07-16 13:13:561604bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021605 base::StringPiece scheme,
1606 bool is_embedded_origin_secure) {
1607 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1608 return true;
Maks Orlovich0e23e312019-07-16 13:13:561609#if BUILDFLAG(ENABLE_EXTENSIONS)
1610 return scheme == extensions::kExtensionScheme;
1611#else
1612 return false;
1613#endif
1614}
1615
Lily Chen0db055b2019-11-15 20:29:021616bool ChromeContentBrowserClient::
1617 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1618 base::StringPiece scheme,
1619 bool is_embedded_origin_secure) {
1620 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1621}
1622
Lukasz Anforowicz7097890d2019-11-20 21:49:221623void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021624 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591625 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021626 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221627 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071628#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221629 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021630 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071631#endif
1632}
1633
[email protected]73b718f2014-01-27 02:59:461634// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1635// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411636void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1637 std::vector<std::string>* additional_schemes) {
1638 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241639 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351640 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061641}
1642
alexmos94875b3b2017-03-16 22:19:011643void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1644 std::vector<std::string>* additional_schemes) {
1645 GetAdditionalWebUISchemes(additional_schemes);
1646
1647#if BUILDFLAG(ENABLE_EXTENSIONS)
1648 additional_schemes->push_back(extensions::kExtensionScheme);
1649#endif
1650}
1651
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521652bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011653 return webui::LogWebUIUrl(web_ui_url);
1654}
1655
John Abd-El-Malek04bfa8532018-07-12 05:28:221656bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1657 const url::Origin& origin) {
1658 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1659 origin);
1660}
1661
[email protected]46fb9442011-12-09 17:57:471662bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1663 return ProfileIOData::IsHandledURL(url);
1664}
1665
[email protected]c4365fa42013-05-14 01:08:241666bool ChromeContentBrowserClient::CanCommitURL(
1667 content::RenderProcessHost* process_host,
1668 const GURL& url) {
brettw00899e62016-11-12 02:10:171669#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441670 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1671 url);
[email protected]d5a74be2014-08-08 01:01:271672#else
1673 return true;
1674#endif
[email protected]c4365fa42013-05-14 01:08:241675}
1676
rdevlin.cronina32a0902016-11-09 15:50:201677void ChromeContentBrowserClient::OverrideNavigationParams(
1678 SiteInstance* site_instance,
1679 ui::PageTransition* transition,
1680 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581681 content::Referrer* referrer,
1682 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201683 DCHECK(transition);
1684 DCHECK(is_renderer_initiated);
1685 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471686 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1687 // use for making security decisions 99.44% of the time, for detecting the NTP
1688 // it is reliable and the correct way. See http://crbug.com/624410.
1689 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201690 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581691 // Clicks on tiles of the new tab page should be treated as if a user
1692 // clicked on a bookmark. This is consistent with native implementations
1693 // like Android's. This also helps ensure that security features (like
1694 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1695 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201696 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1697 *is_renderer_initiated = false;
1698 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581699 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421700 }
1701}
1702
Charles Reis29e9dd12017-09-28 00:59:151703bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1704 const GURL& url,
1705 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471706 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1707 // use for making security decisions 99.44% of the time, for detecting the NTP
1708 // it is reliable and the correct way. See http://crbug.com/624410.
1709 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1710 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151711}
1712
[email protected]2a5221b2011-09-27 23:07:311713bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301714 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311715 const GURL& site_url) {
1716 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301717 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441718 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521719 // share any host.
1720 if (!profile)
1721 return true;
1722
Marc Treib7895941d2017-11-28 12:37:021723#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141724 // Instant URLs should only be in the instant process and instant process
1725 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521726 InstantService* instant_service =
1727 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141728 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441729 bool is_instant_process =
1730 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141731 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131732 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141733 if (is_instant_process || should_be_in_instant_process)
1734 return is_instant_process && should_be_in_instant_process;
1735 }
Marc Treib7895941d2017-11-28 12:37:021736#endif
[email protected]c5dec6292013-01-25 04:54:521737
brettw00899e62016-11-12 02:10:171738#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131739 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1740 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271741#else
1742 return true;
1743#endif
[email protected]2a5221b2011-09-27 23:07:311744}
1745
[email protected]28c5d0b72014-05-13 08:19:591746bool ChromeContentBrowserClient::MayReuseHost(
1747 content::RenderProcessHost* process_host) {
1748 // If there is currently a prerender in progress for the host provided,
1749 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041750 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591751 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371752 prerender::PrerenderManagerFactory::GetForBrowserContext(
1753 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591754 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491755 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591756 return false;
1757 }
1758
1759 return true;
1760}
1761
[email protected]76411f412012-02-22 18:56:061762bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441763 content::BrowserContext* browser_context,
1764 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061765 // It has to be a valid URL for us to check for an extension.
1766 if (!url.is_valid())
1767 return false;
1768
brettw00899e62016-11-12 02:10:171769#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061770 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131771 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441772 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271773#else
1774 return false;
1775#endif
[email protected]76411f412012-02-22 18:56:061776}
1777
Alex Moshchuk9c9e3882018-11-02 19:57:031778bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1779 content::RenderFrameHost* main_frame) {
1780#if BUILDFLAG(ENABLE_EXTENSIONS)
1781 return ChromeContentBrowserClientExtensionsPart::
1782 ShouldSubframesTryToReuseExistingProcess(main_frame);
1783#else
1784 return true;
1785#endif
1786}
1787
[email protected]6f371442011-11-09 06:45:461788void ChromeContentBrowserClient::SiteInstanceGotProcess(
1789 SiteInstance* site_instance) {
1790 CHECK(site_instance->HasProcess());
1791
Aran Gilmanf010bdd2019-08-28 19:55:441792 Profile* profile =
1793 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521794 if (!profile)
1795 return;
1796
Marc Treib7895941d2017-11-28 12:37:021797#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521798 // Remember the ID of the Instant process to signal the renderer process
1799 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131800 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1801 profile)) {
[email protected]c5dec6292013-01-25 04:54:521802 InstantService* instant_service =
1803 InstantServiceFactory::GetForProfile(profile);
1804 if (instant_service)
1805 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1806 }
Marc Treib7895941d2017-11-28 12:37:021807#endif
[email protected]c5dec6292013-01-25 04:54:521808
[email protected]a48ab7112014-08-01 16:48:031809 for (size_t i = 0; i < extra_parts_.size(); ++i)
1810 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461811}
1812
1813void ChromeContentBrowserClient::SiteInstanceDeleting(
1814 SiteInstance* site_instance) {
1815 if (!site_instance->HasProcess())
1816 return;
1817
[email protected]a48ab7112014-08-01 16:48:031818 for (size_t i = 0; i < extra_parts_.size(); ++i)
1819 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461820}
1821
[email protected]453f5432013-11-26 19:43:001822bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141823 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561824 const GURL& current_effective_url,
1825 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171826#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131827 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561828 ShouldSwapBrowsingInstancesForNavigation(
1829 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271830#else
1831 return false;
1832#endif
[email protected]e3daf3c2011-10-05 21:17:081833}
1834
Nasko Oskovd83b5712018-05-04 04:50:571835bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1836 // TODO(nasko): Consider supporting error page isolation in subframes if
1837 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381838 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571839}
1840
[email protected]3d831992013-07-04 01:13:291841bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1842 return !url.SchemeIs(chrome::kChromeNativeScheme);
1843}
1844
Alex Moshchukd252c192017-07-17 22:03:481845std::vector<url::Origin>
1846ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1847 std::vector<url::Origin> isolated_origin_list;
1848
Alex Moshchuk89352a72017-10-25 20:25:591849// Sign-in process isolation is not needed on Android, see
1850// https://crbug.com/739418.
1851#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381852 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121853 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591854#endif
Alex Moshchukd252c192017-07-17 22:03:481855
Alex Moshchuk81d2a29e2019-07-16 01:14:381856#if BUILDFLAG(ENABLE_EXTENSIONS)
1857 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1858 GetOriginsRequiringDedicatedProcess();
1859 std::move(std::begin(origins_from_extensions),
1860 std::end(origins_from_extensions),
1861 std::back_inserter(isolated_origin_list));
1862#endif
1863
Alex Moshchuk51e1428b2020-04-22 18:00:541864 // Include additional origins preloaded with specific browser configurations,
1865 // if any. For example, this is used on Google Chrome for Android to preload
1866 // a list of important sites to isolate.
1867 auto built_in_origins =
1868 site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins();
1869 std::move(std::begin(built_in_origins), std::end(built_in_origins),
1870 std::back_inserter(isolated_origin_list));
1871
Alex Moshchukd252c192017-07-17 22:03:481872 return isolated_origin_list;
1873}
1874
Lukasz Anforowicz5e201abd2018-03-24 00:41:061875bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341876 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1877}
1878
1879bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371880 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061881}
1882
Alex Moshchuk082b5f82019-03-14 01:34:161883std::vector<std::string>
1884ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1885 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1886 return {"Isolate Password Sites"};
1887 else
1888 return {};
1889}
1890
Alex Moshchuke256d562019-04-26 21:43:571891void ChromeContentBrowserClient::PersistIsolatedOrigin(
1892 content::BrowserContext* context,
1893 const url::Origin& origin) {
1894 DCHECK(!context->IsOffTheRecord());
1895 Profile* profile = Profile::FromBrowserContext(context);
1896 ListPrefUpdate update(profile->GetPrefs(),
1897 prefs::kUserTriggeredIsolatedOrigins);
1898 base::ListValue* list = update.Get();
1899 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361900 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121901 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571902}
1903
Ken Rockot314714c2017-11-05 23:36:241904bool ChromeContentBrowserClient::IsFileAccessAllowed(
1905 const base::FilePath& path,
1906 const base::FilePath& absolute_path,
1907 const base::FilePath& profile_path) {
1908 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1909 profile_path);
1910}
1911
[email protected]d2e1a0a2014-06-16 15:49:371912namespace {
1913
1914bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171915 const base::CommandLine& browser_command_line =
1916 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351917 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371918 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351919 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371920 return false;
[email protected]9ef49b42014-08-07 16:44:241921 return true;
[email protected]d2e1a0a2014-06-16 15:49:371922}
1923
bmcquade5d2d9cf32015-06-19 17:42:281924void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1925 const base::CommandLine& browser_command_line,
1926 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521927 // List of field trials that modify the blink-settings command line flag. No
1928 // two field trials in the list should specify the same keys, otherwise one
1929 // field trial may overwrite another. See Source/core/frame/Settings.in in
1930 // Blink for the list of valid keys.
1931 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161932 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1933 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1934 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1935 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521936 };
1937
1938 std::vector<std::string> blink_settings;
1939 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1940 // Each blink-settings field trial should include a forcing_flag group,
1941 // to make sure that clients that specify the blink-settings flag on the
1942 // command line are excluded from the experiment groups. To make
1943 // sure we assign clients that specify this flag to the forcing_flag
1944 // group, we must call GetVariationParams for each field trial first
1945 // (for example, before checking HasSwitch() and returning), since
1946 // GetVariationParams has the side-effect of assigning the client to
1947 // a field trial group.
1948 std::map<std::string, std::string> params;
1949 if (variations::GetVariationParams(field_trial_name, &params)) {
1950 for (const auto& param : params) {
1951 blink_settings.push_back(base::StringPrintf(
1952 "%s=%s", param.first.c_str(), param.second.c_str()));
1953 }
1954 }
1955 }
pmeenan9ac669682015-08-17 14:57:031956
bmcquade9dd54cc2015-06-22 16:56:521957 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281958 return;
1959 }
1960
1961 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1962 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031963 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521964 // blink-settings flag into a group with no params, and we return
1965 // above if no params were specified, so it's an error if we reach
1966 // this point.
bmcquade5d2d9cf32015-06-19 17:42:281967 LOG(WARNING) << "Received field trial params, "
1968 "but blink-settings switch already specified.";
1969 return;
1970 }
1971
bmcquade5d2d9cf32015-06-19 17:42:281972 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:261973 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:281974}
1975
[email protected]d2e1a0a2014-06-16 15:49:371976} // namespace
1977
[email protected]b80f68432011-05-02 17:22:301978void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:171979 base::CommandLine* command_line,
1980 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:061981#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:351982 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:061983 GoogleUpdateSettings::LoadMetricsClientInfo();
1984 if (client_info) {
1985 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1986 client_info->client_id);
1987 }
1988#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:021989#if defined(OS_ANDROID)
1990 bool enable_crash_reporter = true;
1991#else
Joshua Perazace68e2f2019-09-23 18:44:241992 bool enable_crash_reporter = false;
1993 if (crash_reporter::IsCrashpadEnabled()) {
1994 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
1995 enable_crash_reporter = true;
1996
1997 int fd;
1998 pid_t pid;
1999 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2000 command_line->AppendSwitchASCII(
2001 crash_reporter::switches::kCrashpadHandlerPid,
2002 base::NumberToString(pid));
2003 }
2004 } else {
2005 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2006 }
Joshua Perazaf890e4b2019-01-03 19:19:022007#endif
2008 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512009 std::string switch_value;
dcheng4af48582016-04-19 00:29:352010 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532011 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512012 if (client_info)
2013 switch_value = client_info->client_id;
2014 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252015 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302016 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512017 switch_value);
[email protected]b80f68432011-05-02 17:22:302018 }
Mark Mentovaic67fa64f2015-03-24 14:00:062019#endif
[email protected]b80f68432011-05-02 17:22:302020
[email protected]f1933792011-06-14 00:49:342021 if (logging::DialogsAreSuppressed())
2022 command_line->AppendSwitch(switches::kNoErrorDialogs);
2023
[email protected]b80f68432011-05-02 17:22:302024 std::string process_type =
2025 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172026 const base::CommandLine& browser_command_line =
2027 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322028
[email protected]7c9b6f92013-09-10 18:11:352029 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442030 switches::kUserAgent,
2031 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352032 };
2033 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372034 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322035
fqj15ff3f72015-10-09 19:20:022036 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432037 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312038 };
fqj15ff3f72015-10-09 19:20:022039 command_line->CopySwitchesFrom(browser_command_line,
2040 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372041 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312042
David Van Cleve3df6abb2019-11-26 17:52:512043 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2044 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2045
fqj15ff3f72015-10-09 19:20:022046#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332047 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2048 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522049 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332050 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2051 homedir.value().c_str());
2052#endif
2053
[email protected]718eab62011-10-05 21:16:522054 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032055 content::RenderProcessHost* process =
2056 content::RenderProcessHost::FromID(child_process_id);
2057 Profile* profile =
2058 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442059 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032060 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442061 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2062 process, profile);
[email protected]a48ab7112014-08-01 16:48:032063 }
2064
[email protected]b80f68432011-05-02 17:22:302065#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442066 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2067 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302068 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442069 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2070 login_profile);
[email protected]b80f68432011-05-02 17:22:302071#endif
2072
Aran Gilmanf010bdd2019-08-28 19:55:442073 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222074 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372075 if (process) {
[email protected]a8d851f82011-12-21 00:32:372076 PrefService* prefs = profile->GetPrefs();
2077 // Currently this pref is only registered if applied via a policy.
2078 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2079 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2080 // Turn this policy into a command line switch.
2081 command_line->AppendSwitch(switches::kDisable3DAPIs);
2082 }
[email protected]718eab62011-10-05 21:16:522083
[email protected]1733b782014-06-19 18:51:552084 const base::ListValue* switches =
2085 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2086 if (switches) {
2087 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112088 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552089 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142090 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552091 command_line->AppendSwitch(switch_to_enable);
2092 }
2093 }
2094
[email protected]a8d851f82011-12-21 00:32:372095 // Disable client-side phishing detection in the renderer if it is
2096 // disabled in the Profile preferences or the browser process.
Bettinae83f522c72020-03-12 01:52:332097 if (!safe_browsing::IsSafeBrowsingEnabled(*prefs) ||
[email protected]a8d851f82011-12-21 00:32:372098 !g_browser_process->safe_browsing_detection_service()) {
2099 command_line->AppendSwitch(
2100 switches::kDisableClientSidePhishingDetection);
2101 }
[email protected]0045b0f42012-07-26 11:52:082102
vitalybukaa7ae5052014-09-26 04:11:132103 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2104 command_line->AppendSwitch(switches::kDisablePrintPreview);
2105
Marc Treib7895941d2017-11-28 12:37:022106#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522107 InstantService* instant_service =
2108 InstantServiceFactory::GetForProfile(profile);
2109 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542110 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522111 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542112 }
Marc Treib7895941d2017-11-28 12:37:022113#endif
fqjba8749c2015-10-29 15:33:072114
fqj38306f7b2015-11-02 16:59:062115 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542116 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432117 command_line->AppendSwitch(
2118 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542119 }
Daniel Vogelheim976f1c22017-11-22 16:26:032120
Lukasz Anforowicz60d1253d2019-05-08 16:31:372121 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2122
Amr Aboelkherb04cbf32019-04-29 15:17:102123 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2124 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292125 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102126 }
Katie Dillonc25ee5c92019-09-12 17:05:422127
2128 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2129 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2130 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2131 }
Takashi Toyoshima128441462019-10-16 04:19:172132
Mason Freed490f2a22019-11-05 21:41:292133 if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) &&
2134 prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) {
2135 command_line->AppendSwitch(switches::kWebComponentsV0Enabled);
2136 }
Mason Freed52fa36d72020-02-27 17:52:482137 if (prefs->HasPrefPath(prefs::kUseLegacyFormControls) &&
2138 prefs->GetBoolean(prefs::kUseLegacyFormControls)) {
2139 command_line->AppendSwitch(switches::kUseLegacyFormControls);
2140 }
Mason Freed490f2a22019-11-05 21:41:292141
Daniel Libbyc5bfd91f2020-03-07 03:44:102142 if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) &&
2143 !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) {
2144 command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
2145 }
2146
Takashi Toyoshima0dab73302019-10-18 01:51:362147 if (!profile->ShouldEnableOutOfBlinkCors()) {
2148 command_line->AppendSwitch(
2149 network::switches::kForceToDisableOutOfBlinkCors);
2150 }
[email protected]47c7ec82012-01-18 03:29:212151 }
[email protected]4287a3d2011-06-13 23:56:512152
[email protected]d2e1a0a2014-06-16 15:49:372153 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352154 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042155
Aran Gilmanf010bdd2019-08-28 19:55:442156 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2157 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282158
mdjonesa6b9e172016-09-23 16:24:302159#if defined(OS_ANDROID)
2160 // If the platform is Android, force the distillability service on.
2161 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2162#endif
2163
[email protected]47c7ec82012-01-18 03:29:212164 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512165 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192166 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412167 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302168#if defined(OS_CHROMEOS)
2169 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2170#endif
brettw00899e62016-11-12 02:10:172171#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512172 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272173 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172174 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512175 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272176 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172177 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172178 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282179#endif
estark4b003b332015-02-14 01:07:052180 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512181 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482182 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512183 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502184 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572185 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462186 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302187 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512188 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172189#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242190 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482191 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552192#endif
[email protected]ce304ce2013-02-22 21:54:452193 switches::kEnableNetBenchmarking,
Anatoliy Potapchukce6f8802020-01-30 09:30:342194#if defined(OS_CHROMEOS)
2195 switches::kForceAppMode,
2196#endif
Nico Weberaf3b00b2017-09-11 17:58:172197#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592198 switches::kForcePNaClSubzero,
2199#endif
Marc Treibad33cf942017-08-24 11:19:002200 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512201 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102202 switches::kEnableExperimentalWebAssemblyFeatures,
Clark DuVall3d4e89b92020-04-03 23:07:322203 embedder_support::kOriginTrialDisabledFeatures,
2204 embedder_support::kOriginTrialDisabledTokens,
2205 embedder_support::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512206 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512207 switches::kPpapiFlashPath,
2208 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032209 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092210 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512211 };
2212
2213 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372214 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172215 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172216#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382217 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442218 extensions::switches::kAllowHTTPBackgroundPage,
2219 extensions::switches::kEnableExperimentalExtensionApis,
2220 extensions::switches::kExtensionsOnChromeURLs,
2221 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382222 };
2223
2224 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372225 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282226#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372227 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132228 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512229 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512230 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502231 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172232#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242233 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582234 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592235 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412236 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552237#endif
[email protected]4287a3d2011-06-13 23:56:512238 switches::kPpapiFlashPath,
2239 switches::kPpapiFlashVersion,
2240 };
2241
2242 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372243 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112244 } else if (process_type == switches::kGpuProcess) {
2245 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2246 // because GPU is expected to be unreliable.
2247 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2248 !command_line->HasSwitch(switches::kDisableBreakpad))
2249 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302250 }
[email protected]6f08af82011-09-15 01:19:032251
Ian Barkley-Yeung550aae052019-07-11 00:11:112252#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302253 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112254 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292255 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112256 };
2257 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2258 base::size(kSwitchNames));
2259 }
2260#endif
2261
wittman832321f52016-10-10 18:18:382262 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442263 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342264
2265#if defined(OS_LINUX)
2266 // Processes may only query perf_event_open with the BPF sandbox disabled.
2267 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2268 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2269 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2270 }
2271#endif
[email protected]b80f68432011-05-02 17:22:302272}
2273
Olivier Yiptong0daa93f2019-08-22 19:40:082274std::string
2275ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2276 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2277}
2278
[email protected]b80f68432011-05-02 17:22:302279std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432280 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332281 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302282 return g_browser_process->GetApplicationLocale();
2283}
2284
[email protected]597a867b2011-11-18 18:31:202285std::string ChromeContentBrowserClient::GetAcceptLangs(
2286 content::BrowserContext* context) {
2287 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202288 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082289}
2290
Dana Fried34d580002019-04-24 20:05:482291gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492292 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482293 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082294}
2295
bengre8a146f2016-03-10 01:20:222296bool ChromeContentBrowserClient::IsDataSaverEnabled(
2297 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382298 if (!browser_context || browser_context->IsOffTheRecord())
2299 return false;
2300
Robert Ogdenc995d4fe2019-03-25 19:18:372301 Profile* profile = Profile::FromBrowserContext(browser_context);
2302 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412303 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2304 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222305}
2306
Kenichi Ishibashi46329872018-07-17 09:43:402307void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2308 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192309 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402310 DCHECK(browser_context);
2311 DCHECK(out_prefs);
2312 renderer_preferences_util::UpdateFromSystemSettings(
2313 out_prefs, Profile::FromBrowserContext(browser_context));
2314}
2315
Clark DuVall5690e742019-07-17 18:26:172316bool ChromeContentBrowserClient::AllowAppCache(
2317 const GURL& manifest_url,
2318 const GURL& first_party,
2319 content::BrowserContext* context) {
2320 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2321 return CookieSettingsFactory::GetForProfile(
2322 Profile::FromBrowserContext(context))
2323 ->IsCookieAccessAllowed(manifest_url, first_party);
2324}
2325
Matt Falkenhagen7b509e52019-08-15 23:11:412326bool ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072327 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542328 const GURL& site_for_cookies,
2329 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362330 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202331 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342332 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522333 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542334 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452335
brettw00899e62016-11-12 02:10:172336#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452337 // Check if this is an extension-related service worker, and, if so, if it's
2338 // allowed (this can return false if, e.g., the extension is disabled).
2339 // If it's not allowed, return immediately. We deliberately do *not* report
2340 // to the TabSpecificContentSettings, since the service worker is blocked
2341 // because of the extension, rather than because of the user's content
2342 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022343 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362344 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452345 return false;
2346 }
2347#endif
2348
falken3dbc36e2014-10-10 16:48:072349 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202350
shimazuce8af88122016-10-06 23:49:212351 // Check if JavaScript is allowed.
2352 content_settings::SettingInfo info;
2353 std::unique_ptr<base::Value> value =
2354 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452355 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212356 std::string(), &info);
2357 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2358 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2359
2360 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542361 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2362 scope, site_for_cookies, top_frame_origin);
falken4a22dce2015-04-30 08:25:202363 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242364 // Only post the task if this is for a specific tab.
2365 if (!wc_getter.is_null()) {
Sami Kyostila5e1306d2019-08-14 11:01:292366 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:282367 FROM_HERE, {BrowserThread::UI},
Clark DuVall84a33d612020-04-17 16:01:002368 base::BindOnce(&content_settings::TabSpecificContentSettings::
2369 ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342370 std::move(wc_getter), scope, !allow_javascript,
Christian Dullweber2a2f2182019-09-25 15:44:542371 !allow_cookies));
rdevlin.croninf5863da2015-09-10 19:21:452372 }
Christian Dullweber2a2f2182019-09-25 15:44:542373 return allow_javascript && allow_cookies;
falken3dbc36e2014-10-10 16:48:072374}
2375
Matt Falkenhagen7b509e52019-08-15 23:11:412376bool ChromeContentBrowserClient::AllowServiceWorkerOnUI(
2377 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542378 const GURL& site_for_cookies,
2379 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412380 const GURL& script_url,
2381 content::BrowserContext* context,
2382 base::RepeatingCallback<content::WebContents*()> wc_getter) {
2383 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542384 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412385
2386#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022387 // Check if this is an extension-related service worker, and, if so, if it's
2388 // allowed (this can return false if, e.g., the extension is disabled).
2389 // If it's not allowed, return immediately. We deliberately do *not* report
2390 // to the TabSpecificContentSettings, since the service worker is blocked
2391 // because of the extension, rather than because of the user's content
2392 // settings.
2393 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2394 scope, first_party_url, script_url, context)) {
2395 return false;
2396 }
Matt Falkenhagen7b509e52019-08-15 23:11:412397#endif
2398
2399 Profile* profile = Profile::FromBrowserContext(context);
2400
2401 // Check if JavaScript is allowed.
2402 content_settings::SettingInfo info;
2403 std::unique_ptr<base::Value> value =
2404 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452405 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412406 std::string(), &info);
2407 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2408 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2409
2410 // Check if cookies are allowed.
2411 bool allow_cookies =
2412 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542413 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412414
2415 // Record access to database for potential display in UI.
2416 // Only post the task if this is for a specific tab.
2417 if (!wc_getter.is_null()) {
Clark DuVall84a33d612020-04-17 16:01:002418 content_settings::TabSpecificContentSettings::ServiceWorkerAccessed(
Matt Falkenhagen7b509e52019-08-15 23:11:412419 std::move(wc_getter), scope, !allow_javascript, !allow_cookies);
2420 }
2421 return allow_javascript && allow_cookies;
2422}
2423
Jochen Eisinger0ff7645c2017-11-28 08:11:262424bool ChromeContentBrowserClient::AllowSharedWorker(
2425 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542426 const GURL& site_for_cookies,
2427 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262428 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372429 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262430 content::BrowserContext* context,
2431 int render_process_id,
2432 int render_frame_id) {
2433 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2434
2435 // Check if cookies are allowed.
2436 bool allow =
2437 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542438 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2439 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262440
Clark DuVall84a33d612020-04-17 16:01:002441 content_settings::TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372442 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2443 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262444 return allow;
2445}
2446
Patrick Monette6cb099a2019-09-18 19:31:272447bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2448 const std::string& scheme) {
2449#if BUILDFLAG(ENABLE_EXTENSIONS)
2450 // Extensions are allowed to start cross-origin shared workers.
2451 if (scheme == extensions::kExtensionScheme)
2452 return true;
2453#endif
2454
2455 return false;
2456}
2457
Clark DuVallab63d142019-07-23 04:24:362458bool ChromeContentBrowserClient::AllowSignedExchange(
2459 content::BrowserContext* browser_context) {
2460 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2461 Profile* profile = Profile::FromBrowserContext(browser_context);
2462 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2463}
2464
[email protected]f917df22014-07-10 07:45:492465void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352466 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572467 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172468 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572469 base::OnceCallback<void(bool)> callback) {
2470 Profile* profile = Profile::FromBrowserContext(browser_context);
2471 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002472 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352473
brettw00899e62016-11-12 02:10:172474#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572475 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492476#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572477 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492478#endif
2479}
2480
brettw00899e62016-11-12 02:10:172481#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492482void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2483 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172484 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572485 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492486 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572487 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492488 std::map<int, int> process_map;
2489 std::map<int, int>::const_iterator it;
2490 bool has_web_view_guest = false;
2491 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172492 for (const auto& it : render_frames) {
2493 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492494 continue;
2495
Lukasz Anforowicz09060bdf72018-08-23 15:53:172496 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492497
Lukasz Anforowicz09060bdf72018-08-23 15:53:172498 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492499 has_web_view_guest = true;
2500 }
2501 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572502 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492503 return;
2504 }
[email protected]dffb9fc2014-07-16 04:14:022505 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492506 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492507
[email protected]140d6cd92014-08-12 18:26:462508 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572509 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2510 web_view_permission_helper->RequestFileSystemPermission(
2511 url, allow,
2512 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2513 weak_factory_.GetWeakPtr(), url, render_frames,
2514 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492515}
2516#endif
2517
2518void ChromeContentBrowserClient::FileSystemAccessed(
2519 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172520 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572521 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492522 bool allow) {
[email protected]62151052012-02-01 18:40:482523 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172524 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002525 content_settings::TabSpecificContentSettings::FileSystemAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572526 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352527 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572528 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352529}
2530
[email protected]7c5ff9a2012-03-02 07:42:492531bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2532 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572533 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172534 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572535 Profile* profile = Profile::FromBrowserContext(browser_context);
2536 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2537
falken71691402017-01-27 03:38:002538 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492539
2540 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172541 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002542 content_settings::TabSpecificContentSettings::IndexedDBAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572543 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492544 }
2545
2546 return allow;
2547}
2548
Ben Kelly6b2e61c2019-03-14 16:06:292549bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2550 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572551 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292552 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572553 Profile* profile = Profile::FromBrowserContext(browser_context);
2554 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292555 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2556
2557 // Record access to CacheStorage for potential display in UI.
2558 for (const auto& it : render_frames) {
Clark DuVall84a33d612020-04-17 16:01:002559 content_settings::TabSpecificContentSettings::CacheStorageAccessed(
John Abd-El-Malek2a18d98d2019-08-08 04:31:572560 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292561 }
2562
2563 return allow;
2564}
2565
Joshua Bell1ebc8df2019-11-06 00:27:582566bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2567 const GURL& url,
2568 content::BrowserContext* browser_context,
2569 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2570 Profile* profile = Profile::FromBrowserContext(browser_context);
2571 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2572 return cookie_settings->IsCookieAccessAllowed(url, url);
2573}
2574
jyasskinc993ce8d2016-03-31 00:38:342575ChromeContentBrowserClient::AllowWebBluetoothResult
2576ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452577 content::BrowserContext* browser_context,
2578 const url::Origin& requesting_origin,
2579 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342580 // TODO(crbug.com/598890): Don't disable if
2581 // base::CommandLine::ForCurrentProcess()->
2582 // HasSwitch(switches::kEnableWebBluetooth) is true.
2583 if (variations::GetVariationParamValue(
Clark DuValla11361ad32020-02-20 22:14:272584 permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy,
jyasskinc993ce8d2016-03-31 00:38:342585 "Bluetooth") ==
Clark DuValla11361ad32020-02-20 22:14:272586 permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
jyasskinc993ce8d2016-03-31 00:38:342587 // The kill switch is enabled for this permission. Block requests.
2588 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2589 }
2590
jyasskin98bdd3992016-02-26 20:25:452591 const HostContentSettingsMap* const content_settings =
2592 HostContentSettingsMapFactory::GetForProfile(
2593 Profile::FromBrowserContext(browser_context));
2594
csharrisonaec2c542016-10-12 19:40:362595 if (content_settings->GetContentSetting(
2596 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452597 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362598 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342599 return AllowWebBluetoothResult::BLOCK_POLICY;
2600 }
2601 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452602}
2603
beaufort.francois01135bf2016-11-23 14:37:362604std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2605 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2606 "blocklist_additions");
scheib74250322016-04-07 03:32:212607}
2608
John Abd-El-Malek21bca7c2018-10-26 22:13:332609#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522610void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072611 content::BrowserContext* browser_context) {
2612 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2613 if (user_manager) {
2614 const user_manager::User* user =
2615 chromeos::ProfileHelper::Get()->GetUserByProfile(
2616 Profile::FromBrowserContext(browser_context));
2617 if (user && !user->username_hash().empty()) {
2618 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2619 user->username_hash());
2620 }
2621 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332622}
2623#endif
2624
Reilly Grant19aaccd2018-07-16 22:06:372625scoped_refptr<network::SharedURLLoaderFactory>
2626ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2628 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2629
2630 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372631 return nullptr;
2632
Min Qinda0d55b2018-10-12 18:30:052633 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372634 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042635}
2636
Sean Gilhulyda1ee4b2018-11-13 21:56:092637network::mojom::NetworkContext*
2638ChromeContentBrowserClient::GetSystemNetworkContext() {
2639 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2640 DCHECK(g_browser_process->system_network_context_manager());
2641 return g_browser_process->system_network_context_manager()->GetContext();
2642}
2643
Andrew Moylan17329fc2017-09-25 07:43:302644std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2645 return google_apis::GetAPIKey();
2646}
2647
Ke He21ee87f2018-05-30 02:35:322648#if defined(OS_ANDROID)
2649bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2650 // Indicate that Chrome uses the GMS core location provider.
2651 return true;
2652}
2653#endif
2654
Yeolf3dc22ca2019-04-18 17:25:322655scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412656ChromeContentBrowserClient::CreateQuotaPermissionContext() {
Scott Violet93893782020-03-27 16:23:542657 return new permissions::QuotaPermissionContextImpl();
[email protected]317f96c92011-05-31 06:53:412658}
2659
Mythri Alle0b8de0d2018-10-22 11:06:222660content::GeneratedCodeCacheSettings
2661ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2662 content::BrowserContext* context) {
2663 base::FilePath cache_path;
2664 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2665 // If we pass 0 for size, disk_cache will pick a default size using the
2666 // heuristics based on available disk size. These are implemented in
2667 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162668 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132669 DCHECK(g_browser_process);
2670 PrefService* local_state = g_browser_process->local_state();
2671 if (local_state) {
2672 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2673 base::FilePath disk_cache_dir =
2674 local_state->GetFilePath(prefs::kDiskCacheDir);
2675 if (!disk_cache_dir.empty())
2676 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2677 }
Mythri Ab2486572019-06-13 14:48:162678 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222679}
2680
[email protected]848dd042011-06-04 18:24:032681void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262682 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172683 int cert_error,
2684 const net::SSLInfo& ssl_info,
2685 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232686 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222687 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262688 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262689 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232690 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142691 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022692 // have a context for making the right decision, so block the
2693 // request hard, without an info bar to allow showing the insecure
2694 // content.
estark719dde52016-08-09 03:14:272695 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262696 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022697 return;
2698 }
2699
[email protected]f9034cf2011-07-21 12:43:412700 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572701 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262702 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572703 if (prerender_contents) {
2704 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272705 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262706 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272707 }
[email protected]09667f02014-01-06 15:37:572708 return;
[email protected]f9034cf2011-07-21 12:43:412709 }
2710
Erik Staaba65a6032019-11-27 22:23:262711 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282712 return;
[email protected]848dd042011-06-04 18:24:032713}
2714
Alexander Hendrichbcf2616e2018-05-18 08:21:102715namespace {
2716
Pavol Markob211ab22019-01-23 20:03:042717certificate_matching::CertificatePrincipalPattern
2718ParseCertificatePrincipalPattern(const base::Value* pattern) {
2719 return certificate_matching::CertificatePrincipalPattern::
2720 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2721}
2722
Alexander Hendrichbcf2616e2018-05-18 08:21:102723// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452724// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102725// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2726std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2727 Profile* profile,
2728 const GURL& requesting_url,
2729 net::ClientCertIdentityList& client_certs) {
2730 HostContentSettingsMap* host_content_settings_map =
2731 HostContentSettingsMapFactory::GetForProfile(profile);
2732 std::unique_ptr<base::Value> setting =
2733 host_content_settings_map->GetWebsiteSetting(
2734 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452735 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102736
Pavol Markob211ab22019-01-23 20:03:042737 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102738 return nullptr;
2739
Alexander Hendrichbcf2616e2018-05-18 08:21:102740 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042741 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2742 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102743 // |setting_dict| has the wrong format (e.g. single filter instead of a
2744 // list of filters). This content setting is only provided by
2745 // the |PolicyProvider|, which should always set it to a valid format.
2746 // Therefore, delete the invalid value.
2747 host_content_settings_map->SetWebsiteSettingDefaultScope(
2748 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452749 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042750 return nullptr;
2751 }
2752
2753 for (const base::Value& filter : filters->GetList()) {
2754 DCHECK(filter.is_dict());
2755
2756 auto issuer_pattern = ParseCertificatePrincipalPattern(
2757 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2758 auto subject_pattern = ParseCertificatePrincipalPattern(
2759 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2760 // Use the first certificate that is matched by the filter.
2761 for (auto& client_cert : client_certs) {
2762 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2763 subject_pattern.Matches(client_cert->certificate()->subject())) {
2764 return std::move(client_cert);
2765 }
2766 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102767 }
2768
2769 return nullptr;
2770}
2771
2772} // namespace
2773
Daniel McArdle85735f52019-06-25 03:27:062774base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192775 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402776 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082777 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352778 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022779 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192780 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022781 if (prerender_contents) {
2782 prerender_contents->Destroy(
2783 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062784 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452785 }
2786
[email protected]791879c2013-12-17 07:22:412787 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2788 DCHECK(requesting_url.is_valid())
2789 << "Invalid URL string: https://"
2790 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452791
Pavol Marko230ea2c92017-12-03 22:35:442792 bool may_show_cert_selection = true;
2793
davidben3b8455ae72015-03-11 19:42:192794 Profile* profile =
2795 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442796#if defined(OS_CHROMEOS)
2797 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
Pavol Markoddc4ea42020-01-24 12:02:252798 // On the sign-in profile, never show certificate selection to the user. A
2799 // client certificate is an identifier that can be stable for a long time,
2800 // so only the administrator is allowed to decide which endpoints should see
2801 // it.
2802 may_show_cert_selection = false;
Pavol Marko230ea2c92017-12-03 22:35:442803
2804 content::StoragePartition* storage_partition =
2805 content::BrowserContext::GetStoragePartition(
2806 profile, web_contents->GetSiteInstance());
2807 chromeos::login::SigninPartitionManager* signin_partition_manager =
2808 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2809 profile);
2810
2811 // On the sign-in profile, only allow client certs in the context of the
2812 // sign-in frame.
2813 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2814 storage_partition)) {
2815 LOG(WARNING)
2816 << "Client cert requested in sign-in profile in wrong context.";
2817 // Continue without client certificate. We do this to mimic the case of no
2818 // client certificate being present in the profile's certificate store.
2819 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062820 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442821 }
2822 VLOG(1) << "Client cert requested in sign-in profile.";
2823 }
2824#endif // defined(OS_CHROMEOS)
2825
Alexander Hendrichbcf2616e2018-05-18 08:21:102826 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2827 AutoSelectCertificate(profile, requesting_url, client_certs);
2828 if (auto_selected_identity) {
2829 // The callback will own |auto_selected_identity| and |delegate|, keeping
2830 // them alive until after ContinueWithCertificate is called.
2831 scoped_refptr<net::X509Certificate> cert =
2832 auto_selected_identity->certificate();
2833 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2834 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582835 base::BindOnce(
2836 &content::ClientCertificateDelegate::ContinueWithCertificate,
2837 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322838 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062839 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452840 }
2841
Pavol Marko230ea2c92017-12-03 22:35:442842 if (!may_show_cert_selection) {
2843 LOG(WARNING) << "No client cert matched by policy and user selection is "
2844 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322845 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442846 // Continue without client certificate. We do this to mimic the case of no
2847 // client certificate being present in the profile's certificate store.
2848 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062849 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442850 }
2851
Daniel McArdle85735f52019-06-25 03:27:062852 return chrome::ShowSSLClientCertificateSelector(
2853 web_contents, cert_request_info, std::move(client_certs),
2854 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452855}
2856
[email protected]dc73a7b2012-03-25 15:27:182857content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562858 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182859}
2860
Adrienne Walker80d95f02020-02-07 22:37:042861content::FeatureObserverClient*
2862ChromeContentBrowserClient::GetFeatureObserverClient() {
François Dorayaa3f80102019-10-12 02:29:242863 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
Adrienne Walker80d95f02020-02-07 22:37:042864 ->GetFeatureObserverClient();
Francois Dorayfd823bb12019-10-04 18:03:052865}
2866
peterc26c6c62014-12-10 14:13:592867content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022868ChromeContentBrowserClient::GetPlatformNotificationService(
2869 content::BrowserContext* browser_context) {
2870 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2871 Profile* profile = Profile::FromBrowserContext(browser_context);
2872 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042873}
2874
[email protected]9f3fba52011-06-08 20:37:192875bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352876 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352877 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572878 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352879 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032880 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232881 const GURL& target_url,
2882 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212883 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232884 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482885 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232886 bool user_gesture,
2887 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012888 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352889 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2890 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012891
csharrison95f01e922017-04-24 18:52:352892 content::WebContents* web_contents =
2893 content::WebContents::FromRenderFrameHost(opener);
2894 Profile* profile =
2895 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2896 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012897 *no_javascript_access = false;
2898
[email protected]9f3fba52011-06-08 20:37:192899 // If the opener is trying to create a background window but doesn't have
2900 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032901 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172902#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352903 auto* process_map = extensions::ProcessMap::Get(profile);
2904 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172905 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2906 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012907 return false;
2908 }
2909
[email protected]7b54ca02012-03-02 18:06:532910 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2911 // return a recently installed Extension even if this CanCreateWindow call
2912 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012913 // because the permission check above would have caused an early return
2914 // already. We must use the full URL to find hosted apps, though, and not
2915 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552916 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352917 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292918 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012919 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022920#endif
[email protected]190e5e22013-07-27 05:59:232921
2922 return true;
[email protected]9f3fba52011-06-08 20:37:192923 }
[email protected]056efdc2013-04-06 00:14:532924
brettw00899e62016-11-12 02:10:172925#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462926 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352927 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232928 return true;
lazyboy04b75d32016-02-25 03:12:182929 }
2930
nick0fbc3922016-12-16 20:52:072931 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352932 // Intentionally duplicating |registry| code from above because we want to
2933 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2934 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182935 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352936 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142937 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532938 UMA_HISTOGRAM_ENUMERATION(
2939 "Extensions.AppLoadedInTab",
2940 ClassifyAppLoadedInTabSource(opener_url, extension),
2941 APP_LOADED_IN_TAB_SOURCE_MAX);
2942
2943 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162944 return false;
lazyboy5d5fede02016-03-10 04:10:142945 }
lazyboy04b75d32016-02-25 03:12:182946 }
[email protected]5940b0d2014-07-01 00:18:262947#endif
[email protected]190e5e22013-07-27 05:59:232948
Charles Harrisonaf2acd02017-08-18 22:46:022949#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232950 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352951 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582952 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2953 content_settings, opener_top_level_frame_url, target_url,
2954 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352955 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2956 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582957 return false;
2958 }
2959#endif
2960
Charles Harrisonaf2acd02017-08-18 22:46:022961 // Don't let prerenders open popups.
2962 if (auto* prerender_contents =
2963 prerender::PrerenderContents::FromWebContents(web_contents)) {
2964 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2965 return false;
2966 }
2967
Aaron Colwell9dab1652019-12-09 18:29:492968 BlockedWindowParams blocked_params(
2969 target_url, source_origin, opener->GetSiteInstance(), referrer,
2970 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132971 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:192972 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
2973 &nav_params, nullptr /*=open_url_params*/,
2974 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:192975}
2976
[email protected]c52b2892012-03-07 11:01:022977content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:442978ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002979 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:512980}
2981
Katie D840d9532018-11-27 06:20:482982content::TtsControllerDelegate*
2983ChromeContentBrowserClient::GetTtsControllerDelegate() {
2984 TtsControllerDelegateImpl* delegate =
2985 TtsControllerDelegateImpl::GetInstance();
2986#if !defined(OS_ANDROID)
2987 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
2988 delegate->SetTtsEngineDelegate(tts_extension_engine);
2989#endif
2990 return delegate;
2991}
2992
Katie D4713ee42018-11-30 01:48:272993content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
2994#ifdef OS_CHROMEOS
2995 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:272996#else
2997 return nullptr;
2998#endif
2999}
3000
[email protected]64d69de42012-02-06 00:19:543001void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443002 RenderViewHost* rvh,
3003 WebPreferences* web_prefs) {
3004 Profile* profile =
3005 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063006 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063007
aelias0df335a2017-03-02 23:43:513008// Fill font preferences. These are not registered on Android
3009// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453010#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193011 FontFamilyCache::FillFontFamilyMap(profile,
3012 prefs::kWebKitStandardFontFamilyMap,
3013 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443014 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193015 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443016 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193017 &web_prefs->serif_font_family_map);
3018 FontFamilyCache::FillFontFamilyMap(profile,
3019 prefs::kWebKitSansSerifFontFamilyMap,
3020 &web_prefs->sans_serif_font_family_map);
3021 FontFamilyCache::FillFontFamilyMap(profile,
3022 prefs::kWebKitCursiveFontFamilyMap,
3023 &web_prefs->cursive_font_family_map);
3024 FontFamilyCache::FillFontFamilyMap(profile,
3025 prefs::kWebKitFantasyFontFamilyMap,
3026 &web_prefs->fantasy_font_family_map);
3027 FontFamilyCache::FillFontFamilyMap(profile,
3028 prefs::kWebKitPictographFontFamilyMap,
3029 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063030
[email protected]64d69de42012-02-06 00:19:543031 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403032 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543033 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403034 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543035 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403036 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543037 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403038 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513039#endif
[email protected]f3986f82012-01-03 20:00:063040
[email protected]ddf72142012-05-22 04:52:403041 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063042
[email protected]64d69de42012-02-06 00:19:543043 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063044 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213045 web_prefs->javascript_can_access_clipboard =
3046 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543047 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063048
[email protected]ddf72142012-05-22 04:52:403049 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543050 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573051
Avi Drissman1aa6cb92019-01-23 15:58:383052 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543053 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573054
[email protected]ddf72142012-05-22 04:52:403055 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543056 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543057 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403058 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063059
Zhenyao Moa3fda9972017-09-16 01:34:403060 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3061 web_prefs->webgl1_enabled = false;
3062 web_prefs->webgl2_enabled = false;
3063 }
[email protected]f3986f82012-01-03 20:00:063064
[email protected]64d69de42012-02-06 00:19:543065 web_prefs->allow_running_insecure_content =
3066 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323067#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053068 web_prefs->font_scale_factor =
3069 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
[email protected]d3b935f2012-10-19 23:14:323070 web_prefs->force_enable_zoom =
3071 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493072#endif
Becky Zhoubbfbde32019-02-20 17:07:593073 web_prefs->force_dark_mode_enabled =
3074 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393075
[email protected]af4256d52013-06-04 20:39:073076#if defined(OS_ANDROID)
3077 web_prefs->password_echo_enabled =
3078 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3079#else
[email protected]9d06d88d2012-02-23 22:37:083080 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073081#endif
3082
[email protected]64d69de42012-02-06 00:19:543083 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063084 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543085 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063086 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3087
brettw00899e62016-11-12 02:10:173088#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053089 std::string image_animation_policy =
3090 prefs->GetString(prefs::kAnimationPolicy);
3091 if (image_animation_policy == kAnimationPolicyOnce)
3092 web_prefs->animation_policy =
3093 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3094 else if (image_animation_policy == kAnimationPolicyNone)
3095 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3096 else
3097 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3098#endif
3099
[email protected]f3986f82012-01-03 20:00:063100 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153101 web_prefs->default_encoding =
3102 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543103 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403104 prefs->ClearPref(prefs::kDefaultCharset);
3105 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063106 }
[email protected]64d69de42012-02-06 00:19:543107 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063108
mkwst05544102015-01-10 20:26:163109 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3110 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073111 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163112 web_prefs->strict_mixed_content_checking = true;
3113 web_prefs->strict_powerful_feature_restrictions = true;
3114 }
3115
Robert Ogdencf2872d2019-03-19 18:59:373116 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213117
Tarun Bansal333819e2018-05-15 16:38:423118 web_prefs->data_saver_holdback_web_api_enabled =
3119 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3120 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423121
Jinsuk Kima3d393ce2019-05-27 00:57:423122 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133123 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533124#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423125 auto* delegate = TabAndroid::FromWebContents(contents)
3126 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3127 contents->GetDelegate())
3128 : nullptr;
3129 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133130 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423131 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133132
Mounir Lamouri9c99a1602018-07-05 15:01:443133 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423134 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383135
Alison Maher7f366dc62020-03-03 19:46:003136 web_prefs->preferred_color_scheme =
3137 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3138 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113139 }
Ian Vollick6243dfe02018-03-08 01:08:533140#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533141
Mounir Lamouri6926107f2019-01-31 18:17:433142 // web_app_scope value is platform specific.
3143#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423144 if (delegate)
3145 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433146#elif BUILDFLAG(ENABLE_EXTENSIONS)
3147 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253148 web_prefs->web_app_scope = GURL();
3149 // Set |web_app_scope| based on the app associated with the app window if
3150 // any. Note that the app associated with the window never changes, even
3151 // if the app navigates off scope. This is not a problem because we still
3152 // want to use the scope of the app associated with the window, not the
3153 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433154 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233155 if (browser && browser->app_controller() &&
Alan Cutter1797f46a2020-02-12 02:48:593156 browser->app_controller()->HasAppId()) {
3157 const web_app::AppId& app_id = browser->app_controller()->GetAppId();
3158 const web_app::AppRegistrar& registrar =
3159 web_app::WebAppProviderBase::GetProviderBase(profile)->registrar();
3160 if (registrar.IsLocallyInstalled(app_id))
3161 web_prefs->web_app_scope = registrar.GetAppScope(app_id);
Mounir Lamouri6926107f2019-01-31 18:17:433162 }
Mounir Lamouri6926107f2019-01-31 18:17:433163 }
3164#endif
3165
Ian Vollick6243dfe02018-03-08 01:08:533166 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113167 }
zqzhang93e959d12017-03-16 13:10:203168
Tarun Bansal73d67f02018-01-17 05:56:253169 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3170 // Obtain the maximum effective connection type at which the feature is
3171 // enabled.
3172 std::string effective_connection_type_param =
3173 base::GetFieldTrialParamValueByFeature(
3174 features::kLowPriorityIframes,
3175 "max_effective_connection_type_threshold");
3176
3177 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3178 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3179 if (effective_connection_type) {
3180 web_prefs->low_priority_iframes_threshold =
3181 effective_connection_type.value();
3182 }
3183 }
3184
rajendrant0521cee2019-07-29 06:09:263185 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3186 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003187
Scott Little878f7d6702018-05-31 22:09:063188 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3189 const char* param_name =
3190 web_prefs->data_saver_enabled
3191 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3192 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3193 "saver_enabled";
3194
3195 base::StringPairs pairs;
3196 base::SplitStringIntoKeyValuePairs(
3197 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3198 param_name),
3199 ':', ',', &pairs);
3200
3201 for (const auto& pair : pairs) {
3202 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3203 net::GetEffectiveConnectionTypeForName(pair.first);
3204 int value = 0;
3205 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3206 web_prefs->lazy_frame_loading_distance_thresholds_px
3207 [effective_connection_type.value()] = value;
3208 }
3209 }
3210 }
3211
rajendrantd8026342018-08-29 08:08:393212 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3213 const char* param_name =
3214 web_prefs->data_saver_enabled
3215 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3216 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3217 "saver_enabled";
3218
3219 base::StringPairs pairs;
3220 base::SplitStringIntoKeyValuePairs(
3221 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3222 param_name),
3223 ':', ',', &pairs);
3224
3225 for (const auto& pair : pairs) {
3226 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3227 net::GetEffectiveConnectionTypeForName(pair.first);
3228 int value = 0;
3229 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3230 web_prefs->lazy_image_loading_distance_thresholds_px
3231 [effective_connection_type.value()] = value;
3232 }
3233 }
rajendrant3daeae292019-09-20 07:57:543234
3235 pairs.clear();
3236 base::SplitStringIntoKeyValuePairs(
3237 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3238 "lazy_image_first_k_fully_load"),
3239 ':', ',', &pairs);
3240
3241 for (const auto& pair : pairs) {
3242 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3243 net::GetEffectiveConnectionTypeForName(pair.first);
3244 int value = 0;
3245 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3246 web_prefs
3247 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3248 value;
3249 }
3250 }
rajendrantd8026342018-08-29 08:08:393251 }
3252
Tarun Bansald10f17a02018-09-13 00:23:173253 if (base::FeatureList::IsEnabled(
3254 features::kNetworkQualityEstimatorWebHoldback)) {
3255 std::string effective_connection_type_param =
3256 base::GetFieldTrialParamValueByFeature(
3257 features::kNetworkQualityEstimatorWebHoldback,
3258 "web_effective_connection_type_override");
3259
3260 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3261 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3262 DCHECK(effective_connection_type_param.empty() ||
3263 effective_connection_type);
3264 if (effective_connection_type) {
3265 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3266 effective_connection_type.value());
3267 web_prefs->network_quality_estimator_web_holdback =
3268 effective_connection_type.value();
3269 }
3270 }
3271
Alison Maher7f366dc62020-03-03 19:46:003272 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103273#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563274 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593275 // If autoplay is allowed by policy then force the no user gesture required
3276 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103277 web_prefs->autoplay_policy =
3278 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553279 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593280 web_prefs->autoplay_policy ==
3281 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553282 // If the autoplay disable settings feature is enabled and the autoplay
3283 // policy is set to using the unified policy then set the default autoplay
3284 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593285 web_prefs->autoplay_policy =
3286 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3287 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3288 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103289 }
Alison Maher7f366dc62020-03-03 19:46:003290
3291 switch (native_theme->GetPreferredColorScheme()) {
3292 case ui::NativeTheme::PreferredColorScheme::kDark:
3293 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3294 break;
3295 case ui::NativeTheme::PreferredColorScheme::kLight:
3296 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3297 break;
3298 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3299 web_prefs->preferred_color_scheme =
3300 blink::PreferredColorScheme::kNoPreference;
3301 }
François Beaufort4f8107d2018-03-05 12:12:103302#endif // !defined(OS_ANDROID)
3303
Dave Tapuskac6627e12018-08-30 15:07:193304 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493305
Alison Maher7f366dc62020-03-03 19:46:003306 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3307 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3308 // explicitly uses light (instead of not dark), which is why we don't reset
3309 // back to no-preference. https://crbug.com/965811
3310 if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3311 const GURL url = rvh->GetSiteInstance()->GetSiteURL();
3312 bool force_light = url.SchemeIs(content::kChromeUIScheme);
3313#if BUILDFLAG(ENABLE_EXTENSIONS)
3314 if (!force_light) {
3315 force_light = url.SchemeIs(extensions::kExtensionScheme) &&
3316 url.host_piece() == extension_misc::kPdfExtensionId;
3317 }
3318#endif
3319 if (force_light)
3320 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3321 }
3322
Elly Fong-Jonesf92897392019-01-24 16:05:493323 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213324 base::Optional<ui::CaptionStyle> style;
3325
3326 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3327 ::switches::kForceCaptionStyle)) {
3328 style = ui::CaptionStyle::FromSpec(
3329 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3330 switches::kForceCaptionStyle));
3331 }
3332
3333 // Apply system caption style.
3334 if (!style) {
3335 style = native_theme->GetSystemCaptionStyle();
evliu7a8acef22020-02-27 21:32:323336
3337 base::UmaHistogramBoolean(
3338 "Accessibility.CaptionSettingsLoadedFromSystemSettings",
3339 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213340 }
3341
3342 // Apply caption style from preferences if system caption style is undefined.
evliu21b2a902020-01-27 21:12:563343 if (!style) {
evliubc2aa0472019-08-09 20:19:193344 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
evliuedcbb87d2019-11-22 19:49:413345
3346 base::UmaHistogramBoolean("Accessibility.CaptionSettingsLoadedFromPrefs",
3347 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213348 }
3349
3350 if (style) {
3351 web_prefs->text_track_background_color = style->background_color;
3352 web_prefs->text_track_text_color = style->text_color;
3353 web_prefs->text_track_text_size = style->text_size;
3354 web_prefs->text_track_text_shadow = style->text_shadow;
3355 web_prefs->text_track_font_family = style->font_family;
3356 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563357 web_prefs->text_track_window_color = style->window_color;
3358 web_prefs->text_track_window_padding = style->window_padding;
3359 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213360 }
Elly Fong-Jonesf92897392019-01-24 16:05:493361
[email protected]a48ab7112014-08-01 16:48:033362 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503363 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363364}
3365
[email protected]b8148ac2011-07-13 22:03:253366void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3367 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033368 for (size_t i = 0; i < extra_parts_.size(); ++i)
3369 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253370
[email protected]b3adbd02011-11-30 22:23:273371 // about: handler. Must come before chrome: handler, since it will
3372 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053373 // actually handle them. Also relies on a preliminary fixup phase.
3374 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253375 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3376 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033377
madfbd10852017-01-20 03:15:333378 // The group policy NTP URL handler must be registered before the other NTP
3379 // URL handlers below.
3380 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3381 BrowserURLHandler::null_handler());
3382
zpengdb4a58e2017-01-10 17:40:323383#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033384 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353385 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033386 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453387#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033388 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133389 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3390 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453391#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033392
[email protected]b8148ac2011-07-13 22:03:253393 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313394 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3395 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063396
3397 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3398 // the user.
Robert Ogden0f4d88682019-09-24 22:27:523399 handler->AddHandlerPair(
3400 &previews::HandlePreviewsLitePageRedirectURLRewrite,
3401 &previews::HandlePreviewsLitePageRedirectURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253402}
3403
[email protected]650b2d52013-02-10 03:41:453404base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493405 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323406}
3407
[email protected]c9b6eb62011-10-18 20:49:393408std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3409 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3410}
3411
Dominik Röttsches47347832019-03-12 17:45:013412base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3413 base::FilePath user_data_dir;
3414 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3415 DCHECK(!user_data_dir.empty());
3416 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3417}
3418
jmadill57b52d42015-08-21 18:16:133419base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3420 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523421 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133422 DCHECK(!user_data_dir.empty());
3423 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3424}
3425
Khushal7ca0b782018-07-20 05:53:273426base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3427 base::FilePath user_data_dir;
3428 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3429 DCHECK(!user_data_dir.empty());
3430 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3431}
3432
[email protected]b7631cc2012-09-15 05:08:383433void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3434 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163435#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553436 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543437#endif
[email protected]b7631cc2012-09-15 05:08:383438}
3439
[email protected]0c7193742012-11-07 19:05:033440content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443441ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173442#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553443 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033444 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443445 nacl::NaClProcessHost* host =
3446 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3447 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033448 // Found the plugin.
3449 return host->browser_ppapi_host();
3450 }
3451 ++iter;
3452 }
[email protected]a56f8322014-07-16 21:13:553453#endif
Aran Gilmanf010bdd2019-08-28 19:55:443454 return nullptr;
[email protected]0c7193742012-11-07 19:05:033455}
3456
[email protected]38cd8f7f2012-06-15 22:06:073457bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583458 content::BrowserContext* browser_context,
3459 const GURL& url,
[email protected]dda54822013-06-15 01:26:393460 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123461 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163462#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553463 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
Lei Zhang19736cde2020-02-07 18:51:193464 browser_context, url, private_api, params);
[email protected]93f72062013-05-29 20:29:403465#else
[email protected]a658d452012-03-02 12:45:293466 return false;
[email protected]93f72062013-05-29 20:29:403467#endif
[email protected]e461da2f2012-02-16 19:06:403468}
3469
adrian.belgund54465ba2016-05-18 10:03:583470bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3471 content::BrowserContext* browser_context,
3472 const GURL& url) {
brettw4b461082016-11-19 18:55:163473#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583474 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3475 browser_context, url);
3476#else
3477 return false;
3478#endif
3479}
3480
adrian.belgun5b341c72016-06-22 22:24:083481std::unique_ptr<content::VpnServiceProxy>
3482ChromeContentBrowserClient::GetVpnServiceProxy(
3483 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173484#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083485 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3486 browser_context);
3487#else
3488 return nullptr;
3489#endif
3490}
3491
Brett Wilson804e83c2017-08-18 22:57:333492std::unique_ptr<ui::SelectFilePolicy>
3493ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3494 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433495}
3496
[email protected]7d9424702013-04-14 13:14:163497void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3498 std::vector<std::string>* additional_allowed_schemes) {
3499 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3500 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483501 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293502 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033503 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3504 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3505 additional_allowed_schemes);
3506 }
[email protected]7d9424702013-04-14 13:14:163507}
3508
falkenad185092016-06-16 06:10:023509void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3510 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043511 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023512}
3513
[email protected]c79859b82014-03-20 22:43:553514void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313515 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033516 for (size_t i = 0; i < extra_parts_.size(); ++i)
3517 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553518}
3519
nzolghadrd87a308d2016-12-07 15:45:563520::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3521 return g_browser_process->rappor_service();
3522}
3523
[email protected]f19bbf62013-07-09 01:22:323524void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313525 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533526 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003527 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3528 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313529#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313530 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313531 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313532 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093533 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093534 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3535 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473536 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093537 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3538 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053539 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3540 Profile::FromBrowserContext(browser_context)),
Anand K. Mistry7694c362020-03-17 23:33:343541 std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
3542 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473543 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323544 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313545 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003546 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313547#endif
[email protected]445b7db2013-08-02 04:58:273548
[email protected]a48ab7112014-08-01 16:48:033549 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3550 extra_parts_[i]->GetAdditionalFileSystemBackends(
3551 browser_context, storage_partition_path, additional_backends);
3552 }
[email protected]02250952013-04-24 23:52:533553}
3554
jcivellie6f550742017-01-06 19:29:123555#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183556void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173557 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383558 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203559 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123560#if defined(OS_ANDROID)
3561 base::MemoryMappedFile::Region region;
3562 int fd = ui::GetMainAndroidPackFd(&region);
3563 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003564
Samuel Huang31eadf082019-08-28 19:50:433565 // For Android: Native resources for DFMs should only be used by the browser
3566 // process. Their file descriptors and memory mapped file regions are not
3567 // passed to child processes.
3568
jcivellie6f550742017-01-06 19:29:123569 fd = ui::GetCommonResourcesPackFd(&region);
3570 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393571
jcivellie6f550742017-01-06 19:29:123572 fd = ui::GetLocalePackFd(&region);
3573 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383574
zpeng368afac82017-07-17 18:47:453575 // Optional secondary locale .pak file.
3576 fd = ui::GetSecondaryLocalePackFd(&region);
3577 if (fd != -1) {
3578 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3579 }
3580
[email protected]09560f7f2014-06-10 18:40:283581 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523582 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283583 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023584#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383585 int crash_signal_fd = GetCrashSignalFD(command_line);
3586 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133587 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383588 }
jcivellie6f550742017-01-06 19:29:123589}
3590#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303591
[email protected]4a65826d2011-08-25 16:04:013592#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033593base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223594 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033595 // TODO(wfh): Add support for more process types here. crbug.com/499523
3596 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223597 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363598 return base::string16(install_static::GetSandboxSidPrefix()) +
3599 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223600 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033601 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223602 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033603 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223604 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363605 return base::string16(install_static::GetSandboxSidPrefix()) +
3606 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223607 case service_manager::SandboxType::kInvalid:
3608 case service_manager::SandboxType::kNoSandbox:
3609 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3610 case service_manager::SandboxType::kXrCompositing:
3611 case service_manager::SandboxType::kNetwork:
3612 case service_manager::SandboxType::kCdm:
Alan Screen6cef2c82020-01-14 20:58:523613 case service_manager::SandboxType::kPrintCompositor:
Alex Gough9ab468a6c32019-12-10 19:10:223614 case service_manager::SandboxType::kAudio:
evliu2e5dbee42020-04-09 23:35:293615 case service_manager::SandboxType::kSpeechRecognition:
Will Harrise705a642020-02-26 20:57:053616 case service_manager::SandboxType::kProxyResolver:
Cliff Smolinsky0aa7ca72020-03-09 21:32:463617 case service_manager::SandboxType::kPdfConversion:
Alex Gough63617352020-03-20 02:34:593618 case service_manager::SandboxType::kSharingService:
Alex Gough9ab468a6c32019-12-10 19:10:223619 // Should never reach here.
3620 CHECK(0);
wfh182da09c2015-06-24 19:23:033621 return base::string16();
wfh182da09c2015-06-24 19:23:033622 }
wfh182da09c2015-06-24 19:23:033623}
3624
Will Harris956e0ca2019-08-23 20:47:393625bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3626 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503627// Does not work under component build because all the component DLLs would need
3628// to be manually added and maintained. Does not work under ASAN build because
3629// ASAN has not yet fully initialized its instrumentation by the time the CIG
3630// intercepts run.
3631#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393632 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3633 return true;
Will Harrisc196ed942019-08-03 03:45:303634 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3635 return true;
3636
3637 // Only enable signing mitigation if launching from chrome.exe.
3638 base::FilePath exe_path;
3639 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3640 return true;
3641 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3642 return true;
3643
3644 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3645 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093646 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303647 if (result != sandbox::SBOX_ALL_OK)
3648 return false;
3649
Nico Weberc36b0152020-04-18 03:12:463650 // Allow loading Chrome's DLLs.
3651 for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) {
Will Harrisc196ed942019-08-03 03:45:303652 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3653 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3654 GetModulePath(dll).value().c_str());
3655 if (result != sandbox::SBOX_ALL_OK)
3656 return false;
3657 }
Will Harris1b9b4152019-08-21 22:33:503658#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303659
3660 return true;
[email protected]34f48682013-03-20 00:30:183661}
Will Harris956e0ca2019-08-23 20:47:393662
3663bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3664 PrefService* local_state = g_browser_process->local_state();
3665 if (local_state &&
3666 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3667 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3668 return false;
3669 return true;
3670}
3671
wfhc91e9672016-01-27 00:14:203672#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013673
Mario Sanchez Prada39dee4a2019-07-09 07:15:403674void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113675 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403676 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3677 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113678 render_frame_host);
3679}
3680
Armando Miraglia3a7be232019-11-08 00:33:323681#if defined(OS_WIN) || defined(OS_MACOSX) || \
3682 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3683bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3684 const base::Value* audio_sandbox_enabled_policy_value =
3685 policies.GetValue(policy::key::kAudioSandboxEnabled);
3686 if (audio_sandbox_enabled_policy_value) {
3687 bool force_enable_audio_sandbox;
3688 audio_sandbox_enabled_policy_value->GetAsBoolean(
3689 &force_enable_audio_sandbox);
3690 return force_enable_audio_sandbox;
3691 }
3692
3693 return base::FeatureList::IsEnabled(
3694 service_manager::features::kAudioServiceSandbox);
3695}
3696#endif
3697
Ken Rockotfa5d57112019-05-29 20:57:143698void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123699#if defined(OS_WIN) || defined(OS_MACOSX) || \
3700 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053701 if (startup_data_) {
3702 auto* chrome_feature_list_creator =
3703 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183704 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123705 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053706 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183707 ->GetPolicyService()
3708 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123709 std::string()));
3710
3711#if defined(OS_WIN)
3712 const base::Value* force_network_in_process_value =
3713 policies.GetValue(policy::key::kForceNetworkInProcess);
John Abd-El-Malek27b3ebd22019-02-12 18:59:183714 bool force_network_in_process = false;
3715 if (force_network_in_process_value)
3716 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3717 if (force_network_in_process)
3718 content::ForceInProcessNetworkService(true);
Guido Urdanetad06ae842019-10-10 20:04:123719#endif
3720 bool enable_audio_process =
3721 base::FeatureList::IsEnabled(features::kAudioServiceOutOfProcess);
Armando Miraglia3a7be232019-11-08 00:33:323722
3723 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
3724 if (!service_manager::IsAudioSandboxEnabled() || !enable_audio_process) {
Guido Urdanetad06ae842019-10-10 20:04:123725 // Disabling the audio process or audio sandbox implies disabling APM in
3726 // the audio service for security reasons. Append a switch so that this
3727 // is communicated to the audio and renderer processes.
3728 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3729 switches::kForceDisableWebRtcApmInAudioService);
3730 }
John Abd-El-Malek27b3ebd22019-02-12 18:59:183731 }
3732#endif
xhwang5e630462015-10-30 03:18:483733}
3734
Ken Rockot8f39a272018-12-21 23:38:353735base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173736ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583737 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583738 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583739 return base::nullopt;
benc70c0e32016-09-22 03:50:373740}
3741
peterbbcccc12015-02-11 22:23:333742void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373743 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333744 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293745 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083746 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373747
3748 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083749
zpengdb4a58e2017-01-10 17:40:323750#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223751 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293752 std::move(callback));
jam1c5a91492016-02-24 20:47:533753#else
cm.sanchi2522bc92017-12-04 08:04:133754 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3755 params.url, params.transition);
3756 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083757
3758 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293759 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333760#endif
mlamourieb40d552015-02-05 00:57:083761}
3762
zhaobinf3704f82017-01-12 07:19:363763content::ControllerPresentationServiceDelegate*
3764ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3765 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463766 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093767 return media_router::PresentationServiceDelegateImpl::
3768 GetOrCreateForWebContents(web_contents);
3769 }
haibinlu9e605a92015-06-06 03:45:093770 return nullptr;
3771}
3772
zhaobinf3704f82017-01-12 07:19:363773content::ReceiverPresentationServiceDelegate*
3774ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3775 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363776 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3777 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3778 // created for offscreen presentations. The WebContents must belong to
3779 // an incognito profile.
3780 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3781 FromWebContents(web_contents)) {
3782 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3783 return impl;
3784 }
3785 }
zhaobinf3704f82017-01-12 07:19:363786 return nullptr;
3787}
3788
horo48d4d3e2015-02-27 03:04:003789void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3790 const GURL& url) {
mathp46284f32015-03-11 13:06:413791 if (url.is_valid()) {
3792 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3793 metric, url);
3794 }
horo48d4d3e2015-02-27 03:04:003795}
3796
Matt Falkenhagen8479b202017-07-14 04:35:313797std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3798 // Don't change these returned strings. They are written (in hashed form) into
3799 // UMA logs. If you add more strings, you must update histograms.xml and get
3800 // histograms review. Only Google domains should be here for privacy purposes.
3801 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3802 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193803 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313804 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193805 if (url.host() == "docs.google.com")
3806 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313807 return std::string();
3808}
3809
avid6d88b912017-01-13 00:16:003810std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473811ChromeContentBrowserClient::CreateThrottlesForNavigation(
3812 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003813 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273814
bmcquadeb4556552017-03-24 22:24:373815 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3816 // that may delay or cancel navigations, so only NavigationThrottles that
3817 // don't delay or cancel navigations (e.g. throttles that are only observing
3818 // callbacks without affecting navigation behavior) should be added before
3819 // MetricsNavigationThrottle.
3820 if (handle->IsInMainFrame()) {
3821 throttles.push_back(
3822 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3823 }
3824
brettw4b461082016-11-19 18:55:163825#if BUILDFLAG(ENABLE_PLUGINS)
Lukasz Anforowicz7724d092019-10-03 23:50:213826 MaybeAddThrottle(&throttles,
3827 FlashDownloadInterception::MaybeCreateThrottleFor(handle));
trizzofo8ddaeb72016-09-01 23:18:273828#endif
3829
yilkal240b4f22019-11-27 19:09:063830#if defined(OS_CHROMEOS)
3831 MaybeAddThrottle(
3832 &throttles,
3833 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle));
3834#endif // defined(OS_CHROMEOS)
3835
mmenkedb2637ff2017-03-30 23:59:423836#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213837 MaybeAddThrottle(
3838 &throttles,
3839 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle));
mmenkedb2637ff2017-03-30 23:59:423840#endif
3841
clamy40c9e142015-09-29 11:18:473842#if defined(OS_ANDROID)
3843 // TODO(davidben): This is insufficient to integrate with prerender properly.
3844 // https://crbug.com/370595
3845 prerender::PrerenderContents* prerender_contents =
3846 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3847 if (!prerender_contents && handle->IsInMainFrame()) {
3848 throttles.push_back(
3849 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303850 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473851 }
Min Qin0ab0e162017-11-14 21:57:193852 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043853
3854#if BUILDFLAG(DFMIFY_DEV_UI)
3855 // If the DevUI DFM is already installed, then this is a no-op, except for the
3856 // side effect of ensuring that the DevUI DFM is loaded.
3857 MaybeAddThrottle(&throttles,
3858 dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle));
3859#endif // BUILDFLAG(DFMIFY_DEV_UI)
3860
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573861#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473862 if (handle->IsInMainFrame()) {
3863 // Redirect some navigations to apps that have registered matching URL
3864 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573865 auto url_to_app_throttle =
3866 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:473867 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:093868 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:473869 }
3870#endif
clamy49678312015-10-22 21:59:003871
3872#if defined(OS_CHROMEOS)
3873 // Check if we need to add merge session throttle. This throttle will postpone
3874 // loading of main frames.
3875 if (handle->IsInMainFrame()) {
3876 // Add interstitial page while merge session process (cookie reconstruction
3877 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3878 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023879 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3880 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003881 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3882 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3883 }
Maggie Caia2f03f52019-04-02 02:13:283884 }
3885#endif
djacobo21e56e02016-07-02 01:14:313886
Maggie Caia2f03f52019-04-02 02:13:283887#if !defined(OS_ANDROID)
3888 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:153889 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283890#if defined(OS_CHROMEOS)
Maggie Cai00e2a21e2019-10-16 00:47:513891 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3892 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3893 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253894#elif defined(OS_MACOSX)
3895 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283896#else
3897 apps::AppsNavigationThrottle::MaybeCreate(handle);
3898#endif
Dominick Ng7c289942018-03-27 05:57:153899 if (url_to_apps_throttle)
3900 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003901 }
3902#endif
3903
brettw00899e62016-11-12 02:10:173904#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003905 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093906 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513907
Lukasz Anforowicz7724d092019-10-03 23:50:213908 MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get()
3909 ->GetUserScriptListener()
3910 ->CreateNavigationThrottle(handle));
naskob9164c42016-06-07 01:21:353911#endif
3912
bauerb8f9c37742017-03-30 15:04:123913#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213914 MaybeAddThrottle(
3915 &throttles,
3916 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle));
bauerb8f9c37742017-03-30 15:04:123917#endif
3918
csharrisone985ebc2017-04-04 17:05:033919 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103920 if (auto* subresource_filter_client =
3921 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3922 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3923 &throttles);
csharrisone985ebc2017-04-04 17:05:033924 }
3925
zhenw6edd49c2017-07-12 05:49:453926#if !defined(OS_ANDROID)
3927 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3928 // enabled on non-Android platforms.
Lukasz Anforowicz7724d092019-10-03 23:50:213929 MaybeAddThrottle(&throttles,
3930 resource_coordinator::BackgroundTabNavigationThrottle::
3931 MaybeCreateThrottleFor(handle));
zhenw6edd49c2017-07-12 05:49:453932#endif
3933
Nico Weberbc5b06f2019-07-26 14:00:133934#if BUILDFLAG(FULL_SAFE_BROWSING)
Lukasz Anforowicz7724d092019-10-03 23:50:213935 MaybeAddThrottle(&throttles,
3936 safe_browsing::MaybeCreateNavigationThrottle(handle));
Jialiu Linbdbb81d2017-10-11 21:29:093937#endif
3938
Lukasz Anforowicz7724d092019-10-03 23:50:213939 MaybeAddThrottle(
3940 &throttles,
Emily Starkfa0ddb42019-10-24 15:49:583941 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
Joe DeBlasio6e8409a2019-02-20 23:08:273942
Lukasz Anforowicz7724d092019-10-03 23:50:213943 MaybeAddThrottle(&throttles,
3944 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
Amber Won6b5edc752017-08-17 19:23:543945
Lukasz Anforowicz7724d092019-10-03 23:50:213946 MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle));
Charles Harrison6dd11d282017-10-03 06:14:513947
Jeremy Romanec48d7a2018-03-01 17:35:093948 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533949 handle, handle->GetWebContents()->GetBrowserContext()));
3950
Colin Blundelleaa7377bf2020-01-22 08:49:103951 // Before setting up SSL error detection, configure SSLErrorHandler to invoke
3952 // the relevant extension API whenever an SSL interstitial is shown.
3953 SSLErrorHandler::SetClientCallbackOnInterstitialsShown(
3954 base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent));
Carlos IL5a9e7512019-06-13 22:35:283955 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3956 handle,
3957 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
Colin Blundell9ee731dd2020-01-23 10:42:383958 base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123959
Emily Starkd6896cd32019-08-21 04:55:543960 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3961
Lukasz Anforowicz7724d092019-10-03 23:50:213962 MaybeAddThrottle(
3963 &throttles,
3964 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle));
Christopher Thompson4137cec2017-12-19 05:34:233965
Dmitry Gozman57b92ce2017-12-28 22:24:543966#if !defined(OS_ANDROID)
Lukasz Anforowicz7724d092019-10-03 23:50:213967 MaybeAddThrottle(&throttles,
3968 DevToolsWindow::MaybeCreateNavigationThrottle(handle));
Conley Owensaafcf122018-02-26 18:53:513969
Lukasz Anforowicz7724d092019-10-03 23:50:213970 MaybeAddThrottle(
3971 &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle));
jdoerrie4f9376f2018-12-12 18:26:203972
Lukasz Anforowicz7724d092019-10-03 23:50:213973 MaybeAddThrottle(
3974 &throttles,
3975 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle));
Dmitry Gozman57b92ce2017-12-28 22:24:543976#endif
3977
Carlos IL4ee307e2018-12-22 03:19:003978 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
3979 throttles.push_back(
3980 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
3981 handle));
3982 }
Robert Ogdenafd250b2018-07-25 22:21:033983
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:333984#if defined(OS_WIN) || defined(OS_MACOSX) || \
3985 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Lukasz Anforowicz7724d092019-10-03 23:50:213986 MaybeAddThrottle(&throttles,
3987 browser_switcher::BrowserSwitcherNavigationThrottle::
3988 MaybeCreateThrottleFor(handle));
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:133989#endif
3990
dchenge73d8520c2015-12-27 01:19:093991 return throttles;
clamy40c9e142015-09-29 11:18:473992}
3993
clamy1e5574e2016-09-29 16:48:443994std::unique_ptr<content::NavigationUIData>
3995ChromeContentBrowserClient::GetNavigationUIData(
3996 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:093997 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:443998}
3999
Xiaohan Wanga4e41842018-06-26 18:45:104000void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4001 const std::string& key_system,
Xiaohan Wanga4e41842018-06-26 18:45:104002 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:124003 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:104004#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264005 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104006 if (key_system == kWidevineKeySystem) {
Xiaohan Wangfd9e3542020-04-14 00:39:334007 GetWidevineHardwareCaps(video_codecs, encryption_schemes);
Xiaohan Wanga4e41842018-06-26 18:45:104008 }
4009#endif
4010}
4011
[email protected]487974a2014-06-13 16:49:014012content::DevToolsManagerDelegate*
4013ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354014#if defined(OS_ANDROID)
4015 return new DevToolsManagerDelegateAndroid();
4016#else
[email protected]487974a2014-06-13 16:49:014017 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354018#endif
[email protected]487974a2014-06-13 16:49:014019}
4020
Rayan Kanso411e84e2019-02-13 15:27:404021void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4022 content::BrowserContext* browser_context,
4023 int service,
4024 base::Time expiration_time) {
4025 Profile* profile = Profile::FromBrowserContext(browser_context);
4026 DCHECK(profile);
4027
4028 auto* pref_service = profile->GetPrefs();
4029 DCHECK(pref_service);
4030
4031 DictionaryPrefUpdate pref_update(
4032 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4033 base::DictionaryValue* exp_dict = pref_update.Get();
4034
4035 // Convert |expiration_time| to minutes since that is the most granular
4036 // option that returns an int. base::Value does not accept int64.
4037 int expiration_time_minutes =
4038 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4039 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4040}
4041
4042base::flat_map<int, base::Time>
4043ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4044 content::BrowserContext* browser_context) {
4045 Profile* profile = Profile::FromBrowserContext(browser_context);
4046 DCHECK(profile);
4047
4048 auto* pref_service = profile->GetPrefs();
4049 DCHECK(pref_service);
4050
4051 auto* expiration_dict = pref_service->GetDictionary(
4052 prefs::kDevToolsBackgroundServicesExpirationDict);
4053 DCHECK(expiration_dict);
4054
4055 base::flat_map<int, base::Time> expiration_times;
4056 for (const auto& it : *expiration_dict) {
4057 // key.
4058 int service = 0;
4059 bool did_convert = base::StringToInt(it.first, &service);
4060 DCHECK(did_convert);
4061
4062 // value.
4063 DCHECK(it.second->is_int());
4064 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4065 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4066
4067 expiration_times[service] = expiration_time;
4068 }
4069
4070 return expiration_times;
4071}
4072
oysteinec563c582015-02-13 19:19:524073content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524074 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524075}
4076
[email protected]a6868c22013-10-09 02:50:294077bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4078 content::BrowserContext* browser_context,
4079 const GURL& url) {
brettw4b461082016-11-19 18:55:164080#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554081 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194082 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url);
[email protected]a6868c22013-10-09 02:50:294083#else
4084 return false;
4085#endif
4086}
4087
[email protected]aec5ed52014-06-20 07:51:424088bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4089 content::BrowserContext* browser_context,
4090 const GURL& url) {
brettw4b461082016-11-19 18:55:164091#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554092 return ChromeContentBrowserClientPluginsPart::
Lei Zhang19736cde2020-02-07 18:51:194093 IsPluginAllowedToUseDevChannelAPIs(browser_context, url);
[email protected]8ddc6b7c2013-12-12 20:42:064094#else
4095 return false;
4096#endif
4097}
4098
mlamourif8c23a2002015-01-27 13:10:104099void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014100 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434101 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524102 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104103
4104 WebContents* web_contents =
4105 WebContents::FromRenderFrameHost(render_frame_host);
4106 DCHECK(web_contents);
4107
mlamourif8c23a2002015-01-27 13:10:104108 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374109 prerender::PrerenderManagerFactory::GetForBrowserContext(
4110 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104111 if (prerender_manager &&
4112 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294113 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104114 }
4115}
4116
Robert Sesek466e43e2019-08-19 22:02:024117void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4118 base::FilePath user_data_dir;
4119 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4120 DCHECK(!user_data_dir.empty());
4121 network_contexts_parent_directory_.push_back(user_data_dir);
4122
4123 base::FilePath cache_dir;
4124 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4125 DCHECK(!cache_dir.empty());
4126 // On some platforms, the cache is a child of the user_data_dir so only
4127 // return the one path.
4128 if (!user_data_dir.IsParent(cache_dir))
4129 network_contexts_parent_directory_.push_back(cache_dir);
4130
4131 // If the cache location has been overridden by a switch or preference,
4132 // include that as well.
4133 if (auto* local_state = g_browser_process->local_state()) {
4134 base::FilePath pref_cache_dir =
4135 local_state->GetFilePath(prefs::kDiskCacheDir);
4136 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4137 network_contexts_parent_directory_.push_back(pref_cache_dir);
4138 }
4139}
4140
[email protected]30335fdf02014-02-26 19:51:274141void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174142 base::CommandLine* to_command_line,
4143 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544144 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274145#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544146 const version_info::Channel kMaxDisableEncryptionChannel =
4147 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274148#else
sdefresne6e883e42015-07-30 08:05:544149 const version_info::Channel kMaxDisableEncryptionChannel =
4150 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274151#endif
4152 if (channel <= kMaxDisableEncryptionChannel) {
4153 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444154 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274155 };
Avi Drissmand251e912018-12-26 15:46:374156 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4157 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274158 }
4159}
bashi933629552016-10-13 23:32:404160
miu54dca6c2016-11-17 10:59:384161#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4162void ChromeContentBrowserClient::CreateMediaRemoter(
4163 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504164 mojo::PendingRemote<media::mojom::RemotingSource> source,
4165 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384166 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504167 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384168}
4169#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464170
Michael Giuffrida6802ffe2017-09-29 03:40:254171base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4172 const base::CommandLine& command_line) {
4173 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164174}
4175
John Abd-El-Malek8efa11f2019-01-06 00:51:534176namespace {
4177// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024178class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534179 public:
4180 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174181 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534182 : protocol_handler_registry_(protocol_handler_registry) {}
4183 ~ProtocolHandlerThrottle() override = default;
4184
4185 void WillStartRequest(network::ResourceRequest* request,
4186 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294187 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534188 }
4189
4190 void WillRedirectRequest(net::RedirectInfo* redirect_info,
Lucas Furukawa Gadani011886592019-10-23 17:12:244191 const network::mojom::URLResponseHead& response_head,
John Abd-El-Malek8efa11f2019-01-06 00:51:534192 bool* defer,
4193 std::vector<std::string>* to_be_removed_headers,
4194 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294195 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534196 }
4197
4198 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294199 void TranslateUrl(GURL* url) {
4200 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4201 return;
4202 GURL translated_url = protocol_handler_registry_->Translate(*url);
4203 if (!translated_url.is_empty())
4204 *url = translated_url;
4205 }
4206
Clark DuValla411bda2019-08-02 03:09:174207 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534208};
4209} // namespace
4210
Minggang Wangf6840ecf2019-07-29 05:15:024211std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194212ChromeContentBrowserClient::CreateURLLoaderThrottles(
4213 const network::ResourceRequest& request,
4214 content::BrowserContext* browser_context,
4215 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4216 content::NavigationUIData* navigation_ui_data,
4217 int frame_tree_node_id) {
4218 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4219
Minggang Wangf6840ecf2019-07-29 05:15:024220 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194221
4222 Profile* profile = Profile::FromBrowserContext(browser_context);
4223
4224 ChromeNavigationUIData* chrome_navigation_ui_data =
4225 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4226
Nico Weberbc5b06f2019-07-26 14:00:134227#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564228 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4229 request.url, *profile->GetPrefs());
4230 if (!matches_enterprise_whitelist) {
Xinghui Lue17b19942020-02-24 21:19:584231 // |url_lookup_service| is used when real time url check is enabled.
4232 safe_browsing::RealTimeUrlLookupService* url_lookup_service =
4233 // |safe_browsing_service_| may be unavailable in tests.
4234 safe_browsing_service_ &&
4235 safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup(
Xinghui Lu8fe39982020-03-02 22:31:384236 profile->GetPrefs(), profile->IsOffTheRecord())
Xinghui Lue17b19942020-02-24 21:19:584237 ? safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile(
4238 profile)
4239 : nullptr;
Xinghui Lu0abc17b2020-02-20 22:50:194240
Clark DuVall5497288d2019-07-17 00:17:564241 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4242 base::BindOnce(
4243 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Matt Menke562675cfe2020-01-07 15:50:534244 base::Unretained(this),
Bettinae83f522c72020-03-12 01:52:334245 safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs())),
Xinghui Lua142c102020-03-02 20:50:084246 wc_getter, frame_tree_node_id,
Xinghui Lue17b19942020-02-24 21:19:584247 url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr));
Clark DuVall5497288d2019-07-17 00:17:564248 }
Nico Weberbc5b06f2019-07-26 14:00:134249#endif
Clark DuVall5497288d2019-07-17 00:17:564250
dalykba7bbfc2019-12-18 19:59:214251#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4252 result.push_back(
Colin Blundell27331f92020-02-05 21:13:014253 std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
4254 wc_getter.Run()));
dalykba7bbfc2019-12-18 19:59:214255#endif
4256
Clark DuVallfffa41e2019-06-25 20:27:194257 if (chrome_navigation_ui_data &&
4258 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4259 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4260 chrome_navigation_ui_data->prerender_mode(),
4261 chrome_navigation_ui_data->prerender_histogram_prefix(),
Darin Fishere41aab52020-01-29 18:31:234262 GetPrerenderCanceler(wc_getter)));
Clark DuVallfffa41e2019-06-25 20:27:194263 }
4264
John Abd-El-Malek4f380d92020-02-19 16:43:364265#if defined(OS_ANDROID)
4266 std::string client_data_header;
John Abd-El-Malekfb9f5462020-02-20 01:18:374267 if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
4268 auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id);
John Abd-El-Malek2ea05542020-03-04 00:03:364269 // Could be null if the FrameTreeNode's RenderFrameHost is shutting down.
4270 if (web_contents) {
4271 auto* client_data_header_observer =
4272 customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
4273 web_contents);
4274 if (client_data_header_observer)
4275 client_data_header = client_data_header_observer->header();
4276 }
John Abd-El-Malekfb9f5462020-02-20 01:18:374277 }
John Abd-El-Malek4f380d92020-02-19 16:43:364278#endif
4279
Clark DuVallfffa41e2019-06-25 20:27:194280 chrome::mojom::DynamicParams dynamic_params = {
4281 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4282 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
Alex Clarke3ebd9772020-02-28 10:50:274283 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)};
4284 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
John Abd-El-Malek4f380d92020-02-19 16:43:364285#if defined(OS_ANDROID)
Alex Clarke3ebd9772020-02-28 10:50:274286 client_data_header,
John Abd-El-Malek4f380d92020-02-19 16:43:364287#endif
Alex Clarke3ebd9772020-02-28 10:50:274288 std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194289
Clark DuValla411bda2019-08-02 03:09:174290 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4291 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214292
Clark DuVall39c2cfc2019-06-25 21:49:284293#if BUILDFLAG(ENABLE_PLUGINS)
4294 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464295 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284296#endif
4297
Robbie McElrath127ad2b2019-07-22 22:38:114298 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404299 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
David Roger615cb9f02020-01-30 12:06:584300 auto signin_throttle =
4301 signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter);
Robbie McElrath127ad2b2019-07-22 22:38:114302 if (signin_throttle)
4303 result.push_back(std::move(signin_throttle));
4304
Clark DuVallfffa41e2019-06-25 20:27:194305 return result;
4306}
4307
Ken Rockot6414c4d92017-11-08 19:58:324308void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464309 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324310 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414311#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464312 content::WebContents* web_contents =
4313 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414314#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324315 factories->emplace(
4316 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574317 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464318 web_contents->GetBrowserContext(),
4319 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414320#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4321#if defined(OS_CHROMEOS)
4322 Profile* profile =
4323 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304324 factories->emplace(content::kExternalFileScheme,
4325 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4326 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414327#endif // defined(OS_CHROMEOS)
4328#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324329}
4330
Ting Shao2dc60582019-07-15 04:43:364331void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344332 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4333 content::BrowserContext* browser_context,
4334 NonNetworkURLLoaderFactoryMap* factories) {
4335#if BUILDFLAG(ENABLE_EXTENSIONS)
4336 DCHECK(browser_context);
4337 DCHECK(factories);
4338 factories->emplace(
4339 extensions::kExtensionScheme,
4340 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4341 browser_context));
4342#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4343}
4344
4345void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364346 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4347 content::BrowserContext* browser_context,
4348 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114349#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364350 DCHECK(browser_context);
4351 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364352 factories->emplace(
4353 extensions::kExtensionScheme,
4354 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4355 browser_context));
4356#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364357}
4358
Jay Civelli2578ebe2018-06-05 18:44:314359namespace {
4360
4361// The FileURLLoaderFactory provided to the extension background pages.
4362// Checks with the ChildProcessSecurityPolicy to validate the file access.
4363class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4364 public:
4365 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4366
4367 private:
4368 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274369 void CreateLoaderAndStart(
4370 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4371 int32_t routing_id,
4372 int32_t request_id,
4373 uint32_t options,
4374 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304375 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274376 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4377 override {
Jay Civelli2578ebe2018-06-05 18:44:314378 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4379 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304380 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4381 ->OnComplete(
4382 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314383 return;
4384 }
Yutaka Hiranodf83dca42020-01-07 06:24:554385 content::CreateFileURLLoaderBypassingSecurityChecks(
4386 request, std::move(loader), std::move(client),
4387 /*observer=*/nullptr,
4388 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314389 }
4390
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524391 void Clone(
4392 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4393 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314394 }
4395
4396 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524397 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314398 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4399};
4400
4401} // namespace
4402
Ken Rockot6414c4d92017-11-08 19:58:324403void ChromeContentBrowserClient::
4404 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464405 int render_process_id,
4406 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324407 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414408#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4409 content::RenderFrameHost* frame_host =
4410 RenderFrameHost::FromID(render_process_id, render_frame_id);
4411 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4412#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4413
4414#if defined(OS_CHROMEOS)
4415 if (web_contents) {
4416 Profile* profile =
4417 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304418 factories->emplace(content::kExternalFileScheme,
4419 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4420 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414421 }
4422#endif // defined(OS_CHROMEOS)
4423
Ken Rockot6414c4d92017-11-08 19:58:324424#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464425 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4426 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324427 if (factory)
4428 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234429
4430 // This logic should match
4431 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314432 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234433 return;
Jay Civellic9bbf72d2018-03-24 01:58:314434
4435 Profile* profile =
4436 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4437 InstantService* instant_service =
4438 InstantServiceFactory::GetForProfile(profile);
4439 // The test below matches what's done by ShouldServiceRequestIOThread in
4440 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464441 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314442 factories->emplace(
4443 chrome::kChromeSearchScheme,
4444 content::CreateWebUIURLLoader(
4445 frame_host, chrome::kChromeSearchScheme,
4446 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234447 }
Jay Civellic9bbf72d2018-03-24 01:58:314448
Chris Mumfordbae8a742018-03-01 23:02:234449 extensions::ChromeExtensionWebContentsObserver* web_observer =
4450 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4451 web_contents);
4452
Karan Bhatia91928572018-03-06 01:18:074453 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4454 // to the |web_contents|.
4455 if (!web_observer)
4456 return;
4457
Chris Mumfordbae8a742018-03-01 23:02:234458 const Extension* extension =
4459 web_observer->GetExtensionFromFrame(frame_host, false);
4460 if (!extension)
4461 return;
4462
Sam McNally7414eeb72018-09-03 04:05:304463 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234464 // Support for chrome:// scheme if appropriate.
4465 if ((extension->is_extension() || extension->is_platform_app()) &&
4466 Manifest::IsComponentLocation(extension->location())) {
4467 // Components of chrome that are implemented as extensions or platform apps
4468 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304469 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4470 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4471 }
4472 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4473 (extension->is_platform_app() &&
4474 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234475 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024476 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4477 // URLs. Hosted apps are not allowed because they are served via web servers
4478 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304479 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4480 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024481 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304482 }
4483 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234484 factories->emplace(
4485 content::kChromeUIScheme,
4486 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4487 std::move(allowed_webui_hosts)));
4488 }
Jay Civelli2578ebe2018-06-05 18:44:314489
4490 // Extension with a background page get file access that gets approval from
4491 // ChildProcessSecurityPolicy.
4492 extensions::ExtensionHost* host =
4493 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4494 ->GetBackgroundHostForExtension(extension->id());
4495 if (host) {
4496 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4497 render_process_id));
4498 }
Chris Mumfordbae8a742018-03-01 23:02:234499#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324500}
4501
Ken Rockota0dfaca12018-02-15 07:26:254502bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214503 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254504 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384505 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444506 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264507 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004508 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424509 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184510 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4511 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334512 bool* bypass_redirect_checks,
dalyk0018c16f2020-01-08 20:20:084513 bool* disable_secure_dns,
Yutaka Hirano499d13212019-12-04 11:03:334514 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014515 bool use_proxy = false;
4516
Ken Rockota0dfaca12018-02-15 07:26:254517#if BUILDFLAG(ENABLE_EXTENSIONS)
4518 auto* web_request_api =
4519 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214520 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254521
4522 // NOTE: Some unit test environments do not initialize
4523 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014524 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124525 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384526 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004527 browser_context, frame, render_process_id, type,
4528 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124529 if (bypass_redirect_checks)
4530 *bypass_redirect_checks = use_proxy_for_web_request;
4531 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014532 }
Ken Rockota0dfaca12018-02-15 07:26:254533#endif
Reilly Grant24bf8332018-08-27 21:55:014534
Reilly Grantcc22e602018-09-07 15:25:204535 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444536 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4537 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014538
dalyk0018c16f2020-01-08 20:20:084539#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
4540 if (disable_secure_dns) {
4541 WebContents* web_contents = WebContents::FromRenderFrameHost(frame);
4542 *disable_secure_dns =
Colin Blundell27331f92020-02-05 21:13:014543 web_contents &&
4544 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) &&
4545 captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents)
dalyk0018c16f2020-01-08 20:20:084546 ->is_captive_portal_window();
4547 }
4548#endif
4549
Reilly Grant24bf8332018-08-27 21:55:014550 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254551}
4552
Jian Lide7b43792018-06-01 23:22:134553std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4554ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4555 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144556 int frame_tree_node_id,
4557 const scoped_refptr<network::SharedURLLoaderFactory>&
4558 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134559 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4560 interceptors;
4561#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234562 interceptors.push_back(
4563 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4564 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134565#endif
Ryan Sturmaf523742019-01-16 00:15:454566
Robert Ogden3d5d5b42019-04-22 05:13:114567 ChromeNavigationUIData* chrome_navigation_ui_data =
4568 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4569
Ryan Sturm27d93f412019-02-15 21:30:144570 // TODO(ryansturm): Once this is on the UI thread, stop passing
4571 // |network_loader_factory| and have interceptors create one themselves.
4572 // https://crbug.com/931786
Doug Arnett27154792019-10-15 21:00:594573 if (previews::params::IsLitePageServerPreviewsEnabled()) {
Ryan Sturmaf523742019-01-16 00:15:454574 interceptors.push_back(
Robert Ogden0f4d88682019-09-24 22:27:524575 std::make_unique<
4576 previews::PreviewsLitePageRedirectURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114577 network_loader_factory,
4578 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4579 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454580 }
4581
Robert Ogden6946ad42020-01-13 18:01:304582 if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) {
4583 interceptors.push_back(
4584 std::make_unique<IsolatedPrerenderURLLoaderInterceptor>(
4585 frame_tree_node_id));
4586 }
4587
Jian Lide7b43792018-06-01 23:22:134588 return interceptors;
4589}
4590
Yutaka Hirano8e0b4d432019-07-04 07:12:384591bool ChromeContentBrowserClient::WillInterceptWebSocket(
4592 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334593#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384594 if (!frame) {
4595 return false;
4596 }
4597 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334598 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4599 frame->GetProcess()->GetBrowserContext());
4600
4601 // NOTE: Some unit test environments do not initialize
4602 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4603 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384604 return false;
Yutaka Hirano36c94952018-05-30 21:33:334605
Yutaka Hirano8e0b4d432019-07-04 07:12:384606 return web_request_api->MayHaveProxies();
4607#else
4608 return false;
4609#endif
4610}
4611
4612void ChromeContentBrowserClient::CreateWebSocket(
4613 content::RenderFrameHost* frame,
4614 WebSocketFactory factory,
4615 const GURL& url,
Maks Orlovichab27e242020-01-07 18:10:394616 const net::SiteForCookies& site_for_cookies,
Yutaka Hirano8e0b4d432019-07-04 07:12:384617 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404618 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4619 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384620#if BUILDFLAG(ENABLE_EXTENSIONS)
4621 if (!frame) {
4622 return;
4623 }
4624 auto* web_request_api =
4625 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4626 frame->GetProcess()->GetBrowserContext());
4627
4628 DCHECK(web_request_api);
4629 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
Maks Orlovichab27e242020-01-07 18:10:394630 site_for_cookies.RepresentativeUrl(),
4631 user_agent, std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334632#endif
4633}
4634
Maks Orlovich710d5e32019-07-09 20:16:454635bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464636 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454637 content::BrowserContext* browser_context,
4638 const url::Origin& origin,
Maks Orlovichab27e242020-01-07 18:10:394639 const net::SiteForCookies& site_for_cookies,
Maks Orlovich11001fa2019-10-01 20:41:404640 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454641 bool is_service_worker,
4642 int process_id,
4643 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034644 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454645 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4646#if BUILDFLAG(ENABLE_EXTENSIONS)
4647 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464648 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454649 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404650 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4651 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454652 return true;
4653 }
4654#endif
4655 return false;
4656}
4657
Matt Menkeae4fdb12018-06-02 06:32:544658void ChromeContentBrowserClient::OnNetworkServiceCreated(
4659 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534660 PrefService* local_state;
4661 if (g_browser_process) {
4662 DCHECK(g_browser_process->local_state());
4663 local_state = g_browser_process->local_state();
4664 } else {
Xi Han85079c22019-04-18 21:43:054665 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4666 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534667 }
4668
4669 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4670 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4671
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494672 // Create SystemNetworkContextManager if it has not been created yet. We need
4673 // to set up global NetworkService state before anything else uses it and this
4674 // is the first opportunity to initialize SystemNetworkContextManager with the
4675 // NetworkService.
4676 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534677 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074678
Min Qin8caab1d2018-10-03 17:28:134679 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544680 network_service);
4681}
4682
Julie Jeongeun Kim5984e992019-09-11 11:00:464683mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254684ChromeContentBrowserClient::CreateNetworkContext(
4685 content::BrowserContext* context,
4686 bool in_memory,
4687 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504688 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454689 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254690}
4691
Robert Sesek34f68f312019-01-14 20:25:114692std::vector<base::FilePath>
4693ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024694 DCHECK(!network_contexts_parent_directory_.empty());
4695 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114696}
4697
Min Qin75ed6df2017-12-01 20:39:154698bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134699 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154700#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4701 // It is OK to load the saved offline copy, in MHTML format.
4702 ChromeNavigationUIData* chrome_navigation_ui_data =
4703 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4704 if (!chrome_navigation_ui_data)
4705 return false;
4706 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4707 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4708 return offline_page_data && offline_page_data->is_offline_page();
4709#else
4710 return false;
4711#endif
4712}
4713
Min Qin30a78a12017-12-06 01:29:134714bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4715 const GURL& url,
4716 const std::string& mime_type) {
4717#if BUILDFLAG(ENABLE_EXTENSIONS)
4718 // Special-case user scripts to get downloaded instead of viewed.
4719 return extensions::UserScript::IsURLUserScript(url, mime_type);
4720#else
4721 return false;
4722#endif
4723}
4724
Donna Wu838ac362018-08-10 10:36:334725void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344726 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044727 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grant70788202020-04-21 23:58:304728 if (!base::FeatureList::IsEnabled(features::kWebUsb)) {
4729 LOG(INFO) << "WebUSB feature flag is disabled.";
Reilly Grantc31b8192017-12-15 19:54:344730 return;
Reilly Grant70788202020-04-21 23:58:304731 }
Reilly Grantc31b8192017-12-15 19:54:344732
[email protected]95ebe7c2020-04-08 19:12:454733 CHECK(render_frame_host);
4734 FrameUsbServices::CreateFrameUsbServices(render_frame_host,
4735 std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344736}
4737
Ovidio Henriquez3d729f62020-02-07 00:43:294738content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() {
4739 if (!bluetooth_delegate_)
4740 bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>();
4741 return bluetooth_delegate_.get();
4742}
4743
Reilly Grant0d282322019-01-29 02:42:584744#if !defined(OS_ANDROID)
4745content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4746 if (!serial_delegate_)
4747 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4748 return serial_delegate_.get();
4749}
Matt Reynolds93616f9b2019-06-07 01:28:524750
4751content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4752 if (!hid_delegate_)
4753 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4754 return hid_delegate_.get();
4755}
Reilly Grant0d282322019-01-29 02:42:584756
Balazs Engedya7ff70982018-06-04 18:14:474757std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4758ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langley5f3963f12020-01-21 19:10:334759 content::RenderFrameHost* render_frame_host) {
4760 return AuthenticatorRequestScheduler::CreateRequestDelegate(
4761 render_frame_host);
Balazs Engedya7ff70982018-06-04 18:14:474762}
Nina Satragno8c832df2019-07-29 15:59:394763#endif
Balazs Engedya7ff70982018-06-04 18:14:474764
Jun Cai9409ded2018-01-30 00:19:464765std::unique_ptr<net::ClientCertStore>
4766ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104767 content::BrowserContext* browser_context) {
4768 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464769 ->CreateClientCertStore();
4770}
4771
David Benjamineced01fc2019-02-27 18:29:024772std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394773ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584774 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024775 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034776 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244777 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394778 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034779 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394780 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564781 LoginAuthRequiredCallback auth_required_callback) {
Emily Starkf05b3122020-02-10 19:08:104782 return CreateLoginHandler(
David Benjamineced01fc2019-02-27 18:29:024783 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkf05b3122020-02-10 19:08:104784 std::move(response_headers), std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:394785}
4786
John Abd-El-Maleka67add82018-03-09 18:22:014787bool ChromeContentBrowserClient::HandleExternalProtocol(
4788 const GURL& url,
danakjf4b9e942019-11-29 15:43:044789 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014790 int child_id,
4791 content::NavigationUIData* navigation_data,
4792 bool is_main_frame,
4793 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454794 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454795 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104796 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014797#if BUILDFLAG(ENABLE_EXTENSIONS)
4798 // External protocols are disabled for guests. An exception is made for the
4799 // "mailto" protocol, so that pages that utilize it work properly in a
4800 // WebView.
4801 ChromeNavigationUIData* chrome_data =
4802 static_cast<ChromeNavigationUIData*>(navigation_data);
4803 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4804 (chrome_data &&
4805 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4806 !url.SchemeIs(url::kMailToScheme)) {
4807 return false;
4808 }
4809#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4810
4811#if defined(OS_ANDROID)
4812 // Main frame external protocols are handled by
4813 // InterceptNavigationResourceThrottle.
4814 if (is_main_frame)
4815 return false;
4816#endif // defined(ANDROID)
4817
Emily Stark13b66bdf2019-10-04 17:11:454818 base::PostTask(
4819 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044820 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4821 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014822 return true;
4823}
4824
Jennifer Apacible4f854a82018-04-06 22:22:114825std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284826ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4827 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114828 // Note: content::OverlayWindow::Create() is defined by platform-specific
4829 // implementation in chrome/browser/ui/views. This layering hack, which goes
4830 // through //content and ContentBrowserClient, allows us to work around the
4831 // dependency constraints that disallow directly calling
4832 // chrome/browser/ui/views code either from here or from other code in
4833 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284834 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114835}
4836
Kunihiko Sakamoto19aa7082019-02-25 03:14:434837void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564838 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114839 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564840 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434841 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4842 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564843}
4844
dbeam25472e0c2017-06-23 19:02:314845// Static; handles rewriting Web UI URLs.
4846bool ChromeContentBrowserClient::HandleWebUI(
4847 GURL* url,
4848 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394849 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314850 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394851 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314852 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4853 chrome::kChromeUIHelpHost);
4854 return true; // Return true to update the displayed URL.
4855 }
4856
Hector Carmona566a20b2019-09-13 22:44:424857#if defined(OS_WIN)
4858 // TODO(crbug.com/1003960): Remove when issue is resolved.
4859 if (url->SchemeIs(content::kChromeUIScheme) &&
4860 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4861 url::Replacements<char> replacements;
4862 replacements.SetHost(
4863 chrome::kChromeUIWelcomeHost,
4864 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4865 *url = url->ReplaceComponents(replacements);
4866 return true;
4867 }
4868#endif // defined(OS_WIN)
4869
dbeam25472e0c2017-06-23 19:02:314870 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4871 browser_context, *url)) {
4872 return false;
4873 }
4874
4875#if defined(OS_CHROMEOS)
4876 // Special case : in ChromeOS in Guest mode bookmarks and history are
4877 // disabled for security reasons. New tab page explains the reasons, so
4878 // we redirect user to new tab page.
4879 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4880 if (url->SchemeIs(content::kChromeUIScheme) &&
4881 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4882 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4883 // Rewrite with new tab URL
4884 *url = GURL(chrome::kChromeUINewTabURL);
4885 }
4886 }
4887#endif
4888
4889 return true;
4890}
4891
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064892bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
4893 content::BrowserContext* browser_context,
4894 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:324895 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064896#if defined(OS_ANDROID)
4897 return false;
4898#else
4899 payments::PaymentRequestDisplayManagerFactory::GetInstance()
4900 ->GetForBrowserContext(browser_context)
4901 ->ShowPaymentHandlerWindow(url, std::move(callback));
4902 return true;
4903#endif
4904}
4905
Dan Beam141c48932019-08-22 02:29:394906// static
dbeam25472e0c2017-06-23 19:02:314907bool ChromeContentBrowserClient::HandleWebUIReverse(
4908 GURL* url,
4909 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:424910#if defined(OS_WIN)
4911 // TODO(crbug.com/1003960): Remove when issue is resolved.
4912 // No need to actually reverse-rewrite the URL, but return true to update the
4913 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
4914 if (url->SchemeIs(content::kChromeUIScheme) &&
4915 url->host() == chrome::kChromeUIWelcomeHost) {
4916 return true;
4917 }
4918#endif // defined(OS_WIN)
4919
dbeam25472e0c2017-06-23 19:02:314920 // No need to actually reverse-rewrite the URL, but return true to update the
4921 // displayed URL when rewriting chrome://help to chrome://settings/help.
4922 return url->SchemeIs(content::kChromeUIScheme) &&
4923 url->host() == chrome::kChromeUISettingsHost;
4924}
4925
Alison Maher7f366dc62020-03-03 19:46:004926const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:584927 return ui::NativeTheme::GetInstanceForWeb();
4928}
4929
Clark DuVall5497288d2019-07-17 00:17:564930scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:504931ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
Matt Menke562675cfe2020-01-07 15:50:534932 bool safe_browsing_enabled_for_profile) {
Yuzhu Shen44094e22017-07-18 22:52:354933 DCHECK_CURRENTLY_ON(BrowserThread::IO);
4934
Matt Menke562675cfe2020-01-07 15:50:534935 if (!safe_browsing_enabled_for_profile)
Yuzhu Shencb3011f62018-02-08 02:51:504936 return nullptr;
4937
Yuzhu Shen44094e22017-07-18 22:52:354938 // |safe_browsing_service_| may be unavailable in tests.
4939 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
4940 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:434941 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:354942 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:434943 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:354944 }
4945
Clark DuVall5497288d2019-07-17 00:17:564946 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:354947}
Daniel Vogelheim6008f572018-09-24 14:35:144948
4949base::Optional<std::string>
4950ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Domenic Denicolac3fedd42020-03-20 21:16:594951 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:184952 content::NavigationHandle* handle) {
Domenic Denicolac3fedd42020-03-20 21:16:594953 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
4954 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:144955}
Kunihiko Sakamoto73b803d2018-10-05 09:09:524956
Takashi Toyoshima5af383aa2019-07-22 15:24:224957bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:524958 // We require --user-data-dir flag too so that no dangerous changes are made
4959 // in the user's regular profile.
4960 return base::CommandLine::ForCurrentProcess()->HasSwitch(
4961 switches::kUserDataDir);
4962}
rajendrantfeea8592018-10-19 18:26:064963
4964void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
4965 int32_t network_traffic_annotation_id_hash,
4966 int64_t recv_bytes,
4967 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:034968 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
4969 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
4970 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
4971 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:064972 }
4973}
Ryan Sturmaa05092f2018-10-21 03:56:544974
Ken Rockot4e284d32020-03-06 06:26:494975base::FilePath
4976ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() {
4977 return g_browser_process->profile_manager()->user_data_dir();
4978}
4979
Ryan Sturmaa05092f2018-10-21 03:56:544980content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
4981 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:394982 content::NavigationHandle* navigation_handle,
4983 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:134984 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
4985 initial_state, navigation_handle, current_navigation_url);
4986
4987 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
4988}
4989
4990content::PreviewsState
4991ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
4992 content::PreviewsState initial_state,
4993 content::NavigationHandle* navigation_handle,
4994 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:544995 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:294996 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:214997
Ryan Sturmaa05092f2018-10-21 03:56:544998 // If this is not a main frame, return the initial state. If there are no
4999 // previews in the state, return the state as is.
5000 if (!navigation_handle->IsInMainFrame() ||
5001 navigation_handle->IsSameDocument()) {
5002 return initial_state;
5003 }
5004
Robert Ogdena994eb42019-02-14 19:15:085005 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395006 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085007
Doug Arnettb3b99bc2019-08-09 16:55:565008 // Check if initial state specifies no previews should be considered.
5009 if (initial_state == content::PREVIEWS_OFF)
5010 return initial_state;
5011
Robert Ogdena994eb42019-02-14 19:15:085012 // Do not allow previews on POST navigations since the primary opt-out
5013 // mechanism is to reload the page. Because POST navigations are not
5014 // idempotent, we do not want to show a preview on a POST navigation where
5015 // opting out would cause another navigation, i.e.: a reload.
5016 if (navigation_handle->IsPost())
5017 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395018
5019 content::WebContents* web_contents = navigation_handle->GetWebContents();
5020 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5021
Ryan Sturmda2a0e02018-10-25 01:52:215022 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545023
5024 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5025 Profile::FromBrowserContext(browser_context));
5026 auto* data_reduction_proxy_settings =
5027 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5028 browser_context);
5029 // If the profile does not support previews or Data Saver, do not turn on
5030 // Previews.
5031 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355032 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545033 return content::PREVIEWS_OFF;
5034 }
5035
5036 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215037 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545038 // If this tab does not have a PreviewsUITabHelper, no preview should be
5039 // served.
5040 if (!ui_tab_helper)
5041 return content::PREVIEWS_OFF;
5042
5043 DCHECK(!browser_context->IsOffTheRecord());
5044
5045 // Other previews objects should all exist and be initialized if we have made
5046 // it past earlier checks.
5047 previews::PreviewsDeciderImpl* previews_decider_impl =
5048 previews_service->previews_ui_service()->previews_decider_impl();
5049 DCHECK(previews_decider_impl);
5050
Ryan Sturm647d1d92018-11-07 15:41:395051 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545052 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5053
Ryan Sturm647d1d92018-11-07 15:41:395054 previews::PreviewsUserData* previews_data =
5055 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5056
5057 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315058 // previews) and cannot re-evaluate PreviewsState once previews triggering
5059 // logic has already been run, so they should not change. Assume that
5060 // previews triggering logic has run when PreviewsUserData already exists and
5061 // a Lite Page Redirect preview is not being attempted, since it may also
5062 // create a previews_data before this point.
5063 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395064 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315065 previews_triggering_logic_already_ran =
5066 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395067 } else {
5068 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5069 navigation_handle, previews_decider_impl->GeneratePageId());
5070 }
5071
5072 DCHECK(previews_data);
5073
Robert Ogden01770b362019-05-22 17:36:435074 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5075 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435076 return content::ALL_SUPPORTED_PREVIEWS;
5077 }
5078
Ryan Sturmaa05092f2018-10-21 03:56:545079 bool is_reload =
5080 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5081
Ryan Sturm647d1d92018-11-07 15:41:395082 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515083 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395084
5085 // For now, treat server previews types as a single decision, and do not
5086 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5087 // header, nor does the plumbing exist to modify the PreviewsState within the
5088 // URLLoader.
Seanac57e9b92019-04-29 19:19:315089 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395090 // Copy the server state that was used before the redirect for the initial
5091 // URL.
Robert Ogden869986f2019-06-20 19:12:055092 previews_state |=
5093 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395094 } else {
Doug Arnetta3dc71582018-11-08 00:25:105095 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215096 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305097 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395098 previews_state |= server_previews_enabled_state;
5099 }
Ryan Sturmaa05092f2018-10-21 03:56:545100 }
5101
Sophie Changa71fa5d2019-11-19 23:53:515102 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545103 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315104 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355105 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5106 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545107
5108 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395109 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545110 return content::PREVIEWS_OFF;
5111 }
5112
5113 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395114 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545115 return content::PREVIEWS_NO_TRANSFORM;
5116 }
5117
5118 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395119 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5120 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545121 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395122 }
5123
5124 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5125 if (delegate) {
5126 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5127 }
Ryan Sturmaa05092f2018-10-21 03:56:545128
5129 // If the allowed previews are limited by the embedder, ensure previews honors
5130 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395131 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5132 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545133 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5134 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5135 previews_state = content::PREVIEWS_OFF;
5136 }
Ryan Sturm647d1d92018-11-07 15:41:395137 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545138 return previews_state;
5139}
5140
5141// static
5142content::PreviewsState
5143ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5144 const GURL& url,
5145 data_reduction_proxy::DataReductionProxyData* drp_data,
5146 previews::PreviewsUserData* previews_user_data,
5147 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055148 content::PreviewsState initial_state,
5149 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545150 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5151 if (!previews::HasEnabledPreviews(initial_state))
5152 return content::PREVIEWS_OFF;
5153
5154 // Check if the server sent a preview directive.
5155 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555156 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545157
Ryan Sturmaa05092f2018-10-21 03:56:545158 // Check the various other client previews types.
5159 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055160 previews_user_data, url, previews_state, previews_decider,
5161 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545162}
5163
5164content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5165 content::PreviewsState initial_state,
5166 content::NavigationHandle* navigation_handle,
5167 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135168 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5169 initial_state, navigation_handle, response_headers);
5170
5171 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5172}
5173
5174content::PreviewsState
5175ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5176 content::PreviewsState initial_state,
5177 content::NavigationHandle* navigation_handle,
5178 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5180 // Only support HTTP and HTTPS.
5181 if (navigation_handle->IsErrorPage() ||
5182 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5183 return content::PREVIEWS_OFF;
5184 }
5185
5186 // If this is not a main frame, return the initial state. If there are no
5187 // previews in the state, return the state as is.
5188 if (!previews::HasEnabledPreviews(initial_state) ||
5189 !navigation_handle->IsInMainFrame() ||
5190 navigation_handle->IsSameDocument()) {
5191 return initial_state;
5192 }
5193
5194 // WebContents that don't have a PreviewsUITabHelper are not supported.
5195 PreviewsUITabHelper* ui_tab_helper =
5196 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5197 if (!ui_tab_helper)
5198 return content::PREVIEWS_OFF;
5199
5200 // If we did not previously create a PreviewsUserData, do not go any further.
5201 previews::PreviewsUserData* previews_user_data =
5202 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5203 if (!previews_user_data)
5204 return content::PREVIEWS_OFF;
5205
5206 PreviewsService* previews_service =
5207 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5208 navigation_handle->GetWebContents()->GetBrowserContext()));
5209
5210 if (!previews_service || !previews_service->previews_ui_service())
5211 return content::PREVIEWS_OFF;
5212
5213// Check if offline previews are being used and set it in the user data.
5214#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5215 offline_pages::OfflinePageTabHelper* tab_helper =
5216 offline_pages::OfflinePageTabHelper::FromWebContents(
5217 navigation_handle->GetWebContents());
5218
Ryan Sturmfc7d92f2019-02-12 02:24:235219 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5220 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5221
5222 // If this is an offline page, but not a preview, then we should not attempt
5223 // any previews or surface the previews UI.
5224 if (is_offline_page && !is_offline_preview)
5225 return content::PREVIEWS_OFF;
5226
5227 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545228#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5229
5230 // Annotate request if no-transform directive found in response headers.
5231 if (response_headers &&
5232 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265233 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545234 }
5235
5236 previews::PreviewsDeciderImpl* previews_decider_impl =
5237 previews_service->previews_ui_service()->previews_decider_impl();
5238 DCHECK(previews_decider_impl);
5239
Clark DuVall9c5a72cc2018-10-25 01:29:215240 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5241 auto* settings =
5242 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5243 navigation_handle->GetWebContents()->GetBrowserContext());
5244 if (settings) {
5245 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5246 // does not yet have all the response information.
5247 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5248 response_headers);
5249 }
Ryan Sturmaa05092f2018-10-21 03:56:545250
5251 // Determine effective PreviewsState for this committed main frame response.
5252 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215253 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055254 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545255
5256 // Double check that we never serve a preview when we have a
5257 // cache-control:no-transform directive.
5258 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5259 !previews::HasEnabledPreviews(committed_state));
5260
Robert Ogdended292c6f2019-05-03 22:44:515261 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545262 previews_user_data->set_committed_previews_state(committed_state);
5263
5264 previews::PreviewsType committed_type =
5265 previews::GetMainFramePreviewsType(committed_state);
5266
5267 // Capture committed previews type, if any, in PreviewsUserData.
5268 // Note: this is for the subset of previews types that are decided upon
5269 // navigation commit. Previews types that are determined prior to
5270 // navigation (such as for offline pages or for redirecting to another
5271 // url), are not set here.
5272 previews_user_data->SetCommittedPreviewsType(committed_type);
5273
5274 // Log the commit decision.
5275 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5276 previews_decider_impl->LogPreviewDecisionMade(
5277 (previews_user_data->cache_control_no_transform_directive()
5278 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5279 : previews::PreviewsEligibilityReason::COMMITTED),
5280 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055281 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055282 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545283
5284 return committed_state;
5285}
Charlie Harrison650e11422018-12-04 00:37:265286
5287void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5288 content::RenderFrameHost* render_frame_host,
5289 blink::mojom::WebFeature feature) {
5290 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5291 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5292 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5293 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315294
5295 // For the SameSite-by-default-cookies related features, log
5296 // the site engagement score for the site whose cookie was blocked. This is to
5297 // gauge the user impact of the cookies being blocked.
5298 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265299}
Yutaka Hirano968d6252018-12-04 05:09:315300
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525301std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315302 return ::GetProduct();
5303}
5304
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525305std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315306 return ::GetUserAgent();
5307}
Sam McNallyd54e23f92019-01-16 04:42:395308
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525309blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175310 return ::GetUserAgentMetadata();
5311}
5312
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525313base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275314 // This icon is available on Android, but adds 19KiB to the APK. Since it
5315 // isn't used on Android we exclude it to avoid bloat.
5316#if !defined(OS_ANDROID)
5317 return base::Optional<gfx::ImageSkia>(
5318 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5319 IDR_PRODUCT_LOGO_256));
5320#else
5321 return base::nullopt;
5322#endif
5323}
5324
Sam McNallyd54e23f92019-01-16 04:42:395325bool ChromeContentBrowserClient::IsBuiltinComponent(
5326 content::BrowserContext* browser_context,
5327 const url::Origin& origin) {
5328#if BUILDFLAG(ENABLE_EXTENSIONS)
5329 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5330 browser_context, origin);
5331#else
5332 return false;
5333#endif
5334}
Oleg Davydov2cc0167b2019-02-05 14:32:485335
5336bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5337 const GURL& url,
5338 content::BrowserContext* context) {
5339 PolicyBlacklistService* service =
5340 PolicyBlacklistFactory::GetForBrowserContext(context);
5341
5342 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5343 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5344 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5345}
Dominic Mazzoni21fb0282019-02-13 18:32:475346
5347ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5348 content::BrowserContext* browser_context) {
5349 Profile* profile = Profile::FromBrowserContext(browser_context);
5350 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5351}
Eric Karld6cd75b2019-03-14 22:01:365352
5353#if defined(OS_ANDROID)
5354content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525355ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Chris Blume7f752e32020-02-14 22:22:335356 if (viz::AlwaysUseWideColorGamut() ||
Chris Blume5b36a01a2020-03-13 21:35:425357 features::IsDynamicColorGamutEnabled()) {
Eric Karld6cd75b2019-03-14 22:01:365358 return WideColorGamutHeuristic::kUseDisplay;
5359 }
Khushal1fc0da52019-10-09 00:38:565360
5361 if (display::Display::HasForceDisplayColorProfile() &&
5362 display::Display::GetForcedDisplayColorProfile() ==
5363 gfx::ColorSpace::CreateDisplayP3D65()) {
5364 return WideColorGamutHeuristic::kUseDisplay;
5365 }
5366
Eric Karld6cd75b2019-03-14 22:01:365367 return WideColorGamutHeuristic::kNone;
5368}
5369#endif
Ehsan Karamad91413d72019-03-22 16:37:485370
5371base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435372ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465373 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485374 base::flat_set<std::string> mime_types;
5375#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465376 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485377 for (const auto& pair : map)
5378 mime_types.insert(pair.first);
5379#endif
5380 return mime_types;
5381}
Yao Xiaod06607b2019-05-02 23:16:365382
5383void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5384 const content::WebContents* web_contents,
5385 const content::RenderFrameHost* frame_host,
5386 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525387 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365388 const ChromeSubresourceFilterClient* client =
5389 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5390 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045391 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365392 if (!user_gesture) {
5393 if (base::FeatureList::IsEnabled(
5394 blink::features::
5395 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5396 download_policy->SetDisallowed(
5397 content::NavigationDownloadType::kAdFrameNoGesture);
5398 } else {
5399 download_policy->SetAllowed(
5400 content::NavigationDownloadType::kAdFrameNoGesture);
5401 }
Yao Xiaod06607b2019-05-02 23:16:365402 }
5403 }
5404}
Jun Cai732a05e32019-05-29 19:34:195405
5406bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5407 content::BrowserContext* browser_context,
5408 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525409 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195410 const HostContentSettingsMap* const content_settings =
5411 HostContentSettingsMapFactory::GetForProfile(
5412 Profile::FromBrowserContext(browser_context));
5413
5414 if (content_settings->GetContentSetting(
5415 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455416 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195417 std::string()) == CONTENT_SETTING_BLOCK) {
5418 return true;
5419 }
5420
5421 return false;
5422}
5423
5424void ChromeContentBrowserClient::BlockBluetoothScanning(
5425 content::BrowserContext* browser_context,
5426 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525427 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195428 HostContentSettingsMap* const content_settings =
5429 HostContentSettingsMapFactory::GetForProfile(
5430 Profile::FromBrowserContext(browser_context));
5431
5432 content_settings->SetContentSettingDefaultScope(
5433 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455434 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195435 CONTENT_SETTING_BLOCK);
5436}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475437
5438bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5439#if defined(OS_ANDROID)
5440 return extra_icu::ModuleProvider::IsModuleInstalled();
5441#endif
5442 return false;
5443}
Guido Urdaneta4030d6a32019-10-17 09:38:165444
5445bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5446 content::BrowserContext* browser_context,
5447 const GURL& url,
5448 const GURL& site_for_cookies,
5449 const base::Optional<url::Origin>& top_frame_origin) {
5450 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5451 return CookieSettingsFactory::GetForProfile(
5452 Profile::FromBrowserContext(browser_context))
5453 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5454}
Sam Goto5cf068e82019-11-04 23:08:445455
5456#if !defined(OS_ANDROID)
5457void ChromeContentBrowserClient::FetchRemoteSms(
5458 content::BrowserContext* browser_context,
5459 const url::Origin& origin,
5460 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5461 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5462}
5463#endif
Roger Tawa03ffdbd2020-01-16 18:12:545464
5465void ChromeContentBrowserClient::IsClipboardPasteAllowed(
5466 content::WebContents* web_contents,
5467 const GURL& url,
5468 const ui::ClipboardFormatType& data_type,
5469 const std::string& data,
5470 IsClipboardPasteAllowedCallback callback) {
5471#if BUILDFLAG(FULL_SAFE_BROWSING)
5472 // Safe browsing does not support images, so accept without checking.
5473 // TODO(crbug.com/1013584): check policy on what to do about unsupported
5474 // types when it is implemented.
5475 if (data_type.Equals(ui::ClipboardFormatType::GetBitmapType())) {
5476 std::move(callback).Run(ClipboardPasteAllowed(true));
5477 return;
5478 }
5479
5480 Profile* profile =
5481 Profile::FromBrowserContext(web_contents->GetBrowserContext());
5482 safe_browsing::DeepScanningDialogDelegate::Data dialog_data;
5483 if (safe_browsing::DeepScanningDialogDelegate::IsEnabled(profile, url,
5484 &dialog_data)) {
5485 dialog_data.text.push_back(base::UTF8ToUTF16(data));
5486 safe_browsing::DeepScanningDialogDelegate::ShowForWebContents(
5487 web_contents, std::move(dialog_data),
5488 base::BindOnce(
5489 [](IsClipboardPasteAllowedCallback callback,
5490 const safe_browsing::DeepScanningDialogDelegate::Data& data,
5491 const safe_browsing::DeepScanningDialogDelegate::Result&
5492 result) {
5493 std::move(callback).Run(
5494 ClipboardPasteAllowed(result.text_results[0]));
5495 },
Dominique Fauteux-Chapleau5b147162020-01-17 17:08:245496 std::move(callback)),
5497 safe_browsing::DeepScanAccessPoint::PASTE);
Roger Tawa03ffdbd2020-01-16 18:12:545498 } else {
5499 std::move(callback).Run(ClipboardPasteAllowed(true));
5500 }
5501#else
5502 std::move(callback).Run(ClipboardPasteAllowed(true));
5503#endif // BUILDFLAG(FULL_SAFE_BROWSING)
5504}
Lukasz Anforowicz4600ea32020-01-18 02:37:485505
Lukasz Anforowicz1feeba182020-03-16 20:32:025506void ChromeContentBrowserClient::
5507 LogUkmEventForCrossOriginFetchFromContentScript3(
5508 const std::string& isolated_world_host) {
5509#if BUILDFLAG(ENABLE_EXTENSIONS)
5510 const std::string& extension_id = isolated_world_host;
5511 ukm::SourceId source_id =
5512 ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id);
5513 if (source_id != ukm::kInvalidSourceId) {
5514 ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event(
5515 source_id);
5516 ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get());
5517 }
5518#endif
5519}
5520
Lukasz Anforowicz4600ea32020-01-18 02:37:485521#if BUILDFLAG(ENABLE_PLUGINS)
5522bool ChromeContentBrowserClient::ShouldAllowPluginCreation(
5523 const url::Origin& embedder_origin,
5524 const content::PepperPluginInfo& plugin_info) {
5525#if BUILDFLAG(ENABLE_PDF)
5526 if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) {
5527#if BUILDFLAG(ENABLE_EXTENSIONS)
5528 // Allow embedding the internal PDF plugin in the built-in PDF extension.
5529 if (embedder_origin.scheme() == extensions::kExtensionScheme &&
5530 embedder_origin.host() == extension_misc::kPdfExtensionId) {
5531 return true;
5532 }
5533#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5534
5535 // Allow embedding the internal PDF plugin in chrome://print.
5536 if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL)))
5537 return true;
5538
5539 // Only allow the PDF plugin in the known, trustworthy origins that are
5540 // allowlisted above. See also https://crbug.com/520422 and
5541 // https://crbug.com/1027173.
5542 return false;
5543 }
5544#endif // BUILDFLAG(ENABLE_PDF)
5545
5546 return true;
5547}
5548#endif // BUILDFLAG(ENABLE_PLUGINS)
Alexander Cooperc8448702020-03-14 01:39:565549
5550#if BUILDFLAG(ENABLE_VR)
5551content::XrIntegrationClient*
5552ChromeContentBrowserClient::GetXrIntegrationClient() {
5553 if (!xr_integration_client_)
5554 xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>(
5555 util::PassKey<ChromeContentBrowserClient>());
5556 return xr_integration_client_.get();
5557}
5558#endif // BUILDFLAG(ENABLE_VR)