blob: 9eafea4cd9fa8483a5735d242fc42af91807c3cb [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"
[email protected]b8148ac2011-07-13 22:03:2543#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3044#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4745#include "chrome/browser/browsing_data/browsing_data_helper.h"
msramek1c2b3ca2017-03-14 17:57:5646#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
[email protected]d5a74be2014-08-08 01:01:2747#include "chrome/browser/chrome_content_browser_client_parts.h"
[email protected]317f96c92011-05-31 06:53:4148#include "chrome/browser/chrome_quota_permission_context.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"
[email protected]8093a542011-05-13 07:29:3251#include "chrome/browser/content_settings/tab_specific_content_settings.h"
Robbie McElrath1294d242019-05-31 20:46:2252#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
53#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3054#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
55#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0656#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0857#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4958#include "chrome/browser/download/download_prefs.h"
Lily Chenc2c9e9f2019-12-05 19:55:3159#include "chrome/browser/engagement/site_engagement_service.h"
Maks Orlovich710d5e32019-07-09 20:16:4560#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0161#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1962#include "chrome/browser/font_family_cache.h"
Peng Huangee82ef82019-11-22 13:15:2963#include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h"
Matt Reynolds93616f9b2019-06-07 01:28:5264#include "chrome/browser/hid/chrome_hid_delegate.h"
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"
jyasskinc993ce8d2016-03-31 00:38:3488#include "chrome/browser/permissions/permission_context_base.h"
Adam Langley85339f62018-02-12 22:03:5689#include "chrome/browser/permissions/permission_request_manager.h"
[email protected]0609b17f2011-05-31 20:13:4290#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1191#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4892#include "chrome/browser/plugins/plugin_utils.h"
[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"
John Abd-El-Malek1f7fc912018-07-26 02:48:06107#include "chrome/browser/profiles/renderer_updater.h"
108#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56109#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
110#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44111#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40113#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45114#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31115#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
116#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Carlos IL4ee307e2018-12-22 03:19:00117#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40118#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35119#include "chrome/browser/safe_browsing/ui_manager.h"
120#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43121#include "chrome/browser/search/search.h"
Jay Civelli2578ebe2018-06-05 18:44:31122#include "chrome/browser/sessions/session_tab_helper.h"
Sam Goto5cf068e82019-11-04 23:08:44123#include "chrome/browser/sharing/sms/sms_remote_fetcher.h"
Reilly Grantcc22e602018-09-07 15:25:20124#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35125#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40126#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23127#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28128#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02129#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48130#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Joe DeBlasio9b996292019-01-31 05:09:32131#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07132#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35133#include "chrome/browser/ssl/ssl_error_handler.h"
Christopher Thompson4137cec2017-12-19 05:34:23134#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10135#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35136#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45137#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52138#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19139#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44140#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38141#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51142#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08143#include "chrome/browser/ui/browser_navigator.h"
144#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43145#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39146#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54147#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56148#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25149#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44150#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58151#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50152#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01153#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25154#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53155#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25156#include "chrome/browser/web_applications/components/app_registrar.h"
157#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23158#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22159#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01160#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51161#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14162#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22163#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30164#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02165#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50166#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34167#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37168#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12169#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19170#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12171#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22172#include "chrome/common/prerender_util.h"
Mike Wittman08b377d2019-11-27 21:06:32173#include "chrome/common/profiler/stack_sampling_configuration.h"
[email protected]3e69bc82011-05-26 23:22:38174#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28175#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02176#include "chrome/common/secure_origin_whitelist.h"
[email protected]c5dbef02011-05-13 05:06:09177#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47178#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37179#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18180#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30181#include "chrome/installer/util/google_update_settings.h"
brettwf1958912015-10-07 19:43:12182#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53183#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44184#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04185#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48186#include "components/cloud_devices/common/cloud_devices_switches.h"
mukai8eaec822014-10-25 17:53:16187#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09188#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16189#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52190#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45191#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08192#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03193#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09194#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Clark DuVall0e901722019-08-14 23:31:37195#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
Ryan Sturmaa05092f2018-10-21 03:56:54196#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28197#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43198#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09199#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32200#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03201#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24202#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43203#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01204#include "components/feature_engagement/public/feature_constants.h"
205#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39206#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20207#include "components/language/core/browser/pref_names.h"
[email protected]8e885de2014-07-22 23:36:53208#include "components/metrics/client_info.h"
drogerc690e8802015-09-21 14:29:16209#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12210#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
211#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
212#include "components/page_load_metrics/browser/page_load_metrics_util.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06213#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53214#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54215#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18216#include "components/policy/core/common/policy_service.h"
217#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26218#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54219#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08220#include "components/prefs/pref_service.h"
221#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21222#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54223#include "components/previews/content/previews_decider_impl.h"
224#include "components/previews/content/previews_ui_service.h"
225#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54226#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45227#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43228#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56229#include "components/rappor/public/rappor_utils.h"
nzolghadrd87a308d2016-12-07 15:45:56230#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35231#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
Yuzhu Shen44094e22017-07-18 22:52:35232#include "components/safe_browsing/browser/url_checker_delegate.h"
Nico Weberbc5b06f2019-07-26 14:00:13233#include "components/safe_browsing/buildflags.h"
timvolodine89cf11712017-05-15 18:05:07234#include "components/safe_browsing/common/safe_browsing_prefs.h"
Tim Volodinee45938472017-09-21 10:08:22235#include "components/safe_browsing/db/database_manager.h"
Yuzhu Shencb3011f62018-02-08 02:51:50236#include "components/safe_browsing/features.h"
Jialiu Linbdbb81d2017-10-11 21:29:09237#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14238#include "components/security_interstitials/content/origin_policy_ui.h"
Evan Stade1e71d6dd2019-10-29 03:04:49239#include "components/security_interstitials/content/ssl_cert_reporter.h"
240#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
David Rogere8e83f3c2019-09-12 10:56:23241#include "components/signin/public/identity_manager/identity_manager.h"
csharrisone985ebc2017-04-04 17:05:03242#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17243#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21244#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28245#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33246#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46247#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22248#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43249#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30250#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38251#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28252#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03253#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31254#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41255#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09256#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03257#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59258#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19259#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31260#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35261#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47262#include "content/public/browser/navigation_handle.h"
263#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11264#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50265#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30266#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33267#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05268#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34269#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48270#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27271#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13272#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08273#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19274#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21275#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23276#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43277#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18278#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56279#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40280#include "content/public/common/content_switches.h"
Hans Wennborg5ffd1392019-10-16 11:00:02281#include "content/public/common/navigation_policy.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18282#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58283#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57284#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23285#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44286#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31287#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05288#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56289#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43290#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59291#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48292#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30293#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28294#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04295#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31296#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44297#include "media/media_buildflags.h"
298#include "media/mojo/buildflags.h"
Guido Urdanetad06ae842019-10-10 20:04:12299#include "media/webrtc/webrtc_switches.h"
Shimi Zhang6b72d292019-07-12 20:52:42300#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:52301#include "mojo/public/cpp/bindings/receiver_set.h"
Ken Rockot0adc1e42019-05-24 08:20:08302#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53303#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51304#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58305#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23306#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46307#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57308#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14309#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38310#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19311#include "printing/buildflags/buildflags.h"
Takashi Toyoshima128441462019-10-16 04:19:17312#include "services/network/public/cpp/features.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37313#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50314#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50315#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13316#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05317#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34318#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03319#include "services/strings/grit/services_strings.h"
DongJun Kimfebb3c22019-10-21 02:08:06320#include "storage/browser/file_system/external_mount_points.h"
Hans Wennborg5ffd1392019-10-16 11:00:02321#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
John Delaneyac24e572019-04-30 19:47:02322#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02323#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Leon Hanc819dc62019-01-28 04:30:19324#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Lily Chenc2c9e9f2019-12-05 19:55:31325#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17326#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21327#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26328#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18329#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39330#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08331#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35332#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21333#include "ui/base/ui_base_switches.h"
Khushal1fc0da52019-10-09 00:38:56334#include "ui/display/display.h"
Evan Liu7cdbf8872019-06-19 16:47:21335#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49336#include "ui/native_theme/caption_style.h"
337#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57338#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45339#include "url/gurl.h"
340#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26341
[email protected]b48c9182011-10-26 18:03:30342#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20343#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38344#include "chrome/browser/chrome_browser_main_win.h"
Jerry Lina0de7ce2018-06-22 15:18:36345#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18346#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38347#elif defined(OS_MACOSX)
Avi Drissmana2969a552019-10-30 15:32:25348#include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h"
[email protected]199fc7a2011-09-28 22:45:38349#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:30350#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42351#include "ash/public/cpp/tablet_mode.h"
Joshua Peraza30d8fc72019-08-19 17:24:30352#include "chrome/app/chrome_crash_reporter_client.h"
hashimotoa53e7e82016-10-26 06:30:47353#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17354#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30355#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24356#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18357#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08358#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48359#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41360#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32361#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58362#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00363#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
364#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44365#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39366#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31367#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33368#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44369#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10370#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36371#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27372#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31373#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10374#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21375#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10376#include "chromeos/constants/chromeos_switches.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11377#include "components/crash/content/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07378#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58379#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50380#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26381#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30382#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09383#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35384#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45385#include "chrome/android/features/dev_ui/buildflags.h"
Tibor Goldschwendtbf1b96e2019-10-07 22:03:47386#include "chrome/android/modules/extra_icu/provider/module_provider.h"
zqzhang93e959d12017-03-16 13:10:20387#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36388#include "chrome/browser/android/chrome_context_util.h"
389#include "chrome/browser/android/devtools_manager_delegate_android.h"
390#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
391#include "chrome/browser/android/service_tab_launcher.h"
392#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42393#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09394#include "chrome/browser/chrome_browser_main_android.h"
Min Qin869874062019-10-15 19:27:56395#include "chrome/browser/download/android/available_offline_content_provider.h"
396#include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07397#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38398#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11399#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07400#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47401#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36402#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54403#include "services/service_manager/public/cpp/interface_provider.h"
agrieve05398f52015-06-24 18:59:00404#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36405#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45406#if BUILDFLAG(DFMIFY_DEV_UI)
Samuel Huang3a1ce1c32019-10-16 17:34:04407#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h"
Samuel Huange63048d2019-09-03 20:35:45408#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30409#elif defined(OS_POSIX)
410#include "chrome/browser/chrome_browser_main_posix.h"
411#endif
412
tmartinofb341882017-02-10 19:36:53413#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40414#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36415#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54416#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59417#include "chrome/browser/media/unified_autoplay_config.h"
Marc Treib7895941d2017-11-28 12:37:02418#include "chrome/browser/search/instant_service.h"
419#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46420#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51421#include "chrome/browser/ui/browser.h"
422#include "chrome/browser/ui/browser_finder.h"
423#include "chrome/browser/ui/browser_list.h"
424#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20425#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51426#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39427#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
428#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43429#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27430#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28431#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36432
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33433#if defined(OS_WIN) || defined(OS_MACOSX) || \
434 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52435#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
Guido Urdanetad06ae842019-10-10 20:04:12436#include "services/service_manager/sandbox/features.h"
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52437#endif
438
Joshua Perazace68e2f2019-09-23 18:44:24439#if defined(OS_LINUX)
440#include "components/crash/content/app/crash_switches.h"
441#include "components/crash/content/app/crashpad.h"
442#endif
443
[email protected]a220b5932013-09-21 03:47:44444#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02445#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02446#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13447#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02448#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13449#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43450#endif
[email protected]b80f68432011-05-02 17:22:30451
Maggie Caia2f03f52019-04-02 02:13:28452// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
453// single navigation throttle to display the intent picker on all platforms.
454#if !defined(OS_ANDROID)
455#if defined(OS_CHROMEOS)
456#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
Maggie Cai00e2a21e2019-10-16 00:47:51457#include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h"
Maggie Caia2f03f52019-04-02 02:13:28458#else
459#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
460#endif
461#endif
462
[email protected]e8b6ca02013-07-10 18:00:51463#if defined(TOOLKIT_VIEWS)
464#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
465#endif
466
estaded3aa0e82016-02-17 22:55:21467#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22468#if defined(USE_X11)
469#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
470#else
estaded3aa0e82016-02-17 22:55:21471#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22472#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51473#endif
474
Mohsen Izadif1958f22019-01-18 20:29:31475#if defined(USE_OZONE)
476#include "ui/ozone/public/ozone_platform.h"
477#endif
478
[email protected]e8b6ca02013-07-10 18:00:51479#if defined(USE_X11)
480#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
481#endif
482
brettwab78fef2016-10-12 02:56:05483#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19484#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
485#endif
486
Nico Weberaf3b00b2017-09-11 17:58:17487#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55488#include "components/nacl/browser/nacl_browser.h"
489#include "components/nacl/browser/nacl_host_message_filter.h"
490#include "components/nacl/browser/nacl_process_host.h"
491#include "components/nacl/common/nacl_process_type.h"
492#include "components/nacl/common/nacl_switches.h"
493#endif
494
brettw00899e62016-11-12 02:10:17495#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05496#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20497#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27498#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23499#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32500#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51501#include "chrome/browser/extensions/user_script_listener.h"
502#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28503#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Evan Stade1e71d6dd2019-10-29 03:04:49504#include "chrome/browser/ui/browser_commands.h"
Eric Willigers007ef302019-08-29 09:58:46505#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39506#include "components/guest_view/browser/guest_view_base.h"
507#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25508#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31509#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35510#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32511#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12512#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57513#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48514#include "extensions/browser/guest_view/web_view/web_view_guest.h"
515#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
516#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31517#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27518#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28519#include "extensions/common/extension.h"
520#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13521#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28522#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33523#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28524#include "extensions/common/permissions/permissions_data.h"
525#include "extensions/common/permissions/socket_permission.h"
526#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34527#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25528
brettw4b461082016-11-19 18:55:16529#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55530#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27531#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39532#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55533#endif
534
bauerb8f9c37742017-03-30 15:04:12535#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
536#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
537#endif
538
yilkal240b4f22019-11-27 19:09:06539#if defined(OS_CHROMEOS)
540#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h"
541#endif // defined(OS_CHROMEOS)
542
thakis678822e2017-04-20 17:20:34543#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38544#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09545#endif
546
weilifabbf7572017-05-22 19:05:16547#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21548#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16549#endif
Lei Zhanga2fa14c2018-05-15 00:05:21550
Xiaohan Wanga4e41842018-06-26 18:45:10551#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49552#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26553#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10554#include "chrome/browser/media/widevine_hardware_caps_win.h"
555#include "third_party/widevine/cdm/widevine_cdm_common.h"
556#endif
557#endif
558
mmenkedb2637ff2017-03-30 23:59:42559#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
560#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
561#endif
562
Nico Weberbc5b06f2019-07-26 14:00:13563#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35564#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
565#endif
566
Jian Lide7b43792018-06-01 23:22:13567#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54568#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13569#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
570#endif
571
Will Cassella40837ba2019-07-01 21:32:00572#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43573#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
574#endif
575
John Lee0ee748bf2019-12-11 21:35:44576#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
577#include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h"
578#endif
579
[email protected]c7abd422012-09-25 00:20:08580using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39581using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31582using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13583using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59584using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00585using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02586using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11587using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07588using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33589using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13590using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05591using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38592using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39593
[email protected]0daaebfe2014-03-15 00:09:05594#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20595using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05596#endif
597
brettw00899e62016-11-12 02:10:17598#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28599using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27600using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28601using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28602using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27603#endif
604
brettw4b461082016-11-19 18:55:16605#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55606using plugins::ChromeContentBrowserClientPluginsPart;
607#endif
608
[email protected]c5dbef02011-05-13 05:06:09609namespace {
610
michaeln10e5fc352017-02-07 02:07:58611const storage::QuotaSettings* g_default_quota_settings;
612
brettw4b461082016-11-19 18:55:16613#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42614// TODO(teravest): Add renderer-side API-specific checking for these APIs so
615// that blanket permission isn't granted to all dev channel APIs for these.
616// http://crbug.com/386743
617const char* const kPredefinedAllowedDevChannelOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44618 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
619 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
[email protected]aec5ed52014-06-20 07:51:42620};
621
[email protected]9de4da52014-05-24 12:26:50622const char* const kPredefinedAllowedFileHandleOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44623 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
624 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
[email protected]10c39222013-11-13 20:09:25625};
626
[email protected]9de4da52014-05-24 12:26:50627const char* const kPredefinedAllowedSocketOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44628 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
629 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
630 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
631 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
632 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
Aran Gilmanf010bdd2019-08-28 19:55:44633 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
634 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
635 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
636 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
637 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
638 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
639 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
640 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
641 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
642 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
643 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
644 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
645 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40646};
[email protected]93f72062013-05-29 20:29:40647#endif
[email protected]e461da2f2012-02-16 19:06:40648
Will Harris1b9b4152019-08-21 22:33:50649#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30650// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
651// running on Windows 10 1511 and above. See
652// https://blogs.windows.com/blog/tag/code-integrity-guard/.
653const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harrisa9eaa282019-11-01 17:51:35654 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50655#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
656 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30657
lazyboy5d5fede02016-03-10 04:10:14658enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53659 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14660 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53661
662 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14663 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53664
665 // An extension or app tried to load a resource of a different platform app in
666 // a tab.
667 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
668
669 // A non-app and non-extension page tried to load a platform app in a tab.
670 APP_LOADED_IN_TAB_SOURCE_OTHER,
671
lazyboy5d5fede02016-03-10 04:10:14672 APP_LOADED_IN_TAB_SOURCE_MAX
673};
674
Lei Zhang2cfceac2018-11-14 19:36:33675// Cached version of the locale so we can return the locale on the I/O
676// thread.
677std::string& GetIOThreadApplicationLocale() {
678 static base::NoDestructor<std::string> s;
679 return *s;
680}
681
[email protected]f8f93eb2012-09-25 03:06:24682// Returns a copy of the given url with its host set to given host and path set
683// to given path. Other parts of the url will be the same.
684GURL ReplaceURLHostAndPath(const GURL& url,
685 const std::string& host,
686 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05687 url::Replacements<char> replacements;
688 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
689 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24690 return url.ReplaceComponents(replacements);
691}
692
madfbd10852017-01-20 03:15:33693// Handles the rewriting of the new tab page URL based on group policy.
694bool HandleNewTabPageLocationOverride(
695 GURL* url,
696 content::BrowserContext* browser_context) {
697 if (!url->SchemeIs(content::kChromeUIScheme) ||
698 url->host() != chrome::kChromeUINewTabHost)
699 return false;
700
701 Profile* profile = Profile::FromBrowserContext(browser_context);
702 std::string ntp_location =
703 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
704 if (ntp_location.empty())
705 return false;
706
707 *url = GURL(ntp_location);
708 return true;
709}
710
Becca Hughesfe8c32c2018-03-21 13:36:56711#if !defined(OS_ANDROID)
712// Check if the current url is whitelisted based on a list of whitelisted urls.
713bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie8d9034f12019-11-28 14:48:57714 base::Value::ConstListView whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56715 // Only check on HTTP and HTTPS pages.
716 if (!current_url.SchemeIsHTTPOrHTTPS())
717 return false;
718
719 for (auto const& value : whitelisted_urls) {
720 ContentSettingsPattern pattern =
721 ContentSettingsPattern::FromString(value.GetString());
722 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
723 continue;
724 if (pattern.Matches(current_url))
725 return true;
726 }
727
728 return false;
729}
730
731// Check if autoplay is allowed by policy configuration.
732bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
733 PrefService* prefs) {
734 DCHECK(prefs);
735
736 // Check if we have globally allowed autoplay by policy.
737 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
738 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
739 return true;
740 }
741
742 if (!contents)
743 return false;
744
745 // Check if the current URL matches a URL pattern on the whitelist.
746 const base::ListValue* autoplay_whitelist =
747 prefs->GetList(prefs::kAutoplayWhitelist);
748 return autoplay_whitelist &&
749 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
750 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
751}
752#endif
753
Joshua Perazaf890e4b2019-01-03 19:19:02754#if defined(OS_ANDROID)
755int GetCrashSignalFD(const base::CommandLine& command_line) {
756 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
757}
758#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03759breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
760 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02761 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52762 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02763 {
764 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31765 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03766 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50767 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02768 crash_handler->StartUploaderThread();
769 return crash_handler;
770 }
771}
772
avi3ef9ec9e2014-12-22 22:50:17773int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24774 if (crash_reporter::IsCrashpadEnabled()) {
775 int fd;
776 pid_t pid;
777 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
778 }
779
[email protected]9de4da52014-05-24 12:26:50780 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39781 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31782 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02783 if (!crash_handler)
784 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18785 return crash_handler->GetDeathSignalSocket();
786 }
787
788 std::string process_type =
789 command_line.GetSwitchValueASCII(switches::kProcessType);
790
[email protected]779dd282013-10-19 15:57:02791 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31792 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02793 if (!crash_handler)
794 crash_handler = CreateCrashHandlerHost(process_type);
795 return crash_handler->GetDeathSignalSocket();
796 }
[email protected]a1733df2012-06-22 11:24:18797
[email protected]779dd282013-10-19 15:57:02798 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31799 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02800 if (!crash_handler)
801 crash_handler = CreateCrashHandlerHost(process_type);
802 return crash_handler->GetDeathSignalSocket();
803 }
[email protected]a1733df2012-06-22 11:24:18804
[email protected]779dd282013-10-19 15:57:02805 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31806 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02807 if (!crash_handler)
808 crash_handler = CreateCrashHandlerHost(process_type);
809 return crash_handler->GetDeathSignalSocket();
810 }
[email protected]a1733df2012-06-22 11:24:18811
James Cook9207cc12017-10-19 17:08:39812 if (process_type == switches::kUtilityProcess) {
813 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
814 if (!crash_handler)
815 crash_handler = CreateCrashHandlerHost(process_type);
816 return crash_handler->GetDeathSignalSocket();
817 }
818
[email protected]a1733df2012-06-22 11:24:18819 return -1;
820}
Joshua Perazaf890e4b2019-01-03 19:19:02821#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18822
[email protected]eabbfb12013-04-05 23:28:35823void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52824 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33825 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35826}
827
estark3ba11132015-04-10 01:38:33828// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31829// SSLErrorHandler. Uses CertificateReportingService to send reports. The
830// service handles queueing and re-sending of failed reports. Each certificate
831// error creates a new instance of this class.
832class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33833 public:
meacerf43117a2016-12-27 21:02:31834 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12835 content::WebContents* web_contents)
836 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
837 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31838 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33839
840 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55841 void ReportInvalidCertificateChain(
842 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31843 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33844 }
845
846 private:
meacerf43117a2016-12-27 21:02:31847 CertificateReportingService* service_;
848
849 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33850};
851
bshe4f53ce42015-11-30 16:56:31852#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05853float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59854 static const float kMinFSM = 1.05f;
855 static const int kWidthForMinFSM = 320;
856 static const float kMaxFSM = 1.3f;
857 static const int kWidthForMaxFSM = 800;
858
boliu21c5afa2017-01-11 19:34:23859 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59860
861 if (minWidth <= kWidthForMinFSM)
862 return kMinFSM;
863 if (minWidth >= kWidthForMaxFSM)
864 return kMaxFSM;
865
866 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
867 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
Aran Gilmanf010bdd2019-08-28 19:55:44868 (kWidthForMaxFSM - kWidthForMinFSM);
[email protected]b255a8e0e82013-10-22 04:03:59869 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
870}
zpengdb4a58e2017-01-10 17:40:32871
[email protected]916615b2013-09-11 18:19:44872#endif // defined(OS_ANDROID)
873
brettw00899e62016-11-12 02:10:17874#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53875
876AppLoadedInTabSource ClassifyAppLoadedInTabSource(
877 const GURL& opener_url,
878 const extensions::Extension* target_platform_app) {
Lei Zhang7d0b0f42019-10-12 03:47:58879 if (!opener_url.SchemeIs(extensions::kExtensionScheme)) {
880 // The forbidden app URL was being opened by a non-extension page (e.g.
881 // http).
882 return APP_LOADED_IN_TAB_SOURCE_OTHER;
883 }
884
885 if (opener_url.host_piece() != target_platform_app->id()) {
nickb6ae0bd32017-04-18 20:53:53886 // The forbidden app URL was being opened by a different app or extension.
887 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
888 }
Lei Zhang7d0b0f42019-10-12 03:47:58889
890 // This platform app was trying to window.open() one of its own URLs.
891 if (opener_url ==
892 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
893 // Source was the background page.
894 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
895 }
896
897 // Source was a different page inside the app.
898 return APP_LOADED_IN_TAB_SOURCE_APP;
nickb6ae0bd32017-04-18 20:53:53899}
[email protected]9c7656382014-08-08 21:02:30900
Charles Harrison34f67862017-08-22 01:04:17901// Returns true if there is is an extension matching |url| in
902// |opener_render_process_id| with APIPermission::kBackground.
903//
904// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
905// hosted app, even though normal extensions just use the host.
906bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35907 extensions::ProcessMap* process_map,
908 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17909 const GURL& url,
csharrison95f01e922017-04-24 18:52:35910 int opener_render_process_id) {
911 // Note: includes web URLs that are part of an extension's web extent.
912 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17913 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35914 return extension &&
915 extension->permissions_data()->HasAPIPermission(
916 APIPermission::kBackground) &&
917 process_map->Contains(extension->id(), opener_render_process_id);
918}
Kevin Marshall32f99d7e2017-07-11 23:17:46919
csharrison95f01e922017-04-24 18:52:35920#endif
921
John Abd-El-Malekd2377982018-01-08 22:23:12922chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
923 const base::Callback<content::WebContents*()>& wc_getter) {
924 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
925 auto* web_contents = wc_getter.Run();
926 if (!web_contents)
927 return nullptr;
928
929 return prerender::PrerenderContents::FromWebContents(web_contents);
930}
931
John Abd-El-Malek92bf3602019-07-31 02:25:48932void LaunchURL(const GURL& url,
danakjf4b9e942019-11-29 15:43:04933 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Malek92bf3602019-07-31 02:25:48934 ui::PageTransition page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45935 bool has_user_gesture,
936 const base::Optional<url::Origin>& initiating_origin) {
John Abd-El-Maleka67add82018-03-09 18:22:01937 // If there is no longer a WebContents, the request may have raced with tab
938 // closing. Don't fire the external request. (It may have been a prerender.)
danakjf4b9e942019-11-29 15:43:04939 content::WebContents* web_contents = std::move(web_contents_getter).Run();
John Abd-El-Maleka67add82018-03-09 18:22:01940 if (!web_contents)
941 return;
942
943 // Do not launch external requests attached to unswapped prerenders.
944 prerender::PrerenderContents* prerender_contents =
945 prerender::PrerenderContents::FromWebContents(web_contents);
946 if (prerender_contents) {
947 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
948 prerender::ReportPrerenderExternalURL();
949 return;
950 }
951
Robbie McElrath1294d242019-05-31 20:46:22952 // Do not launch external requests for schemes that have a handler registered.
953 ProtocolHandlerRegistry* protocol_handler_registry =
954 ProtocolHandlerRegistryFactory::GetForBrowserContext(
955 web_contents->GetBrowserContext());
956 if (protocol_handler_registry &&
957 protocol_handler_registry->IsHandledProtocol(url.scheme()))
958 return;
959
John Abd-El-Maleka67add82018-03-09 18:22:01960 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01961 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19962 PolicyBlacklistFactory::GetForBrowserContext(
963 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:01964 if (service) {
965 const policy::URLBlacklist::URLBlacklistState url_state =
966 service->GetURLBlacklistState(url);
967 is_whitelisted =
968 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
969 }
970
971 // If the URL is in whitelist, we launch it without asking the user and
972 // without any additional security checks. Since the URL is whitelisted,
973 // we assume it can be executed.
974 if (is_whitelisted) {
975 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
976 } else {
977 ExternalProtocolHandler::LaunchUrl(
978 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
979 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
Emily Stark13b66bdf2019-10-04 17:11:45980 has_user_gesture, initiating_origin);
John Abd-El-Maleka67add82018-03-09 18:22:01981 }
982}
983
Yutaka Hirano968d6252018-12-04 05:09:31984std::string GetProduct() {
985 return version_info::GetProductNameAndVersionForUserAgent();
986}
987
Lukasz Anforowicz60d1253d2019-05-08 16:31:37988void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
989 // |allowlist| combines pref/policy + cmdline switch in the browser process.
990 // For renderer and utility (e.g. NetworkService) processes the switch is the
991 // only available source, so below the combined (pref/policy + cmdline)
992 // allowlist of secure origins is injected into |cmdline| for these other
993 // processes.
994 std::vector<std::string> allowlist =
995 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
996 if (!allowlist.empty()) {
997 cmdline->AppendSwitchASCII(
998 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
999 base::JoinString(allowlist, ","));
1000 }
1001}
1002
Will Harris1b9b4152019-08-21 22:33:501003#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301004// Returns the full path to |module_name|. Both dev builds (where |module_name|
1005// is in the current executable's directory) and proper installs (where
1006// |module_name| is in a versioned sub-directory of the current executable's
1007// directory) are supported. The identified file is not guaranteed to exist.
1008base::FilePath GetModulePath(base::StringPiece16 module_name) {
1009 base::FilePath exe_dir;
1010 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1011 DCHECK(has_path);
1012
1013 // Look for the module in a versioned sub-directory of the current
1014 // executable's directory and return the path if it can be read. This is the
1015 // expected location of modules for proper installs.
1016 const base::FilePath module_path =
1017 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1018 if (base::PathExists(module_path))
1019 return module_path;
1020
1021 // Otherwise, return the path to the module in the current executable's
1022 // directory. This is the expected location of modules for dev builds.
1023 return exe_dir.Append(module_name);
1024}
Will Harris1b9b4152019-08-21 22:33:501025#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1026 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301027
Lukasz Anforowicz7724d092019-10-03 23:50:211028void MaybeAddThrottle(
1029 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles,
1030 std::unique_ptr<content::NavigationThrottle> maybe_throttle) {
1031 if (maybe_throttle)
1032 throttles->push_back(std::move(maybe_throttle));
1033}
1034
Evan Stade1e71d6dd2019-10-29 03:04:491035// Returns whether |web_contents| is within a hosted app.
1036bool IsInHostedApp(WebContents* web_contents) {
1037#if BUILDFLAG(ENABLE_EXTENSIONS)
1038 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1039 return (browser &&
1040 web_app::AppBrowserController::IsForWebAppBrowser(browser));
1041#else
1042 return false;
1043#endif
1044}
1045
Lily Chenc2c9e9f2019-12-05 19:55:311046void MaybeRecordSameSiteCookieEngagementHistogram(
1047 content::RenderFrameHost* render_frame_host,
1048 blink::mojom::WebFeature feature) {
1049 if (feature != blink::mojom::WebFeature::kCookieNoSameSite &&
1050 feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) {
1051 return;
1052 }
1053
1054 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1055 DCHECK(render_frame_host);
1056
1057 content::BrowserContext* browser_context =
1058 WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext();
1059 Profile* profile = Profile::FromBrowserContext(browser_context);
1060 SiteEngagementService* site_engagement_service =
1061 SiteEngagementService::Get(profile);
1062 if (!site_engagement_service)
1063 return;
1064
1065 blink::mojom::EngagementLevel engagement_level =
1066 site_engagement_service->GetEngagementLevel(
1067 render_frame_host->GetLastCommittedURL());
1068 if (feature == blink::mojom::WebFeature::kCookieNoSameSite) {
1069 UMA_HISTOGRAM_ENUMERATION(
1070 "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite",
1071 engagement_level);
1072 } else {
1073 UMA_HISTOGRAM_ENUMERATION(
1074 "Net.SameSiteBlockedCookieSiteEngagement."
1075 "CookieInsecureAndSameSiteNone",
1076 engagement_level);
1077 }
1078}
1079
[email protected]9dbfff12011-07-01 19:37:071080} // namespace
[email protected]c5dbef02011-05-13 05:06:091081
Yutaka Hirano968d6252018-12-04 05:09:311082std::string GetUserAgent() {
1083 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1084 if (command_line->HasSwitch(switches::kUserAgent)) {
1085 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1086 if (net::HttpUtil::IsValidHeaderValue(ua))
1087 return ua;
1088 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1089 }
1090
John Delaneyac24e572019-04-30 19:47:021091 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1092 return content::GetFrozenUserAgent(
1093 command_line->HasSwitch(switches::kUseMobileUserAgent))
1094 .as_string();
1095 }
1096
Yutaka Hirano968d6252018-12-04 05:09:311097 std::string product = GetProduct();
1098#if defined(OS_ANDROID)
1099 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1100 product += " Mobile";
1101#endif
1102 return content::BuildUserAgentFromProduct(product);
1103}
1104
Mike West6e4cbb32019-02-13 09:40:171105blink::UserAgentMetadata GetUserAgentMetadata() {
1106 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171107 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301108 metadata.full_version = version_info::GetVersionNumber();
1109 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171110 metadata.platform = version_info::GetOSType();
Aaron Tagliaboschicb8d3ee2019-12-09 19:31:361111 metadata.architecture = content::BuildCpuInfo();
1112 metadata.model = content::BuildModelInfo();
Mike West6e4cbb32019-02-13 09:40:171113
Aaron Tagliaboschibe775e12019-12-09 19:33:041114 // TODO(crbug.com/1031511): Integrate DevTools and "Request Desktop Site"
1115 metadata.mobile = false;
1116#if defined(OS_ANDROID)
1117 metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch(
1118 switches::kUseMobileUserAgent);
1119#endif
1120
Mike West6e4cbb32019-02-13 09:40:171121 return metadata;
1122}
1123
Ran Jia96d43d42018-05-02 17:14:531124ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051125 StartupData* startup_data)
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:311126 : startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161127#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371128 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421129 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371130 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251131 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371132 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401133 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551134
1135 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401136#endif
[email protected]1deace22013-05-22 06:14:461137
Ahmed Fakhryd70bf37b2018-04-04 17:07:241138#if defined(OS_CHROMEOS)
1139 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1140#endif // defined(OS_CHROMEOS)
1141
John Lee0ee748bf2019-12-11 21:35:441142#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
1143 extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
1144#endif
1145
brettw00899e62016-11-12 02:10:171146#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131147 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271148#endif
bena06f7d62017-04-04 20:48:521149
Sigurdur Asgeirsson70696672019-02-08 16:14:511150 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401151}
1152
1153ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031154 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1155 delete extra_parts_[i];
1156 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401157}
1158
[email protected]bca18382012-06-25 19:15:231159// static
Chris Palmerac7d75642017-11-22 20:12:541160void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1161 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131162 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1163 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541164 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1165 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Francois Doray424bd992019-10-16 20:59:461166 registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true);
Chris Palmerac7d75642017-11-22 20:12:541167}
1168
1169// static
[email protected]37ca3fe02013-07-05 15:32:441170void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341171 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251172 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1173 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1174 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281175 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1176 // user policy in addition to the same named ones in Local State (which are
1177 // used for mapping the command-line flags).
1178 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1179 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571180 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401181 registry->RegisterDictionaryPref(
1182 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041183 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101184#if !defined(OS_ANDROID)
1185 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561186 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101187#endif
Takashi Toyoshima128441462019-10-16 04:19:171188 registry->RegisterListPref(prefs::kCorsMitigationList);
1189 registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false);
[email protected]bca18382012-06-25 19:15:231190}
1191
[email protected]eabbfb12013-04-05 23:28:351192// static
1193void ChromeContentBrowserClient::SetApplicationLocale(
1194 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481195 // The common case is that this function is called early in Chrome startup
1196 // before any threads are created or registered. When there are no threads,
1197 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001198 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331199 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481200 return;
1201 }
1202
1203 // Otherwise we're being called to change the locale. In this case set it on
1204 // the IO thread.
thestig00844cea2015-09-08 21:44:521205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351206
Sami Kyostila5e1306d2019-08-14 11:01:291207 base::PostTask(FROM_HERE, {BrowserThread::IO},
1208 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351209}
1210
Patrick Monette61dfef92019-05-30 23:06:271211std::unique_ptr<content::BrowserMainParts>
1212ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311213 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271214 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301215 // Construct the Main browser parts based on the OS type.
1216#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051217 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271218 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1219#elif defined(OS_MACOSX)
1220 main_parts =
1221 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1222#elif defined(OS_CHROMEOS)
1223 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1224 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261225#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271226 main_parts =
1227 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141228#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271229 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1230 startup_data_);
[email protected]b48c9182011-10-26 18:03:301231#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271232 main_parts =
1233 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041234#else
[email protected]b48c9182011-10-26 18:03:301235 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271236 main_parts =
1237 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301238#endif
1239
Xi Han9fd44002019-04-30 17:39:361240 bool add_profiles_extra_parts = true;
1241#if defined(OS_ANDROID)
1242 if (startup_data_->HasBuiltProfilePrefService())
1243 add_profiles_extra_parts = false;
1244#endif
1245 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271246 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031247
Xi Han9fd44002019-04-30 17:39:361248 // Construct additional browser parts. Stages are called in the order in
1249 // which they are added.
[email protected]c7480942011-11-08 19:18:271250#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221251#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1252#if defined(USE_X11)
1253 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1254#else
estaded3aa0e82016-02-17 22:55:211255 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221256#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211257#else
riajiang7d6ec5c2017-01-25 16:40:331258 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351259#endif
1260#endif
1261
1262#if defined(OS_CHROMEOS)
1263 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331264 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221265#endif
[email protected]dc04be7c2012-03-15 23:57:491266
[email protected]e8b6ca02013-07-10 18:00:511267#if defined(USE_X11)
1268 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241269#endif
1270
Sigurdur Asgeirsson54b72702019-04-12 14:18:541271 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001272
Albert J. Wong59d85acb2017-08-10 00:50:571273 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571274
Sebastien Marchand8c0088102019-10-11 16:47:561275 main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory);
1276
Peng Huangee82ef82019-11-22 13:15:291277 main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu);
1278
Patrick Monette61dfef92019-05-30 23:06:271279 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041280
[email protected]50462bf02011-11-21 19:13:311281 return main_parts;
[email protected]f967b722011-09-07 00:58:041282}
1283
michaeln96f887e22015-04-13 23:58:311284void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091285 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:021286 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211287 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121288 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291289
Robert Sesek466e43e2019-08-19 22:02:021290 InitNetworkContextsParentDirectory();
1291
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291292 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1293 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311294}
1295
falkenb09d443f2016-04-07 12:36:121296bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1297 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1298}
1299
Gabriel Charettec8cca992017-08-10 18:21:491300void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1301 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1302}
1303
John Abd-El-Malek9d57f9c2019-02-20 18:50:041304bool ChromeContentBrowserClient::IsShuttingDown() {
Greg Thompsonae8a5b12019-11-21 12:35:361305 return browser_shutdown::HasShutdownStarted();
John Abd-El-Malek9d57f9c2019-02-20 18:50:041306}
1307
[email protected]e94bbcb2012-09-07 05:33:571308std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191309 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571310 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531311 std::string partition_id;
1312
1313 // The partition ID for webview guest processes is the string value of its
1314 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451315 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531316 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171317#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501318 // The partition ID for extensions with isolated storage is treated similarly
1319 // to the above.
1320 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1321 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1322 partition_id = site.spec();
1323#endif
[email protected]1bc28312012-11-08 08:31:531324
[email protected]056efdc2013-04-06 00:14:531325 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531326 return partition_id;
1327}
1328
1329bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1330 content::BrowserContext* browser_context,
1331 const std::string& partition_id) {
1332 // The default ID is empty and is always valid.
1333 if (partition_id.empty())
1334 return true;
1335
1336 return GURL(partition_id).is_valid();
1337}
1338
1339void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1340 content::BrowserContext* browser_context,
1341 const GURL& site,
[email protected]14acc642012-11-17 12:20:101342 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531343 std::string* partition_domain,
1344 std::string* partition_name,
1345 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101346 // Default to the browser-wide storage partition and override based on |site|
1347 // below.
1348 partition_domain->clear();
1349 partition_name->clear();
1350 *in_memory = false;
1351
brettw00899e62016-11-12 02:10:171352#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451353 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331354 site, partition_domain, partition_name, in_memory);
1355
1356 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101357 // If |can_be_default| is false, the caller is stating that the |site|
1358 // should be parsed as if it had isolated storage. In particular it is
1359 // important to NOT check ExtensionService for the is_storage_isolated()
1360 // attribute because this code path is run during Extension uninstall
1361 // to do cleanup after the Extension has already been unloaded from the
1362 // ExtensionService.
1363 bool is_isolated = !can_be_default;
1364 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341365 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1366 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101367 }
[email protected]1bc28312012-11-08 08:31:531368
[email protected]14acc642012-11-17 12:20:101369 if (is_isolated) {
1370 CHECK(site.has_host());
1371 // For extensions with isolated storage, the the host of the |site| is
1372 // the |partition_domain|. The |in_memory| and |partition_name| are only
1373 // used in guest schemes so they are cleared here.
1374 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531375 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101376 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531377 }
[email protected]1df3d972014-06-11 04:55:181378 success = true;
1379 }
1380#endif
1381
[email protected]14acc642012-11-17 12:20:101382 // Assert that if |can_be_default| is false, the code above must have found a
1383 // non-default partition. If this fails, the caller has a serious logic
1384 // error about which StoragePartition they expect to be in and it is not
1385 // safe to continue.
1386 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441387}
1388
[email protected]38b098f2012-03-14 21:11:571389content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441390ChromeContentBrowserClient::GetWebContentsViewDelegate(
1391 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101392 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321393}
1394
Bo Liu4ade6b1b22017-11-28 02:26:351395bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1396#if defined(OS_ANDROID)
1397 const base::android::ApplicationState app_state =
1398 base::android::ApplicationStatusListener::GetState();
1399 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1400 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1401 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1402#else
1403 return true;
1404#endif
1405}
1406
[email protected]6f2862742013-12-20 07:53:191407void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231408 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301409 int id = host->GetID();
1410 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
thakis678822e2017-04-20 17:20:341411#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491412 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061413#endif
Brett Wilson65f951c2016-11-03 22:06:121414#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401415 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031416#endif
[email protected]ba780c12013-10-01 17:07:061417 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
Darin Fisher8c84328c2019-07-23 02:50:001418
Darin Fisher09aa7222019-08-29 09:27:361419 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001420 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021421
grunell086a4112017-03-02 09:23:041422 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1423 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021424 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121425 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021426 host->SetUserData(
1427 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091428 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021429 audio_debug_recordings_handler));
1430
Nico Weberaf3b00b2017-09-11 17:58:171431#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031432 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1433 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351434#endif
jeremyim364ac1182015-03-03 18:49:431435
Xiaohan Wang9b34281b2017-09-08 23:48:331436#if defined(OS_ANDROID)
1437 // Data cannot be persisted if the profile is off the record.
1438 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061439 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071440
1441 // Register CrashMemoryMetricsCollector to report oom related metrics.
1442 host->SetUserData(
1443 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1444 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331445#endif
1446
Jun Caidb3f93cc2018-07-09 21:54:551447 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061448 RendererUpdaterFactory::GetForProfile(original_profile)
1449 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071450
[email protected]a48ab7112014-08-01 16:48:031451 for (size_t i = 0; i < extra_parts_.size(); ++i)
1452 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141453}
1454
[email protected]3d7474ff2011-07-27 17:47:371455GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571456 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301457 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371458 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521459 if (!profile)
1460 return url;
1461
Marc Treib7d467b792017-12-04 13:31:031462#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291463 // If the input |url| should be assigned to the Instant renderer, make its
1464 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311465 // This needs to happen even if |url| corresponds to an isolated origin; see
1466 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131467 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1468 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031469#endif
[email protected]b3cb3a32013-07-31 01:32:291470
brettw00899e62016-11-12 02:10:171471#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301472 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1473 url);
[email protected]d5a74be2014-08-08 01:01:271474#else
1475 return url;
1476#endif
[email protected]36fb2c7c2011-04-04 15:49:081477}
1478
Alexander Yashkin6aedc6e2018-08-15 08:58:451479bool ChromeContentBrowserClient::
1480 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1481 content::BrowserContext* browser_context,
1482 content::SiteInstance* candidate_site_instance,
1483 bool is_main_frame,
1484 const GURL& candidate_url,
1485 const GURL& destination_url) {
1486 DCHECK(browser_context);
1487 DCHECK(candidate_site_instance);
1488#if BUILDFLAG(ENABLE_EXTENSIONS)
1489 return ChromeContentBrowserClientExtensionsPart::
1490 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1491 browser_context, candidate_site_instance, is_main_frame,
1492 candidate_url, destination_url);
1493#else
1494 return true;
1495#endif
1496}
1497
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521498bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411499#if defined(OS_ANDROID)
1500 return true;
1501#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421502 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411503#else
1504 return false;
1505#endif // defined(OS_ANDROID)
1506}
1507
[email protected]056ad2a2011-07-12 02:13:551508bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441509 content::BrowserContext* browser_context,
1510 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521511 Profile* profile = Profile::FromBrowserContext(browser_context);
1512 if (!profile)
1513 return false;
1514
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301515 // NTP should use process-per-site. This is a performance optimization to
1516 // reduce process count associated with NTP tabs.
1517 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1518 return true;
Peter Boström8e9b1632019-08-22 23:12:471519
1520 // The web footer experiment should share its renderer to not effectively
1521 // instantiate one per window. See https://crbug.com/993502.
1522 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1523 return true;
1524
Marc Treib7d467b792017-12-04 13:31:031525#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131526 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521527 return true;
Marc Treib7d467b792017-12-04 13:31:031528#endif
[email protected]c5dec6292013-01-25 04:54:521529
brettw00899e62016-11-12 02:10:171530#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301531 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1532 profile, effective_url))
1533 return true;
[email protected]d5a74be2014-08-08 01:01:271534#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301535
1536 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1537 // (rather than process-per-site).
1538 return false;
[email protected]056ad2a2011-07-12 02:13:551539}
1540
Lukasz Anforowicz32d27122018-04-09 21:48:331541bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1542 content::BrowserContext* browser_context,
1543 const GURL& site_url) {
1544 Profile* profile = Profile::FromBrowserContext(browser_context);
1545 if (!profile)
1546 return false;
1547
1548#if !defined(OS_ANDROID)
1549 // Instant renderers should not use a spare process, because they require
1550 // passing switches::kInstantProcess to the renderer process when it
1551 // launches. A spare process is launched earlier, before it is known which
1552 // navigation will use it, so it lacks this flag.
1553 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1554 return false;
1555#endif
1556
1557#if BUILDFLAG(ENABLE_EXTENSIONS)
1558 return ChromeContentBrowserClientExtensionsPart::
1559 ShouldUseSpareRenderProcessHost(profile, site_url);
1560#else
1561 return true;
1562#endif
1563}
1564
nickcc0d9142015-10-14 16:27:101565bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421566 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101567 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421568 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171569#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101570 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421571 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101572 return true;
1573 }
1574#endif
1575 return false;
1576}
1577
nick7d0984c2015-08-29 00:13:461578// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1579// origin-lock enforcement, where we don't have a way to efficiently know
1580// effective URLs on the IO thread, and wind up killing processes that e.g.
1581// request cookies for their actual URL. This whole function (and its
1582// ExtensionsPart) should be removed once we add that ability to the IO thread.
1583bool ChromeContentBrowserClient::ShouldLockToOrigin(
1584 content::BrowserContext* browser_context,
1585 const GURL& effective_site_url) {
1586 // Origin lock to the search scheme would kill processes upon legitimate
1587 // requests for cookies from the search engine's domain.
1588 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1589 return false;
1590
brettw00899e62016-11-12 02:10:171591#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461592 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1593 browser_context, effective_site_url)) {
1594 return false;
1595 }
1596#endif
1597 return true;
creise5d6d1732015-08-25 19:47:061598}
1599
Maks Orlovich0e23e312019-07-16 13:13:561600bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
Lily Chen0db055b2019-11-15 20:29:021601 base::StringPiece scheme,
1602 bool is_embedded_origin_secure) {
1603 if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
1604 return true;
Maks Orlovich0e23e312019-07-16 13:13:561605#if BUILDFLAG(ENABLE_EXTENSIONS)
1606 return scheme == extensions::kExtensionScheme;
1607#else
1608 return false;
1609#endif
1610}
1611
Lily Chen0db055b2019-11-15 20:29:021612bool ChromeContentBrowserClient::
1613 ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
1614 base::StringPiece scheme,
1615 bool is_embedded_origin_secure) {
1616 return is_embedded_origin_secure && scheme == content::kChromeUIScheme;
1617}
1618
Lukasz Anforowicz7097890d2019-11-20 21:49:221619void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021620 content::BrowserContext* browser_context,
Lukasz Anforowicz5f3352562019-11-14 16:53:591621 const url::Origin& origin,
Lukasz Anforowicze00adef2019-12-06 23:07:021622 bool is_for_isolated_world,
Lukasz Anforowicz7097890d2019-11-20 21:49:221623 network::mojom::URLLoaderFactoryParams* factory_params) {
Lukasz Anforowicz2f810162018-10-03 21:38:071624#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz7097890d2019-11-20 21:49:221625 ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams(
Lukasz Anforowicze00adef2019-12-06 23:07:021626 browser_context, origin, is_for_isolated_world, factory_params);
Lukasz Anforowicz2f810162018-10-03 21:38:071627#endif
1628}
1629
[email protected]73b718f2014-01-27 02:59:461630// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1631// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411632void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1633 std::vector<std::string>* additional_schemes) {
1634 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241635 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351636 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061637}
1638
alexmos94875b3b2017-03-16 22:19:011639void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1640 std::vector<std::string>* additional_schemes) {
1641 GetAdditionalWebUISchemes(additional_schemes);
1642
1643#if BUILDFLAG(ENABLE_EXTENSIONS)
1644 additional_schemes->push_back(extensions::kExtensionScheme);
1645#endif
1646}
1647
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521648bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011649 return webui::LogWebUIUrl(web_ui_url);
1650}
1651
John Abd-El-Malek04bfa8532018-07-12 05:28:221652bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1653 const url::Origin& origin) {
1654 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1655 origin);
1656}
1657
[email protected]46fb9442011-12-09 17:57:471658bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1659 return ProfileIOData::IsHandledURL(url);
1660}
1661
[email protected]c4365fa42013-05-14 01:08:241662bool ChromeContentBrowserClient::CanCommitURL(
1663 content::RenderProcessHost* process_host,
1664 const GURL& url) {
brettw00899e62016-11-12 02:10:171665#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441666 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1667 url);
[email protected]d5a74be2014-08-08 01:01:271668#else
1669 return true;
1670#endif
[email protected]c4365fa42013-05-14 01:08:241671}
1672
rdevlin.cronina32a0902016-11-09 15:50:201673void ChromeContentBrowserClient::OverrideNavigationParams(
1674 SiteInstance* site_instance,
1675 ui::PageTransition* transition,
1676 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581677 content::Referrer* referrer,
1678 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201679 DCHECK(transition);
1680 DCHECK(is_renderer_initiated);
1681 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471682 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1683 // use for making security decisions 99.44% of the time, for detecting the NTP
1684 // it is reliable and the correct way. See http://crbug.com/624410.
1685 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201686 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581687 // Clicks on tiles of the new tab page should be treated as if a user
1688 // clicked on a bookmark. This is consistent with native implementations
1689 // like Android's. This also helps ensure that security features (like
1690 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1691 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201692 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1693 *is_renderer_initiated = false;
1694 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581695 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421696 }
1697}
1698
Charles Reis29e9dd12017-09-28 00:59:151699bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1700 const GURL& url,
1701 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471702 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1703 // use for making security decisions 99.44% of the time, for detecting the NTP
1704 // it is reliable and the correct way. See http://crbug.com/624410.
1705 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1706 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151707}
1708
[email protected]2a5221b2011-09-27 23:07:311709bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301710 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311711 const GURL& site_url) {
1712 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301713 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441714 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521715 // share any host.
1716 if (!profile)
1717 return true;
1718
Marc Treib7895941d2017-11-28 12:37:021719#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141720 // Instant URLs should only be in the instant process and instant process
1721 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521722 InstantService* instant_service =
1723 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141724 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441725 bool is_instant_process =
1726 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141727 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131728 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141729 if (is_instant_process || should_be_in_instant_process)
1730 return is_instant_process && should_be_in_instant_process;
1731 }
Marc Treib7895941d2017-11-28 12:37:021732#endif
[email protected]c5dec6292013-01-25 04:54:521733
brettw00899e62016-11-12 02:10:171734#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131735 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1736 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271737#else
1738 return true;
1739#endif
[email protected]2a5221b2011-09-27 23:07:311740}
1741
[email protected]28c5d0b72014-05-13 08:19:591742bool ChromeContentBrowserClient::MayReuseHost(
1743 content::RenderProcessHost* process_host) {
1744 // If there is currently a prerender in progress for the host provided,
1745 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041746 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591747 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371748 prerender::PrerenderManagerFactory::GetForBrowserContext(
1749 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591750 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491751 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591752 return false;
1753 }
1754
1755 return true;
1756}
1757
[email protected]76411f412012-02-22 18:56:061758bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441759 content::BrowserContext* browser_context,
1760 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061761 // It has to be a valid URL for us to check for an extension.
1762 if (!url.is_valid())
1763 return false;
1764
brettw00899e62016-11-12 02:10:171765#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061766 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131767 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441768 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271769#else
1770 return false;
1771#endif
[email protected]76411f412012-02-22 18:56:061772}
1773
Alex Moshchuk9c9e3882018-11-02 19:57:031774bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1775 content::RenderFrameHost* main_frame) {
1776#if BUILDFLAG(ENABLE_EXTENSIONS)
1777 return ChromeContentBrowserClientExtensionsPart::
1778 ShouldSubframesTryToReuseExistingProcess(main_frame);
1779#else
1780 return true;
1781#endif
1782}
1783
[email protected]6f371442011-11-09 06:45:461784void ChromeContentBrowserClient::SiteInstanceGotProcess(
1785 SiteInstance* site_instance) {
1786 CHECK(site_instance->HasProcess());
1787
Aran Gilmanf010bdd2019-08-28 19:55:441788 Profile* profile =
1789 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521790 if (!profile)
1791 return;
1792
Marc Treib7895941d2017-11-28 12:37:021793#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521794 // Remember the ID of the Instant process to signal the renderer process
1795 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131796 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1797 profile)) {
[email protected]c5dec6292013-01-25 04:54:521798 InstantService* instant_service =
1799 InstantServiceFactory::GetForProfile(profile);
1800 if (instant_service)
1801 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1802 }
Marc Treib7895941d2017-11-28 12:37:021803#endif
[email protected]c5dec6292013-01-25 04:54:521804
[email protected]a48ab7112014-08-01 16:48:031805 for (size_t i = 0; i < extra_parts_.size(); ++i)
1806 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461807}
1808
1809void ChromeContentBrowserClient::SiteInstanceDeleting(
1810 SiteInstance* site_instance) {
1811 if (!site_instance->HasProcess())
1812 return;
1813
[email protected]a48ab7112014-08-01 16:48:031814 for (size_t i = 0; i < extra_parts_.size(); ++i)
1815 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461816}
1817
[email protected]453f5432013-11-26 19:43:001818bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141819 SiteInstance* site_instance,
Aaron Colwell16b4985d2019-11-13 00:20:561820 const GURL& current_effective_url,
1821 const GURL& destination_effective_url) {
brettw00899e62016-11-12 02:10:171822#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131823 return ChromeContentBrowserClientExtensionsPart::
Aaron Colwell16b4985d2019-11-13 00:20:561824 ShouldSwapBrowsingInstancesForNavigation(
1825 site_instance, current_effective_url, destination_effective_url);
[email protected]d5a74be2014-08-08 01:01:271826#else
1827 return false;
1828#endif
[email protected]e3daf3c2011-10-05 21:17:081829}
1830
Nasko Oskovd83b5712018-05-04 04:50:571831bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1832 // TODO(nasko): Consider supporting error page isolation in subframes if
1833 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381834 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571835}
1836
[email protected]3d831992013-07-04 01:13:291837bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1838 return !url.SchemeIs(chrome::kChromeNativeScheme);
1839}
1840
Alex Moshchukd252c192017-07-17 22:03:481841std::vector<url::Origin>
1842ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1843 std::vector<url::Origin> isolated_origin_list;
1844
Alex Moshchuk89352a72017-10-25 20:25:591845// Sign-in process isolation is not needed on Android, see
1846// https://crbug.com/739418.
1847#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381848 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121849 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591850#endif
Alex Moshchukd252c192017-07-17 22:03:481851
Alex Moshchuk81d2a29e2019-07-16 01:14:381852#if BUILDFLAG(ENABLE_EXTENSIONS)
1853 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1854 GetOriginsRequiringDedicatedProcess();
1855 std::move(std::begin(origins_from_extensions),
1856 std::end(origins_from_extensions),
1857 std::back_inserter(isolated_origin_list));
1858#endif
1859
Alex Moshchukd252c192017-07-17 22:03:481860 return isolated_origin_list;
1861}
1862
Lukasz Anforowicz5e201abd2018-03-24 00:41:061863bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341864 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1865}
1866
1867bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Alex Moshchuk7a737b632019-10-10 05:03:371868 return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold();
Lukasz Anforowicz5e201abd2018-03-24 00:41:061869}
1870
Alex Moshchuk082b5f82019-03-14 01:34:161871std::vector<std::string>
1872ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1873 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1874 return {"Isolate Password Sites"};
1875 else
1876 return {};
1877}
1878
Alex Moshchuke256d562019-04-26 21:43:571879void ChromeContentBrowserClient::PersistIsolatedOrigin(
1880 content::BrowserContext* context,
1881 const url::Origin& origin) {
1882 DCHECK(!context->IsOffTheRecord());
1883 Profile* profile = Profile::FromBrowserContext(context);
1884 ListPrefUpdate update(profile->GetPrefs(),
1885 prefs::kUserTriggeredIsolatedOrigins);
1886 base::ListValue* list = update.Get();
1887 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361888 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121889 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571890}
1891
Ken Rockot314714c2017-11-05 23:36:241892bool ChromeContentBrowserClient::IsFileAccessAllowed(
1893 const base::FilePath& path,
1894 const base::FilePath& absolute_path,
1895 const base::FilePath& profile_path) {
1896 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1897 profile_path);
1898}
1899
[email protected]d2e1a0a2014-06-16 15:49:371900namespace {
1901
1902bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171903 const base::CommandLine& browser_command_line =
1904 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351905 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371906 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351907 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371908 return false;
[email protected]9ef49b42014-08-07 16:44:241909 return true;
[email protected]d2e1a0a2014-06-16 15:49:371910}
1911
bmcquade5d2d9cf32015-06-19 17:42:281912void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1913 const base::CommandLine& browser_command_line,
1914 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521915 // List of field trials that modify the blink-settings command line flag. No
1916 // two field trials in the list should specify the same keys, otherwise one
1917 // field trial may overwrite another. See Source/core/frame/Settings.in in
1918 // Blink for the list of valid keys.
1919 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161920 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1921 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1922 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1923 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521924 };
1925
1926 std::vector<std::string> blink_settings;
1927 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1928 // Each blink-settings field trial should include a forcing_flag group,
1929 // to make sure that clients that specify the blink-settings flag on the
1930 // command line are excluded from the experiment groups. To make
1931 // sure we assign clients that specify this flag to the forcing_flag
1932 // group, we must call GetVariationParams for each field trial first
1933 // (for example, before checking HasSwitch() and returning), since
1934 // GetVariationParams has the side-effect of assigning the client to
1935 // a field trial group.
1936 std::map<std::string, std::string> params;
1937 if (variations::GetVariationParams(field_trial_name, &params)) {
1938 for (const auto& param : params) {
1939 blink_settings.push_back(base::StringPrintf(
1940 "%s=%s", param.first.c_str(), param.second.c_str()));
1941 }
1942 }
1943 }
pmeenan9ac669682015-08-17 14:57:031944
bmcquade9dd54cc2015-06-22 16:56:521945 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281946 return;
1947 }
1948
1949 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1950 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031951 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521952 // blink-settings flag into a group with no params, and we return
1953 // above if no params were specified, so it's an error if we reach
1954 // this point.
bmcquade5d2d9cf32015-06-19 17:42:281955 LOG(WARNING) << "Received field trial params, "
1956 "but blink-settings switch already specified.";
1957 return;
1958 }
1959
bmcquade5d2d9cf32015-06-19 17:42:281960 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:261961 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:281962}
1963
[email protected]d2e1a0a2014-06-16 15:49:371964} // namespace
1965
[email protected]b80f68432011-05-02 17:22:301966void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:171967 base::CommandLine* command_line,
1968 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:061969#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:351970 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:061971 GoogleUpdateSettings::LoadMetricsClientInfo();
1972 if (client_info) {
1973 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1974 client_info->client_id);
1975 }
1976#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:021977#if defined(OS_ANDROID)
1978 bool enable_crash_reporter = true;
1979#else
Joshua Perazace68e2f2019-09-23 18:44:241980 bool enable_crash_reporter = false;
1981 if (crash_reporter::IsCrashpadEnabled()) {
1982 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
1983 enable_crash_reporter = true;
1984
1985 int fd;
1986 pid_t pid;
1987 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
1988 command_line->AppendSwitchASCII(
1989 crash_reporter::switches::kCrashpadHandlerPid,
1990 base::NumberToString(pid));
1991 }
1992 } else {
1993 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
1994 }
Joshua Perazaf890e4b2019-01-03 19:19:021995#endif
1996 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:511997 std::string switch_value;
dcheng4af48582016-04-19 00:29:351998 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:531999 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512000 if (client_info)
2001 switch_value = client_info->client_id;
2002 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252003 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302004 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512005 switch_value);
[email protected]b80f68432011-05-02 17:22:302006 }
Mark Mentovaic67fa64f2015-03-24 14:00:062007#endif
[email protected]b80f68432011-05-02 17:22:302008
[email protected]f1933792011-06-14 00:49:342009 if (logging::DialogsAreSuppressed())
2010 command_line->AppendSwitch(switches::kNoErrorDialogs);
2011
[email protected]b80f68432011-05-02 17:22:302012 std::string process_type =
2013 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172014 const base::CommandLine& browser_command_line =
2015 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322016
[email protected]7c9b6f92013-09-10 18:11:352017 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442018 switches::kUserAgent,
2019 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352020 };
2021 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372022 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322023
fqj15ff3f72015-10-09 19:20:022024 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432025 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312026 };
fqj15ff3f72015-10-09 19:20:022027 command_line->CopySwitchesFrom(browser_command_line,
2028 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372029 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312030
David Van Cleve3df6abb2019-11-26 17:52:512031 if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy())
2032 command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy);
2033
fqj15ff3f72015-10-09 19:20:022034#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332035 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2036 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522037 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332038 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2039 homedir.value().c_str());
2040#endif
2041
[email protected]718eab62011-10-05 21:16:522042 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032043 content::RenderProcessHost* process =
2044 content::RenderProcessHost::FromID(child_process_id);
2045 Profile* profile =
2046 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442047 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032048 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442049 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2050 process, profile);
[email protected]a48ab7112014-08-01 16:48:032051 }
2052
[email protected]b80f68432011-05-02 17:22:302053#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442054 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2055 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302056 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442057 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2058 login_profile);
[email protected]b80f68432011-05-02 17:22:302059#endif
2060
Aran Gilmanf010bdd2019-08-28 19:55:442061 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222062 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372063 if (process) {
[email protected]a8d851f82011-12-21 00:32:372064 PrefService* prefs = profile->GetPrefs();
2065 // Currently this pref is only registered if applied via a policy.
2066 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2067 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2068 // Turn this policy into a command line switch.
2069 command_line->AppendSwitch(switches::kDisable3DAPIs);
2070 }
[email protected]718eab62011-10-05 21:16:522071
[email protected]1733b782014-06-19 18:51:552072 const base::ListValue* switches =
2073 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2074 if (switches) {
2075 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112076 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552077 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142078 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552079 command_line->AppendSwitch(switch_to_enable);
2080 }
2081 }
2082
[email protected]a8d851f82011-12-21 00:32:372083 // Disable client-side phishing detection in the renderer if it is
2084 // disabled in the Profile preferences or the browser process.
2085 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2086 !g_browser_process->safe_browsing_detection_service()) {
2087 command_line->AppendSwitch(
2088 switches::kDisableClientSidePhishingDetection);
2089 }
[email protected]0045b0f42012-07-26 11:52:082090
vitalybukaa7ae5052014-09-26 04:11:132091 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2092 command_line->AppendSwitch(switches::kDisablePrintPreview);
2093
Marc Treib7895941d2017-11-28 12:37:022094#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522095 InstantService* instant_service =
2096 InstantServiceFactory::GetForProfile(profile);
2097 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542098 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522099 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542100 }
Marc Treib7895941d2017-11-28 12:37:022101#endif
fqjba8749c2015-10-29 15:33:072102
fqj38306f7b2015-11-02 16:59:062103 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542104 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432105 command_line->AppendSwitch(
2106 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542107 }
Daniel Vogelheim976f1c22017-11-22 16:26:032108
Lukasz Anforowicz60d1253d2019-05-08 16:31:372109 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2110
Amr Aboelkherb04cbf32019-04-29 15:17:102111 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2112 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292113 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102114 }
Katie Dillonc25ee5c92019-09-12 17:05:422115
2116 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2117 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2118 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2119 }
Takashi Toyoshima128441462019-10-16 04:19:172120
Mason Freed490f2a22019-11-05 21:41:292121 if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) &&
2122 prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) {
2123 command_line->AppendSwitch(switches::kWebComponentsV0Enabled);
2124 }
2125
Takashi Toyoshima0dab73302019-10-18 01:51:362126 if (!profile->ShouldEnableOutOfBlinkCors()) {
2127 command_line->AppendSwitch(
2128 network::switches::kForceToDisableOutOfBlinkCors);
2129 }
[email protected]47c7ec82012-01-18 03:29:212130 }
[email protected]4287a3d2011-06-13 23:56:512131
[email protected]d2e1a0a2014-06-16 15:49:372132 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352133 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042134
Aran Gilmanf010bdd2019-08-28 19:55:442135 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2136 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282137
mdjonesa6b9e172016-09-23 16:24:302138#if defined(OS_ANDROID)
2139 // If the platform is Android, force the distillability service on.
2140 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2141#endif
2142
[email protected]47c7ec82012-01-18 03:29:212143 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512144 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192145 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412146 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302147#if defined(OS_CHROMEOS)
2148 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2149#endif
brettw00899e62016-11-12 02:10:172150#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512151 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272152 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172153 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512154 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272155 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172156 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172157 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282158#endif
estark4b003b332015-02-14 01:07:052159 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512160 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482161 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512162 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502163 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572164 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462165 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302166 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512167 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172168#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242169 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482170 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552171#endif
[email protected]ce304ce2013-02-22 21:54:452172 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172173#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592174 switches::kForcePNaClSubzero,
2175#endif
Marc Treibad33cf942017-08-24 11:19:002176 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512177 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102178 switches::kEnableExperimentalWebAssemblyFeatures,
iclelland79237e92016-06-23 12:03:512179 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552180 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022181 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512182 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512183 switches::kPpapiFlashPath,
2184 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032185 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092186 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512187 };
2188
2189 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372190 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172191 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172192#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382193 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442194 extensions::switches::kAllowHTTPBackgroundPage,
2195 extensions::switches::kEnableExperimentalExtensionApis,
2196 extensions::switches::kExtensionsOnChromeURLs,
2197 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382198 };
2199
2200 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372201 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282202#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372203 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132204 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512205 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512206 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502207 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172208#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242209 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582210 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592211 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412212 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552213#endif
[email protected]4287a3d2011-06-13 23:56:512214 switches::kPpapiFlashPath,
2215 switches::kPpapiFlashVersion,
2216 };
2217
2218 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372219 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112220 } else if (process_type == switches::kGpuProcess) {
2221 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2222 // because GPU is expected to be unreliable.
2223 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2224 !command_line->HasSwitch(switches::kDisableBreakpad))
2225 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302226 }
[email protected]6f08af82011-09-15 01:19:032227
Ian Barkley-Yeung550aae052019-07-11 00:11:112228#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302229 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112230 static const char* const kSwitchNames[] = {
Joshua Peraza86b79582019-10-08 15:56:292231 crash_reporter::switches::kCrashLoopBefore,
Ian Barkley-Yeung550aae052019-07-11 00:11:112232 };
2233 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2234 base::size(kSwitchNames));
2235 }
2236#endif
2237
wittman832321f52016-10-10 18:18:382238 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442239 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342240
2241#if defined(OS_LINUX)
2242 // Processes may only query perf_event_open with the BPF sandbox disabled.
2243 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2244 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2245 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2246 }
2247#endif
[email protected]b80f68432011-05-02 17:22:302248}
2249
Olivier Yiptong0daa93f2019-08-22 19:40:082250std::string
2251ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2252 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2253}
2254
[email protected]b80f68432011-05-02 17:22:302255std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432256 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332257 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302258 return g_browser_process->GetApplicationLocale();
2259}
2260
[email protected]597a867b2011-11-18 18:31:202261std::string ChromeContentBrowserClient::GetAcceptLangs(
2262 content::BrowserContext* context) {
2263 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202264 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082265}
2266
Dana Fried34d580002019-04-24 20:05:482267gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492268 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482269 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082270}
2271
bengre8a146f2016-03-10 01:20:222272bool ChromeContentBrowserClient::IsDataSaverEnabled(
2273 content::BrowserContext* browser_context) {
rajendrantfb95964d2019-10-17 20:05:382274 if (!browser_context || browser_context->IsOffTheRecord())
2275 return false;
2276
Robert Ogdenc995d4fe2019-03-25 19:18:372277 Profile* profile = Profile::FromBrowserContext(browser_context);
2278 return profile && data_reduction_proxy::DataReductionProxySettings::
Tarun Bansalc91d5bb82019-11-05 00:17:412279 IsDataSaverEnabledByUser(profile->IsOffTheRecord(),
2280 profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222281}
2282
Kenichi Ishibashi46329872018-07-17 09:43:402283void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2284 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192285 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402286 DCHECK(browser_context);
2287 DCHECK(out_prefs);
2288 renderer_preferences_util::UpdateFromSystemSettings(
2289 out_prefs, Profile::FromBrowserContext(browser_context));
2290}
2291
Clark DuVall5690e742019-07-17 18:26:172292bool ChromeContentBrowserClient::AllowAppCache(
2293 const GURL& manifest_url,
2294 const GURL& first_party,
2295 content::BrowserContext* context) {
2296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2297 return CookieSettingsFactory::GetForProfile(
2298 Profile::FromBrowserContext(context))
2299 ->IsCookieAccessAllowed(manifest_url, first_party);
2300}
2301
Matt Falkenhagen7b509e52019-08-15 23:11:412302bool ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072303 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542304 const GURL& site_for_cookies,
2305 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362306 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202307 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342308 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522309 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542310 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452311
brettw00899e62016-11-12 02:10:172312#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452313 // Check if this is an extension-related service worker, and, if so, if it's
2314 // allowed (this can return false if, e.g., the extension is disabled).
2315 // If it's not allowed, return immediately. We deliberately do *not* report
2316 // to the TabSpecificContentSettings, since the service worker is blocked
2317 // because of the extension, rather than because of the user's content
2318 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022319 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362320 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452321 return false;
2322 }
2323#endif
2324
falken3dbc36e2014-10-10 16:48:072325 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202326
shimazuce8af88122016-10-06 23:49:212327 // Check if JavaScript is allowed.
2328 content_settings::SettingInfo info;
2329 std::unique_ptr<base::Value> value =
2330 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452331 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
shimazuce8af88122016-10-06 23:49:212332 std::string(), &info);
2333 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2334 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2335
2336 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542337 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2338 scope, site_for_cookies, top_frame_origin);
falken4a22dce2015-04-30 08:25:202339 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242340 // Only post the task if this is for a specific tab.
2341 if (!wc_getter.is_null()) {
Sami Kyostila5e1306d2019-08-14 11:01:292342 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:282343 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512344 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342345 std::move(wc_getter), scope, !allow_javascript,
Christian Dullweber2a2f2182019-09-25 15:44:542346 !allow_cookies));
rdevlin.croninf5863da2015-09-10 19:21:452347 }
Christian Dullweber2a2f2182019-09-25 15:44:542348 return allow_javascript && allow_cookies;
falken3dbc36e2014-10-10 16:48:072349}
2350
Matt Falkenhagen7b509e52019-08-15 23:11:412351bool ChromeContentBrowserClient::AllowServiceWorkerOnUI(
2352 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542353 const GURL& site_for_cookies,
2354 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412355 const GURL& script_url,
2356 content::BrowserContext* context,
2357 base::RepeatingCallback<content::WebContents*()> wc_getter) {
2358 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542359 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412360
2361#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022362 // Check if this is an extension-related service worker, and, if so, if it's
2363 // allowed (this can return false if, e.g., the extension is disabled).
2364 // If it's not allowed, return immediately. We deliberately do *not* report
2365 // to the TabSpecificContentSettings, since the service worker is blocked
2366 // because of the extension, rather than because of the user's content
2367 // settings.
2368 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2369 scope, first_party_url, script_url, context)) {
2370 return false;
2371 }
Matt Falkenhagen7b509e52019-08-15 23:11:412372#endif
2373
2374 Profile* profile = Profile::FromBrowserContext(context);
2375
2376 // Check if JavaScript is allowed.
2377 content_settings::SettingInfo info;
2378 std::unique_ptr<base::Value> value =
2379 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
Darin Fisher42f5e7d2019-10-30 07:15:452380 first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT,
Matt Falkenhagen7b509e52019-08-15 23:11:412381 std::string(), &info);
2382 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2383 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2384
2385 // Check if cookies are allowed.
2386 bool allow_cookies =
2387 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542388 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412389
2390 // Record access to database for potential display in UI.
2391 // Only post the task if this is for a specific tab.
2392 if (!wc_getter.is_null()) {
2393 TabSpecificContentSettings::ServiceWorkerAccessed(
2394 std::move(wc_getter), scope, !allow_javascript, !allow_cookies);
2395 }
2396 return allow_javascript && allow_cookies;
2397}
2398
Jochen Eisinger0ff7645c2017-11-28 08:11:262399bool ChromeContentBrowserClient::AllowSharedWorker(
2400 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542401 const GURL& site_for_cookies,
2402 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262403 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372404 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262405 content::BrowserContext* context,
2406 int render_process_id,
2407 int render_frame_id) {
2408 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2409
2410 // Check if cookies are allowed.
2411 bool allow =
2412 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542413 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2414 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262415
2416 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372417 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2418 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262419 return allow;
2420}
2421
Patrick Monette6cb099a2019-09-18 19:31:272422bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2423 const std::string& scheme) {
2424#if BUILDFLAG(ENABLE_EXTENSIONS)
2425 // Extensions are allowed to start cross-origin shared workers.
2426 if (scheme == extensions::kExtensionScheme)
2427 return true;
2428#endif
2429
2430 return false;
2431}
2432
Clark DuVallab63d142019-07-23 04:24:362433bool ChromeContentBrowserClient::AllowSignedExchange(
2434 content::BrowserContext* browser_context) {
2435 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2436 Profile* profile = Profile::FromBrowserContext(browser_context);
2437 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2438}
2439
[email protected]f917df22014-07-10 07:45:492440void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352441 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572442 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172443 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572444 base::OnceCallback<void(bool)> callback) {
2445 Profile* profile = Profile::FromBrowserContext(browser_context);
2446 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002447 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352448
brettw00899e62016-11-12 02:10:172449#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572450 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492451#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572452 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492453#endif
2454}
2455
brettw00899e62016-11-12 02:10:172456#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492457void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2458 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172459 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572460 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492461 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492463 std::map<int, int> process_map;
2464 std::map<int, int>::const_iterator it;
2465 bool has_web_view_guest = false;
2466 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172467 for (const auto& it : render_frames) {
2468 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492469 continue;
2470
Lukasz Anforowicz09060bdf72018-08-23 15:53:172471 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492472
Lukasz Anforowicz09060bdf72018-08-23 15:53:172473 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492474 has_web_view_guest = true;
2475 }
2476 if (!has_web_view_guest) {
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 return;
2479 }
[email protected]dffb9fc2014-07-16 04:14:022480 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492481 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492482
[email protected]140d6cd92014-08-12 18:26:462483 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572484 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2485 web_view_permission_helper->RequestFileSystemPermission(
2486 url, allow,
2487 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2488 weak_factory_.GetWeakPtr(), url, render_frames,
2489 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492490}
2491#endif
2492
2493void ChromeContentBrowserClient::FileSystemAccessed(
2494 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172495 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572496 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492497 bool allow) {
[email protected]62151052012-02-01 18:40:482498 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172499 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572500 TabSpecificContentSettings::FileSystemAccessed(
2501 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352502 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572503 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352504}
2505
[email protected]7c5ff9a2012-03-02 07:42:492506bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2507 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572508 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172509 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572510 Profile* profile = Profile::FromBrowserContext(browser_context);
2511 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2512
falken71691402017-01-27 03:38:002513 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492514
2515 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172516 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572517 TabSpecificContentSettings::IndexedDBAccessed(
2518 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492519 }
2520
2521 return allow;
2522}
2523
Ben Kelly6b2e61c2019-03-14 16:06:292524bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2525 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572526 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292527 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572528 Profile* profile = Profile::FromBrowserContext(browser_context);
2529 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292530 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2531
2532 // Record access to CacheStorage for potential display in UI.
2533 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572534 TabSpecificContentSettings::CacheStorageAccessed(
2535 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292536 }
2537
2538 return allow;
2539}
2540
Joshua Bell1ebc8df2019-11-06 00:27:582541bool ChromeContentBrowserClient::AllowWorkerWebLocks(
2542 const GURL& url,
2543 content::BrowserContext* browser_context,
2544 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2545 Profile* profile = Profile::FromBrowserContext(browser_context);
2546 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2547 return cookie_settings->IsCookieAccessAllowed(url, url);
2548}
2549
jyasskinc993ce8d2016-03-31 00:38:342550ChromeContentBrowserClient::AllowWebBluetoothResult
2551ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452552 content::BrowserContext* browser_context,
2553 const url::Origin& requesting_origin,
2554 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342555 // TODO(crbug.com/598890): Don't disable if
2556 // base::CommandLine::ForCurrentProcess()->
2557 // HasSwitch(switches::kEnableWebBluetooth) is true.
2558 if (variations::GetVariationParamValue(
2559 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2560 "Bluetooth") ==
2561 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2562 // The kill switch is enabled for this permission. Block requests.
2563 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2564 }
2565
jyasskin98bdd3992016-02-26 20:25:452566 const HostContentSettingsMap* const content_settings =
2567 HostContentSettingsMapFactory::GetForProfile(
2568 Profile::FromBrowserContext(browser_context));
2569
csharrisonaec2c542016-10-12 19:40:362570 if (content_settings->GetContentSetting(
2571 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:452572 ContentSettingsType::BLUETOOTH_GUARD,
csharrisonaec2c542016-10-12 19:40:362573 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342574 return AllowWebBluetoothResult::BLOCK_POLICY;
2575 }
2576 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452577}
2578
beaufort.francois01135bf2016-11-23 14:37:362579std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2580 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2581 "blocklist_additions");
scheib74250322016-04-07 03:32:212582}
2583
John Abd-El-Malek21bca7c2018-10-26 22:13:332584#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522585void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072586 content::BrowserContext* browser_context) {
2587 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2588 if (user_manager) {
2589 const user_manager::User* user =
2590 chromeos::ProfileHelper::Get()->GetUserByProfile(
2591 Profile::FromBrowserContext(browser_context));
2592 if (user && !user->username_hash().empty()) {
2593 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2594 user->username_hash());
2595 }
2596 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332597}
2598#endif
2599
Reilly Grant19aaccd2018-07-16 22:06:372600scoped_refptr<network::SharedURLLoaderFactory>
2601ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2603 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2604
2605 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372606 return nullptr;
2607
Min Qinda0d55b2018-10-12 18:30:052608 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372609 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042610}
2611
Sean Gilhulyda1ee4b2018-11-13 21:56:092612network::mojom::NetworkContext*
2613ChromeContentBrowserClient::GetSystemNetworkContext() {
2614 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2615 DCHECK(g_browser_process->system_network_context_manager());
2616 return g_browser_process->system_network_context_manager()->GetContext();
2617}
2618
Andrew Moylan17329fc2017-09-25 07:43:302619std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2620 return google_apis::GetAPIKey();
2621}
2622
Ke He21ee87f2018-05-30 02:35:322623#if defined(OS_ANDROID)
2624bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2625 // Indicate that Chrome uses the GMS core location provider.
2626 return true;
2627}
2628#endif
2629
Yeolf3dc22ca2019-04-18 17:25:322630scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412631ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2632 return new ChromeQuotaPermissionContext();
2633}
2634
michaeln10e5fc352017-02-07 02:07:582635void ChromeContentBrowserClient::GetQuotaSettings(
2636 content::BrowserContext* context,
2637 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452638 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582639 if (g_default_quota_settings) {
2640 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452641 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582642 return;
2643 }
taptede6d878e2017-06-24 01:53:452644 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062645 partition->GetPath(), context->IsOffTheRecord(),
Jarryd1f02b902019-11-07 03:29:572646 storage::GetDefaultDeviceInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512647}
2648
Mythri Alle0b8de0d2018-10-22 11:06:222649content::GeneratedCodeCacheSettings
2650ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2651 content::BrowserContext* context) {
2652 base::FilePath cache_path;
2653 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2654 // If we pass 0 for size, disk_cache will pick a default size using the
2655 // heuristics based on available disk size. These are implemented in
2656 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162657 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132658 DCHECK(g_browser_process);
2659 PrefService* local_state = g_browser_process->local_state();
2660 if (local_state) {
2661 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2662 base::FilePath disk_cache_dir =
2663 local_state->GetFilePath(prefs::kDiskCacheDir);
2664 if (!disk_cache_dir.empty())
2665 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2666 }
Mythri Ab2486572019-06-13 14:48:162667 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222668}
2669
[email protected]848dd042011-06-04 18:24:032670void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262671 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172672 int cert_error,
2673 const net::SSLInfo& ssl_info,
2674 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232675 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222676 bool strict_enforcement,
Erik Staaba65a6032019-11-27 22:23:262677 base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
clamy0d32d6d2015-11-24 11:16:262678 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232679 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142680 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022681 // have a context for making the right decision, so block the
2682 // request hard, without an info bar to allow showing the insecure
2683 // content.
estark719dde52016-08-09 03:14:272684 if (!callback.is_null())
Erik Staaba65a6032019-11-27 22:23:262685 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022686 return;
2687 }
2688
[email protected]f9034cf2011-07-21 12:43:412689 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572690 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262691 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572692 if (prerender_contents) {
2693 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272694 if (!callback.is_null()) {
Erik Staaba65a6032019-11-27 22:23:262695 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
estark719dde52016-08-09 03:14:272696 }
[email protected]09667f02014-01-06 15:37:572697 return;
[email protected]f9034cf2011-07-21 12:43:412698 }
2699
Erik Staaba65a6032019-11-27 22:23:262700 std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
Carlos IL5a9e7512019-06-13 22:35:282701 return;
[email protected]848dd042011-06-04 18:24:032702}
2703
Alexander Hendrichbcf2616e2018-05-18 08:21:102704namespace {
2705
Pavol Markob211ab22019-01-23 20:03:042706certificate_matching::CertificatePrincipalPattern
2707ParseCertificatePrincipalPattern(const base::Value* pattern) {
2708 return certificate_matching::CertificatePrincipalPattern::
2709 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2710}
2711
Alexander Hendrichbcf2616e2018-05-18 08:21:102712// Attempts to auto-select a client certificate according to the value of
Darin Fisher42f5e7d2019-10-30 07:15:452713// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for
Alexander Hendrichbcf2616e2018-05-18 08:21:102714// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2715std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2716 Profile* profile,
2717 const GURL& requesting_url,
2718 net::ClientCertIdentityList& client_certs) {
2719 HostContentSettingsMap* host_content_settings_map =
2720 HostContentSettingsMapFactory::GetForProfile(profile);
2721 std::unique_ptr<base::Value> setting =
2722 host_content_settings_map->GetWebsiteSetting(
2723 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452724 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102725
Pavol Markob211ab22019-01-23 20:03:042726 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102727 return nullptr;
2728
Alexander Hendrichbcf2616e2018-05-18 08:21:102729 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042730 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2731 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102732 // |setting_dict| has the wrong format (e.g. single filter instead of a
2733 // list of filters). This content setting is only provided by
2734 // the |PolicyProvider|, which should always set it to a valid format.
2735 // Therefore, delete the invalid value.
2736 host_content_settings_map->SetWebsiteSettingDefaultScope(
2737 requesting_url, requesting_url,
Darin Fisher42f5e7d2019-10-30 07:15:452738 ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042739 return nullptr;
2740 }
2741
2742 for (const base::Value& filter : filters->GetList()) {
2743 DCHECK(filter.is_dict());
2744
2745 auto issuer_pattern = ParseCertificatePrincipalPattern(
2746 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2747 auto subject_pattern = ParseCertificatePrincipalPattern(
2748 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2749 // Use the first certificate that is matched by the filter.
2750 for (auto& client_cert : client_certs) {
2751 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2752 subject_pattern.Matches(client_cert->certificate()->subject())) {
2753 return std::move(client_cert);
2754 }
2755 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102756 }
2757
2758 return nullptr;
2759}
2760
2761} // namespace
2762
Daniel McArdle85735f52019-06-25 03:27:062763base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192764 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402765 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082766 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352767 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022768 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192769 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022770 if (prerender_contents) {
2771 prerender_contents->Destroy(
2772 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062773 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452774 }
2775
[email protected]791879c2013-12-17 07:22:412776 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2777 DCHECK(requesting_url.is_valid())
2778 << "Invalid URL string: https://"
2779 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452780
Pavol Marko230ea2c92017-12-03 22:35:442781 bool may_show_cert_selection = true;
2782
davidben3b8455ae72015-03-11 19:42:192783 Profile* profile =
2784 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442785#if defined(OS_CHROMEOS)
2786 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2787 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2788 // and remove the command-line flag after prototype phase when the
2789 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2790 may_show_cert_selection =
2791 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2792
2793 content::StoragePartition* storage_partition =
2794 content::BrowserContext::GetStoragePartition(
2795 profile, web_contents->GetSiteInstance());
2796 chromeos::login::SigninPartitionManager* signin_partition_manager =
2797 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2798 profile);
2799
2800 // On the sign-in profile, only allow client certs in the context of the
2801 // sign-in frame.
2802 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2803 storage_partition)) {
2804 LOG(WARNING)
2805 << "Client cert requested in sign-in profile in wrong context.";
2806 // Continue without client certificate. We do this to mimic the case of no
2807 // client certificate being present in the profile's certificate store.
2808 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062809 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442810 }
2811 VLOG(1) << "Client cert requested in sign-in profile.";
2812 }
2813#endif // defined(OS_CHROMEOS)
2814
Alexander Hendrichbcf2616e2018-05-18 08:21:102815 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2816 AutoSelectCertificate(profile, requesting_url, client_certs);
2817 if (auto_selected_identity) {
2818 // The callback will own |auto_selected_identity| and |delegate|, keeping
2819 // them alive until after ContinueWithCertificate is called.
2820 scoped_refptr<net::X509Certificate> cert =
2821 auto_selected_identity->certificate();
2822 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2823 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582824 base::BindOnce(
2825 &content::ClientCertificateDelegate::ContinueWithCertificate,
2826 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322827 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062828 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452829 }
2830
Pavol Marko230ea2c92017-12-03 22:35:442831 if (!may_show_cert_selection) {
2832 LOG(WARNING) << "No client cert matched by policy and user selection is "
2833 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322834 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442835 // Continue without client certificate. We do this to mimic the case of no
2836 // client certificate being present in the profile's certificate store.
2837 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062838 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442839 }
2840
Daniel McArdle85735f52019-06-25 03:27:062841 return chrome::ShowSSLClientCertificateSelector(
2842 web_contents, cert_request_info, std::move(client_certs),
2843 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452844}
2845
[email protected]dc73a7b2012-03-25 15:27:182846content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562847 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182848}
2849
Francois Dorayfd823bb12019-10-04 18:03:052850content::LockObserver* ChromeContentBrowserClient::GetLockObserver() {
François Dorayaa3f80102019-10-12 02:29:242851 return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance()
2852 ->GetLockObserver();
Francois Dorayfd823bb12019-10-04 18:03:052853}
2854
peterc26c6c62014-12-10 14:13:592855content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022856ChromeContentBrowserClient::GetPlatformNotificationService(
2857 content::BrowserContext* browser_context) {
2858 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2859 Profile* profile = Profile::FromBrowserContext(browser_context);
2860 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042861}
2862
[email protected]9f3fba52011-06-08 20:37:192863bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352864 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352865 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572866 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352867 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032868 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232869 const GURL& target_url,
2870 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212871 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232872 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482873 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232874 bool user_gesture,
2875 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012876 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352877 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2878 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012879
csharrison95f01e922017-04-24 18:52:352880 content::WebContents* web_contents =
2881 content::WebContents::FromRenderFrameHost(opener);
2882 Profile* profile =
2883 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2884 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012885 *no_javascript_access = false;
2886
[email protected]9f3fba52011-06-08 20:37:192887 // If the opener is trying to create a background window but doesn't have
2888 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032889 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172890#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352891 auto* process_map = extensions::ProcessMap::Get(profile);
2892 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172893 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2894 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012895 return false;
2896 }
2897
[email protected]7b54ca02012-03-02 18:06:532898 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2899 // return a recently installed Extension even if this CanCreateWindow call
2900 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012901 // because the permission check above would have caused an early return
2902 // already. We must use the full URL to find hosted apps, though, and not
2903 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552904 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352905 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292906 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012907 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022908#endif
[email protected]190e5e22013-07-27 05:59:232909
2910 return true;
[email protected]9f3fba52011-06-08 20:37:192911 }
[email protected]056efdc2013-04-06 00:14:532912
brettw00899e62016-11-12 02:10:172913#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462914 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352915 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232916 return true;
lazyboy04b75d32016-02-25 03:12:182917 }
2918
nick0fbc3922016-12-16 20:52:072919 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352920 // Intentionally duplicating |registry| code from above because we want to
2921 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2922 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182923 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352924 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142925 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532926 UMA_HISTOGRAM_ENUMERATION(
2927 "Extensions.AppLoadedInTab",
2928 ClassifyAppLoadedInTabSource(opener_url, extension),
2929 APP_LOADED_IN_TAB_SOURCE_MAX);
2930
2931 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162932 return false;
lazyboy5d5fede02016-03-10 04:10:142933 }
lazyboy04b75d32016-02-25 03:12:182934 }
[email protected]5940b0d2014-07-01 00:18:262935#endif
[email protected]190e5e22013-07-27 05:59:232936
Charles Harrisonaf2acd02017-08-18 22:46:022937#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232938 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352939 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582940 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2941 content_settings, opener_top_level_frame_url, target_url,
2942 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352943 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2944 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582945 return false;
2946 }
2947#endif
2948
Charles Harrisonaf2acd02017-08-18 22:46:022949 // Don't let prerenders open popups.
2950 if (auto* prerender_contents =
2951 prerender::PrerenderContents::FromWebContents(web_contents)) {
2952 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2953 return false;
2954 }
2955
Aaron Colwell9dab1652019-12-09 18:29:492956 BlockedWindowParams blocked_params(
2957 target_url, source_origin, opener->GetSiteInstance(), referrer,
2958 frame_name, disposition, features, user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132959 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:192960 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
2961 &nav_params, nullptr /*=open_url_params*/,
2962 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:192963}
2964
[email protected]c52b2892012-03-07 11:01:022965content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:442966ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002967 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:512968}
2969
Katie D840d9532018-11-27 06:20:482970content::TtsControllerDelegate*
2971ChromeContentBrowserClient::GetTtsControllerDelegate() {
2972 TtsControllerDelegateImpl* delegate =
2973 TtsControllerDelegateImpl::GetInstance();
2974#if !defined(OS_ANDROID)
2975 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
2976 delegate->SetTtsEngineDelegate(tts_extension_engine);
2977#endif
2978 return delegate;
2979}
2980
Katie D4713ee42018-11-30 01:48:272981content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
2982#ifdef OS_CHROMEOS
2983 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:272984#else
2985 return nullptr;
2986#endif
2987}
2988
[email protected]64d69de42012-02-06 00:19:542989void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:442990 RenderViewHost* rvh,
2991 WebPreferences* web_prefs) {
2992 Profile* profile =
2993 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062994 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062995
aelias0df335a2017-03-02 23:43:512996// Fill font preferences. These are not registered on Android
2997// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:452998#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:192999 FontFamilyCache::FillFontFamilyMap(profile,
3000 prefs::kWebKitStandardFontFamilyMap,
3001 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443002 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193003 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443004 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193005 &web_prefs->serif_font_family_map);
3006 FontFamilyCache::FillFontFamilyMap(profile,
3007 prefs::kWebKitSansSerifFontFamilyMap,
3008 &web_prefs->sans_serif_font_family_map);
3009 FontFamilyCache::FillFontFamilyMap(profile,
3010 prefs::kWebKitCursiveFontFamilyMap,
3011 &web_prefs->cursive_font_family_map);
3012 FontFamilyCache::FillFontFamilyMap(profile,
3013 prefs::kWebKitFantasyFontFamilyMap,
3014 &web_prefs->fantasy_font_family_map);
3015 FontFamilyCache::FillFontFamilyMap(profile,
3016 prefs::kWebKitPictographFontFamilyMap,
3017 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063018
[email protected]64d69de42012-02-06 00:19:543019 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403020 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543021 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403022 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543023 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403024 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543025 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403026 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513027#endif
[email protected]f3986f82012-01-03 20:00:063028
[email protected]ddf72142012-05-22 04:52:403029 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063030
[email protected]64d69de42012-02-06 00:19:543031 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063032 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213033 web_prefs->javascript_can_access_clipboard =
3034 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543035 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063036
[email protected]ddf72142012-05-22 04:52:403037 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543038 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573039
Avi Drissman1aa6cb92019-01-23 15:58:383040 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543041 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573042
[email protected]ddf72142012-05-22 04:52:403043 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543044 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543045 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403046 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063047
Zhenyao Moa3fda9972017-09-16 01:34:403048 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3049 web_prefs->webgl1_enabled = false;
3050 web_prefs->webgl2_enabled = false;
3051 }
[email protected]f3986f82012-01-03 20:00:063052
[email protected]64d69de42012-02-06 00:19:543053 web_prefs->allow_running_insecure_content =
3054 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323055#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053056 web_prefs->font_scale_factor =
3057 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3058 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323059 web_prefs->force_enable_zoom =
3060 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493061#endif
Becky Zhoubbfbde32019-02-20 17:07:593062 web_prefs->force_dark_mode_enabled =
3063 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393064
[email protected]af4256d52013-06-04 20:39:073065#if defined(OS_ANDROID)
3066 web_prefs->password_echo_enabled =
3067 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3068#else
[email protected]9d06d88d2012-02-23 22:37:083069 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073070#endif
3071
[email protected]64d69de42012-02-06 00:19:543072 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063073 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543074 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063075 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3076
brettw00899e62016-11-12 02:10:173077#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053078 std::string image_animation_policy =
3079 prefs->GetString(prefs::kAnimationPolicy);
3080 if (image_animation_policy == kAnimationPolicyOnce)
3081 web_prefs->animation_policy =
3082 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3083 else if (image_animation_policy == kAnimationPolicyNone)
3084 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3085 else
3086 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3087#endif
3088
[email protected]f3986f82012-01-03 20:00:063089 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153090 web_prefs->default_encoding =
3091 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543092 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403093 prefs->ClearPref(prefs::kDefaultCharset);
3094 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063095 }
[email protected]64d69de42012-02-06 00:19:543096 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063097
mkwst05544102015-01-10 20:26:163098 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3099 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073100 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163101 web_prefs->strict_mixed_content_checking = true;
3102 web_prefs->strict_powerful_feature_restrictions = true;
3103 }
3104
Robert Ogdencf2872d2019-03-19 18:59:373105 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213106
Tarun Bansal333819e2018-05-15 16:38:423107 web_prefs->data_saver_holdback_web_api_enabled =
3108 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3109 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423110
Alison Maher28a73e22019-10-18 19:26:353111 auto* native_theme = GetWebTheme();
Jinsuk Kima3d393ce2019-05-27 00:57:423112 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133113 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533114#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423115 auto* delegate = TabAndroid::FromWebContents(contents)
3116 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3117 contents->GetDelegate())
3118 : nullptr;
3119 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133120 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423121 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133122
Mounir Lamouri9c99a1602018-07-05 15:01:443123 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423124 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383125
Alison Maher28a73e22019-10-18 19:26:353126 // Notify NativeTheme of changes to night mode.
3127 native_theme->set_preferred_color_scheme(
3128 delegate->IsNightModeEnabled()
3129 ? ui::NativeTheme::PreferredColorScheme::kDark
3130 : ui::NativeTheme::PreferredColorScheme::kLight);
zqzhang183dc822017-02-15 17:04:113131 }
Ian Vollick6243dfe02018-03-08 01:08:533132#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533133
Mounir Lamouri6926107f2019-01-31 18:17:433134 // web_app_scope value is platform specific.
3135#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423136 if (delegate)
3137 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433138#elif BUILDFLAG(ENABLE_EXTENSIONS)
3139 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253140 web_prefs->web_app_scope = GURL();
3141 // Set |web_app_scope| based on the app associated with the app window if
3142 // any. Note that the app associated with the window never changes, even
3143 // if the app navigates off scope. This is not a problem because we still
3144 // want to use the scope of the app associated with the window, not the
3145 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433146 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233147 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443148 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273149 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443150 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253151 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053152 // for profiles that support them, so we should always be able to
3153 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253154 //
3155 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123156 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253157 web_prefs->web_app_scope =
3158 web_app::WebAppProvider::Get(profile)
3159 ->registrar()
Jiewei Qianf33ba1a2019-11-04 23:23:033160 .GetAppScope(browser->app_controller()->GetAppId())
Alan Cutterf25cfe42019-07-16 02:40:123161 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433162 }
Mounir Lamouri6926107f2019-01-31 18:17:433163 }
3164#endif
3165
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533166#if BUILDFLAG(ENABLE_EXTENSIONS)
3167 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443168 if (browser && browser->app_controller() &&
3169 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533170 web_prefs->strict_mixed_content_checking = true;
3171 }
3172#endif
3173
Ian Vollick6243dfe02018-03-08 01:08:533174 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113175 }
zqzhang93e959d12017-03-16 13:10:203176
Ian Vollick6243dfe02018-03-08 01:08:533177#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143178 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113179#endif // defined(OS_ANDROID)
3180
Tarun Bansal73d67f02018-01-17 05:56:253181 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3182 // Obtain the maximum effective connection type at which the feature is
3183 // enabled.
3184 std::string effective_connection_type_param =
3185 base::GetFieldTrialParamValueByFeature(
3186 features::kLowPriorityIframes,
3187 "max_effective_connection_type_threshold");
3188
3189 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3190 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3191 if (effective_connection_type) {
3192 web_prefs->low_priority_iframes_threshold =
3193 effective_connection_type.value();
3194 }
3195 }
3196
rajendrant0521cee2019-07-29 06:09:263197 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3198 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003199
Scott Little878f7d6702018-05-31 22:09:063200 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3201 const char* param_name =
3202 web_prefs->data_saver_enabled
3203 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3204 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3205 "saver_enabled";
3206
3207 base::StringPairs pairs;
3208 base::SplitStringIntoKeyValuePairs(
3209 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3210 param_name),
3211 ':', ',', &pairs);
3212
3213 for (const auto& pair : pairs) {
3214 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3215 net::GetEffectiveConnectionTypeForName(pair.first);
3216 int value = 0;
3217 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3218 web_prefs->lazy_frame_loading_distance_thresholds_px
3219 [effective_connection_type.value()] = value;
3220 }
3221 }
3222 }
3223
rajendrantd8026342018-08-29 08:08:393224 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3225 const char* param_name =
3226 web_prefs->data_saver_enabled
3227 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3228 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3229 "saver_enabled";
3230
3231 base::StringPairs pairs;
3232 base::SplitStringIntoKeyValuePairs(
3233 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3234 param_name),
3235 ':', ',', &pairs);
3236
3237 for (const auto& pair : pairs) {
3238 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3239 net::GetEffectiveConnectionTypeForName(pair.first);
3240 int value = 0;
3241 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3242 web_prefs->lazy_image_loading_distance_thresholds_px
3243 [effective_connection_type.value()] = value;
3244 }
3245 }
rajendrant3daeae292019-09-20 07:57:543246
3247 pairs.clear();
3248 base::SplitStringIntoKeyValuePairs(
3249 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3250 "lazy_image_first_k_fully_load"),
3251 ':', ',', &pairs);
3252
3253 for (const auto& pair : pairs) {
3254 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3255 net::GetEffectiveConnectionTypeForName(pair.first);
3256 int value = 0;
3257 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3258 web_prefs
3259 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3260 value;
3261 }
3262 }
rajendrantd8026342018-08-29 08:08:393263 }
3264
Tarun Bansald10f17a02018-09-13 00:23:173265 if (base::FeatureList::IsEnabled(
3266 features::kNetworkQualityEstimatorWebHoldback)) {
3267 std::string effective_connection_type_param =
3268 base::GetFieldTrialParamValueByFeature(
3269 features::kNetworkQualityEstimatorWebHoldback,
3270 "web_effective_connection_type_override");
3271
3272 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3273 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3274 DCHECK(effective_connection_type_param.empty() ||
3275 effective_connection_type);
3276 if (effective_connection_type) {
3277 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3278 effective_connection_type.value());
3279 web_prefs->network_quality_estimator_web_holdback =
3280 effective_connection_type.value();
3281 }
3282 }
3283
François Beaufort4f8107d2018-03-05 12:12:103284#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563285 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593286 // If autoplay is allowed by policy then force the no user gesture required
3287 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103288 web_prefs->autoplay_policy =
3289 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553290 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593291 web_prefs->autoplay_policy ==
3292 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553293 // If the autoplay disable settings feature is enabled and the autoplay
3294 // policy is set to using the unified policy then set the default autoplay
3295 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593296 web_prefs->autoplay_policy =
3297 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3298 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3299 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103300 }
3301#endif // !defined(OS_ANDROID)
3302
Dave Tapuskac6627e12018-08-30 15:07:193303 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493304
3305 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213306 base::Optional<ui::CaptionStyle> style;
3307
3308 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3309 ::switches::kForceCaptionStyle)) {
3310 style = ui::CaptionStyle::FromSpec(
3311 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3312 switches::kForceCaptionStyle));
3313 }
3314
3315 // Apply system caption style.
3316 if (!style) {
3317 style = native_theme->GetSystemCaptionStyle();
3318 }
3319
3320 // Apply caption style from preferences if system caption style is undefined.
3321 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
evliubc2aa0472019-08-09 20:19:193322 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
evliuedcbb87d2019-11-22 19:49:413323
3324 base::UmaHistogramBoolean("Accessibility.CaptionSettingsLoadedFromPrefs",
3325 style.has_value());
Evan Liu7cdbf8872019-06-19 16:47:213326 }
3327
3328 if (style) {
3329 web_prefs->text_track_background_color = style->background_color;
3330 web_prefs->text_track_text_color = style->text_color;
3331 web_prefs->text_track_text_size = style->text_size;
3332 web_prefs->text_track_text_shadow = style->text_shadow;
3333 web_prefs->text_track_font_family = style->font_family;
3334 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563335 web_prefs->text_track_window_color = style->window_color;
3336 web_prefs->text_track_window_padding = style->window_padding;
3337 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213338 }
Elly Fong-Jonesf92897392019-01-24 16:05:493339
[email protected]a48ab7112014-08-01 16:48:033340 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503341 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363342}
3343
[email protected]b8148ac2011-07-13 22:03:253344void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3345 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033346 for (size_t i = 0; i < extra_parts_.size(); ++i)
3347 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253348
[email protected]b3adbd02011-11-30 22:23:273349 // about: handler. Must come before chrome: handler, since it will
3350 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053351 // actually handle them. Also relies on a preliminary fixup phase.
3352 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253353 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3354 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033355
madfbd10852017-01-20 03:15:333356 // The group policy NTP URL handler must be registered before the other NTP
3357 // URL handlers below.
3358 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3359 BrowserURLHandler::null_handler());
3360
zpengdb4a58e2017-01-10 17:40:323361#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033362 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353363 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033364 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453365#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033366 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133367 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3368 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453369#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033370
[email protected]b8148ac2011-07-13 22:03:253371 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313372 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3373 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063374
3375 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3376 // the user.
Robert Ogden0f4d88682019-09-24 22:27:523377 handler->AddHandlerPair(
3378 &previews::HandlePreviewsLitePageRedirectURLRewrite,
3379 &previews::HandlePreviewsLitePageRedirectURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253380}
3381
[email protected]650b2d52013-02-10 03:41:453382base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493383 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323384}
3385
[email protected]c9b6eb62011-10-18 20:49:393386std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3387 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3388}
3389
Dominik Röttsches47347832019-03-12 17:45:013390base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3391 base::FilePath user_data_dir;
3392 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3393 DCHECK(!user_data_dir.empty());
3394 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3395}
3396
jmadill57b52d42015-08-21 18:16:133397base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3398 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523399 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133400 DCHECK(!user_data_dir.empty());
3401 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3402}
3403
Khushal7ca0b782018-07-20 05:53:273404base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3405 base::FilePath user_data_dir;
3406 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3407 DCHECK(!user_data_dir.empty());
3408 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3409}
3410
[email protected]b7631cc2012-09-15 05:08:383411void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3412 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163413#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553414 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543415#endif
[email protected]b7631cc2012-09-15 05:08:383416}
3417
[email protected]0c7193742012-11-07 19:05:033418content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443419ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173420#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553421 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033422 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443423 nacl::NaClProcessHost* host =
3424 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3425 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033426 // Found the plugin.
3427 return host->browser_ppapi_host();
3428 }
3429 ++iter;
3430 }
[email protected]a56f8322014-07-16 21:13:553431#endif
Aran Gilmanf010bdd2019-08-28 19:55:443432 return nullptr;
[email protected]0c7193742012-11-07 19:05:033433}
3434
[email protected]38cd8f7f2012-06-15 22:06:073435bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583436 content::BrowserContext* browser_context,
3437 const GURL& url,
[email protected]dda54822013-06-15 01:26:393438 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123439 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163440#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553441 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3442 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403443#else
[email protected]a658d452012-03-02 12:45:293444 return false;
[email protected]93f72062013-05-29 20:29:403445#endif
[email protected]e461da2f2012-02-16 19:06:403446}
3447
adrian.belgund54465ba2016-05-18 10:03:583448bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3449 content::BrowserContext* browser_context,
3450 const GURL& url) {
brettw4b461082016-11-19 18:55:163451#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583452 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3453 browser_context, url);
3454#else
3455 return false;
3456#endif
3457}
3458
adrian.belgun5b341c72016-06-22 22:24:083459std::unique_ptr<content::VpnServiceProxy>
3460ChromeContentBrowserClient::GetVpnServiceProxy(
3461 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173462#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083463 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3464 browser_context);
3465#else
3466 return nullptr;
3467#endif
3468}
3469
Brett Wilson804e83c2017-08-18 22:57:333470std::unique_ptr<ui::SelectFilePolicy>
3471ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3472 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433473}
3474
[email protected]7d9424702013-04-14 13:14:163475void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3476 std::vector<std::string>* additional_allowed_schemes) {
3477 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3478 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483479 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293480 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033481 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3482 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3483 additional_allowed_schemes);
3484 }
[email protected]7d9424702013-04-14 13:14:163485}
3486
falkenad185092016-06-16 06:10:023487void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3488 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043489 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023490}
3491
[email protected]c79859b82014-03-20 22:43:553492void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313493 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033494 for (size_t i = 0; i < extra_parts_.size(); ++i)
3495 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553496}
3497
nzolghadrd87a308d2016-12-07 15:45:563498::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3499 return g_browser_process->rappor_service();
3500}
3501
[email protected]f19bbf62013-07-09 01:22:323502void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313503 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533504 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003505 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3506 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313507#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313508 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313509 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313510 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093511 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093512 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3513 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473514 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093515 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3516 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053517 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3518 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473519 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323520 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313521 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003522 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313523#endif
[email protected]445b7db2013-08-02 04:58:273524
[email protected]a48ab7112014-08-01 16:48:033525 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3526 extra_parts_[i]->GetAdditionalFileSystemBackends(
3527 browser_context, storage_partition_path, additional_backends);
3528 }
[email protected]02250952013-04-24 23:52:533529}
3530
jcivellie6f550742017-01-06 19:29:123531#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183532void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173533 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383534 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203535 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123536#if defined(OS_ANDROID)
3537 base::MemoryMappedFile::Region region;
3538 int fd = ui::GetMainAndroidPackFd(&region);
3539 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003540
Samuel Huang31eadf082019-08-28 19:50:433541 // For Android: Native resources for DFMs should only be used by the browser
3542 // process. Their file descriptors and memory mapped file regions are not
3543 // passed to child processes.
3544
jcivellie6f550742017-01-06 19:29:123545 fd = ui::GetCommonResourcesPackFd(&region);
3546 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393547
jcivellie6f550742017-01-06 19:29:123548 fd = ui::GetLocalePackFd(&region);
3549 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383550
zpeng368afac82017-07-17 18:47:453551 // Optional secondary locale .pak file.
3552 fd = ui::GetSecondaryLocalePackFd(&region);
3553 if (fd != -1) {
3554 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3555 }
3556
[email protected]09560f7f2014-06-10 18:40:283557 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523558 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283559 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023560#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383561 int crash_signal_fd = GetCrashSignalFD(command_line);
3562 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133563 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383564 }
jcivellie6f550742017-01-06 19:29:123565}
3566#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303567
[email protected]4a65826d2011-08-25 16:04:013568#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033569base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Alex Gough9ab468a6c32019-12-10 19:10:223570 service_manager::SandboxType sandbox_type) {
wfh182da09c2015-06-24 19:23:033571 // TODO(wfh): Add support for more process types here. crbug.com/499523
3572 switch (sandbox_type) {
Alex Gough9ab468a6c32019-12-10 19:10:223573 case service_manager::SandboxType::kRenderer:
Jerry Lina0de7ce2018-06-22 15:18:363574 return base::string16(install_static::GetSandboxSidPrefix()) +
3575 L"129201922";
Alex Gough9ab468a6c32019-12-10 19:10:223576 case service_manager::SandboxType::kUtility:
wfh182da09c2015-06-24 19:23:033577 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223578 case service_manager::SandboxType::kGpu:
wfh182da09c2015-06-24 19:23:033579 return base::string16();
Alex Gough9ab468a6c32019-12-10 19:10:223580 case service_manager::SandboxType::kPpapi:
Jerry Lina0de7ce2018-06-22 15:18:363581 return base::string16(install_static::GetSandboxSidPrefix()) +
3582 L"129201925";
Alex Gough9ab468a6c32019-12-10 19:10:223583 case service_manager::SandboxType::kInvalid:
3584 case service_manager::SandboxType::kNoSandbox:
3585 case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges:
3586 case service_manager::SandboxType::kXrCompositing:
3587 case service_manager::SandboxType::kNetwork:
3588 case service_manager::SandboxType::kCdm:
3589 case service_manager::SandboxType::kPdfCompositor:
3590 case service_manager::SandboxType::kProfiling:
3591 case service_manager::SandboxType::kAudio:
3592 // Should never reach here.
3593 CHECK(0);
wfh182da09c2015-06-24 19:23:033594 return base::string16();
wfh182da09c2015-06-24 19:23:033595 }
wfh182da09c2015-06-24 19:23:033596}
3597
Will Harris956e0ca2019-08-23 20:47:393598bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3599 RendererSpawnFlags flags) {
Will Harris1b9b4152019-08-21 22:33:503600// Does not work under component build because all the component DLLs would need
3601// to be manually added and maintained. Does not work under ASAN build because
3602// ASAN has not yet fully initialized its instrumentation by the time the CIG
3603// intercepts run.
3604#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393605 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3606 return true;
Will Harrisc196ed942019-08-03 03:45:303607 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3608 return true;
3609
3610 // Only enable signing mitigation if launching from chrome.exe.
3611 base::FilePath exe_path;
3612 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3613 return true;
3614 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3615 return true;
3616
3617 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3618 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
Alex Gough59f406b2019-12-03 18:04:093619 sandbox::ResultCode result = policy->SetProcessMitigations(mitigations);
Will Harrisc196ed942019-08-03 03:45:303620 if (result != sandbox::SBOX_ALL_OK)
3621 return false;
3622
Aran Gilmanf010bdd2019-08-28 19:55:443623 // Allow loading Chrome's DLLs. The name of this depends on whether
3624 // is_multi_dll_chrome is defined or not. For multi-DLL Chrome,
3625 // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the
3626 // same DLL as the browser process.
Will Harrisc196ed942019-08-03 03:45:303627#if defined(CHROME_MULTIPLE_DLL_BROWSER)
3628 constexpr auto* child_dll_path = chrome::kChildDll;
3629#else
3630 constexpr auto* child_dll_path = chrome::kBrowserResourcesDll;
3631#endif
3632 for (const auto* dll : {child_dll_path, chrome::kElfDll}) {
3633 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3634 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3635 GetModulePath(dll).value().c_str());
3636 if (result != sandbox::SBOX_ALL_OK)
3637 return false;
3638 }
Will Harris1b9b4152019-08-21 22:33:503639#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303640
3641 return true;
[email protected]34f48682013-03-20 00:30:183642}
Will Harris956e0ca2019-08-23 20:47:393643
3644bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3645 PrefService* local_state = g_browser_process->local_state();
3646 if (local_state &&
3647 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3648 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3649 return false;
3650 return true;
3651}
3652
wfhc91e9672016-01-27 00:14:203653#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013654
Mario Sanchez Prada39dee4a2019-07-09 07:15:403655void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113656 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403657 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3658 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113659 render_frame_host);
3660}
3661
Armando Miraglia3a7be232019-11-08 00:33:323662#if defined(OS_WIN) || defined(OS_MACOSX) || \
3663 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
3664bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) {
3665 const base::Value* audio_sandbox_enabled_policy_value =
3666 policies.GetValue(policy::key::kAudioSandboxEnabled);
3667 if (audio_sandbox_enabled_policy_value) {
3668 bool force_enable_audio_sandbox;
3669 audio_sandbox_enabled_policy_value->GetAsBoolean(
3670 &force_enable_audio_sandbox);
3671 return force_enable_audio_sandbox;
3672 }
3673
3674 return base::FeatureList::IsEnabled(
3675 service_manager::features::kAudioServiceSandbox);
3676}
3677#endif
3678
Ken Rockotfa5d57112019-05-29 20:57:143679void ChromeContentBrowserClient::WillStartServiceManager() {
Guido Urdanetad06ae842019-10-10 20:04:123680#if defined(OS_WIN) || defined(OS_MACOSX) || \
3681 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Xi Han85079c22019-04-18 21:43:053682 if (startup_data_) {
3683 auto* chrome_feature_list_creator =
3684 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183685 // This has to run very early before ServiceManagerContext is created.
Guido Urdanetad06ae842019-10-10 20:04:123686 const policy::PolicyMap& policies =
Xi Han85079c22019-04-18 21:43:053687 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183688 ->GetPolicyService()
3689 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
Guido Urdanetad06ae842019-10-10 20:04:123690 std::string()));
3691
3692#if defined(OS_WIN)
3693 const base::Value* force_network_in_process_value =
3694 policies.GetValue(policy::key::kForceNetworkInProcess);
John Abd-El-Malek27b3ebd22019-02-12 18:59:183695 bool force_network_in_process = false;
3696 if (force_network_in_process_value)
3697 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3698 if (force_network_in_process)
3699 content::ForceInProcessNetworkService(true);
Guido Urdanetad06ae842019-10-10 20:04:123700#endif
3701 bool enable_audio_process =
3702 base::FeatureList::IsEnabled(features::kAudioServiceOutOfProcess);
Armando Miraglia3a7be232019-11-08 00:33:323703
3704 service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies));
3705 if (!service_manager::IsAudioSandboxEnabled() || !enable_audio_process) {
Guido Urdanetad06ae842019-10-10 20:04:123706 // Disabling the audio process or audio sandbox implies disabling APM in
3707 // the audio service for security reasons. Append a switch so that this
3708 // is communicated to the audio and renderer processes.
3709 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3710 switches::kForceDisableWebRtcApmInAudioService);
3711 }
John Abd-El-Malek27b3ebd22019-02-12 18:59:183712 }
3713#endif
xhwang5e630462015-10-30 03:18:483714}
3715
Ken Rockot8f39a272018-12-21 23:38:353716base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173717ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583718 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583719 return GetChromeContentBrowserOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583720 return base::nullopt;
benc70c0e32016-09-22 03:50:373721}
3722
peterbbcccc12015-02-11 22:23:333723void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:373724 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:333725 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:293726 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:083727 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:373728
3729 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:083730
zpengdb4a58e2017-01-10 17:40:323731#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:223732 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:293733 std::move(callback));
jam1c5a91492016-02-24 20:47:533734#else
cm.sanchi2522bc92017-12-04 08:04:133735 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
3736 params.url, params.transition);
3737 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:083738
3739 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:293740 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:333741#endif
mlamourieb40d552015-02-05 00:57:083742}
3743
zhaobinf3704f82017-01-12 07:19:363744content::ControllerPresentationServiceDelegate*
3745ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
3746 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:463747 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:093748 return media_router::PresentationServiceDelegateImpl::
3749 GetOrCreateForWebContents(web_contents);
3750 }
haibinlu9e605a92015-06-06 03:45:093751 return nullptr;
3752}
3753
zhaobinf3704f82017-01-12 07:19:363754content::ReceiverPresentationServiceDelegate*
3755ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
3756 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:363757 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
3758 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
3759 // created for offscreen presentations. The WebContents must belong to
3760 // an incognito profile.
3761 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
3762 FromWebContents(web_contents)) {
3763 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
3764 return impl;
3765 }
3766 }
zhaobinf3704f82017-01-12 07:19:363767 return nullptr;
3768}
3769
horo48d4d3e2015-02-27 03:04:003770void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
3771 const GURL& url) {
mathp46284f32015-03-11 13:06:413772 if (url.is_valid()) {
3773 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
3774 metric, url);
3775 }
horo48d4d3e2015-02-27 03:04:003776}
3777
Matt Falkenhagen8479b202017-07-14 04:35:313778std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
3779 // Don't change these returned strings. They are written (in hashed form) into
3780 // UMA logs. If you add more strings, you must update histograms.xml and get
3781 // histograms review. Only Google domains should be here for privacy purposes.
3782 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
3783 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193784 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:313785 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:193786 if (url.host() == "docs.google.com")
3787 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:313788 return std::string();
3789}
3790
avid6d88b912017-01-13 00:16:003791std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:473792ChromeContentBrowserClient::CreateThrottlesForNavigation(
3793 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:003794 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:273795
bmcquadeb4556552017-03-24 22:24:373796 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
3797 // that may delay or cancel navigations, so only NavigationThrottles that
3798 // don't delay or cancel navigations (e.g. throttles that are only observing
3799 // callbacks without affecting navigation behavior) should be added before
3800 // MetricsNavigationThrottle.
3801 if (handle->IsInMainFrame()) {
3802 throttles.push_back(
3803 page_load_metrics::MetricsNavigationThrottle::Create(handle));
3804 }
3805
brettw4b461082016-11-19 18:55:163806#if BUILDFLAG(ENABLE_PLUGINS)
Lukasz Anforowicz7724d092019-10-03 23:50:213807 MaybeAddThrottle(&throttles,
3808 FlashDownloadInterception::MaybeCreateThrottleFor(handle));
trizzofo8ddaeb72016-09-01 23:18:273809#endif
3810
yilkal240b4f22019-11-27 19:09:063811#if defined(OS_CHROMEOS)
3812 MaybeAddThrottle(
3813 &throttles,
3814 chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle));
3815#endif // defined(OS_CHROMEOS)
3816
mmenkedb2637ff2017-03-30 23:59:423817#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213818 MaybeAddThrottle(
3819 &throttles,
3820 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle));
mmenkedb2637ff2017-03-30 23:59:423821#endif
3822
clamy40c9e142015-09-29 11:18:473823#if defined(OS_ANDROID)
3824 // TODO(davidben): This is insufficient to integrate with prerender properly.
3825 // https://crbug.com/370595
3826 prerender::PrerenderContents* prerender_contents =
3827 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
3828 if (!prerender_contents && handle->IsInMainFrame()) {
3829 throttles.push_back(
3830 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:303831 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:473832 }
Min Qin0ab0e162017-11-14 21:57:193833 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Samuel Huang3a1ce1c32019-10-16 17:34:043834
3835#if BUILDFLAG(DFMIFY_DEV_UI)
3836 // If the DevUI DFM is already installed, then this is a no-op, except for the
3837 // side effect of ensuring that the DevUI DFM is loaded.
3838 MaybeAddThrottle(&throttles,
3839 dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle));
3840#endif // BUILDFLAG(DFMIFY_DEV_UI)
3841
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573842#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:473843 if (handle->IsInMainFrame()) {
3844 // Redirect some navigations to apps that have registered matching URL
3845 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:573846 auto url_to_app_throttle =
3847 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:473848 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:093849 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:473850 }
3851#endif
clamy49678312015-10-22 21:59:003852
3853#if defined(OS_CHROMEOS)
3854 // Check if we need to add merge session throttle. This throttle will postpone
3855 // loading of main frames.
3856 if (handle->IsInMainFrame()) {
3857 // Add interstitial page while merge session process (cookie reconstruction
3858 // from OAuth2 refresh token in ChromeOS login) is still in progress while
3859 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:023860 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
3861 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:003862 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
3863 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
3864 }
Maggie Caia2f03f52019-04-02 02:13:283865 }
3866#endif
djacobo21e56e02016-07-02 01:14:313867
Maggie Caia2f03f52019-04-02 02:13:283868#if !defined(OS_ANDROID)
3869 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:153870 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:283871#if defined(OS_CHROMEOS)
Maggie Cai00e2a21e2019-10-16 00:47:513872 base::FeatureList::IsEnabled(features::kAppServiceIntentHandling)
3873 ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle)
3874 : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
Avi Drissmana2969a552019-10-30 15:32:253875#elif defined(OS_MACOSX)
3876 apps::MacAppsNavigationThrottle::MaybeCreate(handle);
Maggie Caia2f03f52019-04-02 02:13:283877#else
3878 apps::AppsNavigationThrottle::MaybeCreate(handle);
3879#endif
Dominick Ng7c289942018-03-27 05:57:153880 if (url_to_apps_throttle)
3881 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:003882 }
3883#endif
3884
brettw00899e62016-11-12 02:10:173885#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:003886 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:093887 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:513888
Lukasz Anforowicz7724d092019-10-03 23:50:213889 MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get()
3890 ->GetUserScriptListener()
3891 ->CreateNavigationThrottle(handle));
naskob9164c42016-06-07 01:21:353892#endif
3893
bauerb8f9c37742017-03-30 15:04:123894#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Lukasz Anforowicz7724d092019-10-03 23:50:213895 MaybeAddThrottle(
3896 &throttles,
3897 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle));
bauerb8f9c37742017-03-30 15:04:123898#endif
3899
csharrisone985ebc2017-04-04 17:05:033900 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:103901 if (auto* subresource_filter_client =
3902 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
3903 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
3904 &throttles);
csharrisone985ebc2017-04-04 17:05:033905 }
3906
zhenw6edd49c2017-07-12 05:49:453907#if !defined(OS_ANDROID)
3908 // BackgroundTabNavigationThrottle is used by TabManager, which is only
3909 // enabled on non-Android platforms.
Lukasz Anforowicz7724d092019-10-03 23:50:213910 MaybeAddThrottle(&throttles,
3911 resource_coordinator::BackgroundTabNavigationThrottle::
3912 MaybeCreateThrottleFor(handle));
zhenw6edd49c2017-07-12 05:49:453913#endif
3914
Nico Weberbc5b06f2019-07-26 14:00:133915#if BUILDFLAG(FULL_SAFE_BROWSING)
Lukasz Anforowicz7724d092019-10-03 23:50:213916 MaybeAddThrottle(&throttles,
3917 safe_browsing::MaybeCreateNavigationThrottle(handle));
Jialiu Linbdbb81d2017-10-11 21:29:093918#endif
3919
Lukasz Anforowicz7724d092019-10-03 23:50:213920 MaybeAddThrottle(
3921 &throttles,
Emily Starkfa0ddb42019-10-24 15:49:583922 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
Joe DeBlasio6e8409a2019-02-20 23:08:273923
Lukasz Anforowicz7724d092019-10-03 23:50:213924 MaybeAddThrottle(&throttles,
3925 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
Amber Won6b5edc752017-08-17 19:23:543926
Lukasz Anforowicz7724d092019-10-03 23:50:213927 MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle));
Charles Harrison6dd11d282017-10-03 06:14:513928
Jeremy Romanec48d7a2018-03-01 17:35:093929 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:533930 handle, handle->GetWebContents()->GetBrowserContext()));
3931
Carlos IL5a9e7512019-06-13 22:35:283932 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
3933 handle,
3934 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
danakj20514c92019-12-13 17:30:193935 base::BindOnce(&SSLErrorHandler::HandleSSLError),
3936 base::BindOnce(&IsInHostedApp)));
Lucas Garron94b16052017-11-11 01:58:123937
Emily Starkd6896cd32019-08-21 04:55:543938 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
3939
Lukasz Anforowicz7724d092019-10-03 23:50:213940 MaybeAddThrottle(
3941 &throttles,
3942 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle));
Christopher Thompson4137cec2017-12-19 05:34:233943
Dmitry Gozman57b92ce2017-12-28 22:24:543944#if !defined(OS_ANDROID)
Lukasz Anforowicz7724d092019-10-03 23:50:213945 MaybeAddThrottle(&throttles,
3946 DevToolsWindow::MaybeCreateNavigationThrottle(handle));
Conley Owensaafcf122018-02-26 18:53:513947
Lukasz Anforowicz7724d092019-10-03 23:50:213948 MaybeAddThrottle(
3949 &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle));
jdoerrie4f9376f2018-12-12 18:26:203950
Lukasz Anforowicz7724d092019-10-03 23:50:213951 MaybeAddThrottle(
3952 &throttles,
3953 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle));
Dmitry Gozman57b92ce2017-12-28 22:24:543954#endif
3955
Carlos IL4ee307e2018-12-22 03:19:003956 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
3957 throttles.push_back(
3958 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
3959 handle));
3960 }
Robert Ogdenafd250b2018-07-25 22:21:033961
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:333962#if defined(OS_WIN) || defined(OS_MACOSX) || \
3963 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Lukasz Anforowicz7724d092019-10-03 23:50:213964 MaybeAddThrottle(&throttles,
3965 browser_switcher::BrowserSwitcherNavigationThrottle::
3966 MaybeCreateThrottleFor(handle));
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:133967#endif
3968
dchenge73d8520c2015-12-27 01:19:093969 return throttles;
clamy40c9e142015-09-29 11:18:473970}
3971
clamy1e5574e2016-09-29 16:48:443972std::unique_ptr<content::NavigationUIData>
3973ChromeContentBrowserClient::GetNavigationUIData(
3974 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:093975 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:443976}
3977
Xiaohan Wanga4e41842018-06-26 18:45:103978void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
3979 const std::string& key_system,
3980 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
3981 base::flat_set<media::VideoCodec>* video_codecs,
Yuchen Liub33bfc12019-11-08 20:16:123982 base::flat_set<media::EncryptionScheme>* encryption_schemes) {
Xiaohan Wanga4e41842018-06-26 18:45:103983#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:263984 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:103985 if (key_system == kWidevineKeySystem) {
3986 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
3987 encryption_schemes);
3988 }
3989#endif
3990}
3991
[email protected]487974a2014-06-13 16:49:013992content::DevToolsManagerDelegate*
3993ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:353994#if defined(OS_ANDROID)
3995 return new DevToolsManagerDelegateAndroid();
3996#else
[email protected]487974a2014-06-13 16:49:013997 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:353998#endif
[email protected]487974a2014-06-13 16:49:013999}
4000
Rayan Kanso411e84e2019-02-13 15:27:404001void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4002 content::BrowserContext* browser_context,
4003 int service,
4004 base::Time expiration_time) {
4005 Profile* profile = Profile::FromBrowserContext(browser_context);
4006 DCHECK(profile);
4007
4008 auto* pref_service = profile->GetPrefs();
4009 DCHECK(pref_service);
4010
4011 DictionaryPrefUpdate pref_update(
4012 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4013 base::DictionaryValue* exp_dict = pref_update.Get();
4014
4015 // Convert |expiration_time| to minutes since that is the most granular
4016 // option that returns an int. base::Value does not accept int64.
4017 int expiration_time_minutes =
4018 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4019 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4020}
4021
4022base::flat_map<int, base::Time>
4023ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4024 content::BrowserContext* browser_context) {
4025 Profile* profile = Profile::FromBrowserContext(browser_context);
4026 DCHECK(profile);
4027
4028 auto* pref_service = profile->GetPrefs();
4029 DCHECK(pref_service);
4030
4031 auto* expiration_dict = pref_service->GetDictionary(
4032 prefs::kDevToolsBackgroundServicesExpirationDict);
4033 DCHECK(expiration_dict);
4034
4035 base::flat_map<int, base::Time> expiration_times;
4036 for (const auto& it : *expiration_dict) {
4037 // key.
4038 int service = 0;
4039 bool did_convert = base::StringToInt(it.first, &service);
4040 DCHECK(did_convert);
4041
4042 // value.
4043 DCHECK(it.second->is_int());
4044 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4045 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4046
4047 expiration_times[service] = expiration_time;
4048 }
4049
4050 return expiration_times;
4051}
4052
oysteinec563c582015-02-13 19:19:524053content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524054 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524055}
4056
[email protected]a6868c22013-10-09 02:50:294057bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4058 content::BrowserContext* browser_context,
4059 const GURL& url) {
brettw4b461082016-11-19 18:55:164060#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554061 return ChromeContentBrowserClientPluginsPart::
4062 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4063 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294064#else
4065 return false;
4066#endif
4067}
4068
[email protected]aec5ed52014-06-20 07:51:424069bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4070 content::BrowserContext* browser_context,
4071 const GURL& url) {
brettw4b461082016-11-19 18:55:164072#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554073 return ChromeContentBrowserClientPluginsPart::
4074 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4075 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064076#else
4077 return false;
4078#endif
4079}
4080
mlamourif8c23a2002015-01-27 13:10:104081void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014082 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434083 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524084 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104085
4086 WebContents* web_contents =
4087 WebContents::FromRenderFrameHost(render_frame_host);
4088 DCHECK(web_contents);
4089
mlamourif8c23a2002015-01-27 13:10:104090 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374091 prerender::PrerenderManagerFactory::GetForBrowserContext(
4092 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104093 if (prerender_manager &&
4094 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
Collin Baker98457b52019-11-06 21:34:294095 *visibility_state = content::PageVisibilityState::kHiddenButPainting;
mlamourif8c23a2002015-01-27 13:10:104096 }
4097}
4098
Sam McNallyfaf9a402017-10-31 03:06:314099void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094100 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4101 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014102 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Ben Goodger6a695c012017-06-20 20:21:204103}
4104
Robert Sesek466e43e2019-08-19 22:02:024105void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4106 base::FilePath user_data_dir;
4107 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4108 DCHECK(!user_data_dir.empty());
4109 network_contexts_parent_directory_.push_back(user_data_dir);
4110
4111 base::FilePath cache_dir;
4112 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4113 DCHECK(!cache_dir.empty());
4114 // On some platforms, the cache is a child of the user_data_dir so only
4115 // return the one path.
4116 if (!user_data_dir.IsParent(cache_dir))
4117 network_contexts_parent_directory_.push_back(cache_dir);
4118
4119 // If the cache location has been overridden by a switch or preference,
4120 // include that as well.
4121 if (auto* local_state = g_browser_process->local_state()) {
4122 base::FilePath pref_cache_dir =
4123 local_state->GetFilePath(prefs::kDiskCacheDir);
4124 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4125 network_contexts_parent_directory_.push_back(pref_cache_dir);
4126 }
4127}
4128
[email protected]30335fdf02014-02-26 19:51:274129void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174130 base::CommandLine* to_command_line,
4131 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544132 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274133#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544134 const version_info::Channel kMaxDisableEncryptionChannel =
4135 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274136#else
sdefresne6e883e42015-07-30 08:05:544137 const version_info::Channel kMaxDisableEncryptionChannel =
4138 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274139#endif
4140 if (channel <= kMaxDisableEncryptionChannel) {
4141 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444142 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274143 };
Avi Drissmand251e912018-12-26 15:46:374144 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4145 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274146 }
4147}
bashi933629552016-10-13 23:32:404148
miu54dca6c2016-11-17 10:59:384149#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4150void ChromeContentBrowserClient::CreateMediaRemoter(
4151 content::RenderFrameHost* render_frame_host,
Gyuyoung Kima4f9f942019-10-26 02:55:504152 mojo::PendingRemote<media::mojom::RemotingSource> source,
4153 mojo::PendingReceiver<media::mojom::Remoter> receiver) {
miu54dca6c2016-11-17 10:59:384154 CastRemotingConnector::CreateMediaRemoter(
Gyuyoung Kima4f9f942019-10-26 02:55:504155 render_frame_host, std::move(source), std::move(receiver));
miu54dca6c2016-11-17 10:59:384156}
4157#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464158
Michael Giuffrida6802ffe2017-09-29 03:40:254159base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4160 const base::CommandLine& command_line) {
4161 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164162}
4163
John Abd-El-Malek8efa11f2019-01-06 00:51:534164namespace {
4165// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024166class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534167 public:
4168 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174169 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534170 : protocol_handler_registry_(protocol_handler_registry) {}
4171 ~ProtocolHandlerThrottle() override = default;
4172
4173 void WillStartRequest(network::ResourceRequest* request,
4174 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294175 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534176 }
4177
4178 void WillRedirectRequest(net::RedirectInfo* redirect_info,
Lucas Furukawa Gadani011886592019-10-23 17:12:244179 const network::mojom::URLResponseHead& response_head,
John Abd-El-Malek8efa11f2019-01-06 00:51:534180 bool* defer,
4181 std::vector<std::string>* to_be_removed_headers,
4182 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294183 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534184 }
4185
4186 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294187 void TranslateUrl(GURL* url) {
4188 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4189 return;
4190 GURL translated_url = protocol_handler_registry_->Translate(*url);
4191 if (!translated_url.is_empty())
4192 *url = translated_url;
4193 }
4194
Clark DuValla411bda2019-08-02 03:09:174195 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534196};
4197} // namespace
4198
Minggang Wangf6840ecf2019-07-29 05:15:024199std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194200ChromeContentBrowserClient::CreateURLLoaderThrottles(
4201 const network::ResourceRequest& request,
4202 content::BrowserContext* browser_context,
4203 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4204 content::NavigationUIData* navigation_ui_data,
4205 int frame_tree_node_id) {
4206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4207
Minggang Wangf6840ecf2019-07-29 05:15:024208 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194209
4210 Profile* profile = Profile::FromBrowserContext(browser_context);
4211
4212 ChromeNavigationUIData* chrome_navigation_ui_data =
4213 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4214
Clark DuVall68eb997f2019-06-28 05:42:284215 auto* drp_settings =
4216 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4217 browser_context);
4218 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4219 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4220 drp_settings) {
4221 if (!data_reduction_proxy_throttle_manager_) {
Wojciech Dzierżanowskie7c8e3f2019-09-27 20:50:314222 data_reduction_proxy_throttle_manager_ = std::make_unique<
4223 data_reduction_proxy::DataReductionProxyThrottleManager>(
4224 drp_settings->data_reduction_proxy_service(),
4225 data_reduction_proxy::DataReductionProxyThrottleManager::CreateConfig(
4226 drp_settings->data_reduction_proxy_service()
4227 ->config()
4228 ->GetProxiesForHttp()));
Clark DuVall68eb997f2019-06-28 05:42:284229 }
4230 net::HttpRequestHeaders headers;
4231 data_reduction_proxy::DataReductionProxyRequestOptions::
4232 AddPageIDRequestHeader(
4233 &headers,
4234 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4235 result.push_back(std::make_unique<
4236 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4237 headers, data_reduction_proxy_throttle_manager_.get()));
4238 }
4239
Nico Weberbc5b06f2019-07-26 14:00:134240#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564241 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4242 request.url, *profile->GetPrefs());
4243 if (!matches_enterprise_whitelist) {
4244 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4245 base::BindOnce(
4246 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4247 base::Unretained(this)),
4248 wc_getter, frame_tree_node_id, profile->GetResourceContext()));
4249 }
Nico Weberbc5b06f2019-07-26 14:00:134250#endif
Clark DuVall5497288d2019-07-17 00:17:564251
Clark DuVallfffa41e2019-06-25 20:27:194252 if (chrome_navigation_ui_data &&
4253 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4254 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4255 chrome_navigation_ui_data->prerender_mode(),
4256 chrome_navigation_ui_data->prerender_histogram_prefix(),
4257 base::BindOnce(GetPrerenderCanceller, wc_getter),
Sami Kyostila5e1306d2019-08-14 11:01:294258 base::CreateSingleThreadTaskRunner({BrowserThread::UI})));
Clark DuVallfffa41e2019-06-25 20:27:194259 }
4260
David Rogere8e83f3c2019-09-12 10:56:234261 signin::IdentityManager* identity_manager =
4262 IdentityManagerFactory::GetForProfile(profile);
4263 bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount();
Clark DuVallfffa41e2019-06-25 20:27:194264
4265 chrome::mojom::DynamicParams dynamic_params = {
4266 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4267 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4268 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4269 variations::VariationsHttpHeaderProvider::GetInstance()
4270 ->GetClientDataHeader(is_signed_in)};
4271 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
David Rogere8e83f3c2019-09-12 10:56:234272 profile->IsOffTheRecord(), std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194273
Clark DuValla411bda2019-08-02 03:09:174274 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4275 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214276
Clark DuVall39c2cfc2019-06-25 21:49:284277#if BUILDFLAG(ENABLE_PLUGINS)
4278 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464279 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284280#endif
4281
Robbie McElrath127ad2b2019-07-22 22:38:114282 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404283 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
Robbie McElrath127ad2b2019-07-22 22:38:114284 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4285 std::move(delegate), navigation_ui_data, wc_getter);
4286 if (signin_throttle)
4287 result.push_back(std::move(signin_throttle));
4288
Clark DuVallfffa41e2019-06-25 20:27:194289 return result;
4290}
4291
Ken Rockot6414c4d92017-11-08 19:58:324292void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464293 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324294 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414295#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464296 content::WebContents* web_contents =
4297 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414298#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324299 factories->emplace(
4300 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574301 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464302 web_contents->GetBrowserContext(),
4303 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414304#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4305#if defined(OS_CHROMEOS)
4306 Profile* profile =
4307 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304308 factories->emplace(content::kExternalFileScheme,
4309 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4310 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414311#endif // defined(OS_CHROMEOS)
4312#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324313}
4314
Ting Shao2dc60582019-07-15 04:43:364315void ChromeContentBrowserClient::
Hiroki Nakagawa1efa31d2019-10-01 22:36:344316 RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
4317 content::BrowserContext* browser_context,
4318 NonNetworkURLLoaderFactoryMap* factories) {
4319#if BUILDFLAG(ENABLE_EXTENSIONS)
4320 DCHECK(browser_context);
4321 DCHECK(factories);
4322 factories->emplace(
4323 extensions::kExtensionScheme,
4324 extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(
4325 browser_context));
4326#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4327}
4328
4329void ChromeContentBrowserClient::
Ting Shao2dc60582019-07-15 04:43:364330 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4331 content::BrowserContext* browser_context,
4332 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114333#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364334 DCHECK(browser_context);
4335 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364336 factories->emplace(
4337 extensions::kExtensionScheme,
4338 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4339 browser_context));
4340#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364341}
4342
Jay Civelli2578ebe2018-06-05 18:44:314343namespace {
4344
4345// The FileURLLoaderFactory provided to the extension background pages.
4346// Checks with the ChildProcessSecurityPolicy to validate the file access.
4347class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4348 public:
4349 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4350
4351 private:
4352 // network::mojom::URLLoaderFactory:
Julie Jeongeun Kime003de52019-10-29 05:14:274353 void CreateLoaderAndStart(
4354 mojo::PendingReceiver<network::mojom::URLLoader> loader,
4355 int32_t routing_id,
4356 int32_t request_id,
4357 uint32_t options,
4358 const network::ResourceRequest& request,
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304359 mojo::PendingRemote<network::mojom::URLLoaderClient> client,
Julie Jeongeun Kime003de52019-10-29 05:14:274360 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
4361 override {
Jay Civelli2578ebe2018-06-05 18:44:314362 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4363 child_id_, request.url)) {
Julie Jeongeun Kim6dd4c7b2019-11-18 05:56:304364 mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
4365 ->OnComplete(
4366 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
Jay Civelli2578ebe2018-06-05 18:44:314367 return;
4368 }
4369 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454370 /*observer=*/nullptr,
4371 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314372 }
4373
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524374 void Clone(
4375 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
4376 receivers_.Add(this, std::move(loader));
Jay Civelli2578ebe2018-06-05 18:44:314377 }
4378
4379 int child_id_;
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:524380 mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
Jay Civelli2578ebe2018-06-05 18:44:314381 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4382};
4383
4384} // namespace
4385
Ken Rockot6414c4d92017-11-08 19:58:324386void ChromeContentBrowserClient::
4387 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464388 int render_process_id,
4389 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324390 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414391#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4392 content::RenderFrameHost* frame_host =
4393 RenderFrameHost::FromID(render_process_id, render_frame_id);
4394 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4395#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4396
4397#if defined(OS_CHROMEOS)
4398 if (web_contents) {
4399 Profile* profile =
4400 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304401 factories->emplace(content::kExternalFileScheme,
4402 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4403 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414404 }
4405#endif // defined(OS_CHROMEOS)
4406
Ken Rockot6414c4d92017-11-08 19:58:324407#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464408 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4409 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324410 if (factory)
4411 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234412
4413 // This logic should match
4414 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314415 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234416 return;
Jay Civellic9bbf72d2018-03-24 01:58:314417
4418 Profile* profile =
4419 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4420 InstantService* instant_service =
4421 InstantServiceFactory::GetForProfile(profile);
4422 // The test below matches what's done by ShouldServiceRequestIOThread in
4423 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464424 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314425 factories->emplace(
4426 chrome::kChromeSearchScheme,
4427 content::CreateWebUIURLLoader(
4428 frame_host, chrome::kChromeSearchScheme,
4429 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234430 }
Jay Civellic9bbf72d2018-03-24 01:58:314431
Chris Mumfordbae8a742018-03-01 23:02:234432 extensions::ChromeExtensionWebContentsObserver* web_observer =
4433 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4434 web_contents);
4435
Karan Bhatia91928572018-03-06 01:18:074436 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4437 // to the |web_contents|.
4438 if (!web_observer)
4439 return;
4440
Chris Mumfordbae8a742018-03-01 23:02:234441 const Extension* extension =
4442 web_observer->GetExtensionFromFrame(frame_host, false);
4443 if (!extension)
4444 return;
4445
Sam McNally7414eeb72018-09-03 04:05:304446 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234447 // Support for chrome:// scheme if appropriate.
4448 if ((extension->is_extension() || extension->is_platform_app()) &&
4449 Manifest::IsComponentLocation(extension->location())) {
4450 // Components of chrome that are implemented as extensions or platform apps
4451 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304452 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4453 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4454 }
4455 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4456 (extension->is_platform_app() &&
4457 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234458 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024459 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4460 // URLs. Hosted apps are not allowed because they are served via web servers
4461 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304462 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4463 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024464 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304465 }
4466 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234467 factories->emplace(
4468 content::kChromeUIScheme,
4469 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4470 std::move(allowed_webui_hosts)));
4471 }
Jay Civelli2578ebe2018-06-05 18:44:314472
4473 // Extension with a background page get file access that gets approval from
4474 // ChildProcessSecurityPolicy.
4475 extensions::ExtensionHost* host =
4476 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4477 ->GetBackgroundHostForExtension(extension->id());
4478 if (host) {
4479 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4480 render_process_id));
4481 }
Chris Mumfordbae8a742018-03-01 23:02:234482#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324483}
4484
Ken Rockota0dfaca12018-02-15 07:26:254485bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214486 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254487 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384488 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444489 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264490 const url::Origin& request_initiator,
Karan Bhatia303d0ac02019-12-05 03:01:004491 base::Optional<int64_t> navigation_id,
Dominic Farolino1be897a2019-07-20 08:11:424492 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184493 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4494 header_client,
Yutaka Hirano499d13212019-12-04 11:03:334495 bool* bypass_redirect_checks,
4496 network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
Reilly Grant24bf8332018-08-27 21:55:014497 bool use_proxy = false;
4498
Ken Rockota0dfaca12018-02-15 07:26:254499#if BUILDFLAG(ENABLE_EXTENSIONS)
4500 auto* web_request_api =
4501 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214502 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254503
4504 // NOTE: Some unit test environments do not initialize
4505 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014506 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124507 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384508 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia303d0ac02019-12-05 03:01:004509 browser_context, frame, render_process_id, type,
4510 std::move(navigation_id), factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124511 if (bypass_redirect_checks)
4512 *bypass_redirect_checks = use_proxy_for_web_request;
4513 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014514 }
Ken Rockota0dfaca12018-02-15 07:26:254515#endif
Reilly Grant24bf8332018-08-27 21:55:014516
Reilly Grantcc22e602018-09-07 15:25:204517 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444518 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4519 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014520
4521 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254522}
4523
Jian Lide7b43792018-06-01 23:22:134524std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4525ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4526 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144527 int frame_tree_node_id,
4528 const scoped_refptr<network::SharedURLLoaderFactory>&
4529 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134530 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4531 interceptors;
4532#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234533 interceptors.push_back(
4534 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4535 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134536#endif
Ryan Sturmaf523742019-01-16 00:15:454537
Robert Ogden3d5d5b42019-04-22 05:13:114538 ChromeNavigationUIData* chrome_navigation_ui_data =
4539 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4540
Ryan Sturm27d93f412019-02-15 21:30:144541 // TODO(ryansturm): Once this is on the UI thread, stop passing
4542 // |network_loader_factory| and have interceptors create one themselves.
4543 // https://crbug.com/931786
Doug Arnett27154792019-10-15 21:00:594544 if (previews::params::IsLitePageServerPreviewsEnabled()) {
Ryan Sturmaf523742019-01-16 00:15:454545 interceptors.push_back(
Robert Ogden0f4d88682019-09-24 22:27:524546 std::make_unique<
4547 previews::PreviewsLitePageRedirectURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114548 network_loader_factory,
4549 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4550 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454551 }
4552
Jian Lide7b43792018-06-01 23:22:134553 return interceptors;
4554}
4555
Yutaka Hirano8e0b4d432019-07-04 07:12:384556bool ChromeContentBrowserClient::WillInterceptWebSocket(
4557 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334558#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384559 if (!frame) {
4560 return false;
4561 }
4562 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334563 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4564 frame->GetProcess()->GetBrowserContext());
4565
4566 // NOTE: Some unit test environments do not initialize
4567 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4568 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384569 return false;
Yutaka Hirano36c94952018-05-30 21:33:334570
Yutaka Hirano8e0b4d432019-07-04 07:12:384571 return web_request_api->MayHaveProxies();
4572#else
4573 return false;
4574#endif
4575}
4576
4577void ChromeContentBrowserClient::CreateWebSocket(
4578 content::RenderFrameHost* frame,
4579 WebSocketFactory factory,
4580 const GURL& url,
4581 const GURL& site_for_cookies,
4582 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404583 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4584 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384585#if BUILDFLAG(ENABLE_EXTENSIONS)
4586 if (!frame) {
4587 return;
4588 }
4589 auto* web_request_api =
4590 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4591 frame->GetProcess()->GetBrowserContext());
4592
4593 DCHECK(web_request_api);
4594 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
4595 site_for_cookies, user_agent,
4596 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334597#endif
4598}
4599
Maks Orlovich710d5e32019-07-09 20:16:454600bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464601 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454602 content::BrowserContext* browser_context,
4603 const url::Origin& origin,
Maks Orlovich11001fa2019-10-01 20:41:404604 const GURL& site_for_cookies,
4605 const url::Origin& top_frame_origin,
Maks Orlovich710d5e32019-07-09 20:16:454606 bool is_service_worker,
4607 int process_id,
4608 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034609 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454610 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4611#if BUILDFLAG(ENABLE_EXTENSIONS)
4612 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464613 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454614 extensions::ChromeExtensionCookies::Get(browser_context)
Maks Orlovich11001fa2019-10-01 20:41:404615 ->CreateRestrictedCookieManager(origin, site_for_cookies,
4616 top_frame_origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454617 return true;
4618 }
4619#endif
4620 return false;
4621}
4622
Matt Menkeae4fdb12018-06-02 06:32:544623void ChromeContentBrowserClient::OnNetworkServiceCreated(
4624 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534625 PrefService* local_state;
4626 if (g_browser_process) {
4627 DCHECK(g_browser_process->local_state());
4628 local_state = g_browser_process->local_state();
4629 } else {
Xi Han85079c22019-04-18 21:43:054630 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4631 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534632 }
4633
4634 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4635 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4636
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494637 // Create SystemNetworkContextManager if it has not been created yet. We need
4638 // to set up global NetworkService state before anything else uses it and this
4639 // is the first opportunity to initialize SystemNetworkContextManager with the
4640 // NetworkService.
4641 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534642 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074643
Min Qin8caab1d2018-10-03 17:28:134644 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544645 network_service);
4646}
4647
Julie Jeongeun Kim5984e992019-09-11 11:00:464648mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254649ChromeContentBrowserClient::CreateNetworkContext(
4650 content::BrowserContext* context,
4651 bool in_memory,
4652 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504653 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454654 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254655}
4656
Robert Sesek34f68f312019-01-14 20:25:114657std::vector<base::FilePath>
4658ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024659 DCHECK(!network_contexts_parent_directory_.empty());
4660 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114661}
4662
Min Qin75ed6df2017-12-01 20:39:154663bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:134664 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:154665#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
4666 // It is OK to load the saved offline copy, in MHTML format.
4667 ChromeNavigationUIData* chrome_navigation_ui_data =
4668 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4669 if (!chrome_navigation_ui_data)
4670 return false;
4671 offline_pages::OfflinePageNavigationUIData* offline_page_data =
4672 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
4673 return offline_page_data && offline_page_data->is_offline_page();
4674#else
4675 return false;
4676#endif
4677}
4678
Min Qin30a78a12017-12-06 01:29:134679bool ChromeContentBrowserClient::ShouldForceDownloadResource(
4680 const GURL& url,
4681 const std::string& mime_type) {
4682#if BUILDFLAG(ENABLE_EXTENSIONS)
4683 // Special-case user scripts to get downloaded instead of viewed.
4684 return extensions::UserScript::IsURLUserScript(url, mime_type);
4685#else
4686 return false;
4687#endif
4688}
4689
Donna Wu838ac362018-08-10 10:36:334690void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:344691 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:044692 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grantc31b8192017-12-15 19:54:344693 if (!base::FeatureList::IsEnabled(features::kWebUsb))
4694 return;
4695
Reilly Grantc31b8192017-12-15 19:54:344696 WebContents* web_contents =
4697 WebContents::FromRenderFrameHost(render_frame_host);
4698 if (!web_contents) {
4699 NOTREACHED();
4700 return;
4701 }
4702
4703 UsbTabHelper* tab_helper =
4704 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Miyoung Shin62622152019-08-27 05:13:044705 tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:344706}
4707
Reilly Grant0d282322019-01-29 02:42:584708#if !defined(OS_ANDROID)
4709content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
4710 if (!serial_delegate_)
4711 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
4712 return serial_delegate_.get();
4713}
Matt Reynolds93616f9b2019-06-07 01:28:524714
4715content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
4716 if (!hid_delegate_)
4717 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
4718 return hid_delegate_.get();
4719}
Reilly Grant0d282322019-01-29 02:42:584720
Balazs Engedya7ff70982018-06-04 18:14:474721std::unique_ptr<content::AuthenticatorRequestClientDelegate>
4722ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:224723 content::RenderFrameHost* render_frame_host,
4724 const std::string& relying_party_id) {
4725 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
4726 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:474727}
Nina Satragno8c832df2019-07-29 15:59:394728#endif
Balazs Engedya7ff70982018-06-04 18:14:474729
Jun Cai9409ded2018-01-30 00:19:464730std::unique_ptr<net::ClientCertStore>
4731ChromeContentBrowserClient::CreateClientCertStore(
David Benjaminf6a34092019-11-07 19:55:104732 content::BrowserContext* browser_context) {
4733 return ProfileNetworkContextServiceFactory::GetForContext(browser_context)
Jun Cai9409ded2018-01-30 00:19:464734 ->CreateClientCertStore();
4735}
4736
David Benjamineced01fc2019-02-27 18:29:024737std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:394738ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:584739 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:024740 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:034741 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:244742 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:394743 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:034744 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:394745 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:564746 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:034747 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:024748 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:204749 std::move(response_headers), LoginHandler::PRE_COMMIT,
4750 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:394751}
4752
John Abd-El-Maleka67add82018-03-09 18:22:014753bool ChromeContentBrowserClient::HandleExternalProtocol(
4754 const GURL& url,
danakjf4b9e942019-11-29 15:43:044755 content::WebContents::OnceGetter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:014756 int child_id,
4757 content::NavigationUIData* navigation_data,
4758 bool is_main_frame,
4759 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:454760 bool has_user_gesture,
Emily Stark13b66bdf2019-10-04 17:11:454761 const base::Optional<url::Origin>& initiating_origin,
Julie Jeongeun Kimfb6f5302019-10-17 17:24:104762 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:014763#if BUILDFLAG(ENABLE_EXTENSIONS)
4764 // External protocols are disabled for guests. An exception is made for the
4765 // "mailto" protocol, so that pages that utilize it work properly in a
4766 // WebView.
4767 ChromeNavigationUIData* chrome_data =
4768 static_cast<ChromeNavigationUIData*>(navigation_data);
4769 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
4770 (chrome_data &&
4771 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
4772 !url.SchemeIs(url::kMailToScheme)) {
4773 return false;
4774 }
4775#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4776
4777#if defined(OS_ANDROID)
4778 // Main frame external protocols are handled by
4779 // InterceptNavigationResourceThrottle.
4780 if (is_main_frame)
4781 return false;
4782#endif // defined(ANDROID)
4783
Emily Stark13b66bdf2019-10-04 17:11:454784 base::PostTask(
4785 FROM_HERE, {BrowserThread::UI},
danakjf4b9e942019-11-29 15:43:044786 base::BindOnce(&LaunchURL, url, std::move(web_contents_getter),
4787 page_transition, has_user_gesture, initiating_origin));
John Abd-El-Maleka67add82018-03-09 18:22:014788 return true;
4789}
4790
Jennifer Apacible4f854a82018-04-06 22:22:114791std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:284792ChromeContentBrowserClient::CreateWindowForPictureInPicture(
4793 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:114794 // Note: content::OverlayWindow::Create() is defined by platform-specific
4795 // implementation in chrome/browser/ui/views. This layering hack, which goes
4796 // through //content and ContentBrowserClient, allows us to work around the
4797 // dependency constraints that disallow directly calling
4798 // chrome/browser/ui/views code either from here or from other code in
4799 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:284800 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:114801}
4802
Kunihiko Sakamoto19aa7082019-02-25 03:14:434803void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:564804 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:114805 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:564806 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:434807 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
4808 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:564809}
4810
dbeam25472e0c2017-06-23 19:02:314811// Static; handles rewriting Web UI URLs.
4812bool ChromeContentBrowserClient::HandleWebUI(
4813 GURL* url,
4814 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:394815 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:314816 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:394817 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:314818 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
4819 chrome::kChromeUIHelpHost);
4820 return true; // Return true to update the displayed URL.
4821 }
4822
Hector Carmona566a20b2019-09-13 22:44:424823#if defined(OS_WIN)
4824 // TODO(crbug.com/1003960): Remove when issue is resolved.
4825 if (url->SchemeIs(content::kChromeUIScheme) &&
4826 url->host() == chrome::kChromeUIWelcomeWin10Host) {
4827 url::Replacements<char> replacements;
4828 replacements.SetHost(
4829 chrome::kChromeUIWelcomeHost,
4830 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
4831 *url = url->ReplaceComponents(replacements);
4832 return true;
4833 }
4834#endif // defined(OS_WIN)
4835
dbeam25472e0c2017-06-23 19:02:314836 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
4837 browser_context, *url)) {
4838 return false;
4839 }
4840
4841#if defined(OS_CHROMEOS)
4842 // Special case : in ChromeOS in Guest mode bookmarks and history are
4843 // disabled for security reasons. New tab page explains the reasons, so
4844 // we redirect user to new tab page.
4845 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
4846 if (url->SchemeIs(content::kChromeUIScheme) &&
4847 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
4848 url->DomainIs(chrome::kChromeUIHistoryHost))) {
4849 // Rewrite with new tab URL
4850 *url = GURL(chrome::kChromeUINewTabURL);
4851 }
4852 }
4853#endif
4854
4855 return true;
4856}
4857
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064858bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
4859 content::BrowserContext* browser_context,
4860 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:324861 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:064862#if defined(OS_ANDROID)
4863 return false;
4864#else
4865 payments::PaymentRequestDisplayManagerFactory::GetInstance()
4866 ->GetForBrowserContext(browser_context)
4867 ->ShowPaymentHandlerWindow(url, std::move(callback));
4868 return true;
4869#endif
4870}
4871
Dan Beam141c48932019-08-22 02:29:394872// static
dbeam25472e0c2017-06-23 19:02:314873bool ChromeContentBrowserClient::HandleWebUIReverse(
4874 GURL* url,
4875 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:424876#if defined(OS_WIN)
4877 // TODO(crbug.com/1003960): Remove when issue is resolved.
4878 // No need to actually reverse-rewrite the URL, but return true to update the
4879 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
4880 if (url->SchemeIs(content::kChromeUIScheme) &&
4881 url->host() == chrome::kChromeUIWelcomeHost) {
4882 return true;
4883 }
4884#endif // defined(OS_WIN)
4885
dbeam25472e0c2017-06-23 19:02:314886 // No need to actually reverse-rewrite the URL, but return true to update the
4887 // displayed URL when rewriting chrome://help to chrome://settings/help.
4888 return url->SchemeIs(content::kChromeUIScheme) &&
4889 url->host() == chrome::kChromeUISettingsHost;
4890}
4891
Alison Maher28a73e22019-10-18 19:26:354892ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
Dan Beamf0a7e112019-06-07 18:40:584893 return ui::NativeTheme::GetInstanceForWeb();
4894}
4895
scottmgde42fb92017-02-10 17:56:034896// static
michaeln10e5fc352017-02-07 02:07:584897void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
4898 const storage::QuotaSettings* settings) {
4899 g_default_quota_settings = settings;
4900}
Yuzhu Shen44094e22017-07-18 22:52:354901
Clark DuVall5497288d2019-07-17 00:17:564902scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:504903ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
4904 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:354905 DCHECK_CURRENTLY_ON(BrowserThread::IO);
4906
Yuzhu Shencb3011f62018-02-08 02:51:504907 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
4908 if (!io_data->safe_browsing_enabled()->GetValue())
4909 return nullptr;
4910
Yuzhu Shen44094e22017-07-18 22:52:354911 // |safe_browsing_service_| may be unavailable in tests.
4912 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
4913 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:434914 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:354915 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:434916 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:354917 }
4918
Clark DuVall5497288d2019-07-17 00:17:564919 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:354920}
Daniel Vogelheim6008f572018-09-24 14:35:144921
4922base::Optional<std::string>
4923ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:264924 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:184925 content::NavigationHandle* handle) {
4926 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
4927 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:144928}
Kunihiko Sakamoto73b803d2018-10-05 09:09:524929
Takashi Toyoshima5af383aa2019-07-22 15:24:224930bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:524931 // We require --user-data-dir flag too so that no dangerous changes are made
4932 // in the user's regular profile.
4933 return base::CommandLine::ForCurrentProcess()->HasSwitch(
4934 switches::kUserDataDir);
4935}
rajendrantfeea8592018-10-19 18:26:064936
4937void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
4938 int32_t network_traffic_annotation_id_hash,
4939 int64_t recv_bytes,
4940 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:034941 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
4942 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
4943 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
4944 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:064945 }
4946}
Ryan Sturmaa05092f2018-10-21 03:56:544947
4948content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
4949 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:394950 content::NavigationHandle* navigation_handle,
4951 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:134952 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
4953 initial_state, navigation_handle, current_navigation_url);
4954
4955 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
4956}
4957
4958content::PreviewsState
4959ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
4960 content::PreviewsState initial_state,
4961 content::NavigationHandle* navigation_handle,
4962 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:544963 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:294964 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:214965
Ryan Sturmaa05092f2018-10-21 03:56:544966 // If this is not a main frame, return the initial state. If there are no
4967 // previews in the state, return the state as is.
4968 if (!navigation_handle->IsInMainFrame() ||
4969 navigation_handle->IsSameDocument()) {
4970 return initial_state;
4971 }
4972
Robert Ogdena994eb42019-02-14 19:15:084973 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:394974 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:084975
Doug Arnettb3b99bc2019-08-09 16:55:564976 // Check if initial state specifies no previews should be considered.
4977 if (initial_state == content::PREVIEWS_OFF)
4978 return initial_state;
4979
Robert Ogdena994eb42019-02-14 19:15:084980 // Do not allow previews on POST navigations since the primary opt-out
4981 // mechanism is to reload the page. Because POST navigations are not
4982 // idempotent, we do not want to show a preview on a POST navigation where
4983 // opting out would cause another navigation, i.e.: a reload.
4984 if (navigation_handle->IsPost())
4985 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:394986
4987 content::WebContents* web_contents = navigation_handle->GetWebContents();
4988 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
4989
Ryan Sturmda2a0e02018-10-25 01:52:214990 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:544991
4992 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
4993 Profile::FromBrowserContext(browser_context));
4994 auto* data_reduction_proxy_settings =
4995 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4996 browser_context);
4997 // If the profile does not support previews or Data Saver, do not turn on
4998 // Previews.
4999 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355000 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545001 return content::PREVIEWS_OFF;
5002 }
5003
5004 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215005 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545006 // If this tab does not have a PreviewsUITabHelper, no preview should be
5007 // served.
5008 if (!ui_tab_helper)
5009 return content::PREVIEWS_OFF;
5010
5011 DCHECK(!browser_context->IsOffTheRecord());
5012
5013 // Other previews objects should all exist and be initialized if we have made
5014 // it past earlier checks.
5015 previews::PreviewsDeciderImpl* previews_decider_impl =
5016 previews_service->previews_ui_service()->previews_decider_impl();
5017 DCHECK(previews_decider_impl);
5018
Ryan Sturm647d1d92018-11-07 15:41:395019 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545020 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5021
Ryan Sturm647d1d92018-11-07 15:41:395022 previews::PreviewsUserData* previews_data =
5023 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5024
5025 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315026 // previews) and cannot re-evaluate PreviewsState once previews triggering
5027 // logic has already been run, so they should not change. Assume that
5028 // previews triggering logic has run when PreviewsUserData already exists and
5029 // a Lite Page Redirect preview is not being attempted, since it may also
5030 // create a previews_data before this point.
5031 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395032 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315033 previews_triggering_logic_already_ran =
5034 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395035 } else {
5036 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5037 navigation_handle, previews_decider_impl->GeneratePageId());
5038 }
5039
5040 DCHECK(previews_data);
5041
Robert Ogden01770b362019-05-22 17:36:435042 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5043 previews::switches::kForceEnablePreviews)) {
Robert Ogden01770b362019-05-22 17:36:435044 return content::ALL_SUPPORTED_PREVIEWS;
5045 }
5046
Ryan Sturmaa05092f2018-10-21 03:56:545047 bool is_reload =
5048 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5049
Ryan Sturm647d1d92018-11-07 15:41:395050 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515051 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395052
5053 // For now, treat server previews types as a single decision, and do not
5054 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5055 // header, nor does the plumbing exist to modify the PreviewsState within the
5056 // URLLoader.
Seanac57e9b92019-04-29 19:19:315057 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395058 // Copy the server state that was used before the redirect for the initial
5059 // URL.
Robert Ogden869986f2019-06-20 19:12:055060 previews_state |=
5061 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395062 } else {
Doug Arnetta3dc71582018-11-08 00:25:105063 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215064 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305065 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395066 previews_state |= server_previews_enabled_state;
5067 }
Ryan Sturmaa05092f2018-10-21 03:56:545068 }
5069
Sophie Changa71fa5d2019-11-19 23:53:515070 // Evaluate client-side previews.
Ryan Sturmaa05092f2018-10-21 03:56:545071 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315072 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355073 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5074 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545075
5076 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395077 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545078 return content::PREVIEWS_OFF;
5079 }
5080
5081 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395082 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545083 return content::PREVIEWS_NO_TRANSFORM;
5084 }
5085
5086 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395087 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5088 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545089 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395090 }
5091
5092 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5093 if (delegate) {
5094 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5095 }
Ryan Sturmaa05092f2018-10-21 03:56:545096
5097 // If the allowed previews are limited by the embedder, ensure previews honors
5098 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395099 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5100 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545101 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5102 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5103 previews_state = content::PREVIEWS_OFF;
5104 }
Ryan Sturm647d1d92018-11-07 15:41:395105 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545106 return previews_state;
5107}
5108
5109// static
5110content::PreviewsState
5111ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5112 const GURL& url,
5113 data_reduction_proxy::DataReductionProxyData* drp_data,
5114 previews::PreviewsUserData* previews_user_data,
5115 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055116 content::PreviewsState initial_state,
5117 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5119 if (!previews::HasEnabledPreviews(initial_state))
5120 return content::PREVIEWS_OFF;
5121
5122 // Check if the server sent a preview directive.
5123 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555124 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545125
Ryan Sturmaa05092f2018-10-21 03:56:545126 // Check the various other client previews types.
5127 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055128 previews_user_data, url, previews_state, previews_decider,
5129 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545130}
5131
5132content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5133 content::PreviewsState initial_state,
5134 content::NavigationHandle* navigation_handle,
5135 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135136 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5137 initial_state, navigation_handle, response_headers);
5138
5139 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5140}
5141
5142content::PreviewsState
5143ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5144 content::PreviewsState initial_state,
5145 content::NavigationHandle* navigation_handle,
5146 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5148 // Only support HTTP and HTTPS.
5149 if (navigation_handle->IsErrorPage() ||
5150 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5151 return content::PREVIEWS_OFF;
5152 }
5153
5154 // If this is not a main frame, return the initial state. If there are no
5155 // previews in the state, return the state as is.
5156 if (!previews::HasEnabledPreviews(initial_state) ||
5157 !navigation_handle->IsInMainFrame() ||
5158 navigation_handle->IsSameDocument()) {
5159 return initial_state;
5160 }
5161
5162 // WebContents that don't have a PreviewsUITabHelper are not supported.
5163 PreviewsUITabHelper* ui_tab_helper =
5164 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5165 if (!ui_tab_helper)
5166 return content::PREVIEWS_OFF;
5167
5168 // If we did not previously create a PreviewsUserData, do not go any further.
5169 previews::PreviewsUserData* previews_user_data =
5170 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5171 if (!previews_user_data)
5172 return content::PREVIEWS_OFF;
5173
5174 PreviewsService* previews_service =
5175 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5176 navigation_handle->GetWebContents()->GetBrowserContext()));
5177
5178 if (!previews_service || !previews_service->previews_ui_service())
5179 return content::PREVIEWS_OFF;
5180
5181// Check if offline previews are being used and set it in the user data.
5182#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5183 offline_pages::OfflinePageTabHelper* tab_helper =
5184 offline_pages::OfflinePageTabHelper::FromWebContents(
5185 navigation_handle->GetWebContents());
5186
Ryan Sturmfc7d92f2019-02-12 02:24:235187 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5188 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5189
5190 // If this is an offline page, but not a preview, then we should not attempt
5191 // any previews or surface the previews UI.
5192 if (is_offline_page && !is_offline_preview)
5193 return content::PREVIEWS_OFF;
5194
5195 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545196#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5197
5198 // Annotate request if no-transform directive found in response headers.
5199 if (response_headers &&
5200 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265201 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545202 }
5203
5204 previews::PreviewsDeciderImpl* previews_decider_impl =
5205 previews_service->previews_ui_service()->previews_decider_impl();
5206 DCHECK(previews_decider_impl);
5207
Clark DuVall9c5a72cc2018-10-25 01:29:215208 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5209 auto* settings =
5210 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5211 navigation_handle->GetWebContents()->GetBrowserContext());
5212 if (settings) {
5213 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5214 // does not yet have all the response information.
5215 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5216 response_headers);
5217 }
Ryan Sturmaa05092f2018-10-21 03:56:545218
5219 // Determine effective PreviewsState for this committed main frame response.
5220 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215221 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055222 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545223
5224 // Double check that we never serve a preview when we have a
5225 // cache-control:no-transform directive.
5226 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5227 !previews::HasEnabledPreviews(committed_state));
5228
Robert Ogdended292c6f2019-05-03 22:44:515229 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545230 previews_user_data->set_committed_previews_state(committed_state);
5231
5232 previews::PreviewsType committed_type =
5233 previews::GetMainFramePreviewsType(committed_state);
5234
5235 // Capture committed previews type, if any, in PreviewsUserData.
5236 // Note: this is for the subset of previews types that are decided upon
5237 // navigation commit. Previews types that are determined prior to
5238 // navigation (such as for offline pages or for redirecting to another
5239 // url), are not set here.
5240 previews_user_data->SetCommittedPreviewsType(committed_type);
5241
5242 // Log the commit decision.
5243 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5244 previews_decider_impl->LogPreviewDecisionMade(
5245 (previews_user_data->cache_control_no_transform_directive()
5246 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5247 : previews::PreviewsEligibilityReason::COMMITTED),
5248 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055249 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055250 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545251
5252 return committed_state;
5253}
Charlie Harrison650e11422018-12-04 00:37:265254
5255void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5256 content::RenderFrameHost* render_frame_host,
5257 blink::mojom::WebFeature feature) {
5258 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5259 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5260 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5261 render_frame_host, new_features);
Lily Chenc2c9e9f2019-12-05 19:55:315262
5263 // For the SameSite-by-default-cookies related features, log
5264 // the site engagement score for the site whose cookie was blocked. This is to
5265 // gauge the user impact of the cookies being blocked.
5266 MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature);
Charlie Harrison650e11422018-12-04 00:37:265267}
Yutaka Hirano968d6252018-12-04 05:09:315268
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525269std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315270 return ::GetProduct();
5271}
5272
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525273std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315274 return ::GetUserAgent();
5275}
Sam McNallyd54e23f92019-01-16 04:42:395276
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525277blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175278 return ::GetUserAgentMetadata();
5279}
5280
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525281base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275282 // This icon is available on Android, but adds 19KiB to the APK. Since it
5283 // isn't used on Android we exclude it to avoid bloat.
5284#if !defined(OS_ANDROID)
5285 return base::Optional<gfx::ImageSkia>(
5286 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5287 IDR_PRODUCT_LOGO_256));
5288#else
5289 return base::nullopt;
5290#endif
5291}
5292
Sam McNallyd54e23f92019-01-16 04:42:395293bool ChromeContentBrowserClient::IsBuiltinComponent(
5294 content::BrowserContext* browser_context,
5295 const url::Origin& origin) {
5296#if BUILDFLAG(ENABLE_EXTENSIONS)
5297 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5298 browser_context, origin);
5299#else
5300 return false;
5301#endif
5302}
Oleg Davydov2cc0167b2019-02-05 14:32:485303
5304bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5305 const GURL& url,
5306 content::BrowserContext* context) {
5307 PolicyBlacklistService* service =
5308 PolicyBlacklistFactory::GetForBrowserContext(context);
5309
5310 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5311 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5312 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5313}
Dominic Mazzoni21fb0282019-02-13 18:32:475314
5315ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5316 content::BrowserContext* browser_context) {
5317 Profile* profile = Profile::FromBrowserContext(browser_context);
5318 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5319}
Eric Karld6cd75b2019-03-14 22:01:365320
5321#if defined(OS_ANDROID)
5322content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525323ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365324 if (features::UseDisplayWideColorGamut()) {
5325 return WideColorGamutHeuristic::kUseDisplay;
5326 }
Khushal1fc0da52019-10-09 00:38:565327
5328 if (display::Display::HasForceDisplayColorProfile() &&
5329 display::Display::GetForcedDisplayColorProfile() ==
5330 gfx::ColorSpace::CreateDisplayP3D65()) {
5331 return WideColorGamutHeuristic::kUseDisplay;
5332 }
5333
Eric Karld6cd75b2019-03-14 22:01:365334 return WideColorGamutHeuristic::kNone;
5335}
5336#endif
Ehsan Karamad91413d72019-03-22 16:37:485337
5338base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435339ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465340 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485341 base::flat_set<std::string> mime_types;
5342#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465343 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485344 for (const auto& pair : map)
5345 mime_types.insert(pair.first);
5346#endif
5347 return mime_types;
5348}
Yao Xiaod06607b2019-05-02 23:16:365349
5350void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5351 const content::WebContents* web_contents,
5352 const content::RenderFrameHost* frame_host,
5353 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525354 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365355 const ChromeSubresourceFilterClient* client =
5356 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5357 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045358 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365359 if (!user_gesture) {
5360 if (base::FeatureList::IsEnabled(
5361 blink::features::
5362 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5363 download_policy->SetDisallowed(
5364 content::NavigationDownloadType::kAdFrameNoGesture);
5365 } else {
5366 download_policy->SetAllowed(
5367 content::NavigationDownloadType::kAdFrameNoGesture);
5368 }
Yao Xiaod06607b2019-05-02 23:16:365369 }
5370 }
5371}
Jun Cai732a05e32019-05-29 19:34:195372
5373bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5374 content::BrowserContext* browser_context,
5375 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525376 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195377 const HostContentSettingsMap* const content_settings =
5378 HostContentSettingsMapFactory::GetForProfile(
5379 Profile::FromBrowserContext(browser_context));
5380
5381 if (content_settings->GetContentSetting(
5382 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455383 ContentSettingsType::BLUETOOTH_SCANNING,
Jun Cai732a05e32019-05-29 19:34:195384 std::string()) == CONTENT_SETTING_BLOCK) {
5385 return true;
5386 }
5387
5388 return false;
5389}
5390
5391void ChromeContentBrowserClient::BlockBluetoothScanning(
5392 content::BrowserContext* browser_context,
5393 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525394 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195395 HostContentSettingsMap* const content_settings =
5396 HostContentSettingsMapFactory::GetForProfile(
5397 Profile::FromBrowserContext(browser_context));
5398
5399 content_settings->SetContentSettingDefaultScope(
5400 requesting_origin.GetURL(), embedding_origin.GetURL(),
Darin Fisher42f5e7d2019-10-30 07:15:455401 ContentSettingsType::BLUETOOTH_SCANNING, std::string(),
Jun Cai732a05e32019-05-29 19:34:195402 CONTENT_SETTING_BLOCK);
5403}
Tibor Goldschwendtbf1b96e2019-10-07 22:03:475404
5405bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() {
5406#if defined(OS_ANDROID)
5407 return extra_icu::ModuleProvider::IsModuleInstalled();
5408#endif
5409 return false;
5410}
Guido Urdaneta4030d6a32019-10-17 09:38:165411
5412bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
5413 content::BrowserContext* browser_context,
5414 const GURL& url,
5415 const GURL& site_for_cookies,
5416 const base::Optional<url::Origin>& top_frame_origin) {
5417 // Persistent MediaDevice IDs are allowed if cookies are allowed.
5418 return CookieSettingsFactory::GetForProfile(
5419 Profile::FromBrowserContext(browser_context))
5420 ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
5421}
Sam Goto5cf068e82019-11-04 23:08:445422
5423#if !defined(OS_ANDROID)
5424void ChromeContentBrowserClient::FetchRemoteSms(
5425 content::BrowserContext* browser_context,
5426 const url::Origin& origin,
5427 base::OnceCallback<void(base::Optional<std::string>)> callback) {
5428 ::FetchRemoteSms(browser_context, origin, std::move(callback));
5429}
5430#endif