blob: 218dcacb9fc495edb16dfe11e3f5619766ab2c5b [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"
lazyboy5d5fede02016-03-10 04:10:1423#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3324#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3925#include "base/path_service.h"
Avi Drissmand251e912018-12-26 15:46:3726#include "base/stl_util.h"
[email protected]e7463412013-06-10 22:53:4627#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0328#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2829#include "base/strings/string_util.h"
30#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2031#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0332#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2833#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3234#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4135#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1836#include "build/build_config.h"
Ken Rockot06fd2832019-05-24 17:24:4437#include "chrome/app/builtin_service_manifests.h"
Ken Rockot341089f2019-01-11 23:11:5838#include "chrome/app/chrome_content_browser_overlay_manifest.h"
39#include "chrome/app/chrome_content_gpu_overlay_manifest.h"
40#include "chrome/app/chrome_content_renderer_overlay_manifest.h"
Dominic Mazzoni21fb0282019-02-13 18:32:4741#include "chrome/browser/accessibility/accessibility_labels_service.h"
42#include "chrome/browser/accessibility/accessibility_labels_service_factory.h"
michaeln96f887e22015-04-13 23:58:3143#include "chrome/browser/after_startup_task_utils.h"
[email protected]b8148ac2011-07-13 22:03:2544#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3045#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4746#include "chrome/browser/browsing_data/browsing_data_helper.h"
msramek1c2b3ca2017-03-14 17:57:5647#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
nigeltaobeff0a102017-04-29 09:30:3748#include "chrome/browser/cache_stats_recorder.h"
Oksana Zhuravlova4dd171e82019-08-16 20:54:0049#include "chrome/browser/chrome_browser_interface_binders.h"
[email protected]d5a74be2014-08-08 01:01:2750#include "chrome/browser/chrome_content_browser_client_parts.h"
[email protected]317f96c92011-05-31 06:53:4151#include "chrome/browser/chrome_quota_permission_context.h"
drogerb1716972015-06-30 09:04:0952#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0853#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
[email protected]8093a542011-05-13 07:29:3254#include "chrome/browser/content_settings/tab_specific_content_settings.h"
Robbie McElrath1294d242019-05-31 20:46:2255#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
56#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3057#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
58#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0659#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0860#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4961#include "chrome/browser/download/download_prefs.h"
Maks Orlovich710d5e32019-07-09 20:16:4562#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0163#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1964#include "chrome/browser/font_family_cache.h"
Matt Reynolds93616f9b2019-06-07 01:28:5265#include "chrome/browser/hid/chrome_hid_delegate.h"
Anthony Vallee-Duboise2432137a2019-01-17 20:06:0166#include "chrome/browser/language/translate_frame_binder.h"
Avi Drissmand30927342018-05-22 15:04:2767#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2768#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3469#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4270#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
71#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1672#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3673#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Darin Fisher09aa7222019-08-29 09:27:3674#include "chrome/browser/media/webrtc/webrtc_logging_controller.h"
[email protected]95132f52013-04-12 02:19:0475#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0576#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0777#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
Lu Chen5bec7a302018-06-26 18:52:3278#include "chrome/browser/navigation_predictor/navigation_predictor.h"
John Abd-El-Malek7577f262019-06-10 21:23:2379#include "chrome/browser/net/chrome_network_delegate.h"
Matt Menkeae4fdb12018-06-02 06:32:5480#include "chrome/browser/net/system_network_context_manager.h"
dvallet233f57ab2016-12-21 03:17:1081#include "chrome/browser/net_benchmarking.h"
Richard Knolld0eae962019-04-04 12:34:0282#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5983#include "chrome/browser/notifications/platform_notification_service_impl.h"
leon.han952ea3252016-04-13 02:44:5684#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0685#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5486#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5187#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5688#include "chrome/browser/permissions/attestation_permission_request.h"
jyasskinc993ce8d2016-03-31 00:38:3489#include "chrome/browser/permissions/permission_context_base.h"
Adam Langley85339f62018-02-12 22:03:5690#include "chrome/browser/permissions/permission_request_manager.h"
[email protected]0609b17f2011-05-31 20:13:4291#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1192#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4893#include "chrome/browser/plugins/plugin_utils.h"
Alexandr Ilin4909ec82018-06-06 10:22:4894#include "chrome/browser/predictors/loading_predictor.h"
95#include "chrome/browser/predictors/loading_predictor_factory.h"
[email protected]190e5e22013-07-27 05:59:2396#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4197#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5098#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0799#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:01100#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:19101#include "chrome/browser/previews/previews_content_util.h"
Robert Ogden0f4d88682019-09-24 22:27:52102#include "chrome/browser/previews/previews_lite_page_redirect_decider.h"
103#include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.h"
Ryan Sturmaa05092f2018-10-21 03:56:54104#include "chrome/browser/previews/previews_service.h"
105#include "chrome/browser/previews/previews_service_factory.h"
106#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03107#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14108#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32109#include "chrome/browser/profiles/profile_io_data.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06110#include "chrome/browser/profiles/renderer_updater.h"
111#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56112#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
113#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44114#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]05fcf982011-04-19 00:44:14115#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:38116#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40117#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45118#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31119#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
120#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Carlos IL4ee307e2018-12-22 03:19:00121#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40122#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35123#include "chrome/browser/safe_browsing/ui_manager.h"
124#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43125#include "chrome/browser/search/search.h"
Jay Civelli2578ebe2018-06-05 18:44:31126#include "chrome/browser/sessions/session_tab_helper.h"
Reilly Grantcc22e602018-09-07 15:25:20127#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35128#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40129#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23130#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28131#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02132#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48133#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Eric Lawrenced0acf2a7c2017-07-20 18:02:48134#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
[email protected]848dd042011-06-04 18:24:03135#include "chrome/browser/ssl/ssl_blocking_page.h"
estark3ba11132015-04-10 01:38:33136#include "chrome/browser/ssl/ssl_cert_reporter.h"
Joe DeBlasio9b996292019-01-31 05:09:32137#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07138#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35139#include "chrome/browser/ssl/ssl_error_handler.h"
Lucas Garron94b16052017-11-11 01:58:12140#include "chrome/browser/ssl/ssl_error_navigation_throttle.h"
Christopher Thompson4137cec2017-12-19 05:34:23141#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10142#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35143#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45144#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52145#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19146#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44147#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38148#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51149#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08150#include "chrome/browser/ui/browser_navigator.h"
151#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43152#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39153#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54154#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56155#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25156#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44157#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58158#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50159#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01160#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25161#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53162#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25163#include "chrome/browser/web_applications/components/app_registrar.h"
164#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23165#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22166#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01167#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51168#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14169#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22170#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30171#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02172#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50173#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34174#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37175#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12176#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19177#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12178#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22179#include "chrome/common/prerender_util.h"
[email protected]3e69bc82011-05-26 23:22:38180#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28181#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02182#include "chrome/common/secure_origin_whitelist.h"
wittman832321f52016-10-10 18:18:38183#include "chrome/common/stack_sampling_configuration.h"
[email protected]c5dbef02011-05-13 05:06:09184#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47185#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37186#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18187#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30188#include "chrome/installer/util/google_update_settings.h"
leon.han04b276e2016-06-01 01:34:16189#include "components/autofill/content/browser/content_autofill_driver_factory.h"
brettwf1958912015-10-07 19:43:12190#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53191#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44192#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04193#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48194#include "components/cloud_devices/common/cloud_devices_switches.h"
Tao Bai02ab4dd42019-03-06 00:30:37195#include "components/content_capture/browser/content_capture_receiver_manager.h"
mukai8eaec822014-10-25 17:53:16196#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09197#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16198#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52199#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45200#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08201#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03202#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09203#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Clark DuVall0e901722019-08-14 23:31:37204#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
Ryan Sturmaa05092f2018-10-21 03:56:54205#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28206#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43207#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09208#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32209#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03210#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24211#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43212#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01213#include "components/feature_engagement/public/feature_constants.h"
214#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39215#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20216#include "components/language/core/browser/pref_names.h"
wittmane16da2782016-09-21 16:43:04217#include "components/metrics/call_stack_profile_collector.h"
[email protected]8e885de2014-07-22 23:36:53218#include "components/metrics/client_info.h"
Scott Violet9ae82892018-03-01 18:38:12219#include "components/nacl/common/buildflags.h"
sammc2b0375b2016-12-22 01:26:17220#include "components/nacl/common/nacl_constants.h"
drogerc690e8802015-09-21 14:29:16221#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12222#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
223#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
224#include "components/page_load_metrics/browser/page_load_metrics_util.h"
leon.han97e8f752016-09-06 06:13:20225#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06226#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53227#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54228#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18229#include "components/policy/core/common/policy_service.h"
230#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26231#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54232#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08233#include "components/prefs/pref_service.h"
234#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21235#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54236#include "components/previews/content/previews_decider_impl.h"
237#include "components/previews/content/previews_ui_service.h"
238#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54239#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45240#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43241#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56242#include "components/rappor/public/rappor_utils.h"
nigeltao2f673762016-10-14 03:27:28243#include "components/rappor/rappor_recorder_impl.h"
nzolghadrd87a308d2016-12-07 15:45:56244#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35245#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
246#include "components/safe_browsing/browser/mojo_safe_browsing_impl.h"
247#include "components/safe_browsing/browser/url_checker_delegate.h"
Nico Weberbc5b06f2019-07-26 14:00:13248#include "components/safe_browsing/buildflags.h"
timvolodine89cf11712017-05-15 18:05:07249#include "components/safe_browsing/common/safe_browsing_prefs.h"
Tim Volodinee45938472017-09-21 10:08:22250#include "components/safe_browsing/db/database_manager.h"
Yuzhu Shencb3011f62018-02-08 02:51:50251#include "components/safe_browsing/features.h"
Jialiu Linbdbb81d2017-10-11 21:29:09252#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14253#include "components/security_interstitials/content/origin_policy_ui.h"
David Rogere8e83f3c2019-09-12 10:56:23254#include "components/signin/public/identity_manager/identity_manager.h"
Scott Violetd7983c52018-03-03 00:24:41255#include "components/spellcheck/spellcheck_buildflags.h"
Ken Rockot7c6275b2019-08-02 20:00:23256#include "components/startup_metric_utils/browser/startup_metric_host_impl.h"
csharrisone985ebc2017-04-04 17:05:03257#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17258#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21259#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28260#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33261#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46262#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22263#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43264#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30265#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38266#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28267#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03268#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31269#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41270#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09271#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03272#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59273#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19274#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31275#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35276#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47277#include "content/public/browser/navigation_handle.h"
278#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11279#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50280#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30281#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33282#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05283#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34284#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48285#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27286#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13287#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08288#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19289#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21290#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23291#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43292#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18293#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56294#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40295#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18296#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58297#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57298#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23299#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44300#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31301#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05302#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56303#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43304#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59305#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48306#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30307#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28308#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04309#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31310#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44311#include "media/media_buildflags.h"
312#include "media/mojo/buildflags.h"
Jay Civelli2578ebe2018-06-05 18:44:31313#include "mojo/public/cpp/bindings/binding_set.h"
Shimi Zhang6b72d292019-07-12 20:52:42314#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Ken Rockot40a1df792019-05-08 22:15:52315#include "mojo/public/cpp/bindings/pending_receiver.h"
316#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot0adc1e42019-05-24 08:20:08317#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53318#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51319#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58320#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23321#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46322#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57323#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14324#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38325#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19326#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37327#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50328#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50329#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13330#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05331#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34332#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03333#include "services/strings/grit/services_strings.h"
pilgrime92c5fcd2014-09-10 23:31:23334#include "storage/browser/fileapi/external_mount_points.h"
John Delaneyac24e572019-04-30 19:47:02335#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02336#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Julie Jeongeun Kimd3d00a12019-03-25 01:46:25337#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h"
Leon Hanc819dc62019-01-28 04:30:19338#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17339#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Eric Willigers3eeae17c2019-03-13 17:32:10340#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21341#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26342#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18343#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39344#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08345#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35346#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21347#include "ui/base/ui_base_switches.h"
348#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49349#include "ui/native_theme/caption_style.h"
350#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57351#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45352#include "url/gurl.h"
353#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26354
Ken Rockot69aade02019-01-23 21:19:51355#if BUILDFLAG(ENABLE_NACL)
356#include "components/nacl/loader/nacl_loader_manifest.h"
357#if defined(OS_WIN) && defined(ARCH_CPU_X86)
358#include "components/nacl/broker/nacl_broker_manifest.h"
359#endif
360#endif
361
[email protected]b48c9182011-10-26 18:03:30362#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20363#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38364#include "chrome/browser/chrome_browser_main_win.h"
Patrick Monettebb543942019-05-17 17:45:32365#include "chrome/browser/win/conflicts/module_database.h"
366#include "chrome/browser/win/conflicts/module_event_sink_impl.h"
Jerry Lina0de7ce2018-06-22 15:18:36367#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18368#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38369#elif defined(OS_MACOSX)
370#include "chrome/browser/chrome_browser_main_mac.h"
Guido Urdaneta1a2917432018-05-10 18:32:32371#include "services/audio/public/mojom/constants.mojom.h"
[email protected]b48c9182011-10-26 18:03:30372#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42373#include "ash/public/cpp/tablet_mode.h"
Miyoung Shin7e1b1b12019-08-02 12:23:50374#include "ash/public/mojom/constants.mojom.h"
Joshua Peraza30d8fc72019-08-19 17:24:30375#include "chrome/app/chrome_crash_reporter_client.h"
Scott Violet47f00e52018-05-04 22:50:31376#include "chrome/browser/ash_service_registry.h"
hashimotoa53e7e82016-10-26 06:30:47377#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17378#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30379#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24380#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18381#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08382#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48383#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41384#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32385#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58386#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00387#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
388#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44389#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39390#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31391#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33392#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44393#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10394#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36395#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27396#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31397#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10398#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21399#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10400#include "chromeos/constants/chromeos_switches.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11401#include "components/crash/content/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07402#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58403#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50404#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26405#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30406#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09407#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35408#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45409#include "chrome/android/features/dev_ui/buildflags.h"
zqzhang93e959d12017-03-16 13:10:20410#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36411#include "chrome/browser/android/chrome_context_util.h"
412#include "chrome/browser/android/devtools_manager_delegate_android.h"
Dan Harrington964d48c2018-08-03 15:52:24413#include "chrome/browser/android/download/available_offline_content_provider.h"
Min Qin0ab0e162017-11-14 21:57:19414#include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h"
Scott Violetef765b92017-06-09 21:26:36415#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
416#include "chrome/browser/android/service_tab_launcher.h"
417#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42418#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09419#include "chrome/browser/chrome_browser_main_android.h"
Dan Harrington954c8822019-01-09 18:40:48420#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07421#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38422#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11423#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07424#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47425#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36426#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54427#include "services/service_manager/public/cpp/interface_provider.h"
Han Leonabbe7c902018-08-30 02:08:10428#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Julie Jeongeun Kimb6a0a1f2019-03-21 05:08:26429#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
agrieve05398f52015-06-24 18:59:00430#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36431#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45432#if BUILDFLAG(DFMIFY_DEV_UI)
433#include "chrome/browser/android/dev_ui/dev_ui_url_handler.h"
434#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30435#elif defined(OS_POSIX)
436#include "chrome/browser/chrome_browser_main_posix.h"
437#endif
438
tmartinofb341882017-02-10 19:36:53439#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40440#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36441#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54442#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59443#include "chrome/browser/media/unified_autoplay_config.h"
mathpf709499d2017-01-09 20:48:36444#include "chrome/browser/payments/payment_request_factory.h"
Marc Treib7895941d2017-11-28 12:37:02445#include "chrome/browser/search/instant_service.h"
446#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46447#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51448#include "chrome/browser/ui/browser.h"
449#include "chrome/browser/ui/browser_finder.h"
450#include "chrome/browser/ui/browser_list.h"
451#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20452#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51453#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39454#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
455#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43456#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27457#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28458#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36459
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33460#if defined(OS_WIN) || defined(OS_MACOSX) || \
461 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52462#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
463#endif
464
Joshua Perazace68e2f2019-09-23 18:44:24465#if defined(OS_LINUX)
466#include "components/crash/content/app/crash_switches.h"
467#include "components/crash/content/app/crashpad.h"
468#endif
469
[email protected]a220b5932013-09-21 03:47:44470#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02471#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02472#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13473#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02474#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13475#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43476#endif
[email protected]b80f68432011-05-02 17:22:30477
Maggie Caia2f03f52019-04-02 02:13:28478// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
479// single navigation throttle to display the intent picker on all platforms.
480#if !defined(OS_ANDROID)
481#if defined(OS_CHROMEOS)
482#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
483#else
484#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
485#endif
486#endif
487
[email protected]e8b6ca02013-07-10 18:00:51488#if defined(TOOLKIT_VIEWS)
489#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
490#endif
491
estaded3aa0e82016-02-17 22:55:21492#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22493#if defined(USE_X11)
494#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
495#else
estaded3aa0e82016-02-17 22:55:21496#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22497#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51498#endif
499
Mohsen Izadif1958f22019-01-18 20:29:31500#if defined(USE_OZONE)
501#include "ui/ozone/public/ozone_platform.h"
502#endif
503
[email protected]e8b6ca02013-07-10 18:00:51504#if defined(USE_X11)
505#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
506#endif
507
brettwab78fef2016-10-12 02:56:05508#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19509#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
510#endif
511
Nico Weberaf3b00b2017-09-11 17:58:17512#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55513#include "components/nacl/browser/nacl_browser.h"
514#include "components/nacl/browser/nacl_host_message_filter.h"
515#include "components/nacl/browser/nacl_process_host.h"
516#include "components/nacl/common/nacl_process_type.h"
517#include "components/nacl/common/nacl_switches.h"
518#endif
519
brettw00899e62016-11-12 02:10:17520#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05521#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20522#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27523#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23524#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32525#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51526#include "chrome/browser/extensions/user_script_listener.h"
527#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28528#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Eric Willigers007ef302019-08-29 09:58:46529#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39530#include "components/guest_view/browser/guest_view_base.h"
531#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25532#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31533#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35534#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32535#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12536#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57537#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48538#include "extensions/browser/guest_view/web_view/web_view_guest.h"
539#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
540#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31541#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27542#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28543#include "extensions/common/extension.h"
544#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13545#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28546#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33547#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28548#include "extensions/common/permissions/permissions_data.h"
549#include "extensions/common/permissions/socket_permission.h"
550#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34551#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25552
brettw4b461082016-11-19 18:55:16553#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55554#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27555#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39556#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55557#endif
558
bauerb8f9c37742017-03-30 15:04:12559#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
560#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
561#endif
562
thakis678822e2017-04-20 17:20:34563#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38564#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09565#endif
566
weilifabbf7572017-05-22 19:05:16567#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21568#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16569#endif
Lei Zhanga2fa14c2018-05-15 00:05:21570
Xiaohan Wanga4e41842018-06-26 18:45:10571#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49572#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wanga4e41842018-06-26 18:45:10573#include "chrome/browser/media/platform_verification_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26574#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10575#include "chrome/browser/media/widevine_hardware_caps_win.h"
576#include "third_party/widevine/cdm/widevine_cdm_common.h"
577#endif
578#endif
579
xhwangdb24d602017-05-20 06:32:24580#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
xhwang116acb92017-04-03 18:27:20581#include "chrome/browser/media/android/cdm/media_drm_storage_factory.h"
582#endif
xhwangc86d76e42016-03-14 23:38:49583
xhwangdb24d602017-05-20 06:32:24584#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
Aran Gilmanf010bdd2019-08-28 19:55:44585#include "media/mojo/mojom/constants.mojom.h" // nogncheck
xhwangb1d65fd2016-10-19 20:55:52586#include "media/mojo/services/media_service_factory.h" // nogncheck
alokp6ecb2382016-01-27 00:40:00587#endif
588
mmenkedb2637ff2017-03-30 23:59:42589#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
590#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
591#endif
592
Nico Weberbc5b06f2019-07-26 14:00:13593#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35594#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
595#endif
596
Jian Lide7b43792018-06-01 23:22:13597#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54598#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13599#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
600#endif
601
Will Cassella40837ba2019-07-01 21:32:00602#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43603#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
604#endif
605
Ken Rockotc185b2a2019-08-01 22:19:48606#if BUILDFLAG(ENABLE_SPELLCHECK)
607#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
608#include "components/spellcheck/common/spellcheck.mojom.h"
609#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
610#include "chrome/browser/spellchecker/spell_check_panel_host_impl.h"
611#endif
612#endif
613
Michael Thiessen909ba032019-03-26 23:47:43614#if defined(BROWSER_MEDIA_CONTROLS_MENU)
615#include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h"
616#endif
617
Michael Thiessen07c444c2019-04-26 03:53:11618#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
619#include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h"
620#endif
621
[email protected]c7abd422012-09-25 00:20:08622using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39623using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31624using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13625using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59626using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00627using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02628using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11629using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07630using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33631using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13632using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05633using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38634using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39635
[email protected]0daaebfe2014-03-15 00:09:05636#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20637using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05638#endif
639
brettw00899e62016-11-12 02:10:17640#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28641using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27642using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28643using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28644using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27645#endif
646
brettw4b461082016-11-19 18:55:16647#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55648using plugins::ChromeContentBrowserClientPluginsPart;
649#endif
650
[email protected]c5dbef02011-05-13 05:06:09651namespace {
652
michaeln10e5fc352017-02-07 02:07:58653const storage::QuotaSettings* g_default_quota_settings;
654
brettw4b461082016-11-19 18:55:16655#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42656// TODO(teravest): Add renderer-side API-specific checking for these APIs so
657// that blanket permission isn't granted to all dev channel APIs for these.
658// http://crbug.com/386743
659const char* const kPredefinedAllowedDevChannelOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44660 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
661 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
[email protected]aec5ed52014-06-20 07:51:42662};
663
[email protected]9de4da52014-05-24 12:26:50664const char* const kPredefinedAllowedFileHandleOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44665 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
666 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
[email protected]10c39222013-11-13 20:09:25667};
668
[email protected]9de4da52014-05-24 12:26:50669const char* const kPredefinedAllowedSocketOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44670 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
671 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
672 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
673 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
674 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
675 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
676 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
677 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
678 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
679 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
680 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
681 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
682 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
683 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
684 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
685 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
686 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
687 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
688 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
689 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
690 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
691 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40692};
[email protected]93f72062013-05-29 20:29:40693#endif
[email protected]e461da2f2012-02-16 19:06:40694
Will Harris1b9b4152019-08-21 22:33:50695#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30696// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
697// running on Windows 10 1511 and above. See
698// https://blogs.windows.com/blog/tag/code-integrity-guard/.
699const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harris6dd1f842019-08-05 21:01:33700 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50701#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
702 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30703
lazyboy5d5fede02016-03-10 04:10:14704enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53705 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14706 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53707
708 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14709 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53710
711 // An extension or app tried to load a resource of a different platform app in
712 // a tab.
713 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
714
715 // A non-app and non-extension page tried to load a platform app in a tab.
716 APP_LOADED_IN_TAB_SOURCE_OTHER,
717
lazyboy5d5fede02016-03-10 04:10:14718 APP_LOADED_IN_TAB_SOURCE_MAX
719};
720
Lei Zhang2cfceac2018-11-14 19:36:33721// Cached version of the locale so we can return the locale on the I/O
722// thread.
723std::string& GetIOThreadApplicationLocale() {
724 static base::NoDestructor<std::string> s;
725 return *s;
726}
727
[email protected]f8f93eb2012-09-25 03:06:24728// Returns a copy of the given url with its host set to given host and path set
729// to given path. Other parts of the url will be the same.
730GURL ReplaceURLHostAndPath(const GURL& url,
731 const std::string& host,
732 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05733 url::Replacements<char> replacements;
734 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
735 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24736 return url.ReplaceComponents(replacements);
737}
738
madfbd10852017-01-20 03:15:33739// Handles the rewriting of the new tab page URL based on group policy.
740bool HandleNewTabPageLocationOverride(
741 GURL* url,
742 content::BrowserContext* browser_context) {
743 if (!url->SchemeIs(content::kChromeUIScheme) ||
744 url->host() != chrome::kChromeUINewTabHost)
745 return false;
746
747 Profile* profile = Profile::FromBrowserContext(browser_context);
748 std::string ntp_location =
749 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
750 if (ntp_location.empty())
751 return false;
752
753 *url = GURL(ntp_location);
754 return true;
755}
756
Becca Hughesfe8c32c2018-03-21 13:36:56757#if !defined(OS_ANDROID)
758// Check if the current url is whitelisted based on a list of whitelisted urls.
759bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie53e009b2019-09-09 14:17:41760 base::span<const base::Value> whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56761 // Only check on HTTP and HTTPS pages.
762 if (!current_url.SchemeIsHTTPOrHTTPS())
763 return false;
764
765 for (auto const& value : whitelisted_urls) {
766 ContentSettingsPattern pattern =
767 ContentSettingsPattern::FromString(value.GetString());
768 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
769 continue;
770 if (pattern.Matches(current_url))
771 return true;
772 }
773
774 return false;
775}
776
777// Check if autoplay is allowed by policy configuration.
778bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
779 PrefService* prefs) {
780 DCHECK(prefs);
781
782 // Check if we have globally allowed autoplay by policy.
783 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
784 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
785 return true;
786 }
787
788 if (!contents)
789 return false;
790
791 // Check if the current URL matches a URL pattern on the whitelist.
792 const base::ListValue* autoplay_whitelist =
793 prefs->GetList(prefs::kAutoplayWhitelist);
794 return autoplay_whitelist &&
795 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
796 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
797}
798#endif
799
Joshua Perazaf890e4b2019-01-03 19:19:02800#if defined(OS_ANDROID)
801int GetCrashSignalFD(const base::CommandLine& command_line) {
802 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
803}
804#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03805breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
806 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02807 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52808 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02809 {
810 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31811 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03812 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50813 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02814 crash_handler->StartUploaderThread();
815 return crash_handler;
816 }
817}
818
avi3ef9ec9e2014-12-22 22:50:17819int GetCrashSignalFD(const base::CommandLine& command_line) {
Joshua Perazace68e2f2019-09-23 18:44:24820 if (crash_reporter::IsCrashpadEnabled()) {
821 int fd;
822 pid_t pid;
823 return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
824 }
825
[email protected]9de4da52014-05-24 12:26:50826 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39827 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31828 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02829 if (!crash_handler)
830 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18831 return crash_handler->GetDeathSignalSocket();
832 }
833
834 std::string process_type =
835 command_line.GetSwitchValueASCII(switches::kProcessType);
836
[email protected]779dd282013-10-19 15:57:02837 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31838 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02839 if (!crash_handler)
840 crash_handler = CreateCrashHandlerHost(process_type);
841 return crash_handler->GetDeathSignalSocket();
842 }
[email protected]a1733df2012-06-22 11:24:18843
[email protected]779dd282013-10-19 15:57:02844 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31845 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02846 if (!crash_handler)
847 crash_handler = CreateCrashHandlerHost(process_type);
848 return crash_handler->GetDeathSignalSocket();
849 }
[email protected]a1733df2012-06-22 11:24:18850
[email protected]779dd282013-10-19 15:57:02851 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31852 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02853 if (!crash_handler)
854 crash_handler = CreateCrashHandlerHost(process_type);
855 return crash_handler->GetDeathSignalSocket();
856 }
[email protected]a1733df2012-06-22 11:24:18857
James Cook9207cc12017-10-19 17:08:39858 if (process_type == switches::kUtilityProcess) {
859 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
860 if (!crash_handler)
861 crash_handler = CreateCrashHandlerHost(process_type);
862 return crash_handler->GetDeathSignalSocket();
863 }
864
[email protected]a1733df2012-06-22 11:24:18865 return -1;
866}
Joshua Perazaf890e4b2019-01-03 19:19:02867#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18868
[email protected]eabbfb12013-04-05 23:28:35869void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52870 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33871 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35872}
873
estark3ba11132015-04-10 01:38:33874// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31875// SSLErrorHandler. Uses CertificateReportingService to send reports. The
876// service handles queueing and re-sending of failed reports. Each certificate
877// error creates a new instance of this class.
878class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33879 public:
meacerf43117a2016-12-27 21:02:31880 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12881 content::WebContents* web_contents)
882 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
883 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31884 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33885
886 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55887 void ReportInvalidCertificateChain(
888 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31889 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33890 }
891
892 private:
meacerf43117a2016-12-27 21:02:31893 CertificateReportingService* service_;
894
895 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33896};
897
bshe4f53ce42015-11-30 16:56:31898#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05899float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59900 static const float kMinFSM = 1.05f;
901 static const int kWidthForMinFSM = 320;
902 static const float kMaxFSM = 1.3f;
903 static const int kWidthForMaxFSM = 800;
904
boliu21c5afa2017-01-11 19:34:23905 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59906
907 if (minWidth <= kWidthForMinFSM)
908 return kMinFSM;
909 if (minWidth >= kWidthForMaxFSM)
910 return kMaxFSM;
911
912 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
913 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
Aran Gilmanf010bdd2019-08-28 19:55:44914 (kWidthForMaxFSM - kWidthForMinFSM);
[email protected]b255a8e0e82013-10-22 04:03:59915 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
916}
zpengdb4a58e2017-01-10 17:40:32917
[email protected]916615b2013-09-11 18:19:44918#endif // defined(OS_ANDROID)
919
brettw00899e62016-11-12 02:10:17920#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53921
922AppLoadedInTabSource ClassifyAppLoadedInTabSource(
923 const GURL& opener_url,
924 const extensions::Extension* target_platform_app) {
925 if (opener_url.SchemeIs(extensions::kExtensionScheme)) {
926 if (opener_url.host_piece() == target_platform_app->id()) {
927 // This platform app was trying to window.open() one of its own URLs.
928 if (opener_url ==
929 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
930 // Source was the background page.
931 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
932 } else {
933 // Source was a different page inside the app.
934 return APP_LOADED_IN_TAB_SOURCE_APP;
935 }
936 }
937 // The forbidden app URL was being opened by a different app or extension.
938 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
939 }
940 // The forbidden app URL was being opened by a non-extension page (e.g. http).
941 return APP_LOADED_IN_TAB_SOURCE_OTHER;
942}
[email protected]9c7656382014-08-08 21:02:30943
Charles Harrison34f67862017-08-22 01:04:17944// Returns true if there is is an extension matching |url| in
945// |opener_render_process_id| with APIPermission::kBackground.
946//
947// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
948// hosted app, even though normal extensions just use the host.
949bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35950 extensions::ProcessMap* process_map,
951 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17952 const GURL& url,
csharrison95f01e922017-04-24 18:52:35953 int opener_render_process_id) {
954 // Note: includes web URLs that are part of an extension's web extent.
955 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17956 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35957 return extension &&
958 extension->permissions_data()->HasAPIPermission(
959 APIPermission::kBackground) &&
960 process_map->Contains(extension->id(), opener_render_process_id);
961}
Kevin Marshall32f99d7e2017-07-11 23:17:46962
csharrison95f01e922017-04-24 18:52:35963#endif
964
John Abd-El-Malekd2377982018-01-08 22:23:12965chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
966 const base::Callback<content::WebContents*()>& wc_getter) {
967 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
968 auto* web_contents = wc_getter.Run();
969 if (!web_contents)
970 return nullptr;
971
972 return prerender::PrerenderContents::FromWebContents(web_contents);
973}
974
John Abd-El-Malek92bf3602019-07-31 02:25:48975void LaunchURL(const GURL& url,
976 const content::WebContents::Getter& web_contents_getter,
977 ui::PageTransition page_transition,
978 bool has_user_gesture) {
John Abd-El-Maleka67add82018-03-09 18:22:01979 // If there is no longer a WebContents, the request may have raced with tab
980 // closing. Don't fire the external request. (It may have been a prerender.)
981 content::WebContents* web_contents = web_contents_getter.Run();
982 if (!web_contents)
983 return;
984
985 // Do not launch external requests attached to unswapped prerenders.
986 prerender::PrerenderContents* prerender_contents =
987 prerender::PrerenderContents::FromWebContents(web_contents);
988 if (prerender_contents) {
989 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
990 prerender::ReportPrerenderExternalURL();
991 return;
992 }
993
Robbie McElrath1294d242019-05-31 20:46:22994 // Do not launch external requests for schemes that have a handler registered.
995 ProtocolHandlerRegistry* protocol_handler_registry =
996 ProtocolHandlerRegistryFactory::GetForBrowserContext(
997 web_contents->GetBrowserContext());
998 if (protocol_handler_registry &&
999 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1000 return;
1001
John Abd-El-Maleka67add82018-03-09 18:22:011002 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:011003 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:191004 PolicyBlacklistFactory::GetForBrowserContext(
1005 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:011006 if (service) {
1007 const policy::URLBlacklist::URLBlacklistState url_state =
1008 service->GetURLBlacklistState(url);
1009 is_whitelisted =
1010 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1011 }
1012
1013 // If the URL is in whitelist, we launch it without asking the user and
1014 // without any additional security checks. Since the URL is whitelisted,
1015 // we assume it can be executed.
1016 if (is_whitelisted) {
1017 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1018 } else {
1019 ExternalProtocolHandler::LaunchUrl(
1020 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1021 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
1022 has_user_gesture);
1023 }
1024}
1025
Yutaka Hirano968d6252018-12-04 05:09:311026std::string GetProduct() {
1027 return version_info::GetProductNameAndVersionForUserAgent();
1028}
1029
Lukasz Anforowicz60d1253d2019-05-08 16:31:371030void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1031 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1032 // For renderer and utility (e.g. NetworkService) processes the switch is the
1033 // only available source, so below the combined (pref/policy + cmdline)
1034 // allowlist of secure origins is injected into |cmdline| for these other
1035 // processes.
1036 std::vector<std::string> allowlist =
1037 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1038 if (!allowlist.empty()) {
1039 cmdline->AppendSwitchASCII(
1040 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1041 base::JoinString(allowlist, ","));
1042 }
1043}
1044
Will Harris1b9b4152019-08-21 22:33:501045#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301046// Returns the full path to |module_name|. Both dev builds (where |module_name|
1047// is in the current executable's directory) and proper installs (where
1048// |module_name| is in a versioned sub-directory of the current executable's
1049// directory) are supported. The identified file is not guaranteed to exist.
1050base::FilePath GetModulePath(base::StringPiece16 module_name) {
1051 base::FilePath exe_dir;
1052 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1053 DCHECK(has_path);
1054
1055 // Look for the module in a versioned sub-directory of the current
1056 // executable's directory and return the path if it can be read. This is the
1057 // expected location of modules for proper installs.
1058 const base::FilePath module_path =
1059 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1060 if (base::PathExists(module_path))
1061 return module_path;
1062
1063 // Otherwise, return the path to the module in the current executable's
1064 // directory. This is the expected location of modules for dev builds.
1065 return exe_dir.Append(module_name);
1066}
Will Harris1b9b4152019-08-21 22:33:501067#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1068 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301069
[email protected]9dbfff12011-07-01 19:37:071070} // namespace
[email protected]c5dbef02011-05-13 05:06:091071
Yutaka Hirano968d6252018-12-04 05:09:311072std::string GetUserAgent() {
1073 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1074 if (command_line->HasSwitch(switches::kUserAgent)) {
1075 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1076 if (net::HttpUtil::IsValidHeaderValue(ua))
1077 return ua;
1078 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1079 }
1080
John Delaneyac24e572019-04-30 19:47:021081 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1082 return content::GetFrozenUserAgent(
1083 command_line->HasSwitch(switches::kUseMobileUserAgent))
1084 .as_string();
1085 }
1086
Yutaka Hirano968d6252018-12-04 05:09:311087 std::string product = GetProduct();
1088#if defined(OS_ANDROID)
1089 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1090 product += " Mobile";
1091#endif
1092 return content::BuildUserAgentFromProduct(product);
1093}
1094
Mike West6e4cbb32019-02-13 09:40:171095blink::UserAgentMetadata GetUserAgentMetadata() {
1096 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171097 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301098 metadata.full_version = version_info::GetVersionNumber();
1099 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171100 metadata.platform = version_info::GetOSType();
1101
1102 // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces.
1103 metadata.architecture = "";
1104 metadata.model = "";
1105
1106 return metadata;
1107}
1108
Ran Jia96d43d42018-05-02 17:14:531109ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051110 StartupData* startup_data)
Wojciech Dzierżanowski45380802019-04-29 14:50:321111 : data_reduction_proxy_throttle_manager_(
1112 nullptr,
1113 base::OnTaskRunnerDeleter(nullptr)),
Jeremy Roman495db682019-07-12 16:03:241114 startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161115#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371116 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421117 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371118 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251119 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371120 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401121 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551122
1123 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401124#endif
[email protected]1deace22013-05-22 06:14:461125
Ahmed Fakhryd70bf37b2018-04-04 17:07:241126#if defined(OS_CHROMEOS)
1127 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1128#endif // defined(OS_CHROMEOS)
1129
brettw00899e62016-11-12 02:10:171130#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131131 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271132#endif
bena06f7d62017-04-04 20:48:521133
Sigurdur Asgeirsson70696672019-02-08 16:14:511134 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401135}
1136
1137ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031138 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1139 delete extra_parts_[i];
1140 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401141}
1142
[email protected]bca18382012-06-25 19:15:231143// static
Chris Palmerac7d75642017-11-22 20:12:541144void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1145 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131146 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1147 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541148 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1149 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Chris Hamilton8206aad2018-07-18 01:00:031150 registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true);
Julian Pastarmovfac28002018-02-01 11:17:451151 registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies,
1152 false);
Chris Palmerac7d75642017-11-22 20:12:541153}
1154
1155// static
[email protected]37ca3fe02013-07-05 15:32:441156void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341157 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251158 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1159 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1160 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281161 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1162 // user policy in addition to the same named ones in Local State (which are
1163 // used for mapping the command-line flags).
1164 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1165 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571166 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401167 registry->RegisterDictionaryPref(
1168 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041169 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101170#if !defined(OS_ANDROID)
1171 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561172 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101173#endif
[email protected]bca18382012-06-25 19:15:231174}
1175
[email protected]eabbfb12013-04-05 23:28:351176// static
1177void ChromeContentBrowserClient::SetApplicationLocale(
1178 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481179 // The common case is that this function is called early in Chrome startup
1180 // before any threads are created or registered. When there are no threads,
1181 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001182 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331183 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481184 return;
1185 }
1186
1187 // Otherwise we're being called to change the locale. In this case set it on
1188 // the IO thread.
thestig00844cea2015-09-08 21:44:521189 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351190
Sami Kyostila5e1306d2019-08-14 11:01:291191 base::PostTask(FROM_HERE, {BrowserThread::IO},
1192 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351193}
1194
Patrick Monette61dfef92019-05-30 23:06:271195std::unique_ptr<content::BrowserMainParts>
1196ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311197 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271198 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301199 // Construct the Main browser parts based on the OS type.
1200#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051201 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271202 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1203#elif defined(OS_MACOSX)
1204 main_parts =
1205 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1206#elif defined(OS_CHROMEOS)
1207 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1208 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261209#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271210 main_parts =
1211 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141212#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271213 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1214 startup_data_);
[email protected]b48c9182011-10-26 18:03:301215#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271216 main_parts =
1217 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041218#else
[email protected]b48c9182011-10-26 18:03:301219 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271220 main_parts =
1221 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301222#endif
1223
Xi Han9fd44002019-04-30 17:39:361224 bool add_profiles_extra_parts = true;
1225#if defined(OS_ANDROID)
1226 if (startup_data_->HasBuiltProfilePrefService())
1227 add_profiles_extra_parts = false;
1228#endif
1229 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271230 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031231
Xi Han9fd44002019-04-30 17:39:361232 // Construct additional browser parts. Stages are called in the order in
1233 // which they are added.
[email protected]c7480942011-11-08 19:18:271234#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221235#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1236#if defined(USE_X11)
1237 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1238#else
estaded3aa0e82016-02-17 22:55:211239 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221240#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211241#else
riajiang7d6ec5c2017-01-25 16:40:331242 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351243#endif
1244#endif
1245
1246#if defined(OS_CHROMEOS)
1247 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331248 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221249#endif
[email protected]dc04be7c2012-03-15 23:57:491250
[email protected]e8b6ca02013-07-10 18:00:511251#if defined(USE_X11)
1252 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241253#endif
1254
Sigurdur Asgeirsson54b72702019-04-12 14:18:541255 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001256
Albert J. Wong59d85acb2017-08-10 00:50:571257 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571258
Patrick Monette61dfef92019-05-30 23:06:271259 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041260
[email protected]50462bf02011-11-21 19:13:311261 return main_parts;
[email protected]f967b722011-09-07 00:58:041262}
1263
michaeln96f887e22015-04-13 23:58:311264void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091265 const base::Location& from_here,
michaeln96f887e22015-04-13 23:58:311266 const scoped_refptr<base::TaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211267 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121268 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291269
Robert Sesek466e43e2019-08-19 22:02:021270 InitNetworkContextsParentDirectory();
1271
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291272 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1273 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311274}
1275
falkenb09d443f2016-04-07 12:36:121276bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1277 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1278}
1279
Gabriel Charettec8cca992017-08-10 18:21:491280void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1281 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1282}
1283
John Abd-El-Malek9d57f9c2019-02-20 18:50:041284bool ChromeContentBrowserClient::IsShuttingDown() {
1285 return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID;
1286}
1287
[email protected]e94bbcb2012-09-07 05:33:571288std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191289 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571290 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531291 std::string partition_id;
1292
1293 // The partition ID for webview guest processes is the string value of its
1294 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451295 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531296 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171297#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501298 // The partition ID for extensions with isolated storage is treated similarly
1299 // to the above.
1300 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1301 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1302 partition_id = site.spec();
1303#endif
[email protected]1bc28312012-11-08 08:31:531304
[email protected]056efdc2013-04-06 00:14:531305 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531306 return partition_id;
1307}
1308
1309bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1310 content::BrowserContext* browser_context,
1311 const std::string& partition_id) {
1312 // The default ID is empty and is always valid.
1313 if (partition_id.empty())
1314 return true;
1315
1316 return GURL(partition_id).is_valid();
1317}
1318
1319void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1320 content::BrowserContext* browser_context,
1321 const GURL& site,
[email protected]14acc642012-11-17 12:20:101322 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531323 std::string* partition_domain,
1324 std::string* partition_name,
1325 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101326 // Default to the browser-wide storage partition and override based on |site|
1327 // below.
1328 partition_domain->clear();
1329 partition_name->clear();
1330 *in_memory = false;
1331
brettw00899e62016-11-12 02:10:171332#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451333 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331334 site, partition_domain, partition_name, in_memory);
1335
1336 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101337 // If |can_be_default| is false, the caller is stating that the |site|
1338 // should be parsed as if it had isolated storage. In particular it is
1339 // important to NOT check ExtensionService for the is_storage_isolated()
1340 // attribute because this code path is run during Extension uninstall
1341 // to do cleanup after the Extension has already been unloaded from the
1342 // ExtensionService.
1343 bool is_isolated = !can_be_default;
1344 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341345 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1346 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101347 }
[email protected]1bc28312012-11-08 08:31:531348
[email protected]14acc642012-11-17 12:20:101349 if (is_isolated) {
1350 CHECK(site.has_host());
1351 // For extensions with isolated storage, the the host of the |site| is
1352 // the |partition_domain|. The |in_memory| and |partition_name| are only
1353 // used in guest schemes so they are cleared here.
1354 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531355 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101356 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531357 }
[email protected]1df3d972014-06-11 04:55:181358 success = true;
1359 }
1360#endif
1361
[email protected]14acc642012-11-17 12:20:101362 // Assert that if |can_be_default| is false, the code above must have found a
1363 // non-default partition. If this fails, the caller has a serious logic
1364 // error about which StoragePartition they expect to be in and it is not
1365 // safe to continue.
1366 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441367}
1368
[email protected]38b098f2012-03-14 21:11:571369content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441370ChromeContentBrowserClient::GetWebContentsViewDelegate(
1371 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101372 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321373}
1374
Bo Liu4ade6b1b22017-11-28 02:26:351375bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1376#if defined(OS_ANDROID)
1377 const base::android::ApplicationState app_state =
1378 base::android::ApplicationStatusListener::GetState();
1379 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1380 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1381 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1382#else
1383 return true;
1384#endif
1385}
1386
[email protected]6f2862742013-12-20 07:53:191387void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231388 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301389 int id = host->GetID();
1390 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
horo062ef5352017-03-29 08:16:071391 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
thakis678822e2017-04-20 17:20:341392#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491393 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061394#endif
Brett Wilson65f951c2016-11-03 22:06:121395#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401396 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031397#endif
[email protected]ba780c12013-10-01 17:07:061398 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
Darin Fisher8c84328c2019-07-23 02:50:001399
Darin Fisher09aa7222019-08-29 09:27:361400 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001401 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021402
grunell086a4112017-03-02 09:23:041403 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1404 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021405 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121406 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021407 host->SetUserData(
1408 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091409 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021410 audio_debug_recordings_handler));
1411
Nico Weberaf3b00b2017-09-11 17:58:171412#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031413 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1414 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351415#endif
jeremyim364ac1182015-03-03 18:49:431416
Xiaohan Wang9b34281b2017-09-08 23:48:331417#if defined(OS_ANDROID)
1418 // Data cannot be persisted if the profile is off the record.
1419 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061420 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071421
1422 // Register CrashMemoryMetricsCollector to report oom related metrics.
1423 host->SetUserData(
1424 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1425 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331426#endif
1427
Jun Caidb3f93cc2018-07-09 21:54:551428 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061429 RendererUpdaterFactory::GetForProfile(original_profile)
1430 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071431
[email protected]a48ab7112014-08-01 16:48:031432 for (size_t i = 0; i < extra_parts_.size(); ++i)
1433 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141434}
1435
[email protected]3d7474ff2011-07-27 17:47:371436GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571437 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301438 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371439 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521440 if (!profile)
1441 return url;
1442
Marc Treib7d467b792017-12-04 13:31:031443#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291444 // If the input |url| should be assigned to the Instant renderer, make its
1445 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311446 // This needs to happen even if |url| corresponds to an isolated origin; see
1447 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131448 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1449 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031450#endif
[email protected]b3cb3a32013-07-31 01:32:291451
brettw00899e62016-11-12 02:10:171452#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301453 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1454 url);
[email protected]d5a74be2014-08-08 01:01:271455#else
1456 return url;
1457#endif
[email protected]36fb2c7c2011-04-04 15:49:081458}
1459
Alexander Yashkin6aedc6e2018-08-15 08:58:451460bool ChromeContentBrowserClient::
1461 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1462 content::BrowserContext* browser_context,
1463 content::SiteInstance* candidate_site_instance,
1464 bool is_main_frame,
1465 const GURL& candidate_url,
1466 const GURL& destination_url) {
1467 DCHECK(browser_context);
1468 DCHECK(candidate_site_instance);
1469#if BUILDFLAG(ENABLE_EXTENSIONS)
1470 return ChromeContentBrowserClientExtensionsPart::
1471 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1472 browser_context, candidate_site_instance, is_main_frame,
1473 candidate_url, destination_url);
1474#else
1475 return true;
1476#endif
1477}
1478
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521479bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411480#if defined(OS_ANDROID)
1481 return true;
1482#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421483 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411484#else
1485 return false;
1486#endif // defined(OS_ANDROID)
1487}
1488
[email protected]056ad2a2011-07-12 02:13:551489bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441490 content::BrowserContext* browser_context,
1491 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521492 Profile* profile = Profile::FromBrowserContext(browser_context);
1493 if (!profile)
1494 return false;
1495
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301496 // NTP should use process-per-site. This is a performance optimization to
1497 // reduce process count associated with NTP tabs.
1498 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1499 return true;
Peter Boström8e9b1632019-08-22 23:12:471500
1501 // The web footer experiment should share its renderer to not effectively
1502 // instantiate one per window. See https://crbug.com/993502.
1503 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1504 return true;
1505
Marc Treib7d467b792017-12-04 13:31:031506#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131507 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521508 return true;
Marc Treib7d467b792017-12-04 13:31:031509#endif
[email protected]c5dec6292013-01-25 04:54:521510
brettw00899e62016-11-12 02:10:171511#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301512 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1513 profile, effective_url))
1514 return true;
[email protected]d5a74be2014-08-08 01:01:271515#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301516
1517 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1518 // (rather than process-per-site).
1519 return false;
[email protected]056ad2a2011-07-12 02:13:551520}
1521
Lukasz Anforowicz32d27122018-04-09 21:48:331522bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1523 content::BrowserContext* browser_context,
1524 const GURL& site_url) {
1525 Profile* profile = Profile::FromBrowserContext(browser_context);
1526 if (!profile)
1527 return false;
1528
1529#if !defined(OS_ANDROID)
1530 // Instant renderers should not use a spare process, because they require
1531 // passing switches::kInstantProcess to the renderer process when it
1532 // launches. A spare process is launched earlier, before it is known which
1533 // navigation will use it, so it lacks this flag.
1534 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1535 return false;
1536#endif
1537
1538#if BUILDFLAG(ENABLE_EXTENSIONS)
1539 return ChromeContentBrowserClientExtensionsPart::
1540 ShouldUseSpareRenderProcessHost(profile, site_url);
1541#else
1542 return true;
1543#endif
1544}
1545
nickcc0d9142015-10-14 16:27:101546bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421547 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101548 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421549 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171550#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101551 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421552 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101553 return true;
1554 }
1555#endif
1556 return false;
1557}
1558
nick7d0984c2015-08-29 00:13:461559// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1560// origin-lock enforcement, where we don't have a way to efficiently know
1561// effective URLs on the IO thread, and wind up killing processes that e.g.
1562// request cookies for their actual URL. This whole function (and its
1563// ExtensionsPart) should be removed once we add that ability to the IO thread.
1564bool ChromeContentBrowserClient::ShouldLockToOrigin(
1565 content::BrowserContext* browser_context,
1566 const GURL& effective_site_url) {
1567 // Origin lock to the search scheme would kill processes upon legitimate
1568 // requests for cookies from the search engine's domain.
1569 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1570 return false;
1571
brettw00899e62016-11-12 02:10:171572#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461573 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1574 browser_context, effective_site_url)) {
1575 return false;
1576 }
1577#endif
1578 return true;
creise5d6d1732015-08-25 19:47:061579}
1580
Lukasz Anforowicz05f356e2018-03-13 20:26:111581const char*
Lukasz Anforowiczce869f0b2018-08-06 18:33:371582ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() {
Charles Reis358baf472017-12-06 05:30:431583#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz05f356e2018-03-13 20:26:111584 // Don't block responses for extension processes or for content scripts.
1585 // TODO(creis): When every extension fetch (including content scripts) has
1586 // been made to go through an extension-specific URLLoaderFactory, this
1587 // mechanism ought to work by enumerating the host permissions from the
1588 // extension manifest, and forwarding them on to the network service while
1589 // brokering the URLLoaderFactory.
1590 return extensions::kExtensionScheme;
1591#else
1592 return nullptr;
Charles Reis358baf472017-12-06 05:30:431593#endif
Charles Reis358baf472017-12-06 05:30:431594}
1595
Maks Orlovich0e23e312019-07-16 13:13:561596bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
1597 base::StringPiece scheme) {
1598#if BUILDFLAG(ENABLE_EXTENSIONS)
1599 return scheme == extensions::kExtensionScheme;
1600#else
1601 return false;
1602#endif
1603}
1604
Lukasz Anforowicz2f810162018-10-03 21:38:071605network::mojom::URLLoaderFactoryPtrInfo
1606ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests(
1607 content::RenderProcessHost* process,
1608 network::mojom::NetworkContext* network_context,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:181609 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
1610 header_client,
Yao Xiaoc85cf0a2019-09-25 23:35:421611 const url::Origin& request_initiator,
1612 const base::Optional<net::NetworkIsolationKey>& network_isolation_key) {
Lukasz Anforowicz2f810162018-10-03 21:38:071613#if BUILDFLAG(ENABLE_EXTENSIONS)
1614 return ChromeContentBrowserClientExtensionsPart::
Yao Xiaoc85cf0a2019-09-25 23:35:421615 CreateURLLoaderFactoryForNetworkRequests(process, network_context,
1616 header_client, request_initiator,
1617 network_isolation_key);
Lukasz Anforowicz2f810162018-10-03 21:38:071618#else
1619 return network::mojom::URLLoaderFactoryPtrInfo();
1620#endif
1621}
1622
[email protected]73b718f2014-01-27 02:59:461623// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1624// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411625void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1626 std::vector<std::string>* additional_schemes) {
1627 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241628 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351629 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061630}
1631
alexmos94875b3b2017-03-16 22:19:011632void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1633 std::vector<std::string>* additional_schemes) {
1634 GetAdditionalWebUISchemes(additional_schemes);
1635
1636#if BUILDFLAG(ENABLE_EXTENSIONS)
1637 additional_schemes->push_back(extensions::kExtensionScheme);
1638#endif
1639}
1640
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521641bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011642 return webui::LogWebUIUrl(web_ui_url);
1643}
1644
John Abd-El-Malek04bfa8532018-07-12 05:28:221645bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1646 const url::Origin& origin) {
1647 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1648 origin);
1649}
1650
[email protected]46fb9442011-12-09 17:57:471651bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1652 return ProfileIOData::IsHandledURL(url);
1653}
1654
[email protected]c4365fa42013-05-14 01:08:241655bool ChromeContentBrowserClient::CanCommitURL(
1656 content::RenderProcessHost* process_host,
1657 const GURL& url) {
brettw00899e62016-11-12 02:10:171658#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441659 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1660 url);
[email protected]d5a74be2014-08-08 01:01:271661#else
1662 return true;
1663#endif
[email protected]c4365fa42013-05-14 01:08:241664}
1665
[email protected]9a60d1602013-09-11 04:09:121666bool ChromeContentBrowserClient::ShouldAllowOpenURL(
Aran Gilmanf010bdd2019-08-28 19:55:441667 content::SiteInstance* site_instance,
1668 const GURL& url) {
[email protected]879816a92014-04-29 00:53:541669 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1670 // the signin page may host untrusted web content.
alexmos1c3da4f2016-11-03 06:06:111671 GURL from_url = site_instance->GetSiteURL();
[email protected]879816a92014-04-29 00:53:541672 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
1673 url.SchemeIs(content::kChromeUIScheme) &&
brettwb65cd5c2016-01-23 00:46:381674 url.host_piece() != chrome::kChromeUIChromeSigninHost) {
[email protected]879816a92014-04-29 00:53:541675 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
1676 << chrome::kChromeUIChromeSigninURL;
1677 return false;
1678 }
1679
[email protected]9a60d1602013-09-11 04:09:121680 return true;
1681}
1682
rdevlin.cronina32a0902016-11-09 15:50:201683void ChromeContentBrowserClient::OverrideNavigationParams(
1684 SiteInstance* site_instance,
1685 ui::PageTransition* transition,
1686 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581687 content::Referrer* referrer,
1688 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201689 DCHECK(transition);
1690 DCHECK(is_renderer_initiated);
1691 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471692 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1693 // use for making security decisions 99.44% of the time, for detecting the NTP
1694 // it is reliable and the correct way. See http://crbug.com/624410.
1695 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201696 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581697 // Clicks on tiles of the new tab page should be treated as if a user
1698 // clicked on a bookmark. This is consistent with native implementations
1699 // like Android's. This also helps ensure that security features (like
1700 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1701 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201702 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1703 *is_renderer_initiated = false;
1704 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581705 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421706 }
rdevlin.cronina32a0902016-11-09 15:50:201707
brettw00899e62016-11-12 02:10:171708#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.cronina32a0902016-11-09 15:50:201709 ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams(
Lukasz Anforowicz63f3b9432019-05-30 05:42:581710 site_instance, transition, is_renderer_initiated, referrer,
1711 initiator_origin);
rdevlin.cronina32a0902016-11-09 15:50:201712#endif
mastiza77db6992016-06-30 09:48:421713}
1714
Charles Reis29e9dd12017-09-28 00:59:151715bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1716 const GURL& url,
1717 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471718 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1719 // use for making security decisions 99.44% of the time, for detecting the NTP
1720 // it is reliable and the correct way. See http://crbug.com/624410.
1721 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1722 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151723}
1724
[email protected]2a5221b2011-09-27 23:07:311725bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301726 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311727 const GURL& site_url) {
1728 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301729 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441730 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521731 // share any host.
1732 if (!profile)
1733 return true;
1734
Marc Treib7895941d2017-11-28 12:37:021735#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141736 // Instant URLs should only be in the instant process and instant process
1737 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521738 InstantService* instant_service =
1739 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141740 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441741 bool is_instant_process =
1742 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141743 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131744 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141745 if (is_instant_process || should_be_in_instant_process)
1746 return is_instant_process && should_be_in_instant_process;
1747 }
Marc Treib7895941d2017-11-28 12:37:021748#endif
[email protected]c5dec6292013-01-25 04:54:521749
brettw00899e62016-11-12 02:10:171750#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131751 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1752 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271753#else
1754 return true;
1755#endif
[email protected]2a5221b2011-09-27 23:07:311756}
1757
[email protected]28c5d0b72014-05-13 08:19:591758bool ChromeContentBrowserClient::MayReuseHost(
1759 content::RenderProcessHost* process_host) {
1760 // If there is currently a prerender in progress for the host provided,
1761 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041762 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591763 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371764 prerender::PrerenderManagerFactory::GetForBrowserContext(
1765 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591766 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491767 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591768 return false;
1769 }
1770
1771 return true;
1772}
1773
[email protected]76411f412012-02-22 18:56:061774bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441775 content::BrowserContext* browser_context,
1776 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061777 // It has to be a valid URL for us to check for an extension.
1778 if (!url.is_valid())
1779 return false;
1780
brettw00899e62016-11-12 02:10:171781#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061782 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131783 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441784 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271785#else
1786 return false;
1787#endif
[email protected]76411f412012-02-22 18:56:061788}
1789
Alex Moshchuk9c9e3882018-11-02 19:57:031790bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1791 content::RenderFrameHost* main_frame) {
1792#if BUILDFLAG(ENABLE_EXTENSIONS)
1793 return ChromeContentBrowserClientExtensionsPart::
1794 ShouldSubframesTryToReuseExistingProcess(main_frame);
1795#else
1796 return true;
1797#endif
1798}
1799
[email protected]6f371442011-11-09 06:45:461800void ChromeContentBrowserClient::SiteInstanceGotProcess(
1801 SiteInstance* site_instance) {
1802 CHECK(site_instance->HasProcess());
1803
Aran Gilmanf010bdd2019-08-28 19:55:441804 Profile* profile =
1805 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521806 if (!profile)
1807 return;
1808
Marc Treib7895941d2017-11-28 12:37:021809#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521810 // Remember the ID of the Instant process to signal the renderer process
1811 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131812 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1813 profile)) {
[email protected]c5dec6292013-01-25 04:54:521814 InstantService* instant_service =
1815 InstantServiceFactory::GetForProfile(profile);
1816 if (instant_service)
1817 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1818 }
Marc Treib7895941d2017-11-28 12:37:021819#endif
[email protected]c5dec6292013-01-25 04:54:521820
[email protected]a48ab7112014-08-01 16:48:031821 for (size_t i = 0; i < extra_parts_.size(); ++i)
1822 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461823}
1824
1825void ChromeContentBrowserClient::SiteInstanceDeleting(
1826 SiteInstance* site_instance) {
1827 if (!site_instance->HasProcess())
1828 return;
1829
[email protected]a48ab7112014-08-01 16:48:031830 for (size_t i = 0; i < extra_parts_.size(); ++i)
1831 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461832}
1833
[email protected]453f5432013-11-26 19:43:001834bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141835 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081836 const GURL& current_url,
1837 const GURL& new_url) {
brettw00899e62016-11-12 02:10:171838#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131839 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441840 ShouldSwapBrowsingInstancesForNavigation(site_instance, current_url,
1841 new_url);
[email protected]d5a74be2014-08-08 01:01:271842#else
1843 return false;
1844#endif
[email protected]e3daf3c2011-10-05 21:17:081845}
1846
Nasko Oskovd83b5712018-05-04 04:50:571847bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1848 // TODO(nasko): Consider supporting error page isolation in subframes if
1849 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381850 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571851}
1852
[email protected]3d831992013-07-04 01:13:291853bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1854 return !url.SchemeIs(chrome::kChromeNativeScheme);
1855}
1856
Alex Moshchukd252c192017-07-17 22:03:481857std::vector<url::Origin>
1858ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1859 std::vector<url::Origin> isolated_origin_list;
1860
Alex Moshchuk89352a72017-10-25 20:25:591861// Sign-in process isolation is not needed on Android, see
1862// https://crbug.com/739418.
1863#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381864 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121865 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591866#endif
Alex Moshchukd252c192017-07-17 22:03:481867
Alex Moshchuk81d2a29e2019-07-16 01:14:381868#if BUILDFLAG(ENABLE_EXTENSIONS)
1869 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1870 GetOriginsRequiringDedicatedProcess();
1871 std::move(std::begin(origins_from_extensions),
1872 std::end(origins_from_extensions),
1873 std::back_inserter(isolated_origin_list));
1874#endif
1875
Alex Moshchukd252c192017-07-17 22:03:481876 return isolated_origin_list;
1877}
1878
Lukasz Anforowicz5e201abd2018-03-24 00:41:061879bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341880 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1881}
1882
1883bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Lukasz Anforowicz0711a0f2019-03-28 18:15:311884 // Using 1077 rather than 1024 because 1) it helps ensure that devices with
1885 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one
1886 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2.
1887 // See also https://crbug.com/844118.
1888 constexpr int kDefaultMemoryThresholdMb = 1077;
Aaron Colwell25617f72018-11-27 20:56:341889
1890 // TODO(acolwell): Rename feature since it now affects more than just the
1891 // site-per-process case.
Lukasz Anforowicz46275d92018-04-12 14:57:381892 if (base::FeatureList::IsEnabled(
1893 features::kSitePerProcessOnlyForHighMemoryClients)) {
Lukasz Anforowicz46275d92018-04-12 14:57:381894 int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
1895 features::kSitePerProcessOnlyForHighMemoryClients,
1896 features::kSitePerProcessOnlyForHighMemoryClientsParamName,
1897 kDefaultMemoryThresholdMb);
Aaron Colwell25617f72018-11-27 20:56:341898 return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb;
Lukasz Anforowicz46275d92018-04-12 14:57:381899 }
1900
Aaron Colwell25617f72018-11-27 20:56:341901#if defined(OS_ANDROID)
1902 if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) {
1903 return true;
1904 }
1905#endif
1906
1907 return false;
Lukasz Anforowicz5e201abd2018-03-24 00:41:061908}
1909
Alex Moshchuk082b5f82019-03-14 01:34:161910std::vector<std::string>
1911ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1912 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1913 return {"Isolate Password Sites"};
1914 else
1915 return {};
1916}
1917
Alex Moshchuke256d562019-04-26 21:43:571918void ChromeContentBrowserClient::PersistIsolatedOrigin(
1919 content::BrowserContext* context,
1920 const url::Origin& origin) {
1921 DCHECK(!context->IsOffTheRecord());
1922 Profile* profile = Profile::FromBrowserContext(context);
1923 ListPrefUpdate update(profile->GetPrefs(),
1924 prefs::kUserTriggeredIsolatedOrigins);
1925 base::ListValue* list = update.Get();
1926 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361927 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121928 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571929}
1930
Ken Rockot314714c2017-11-05 23:36:241931bool ChromeContentBrowserClient::IsFileAccessAllowed(
1932 const base::FilePath& path,
1933 const base::FilePath& absolute_path,
1934 const base::FilePath& profile_path) {
1935 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1936 profile_path);
1937}
1938
[email protected]d2e1a0a2014-06-16 15:49:371939namespace {
1940
1941bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171942 const base::CommandLine& browser_command_line =
1943 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351944 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371945 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351946 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371947 return false;
[email protected]9ef49b42014-08-07 16:44:241948 return true;
[email protected]d2e1a0a2014-06-16 15:49:371949}
1950
bmcquade5d2d9cf32015-06-19 17:42:281951void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1952 const base::CommandLine& browser_command_line,
1953 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521954 // List of field trials that modify the blink-settings command line flag. No
1955 // two field trials in the list should specify the same keys, otherwise one
1956 // field trial may overwrite another. See Source/core/frame/Settings.in in
1957 // Blink for the list of valid keys.
1958 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161959 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1960 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1961 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1962 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521963 };
1964
1965 std::vector<std::string> blink_settings;
1966 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1967 // Each blink-settings field trial should include a forcing_flag group,
1968 // to make sure that clients that specify the blink-settings flag on the
1969 // command line are excluded from the experiment groups. To make
1970 // sure we assign clients that specify this flag to the forcing_flag
1971 // group, we must call GetVariationParams for each field trial first
1972 // (for example, before checking HasSwitch() and returning), since
1973 // GetVariationParams has the side-effect of assigning the client to
1974 // a field trial group.
1975 std::map<std::string, std::string> params;
1976 if (variations::GetVariationParams(field_trial_name, &params)) {
1977 for (const auto& param : params) {
1978 blink_settings.push_back(base::StringPrintf(
1979 "%s=%s", param.first.c_str(), param.second.c_str()));
1980 }
1981 }
1982 }
pmeenan9ac669682015-08-17 14:57:031983
bmcquade9dd54cc2015-06-22 16:56:521984 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281985 return;
1986 }
1987
1988 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1989 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031990 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521991 // blink-settings flag into a group with no params, and we return
1992 // above if no params were specified, so it's an error if we reach
1993 // this point.
bmcquade5d2d9cf32015-06-19 17:42:281994 LOG(WARNING) << "Received field trial params, "
1995 "but blink-settings switch already specified.";
1996 return;
1997 }
1998
bmcquade5d2d9cf32015-06-19 17:42:281999 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262000 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282001}
2002
zpengdb4a58e2017-01-10 17:40:322003#if defined(OS_ANDROID)
Ben Goodger6a695c012017-06-20 20:21:202004template <typename Interface>
Aran Gilmanf010bdd2019-08-28 19:55:442005void ForwardToJavaFrameRegistry(mojo::InterfaceRequest<Interface> request,
2006 content::RenderFrameHost* render_frame_host) {
Ben Goodger6a695c012017-06-20 20:21:202007 render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request));
mgiuca3d9a1962017-04-07 05:25:442008}
2009
Ben Goodger6a695c012017-06-20 20:21:202010template <typename Interface>
2011void ForwardToJavaWebContentsRegistry(
Ben Goodger6a695c012017-06-20 20:21:202012 mojo::InterfaceRequest<Interface> request,
2013 content::RenderFrameHost* render_frame_host) {
2014 content::WebContents* contents =
2015 content::WebContents::FromRenderFrameHost(render_frame_host);
2016 if (contents)
2017 contents->GetJavaInterfaces()->GetInterface(std::move(request));
sammc0285a442016-10-04 23:03:562018}
2019#endif
2020
[email protected]d2e1a0a2014-06-16 15:49:372021} // namespace
2022
[email protected]b80f68432011-05-02 17:22:302023void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172024 base::CommandLine* command_line,
2025 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062026#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352027 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062028 GoogleUpdateSettings::LoadMetricsClientInfo();
2029 if (client_info) {
2030 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2031 client_info->client_id);
2032 }
2033#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022034#if defined(OS_ANDROID)
2035 bool enable_crash_reporter = true;
2036#else
Joshua Perazace68e2f2019-09-23 18:44:242037 bool enable_crash_reporter = false;
2038 if (crash_reporter::IsCrashpadEnabled()) {
2039 command_line->AppendSwitch(crash_reporter::kEnableCrashpad);
2040 enable_crash_reporter = true;
2041
2042 int fd;
2043 pid_t pid;
2044 if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
2045 command_line->AppendSwitchASCII(
2046 crash_reporter::switches::kCrashpadHandlerPid,
2047 base::NumberToString(pid));
2048 }
2049 } else {
2050 enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2051 }
Joshua Perazaf890e4b2019-01-03 19:19:022052#endif
2053 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512054 std::string switch_value;
dcheng4af48582016-04-19 00:29:352055 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532056 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512057 if (client_info)
2058 switch_value = client_info->client_id;
2059 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252060 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302061 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512062 switch_value);
[email protected]b80f68432011-05-02 17:22:302063 }
Mark Mentovaic67fa64f2015-03-24 14:00:062064#endif
[email protected]b80f68432011-05-02 17:22:302065
[email protected]f1933792011-06-14 00:49:342066 if (logging::DialogsAreSuppressed())
2067 command_line->AppendSwitch(switches::kNoErrorDialogs);
2068
[email protected]b80f68432011-05-02 17:22:302069 std::string process_type =
2070 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172071 const base::CommandLine& browser_command_line =
2072 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322073
[email protected]7c9b6f92013-09-10 18:11:352074 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442075 switches::kUserAgent,
2076 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352077 };
2078 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372079 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322080
fqj15ff3f72015-10-09 19:20:022081 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432082 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312083 };
fqj15ff3f72015-10-09 19:20:022084 command_line->CopySwitchesFrom(browser_command_line,
2085 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372086 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312087
fqj15ff3f72015-10-09 19:20:022088#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332089 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2090 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522091 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332092 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2093 homedir.value().c_str());
2094#endif
2095
[email protected]718eab62011-10-05 21:16:522096 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032097 content::RenderProcessHost* process =
2098 content::RenderProcessHost::FromID(child_process_id);
2099 Profile* profile =
2100 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442101 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032102 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442103 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2104 process, profile);
[email protected]a48ab7112014-08-01 16:48:032105 }
2106
[email protected]b80f68432011-05-02 17:22:302107#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442108 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2109 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302110 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442111 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2112 login_profile);
[email protected]b80f68432011-05-02 17:22:302113#endif
2114
Aran Gilmanf010bdd2019-08-28 19:55:442115 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222116 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372117 if (process) {
[email protected]a8d851f82011-12-21 00:32:372118 PrefService* prefs = profile->GetPrefs();
2119 // Currently this pref is only registered if applied via a policy.
2120 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2121 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2122 // Turn this policy into a command line switch.
2123 command_line->AppendSwitch(switches::kDisable3DAPIs);
2124 }
[email protected]718eab62011-10-05 21:16:522125
[email protected]1733b782014-06-19 18:51:552126 const base::ListValue* switches =
2127 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2128 if (switches) {
2129 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112130 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552131 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142132 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552133 command_line->AppendSwitch(switch_to_enable);
2134 }
2135 }
2136
[email protected]a8d851f82011-12-21 00:32:372137 // Disable client-side phishing detection in the renderer if it is
2138 // disabled in the Profile preferences or the browser process.
2139 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2140 !g_browser_process->safe_browsing_detection_service()) {
2141 command_line->AppendSwitch(
2142 switches::kDisableClientSidePhishingDetection);
2143 }
[email protected]0045b0f42012-07-26 11:52:082144
vitalybukaa7ae5052014-09-26 04:11:132145 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2146 command_line->AppendSwitch(switches::kDisablePrintPreview);
2147
Marc Treib7895941d2017-11-28 12:37:022148#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522149 InstantService* instant_service =
2150 InstantServiceFactory::GetForProfile(profile);
2151 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542152 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522153 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542154 }
Marc Treib7895941d2017-11-28 12:37:022155#endif
fqjba8749c2015-10-29 15:33:072156
fqj38306f7b2015-11-02 16:59:062157 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542158 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432159 command_line->AppendSwitch(
2160 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542161 }
Daniel Vogelheim976f1c22017-11-22 16:26:032162
Lukasz Anforowicz60d1253d2019-05-08 16:31:372163 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2164
Amr Aboelkherb04cbf32019-04-29 15:17:102165 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2166 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292167 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102168 }
Katie Dillonc25ee5c92019-09-12 17:05:422169
2170 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2171 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2172 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2173 }
[email protected]47c7ec82012-01-18 03:29:212174 }
[email protected]4287a3d2011-06-13 23:56:512175
[email protected]d2e1a0a2014-06-16 15:49:372176 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352177 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042178
Aran Gilmanf010bdd2019-08-28 19:55:442179 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2180 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282181
mdjonesa6b9e172016-09-23 16:24:302182#if defined(OS_ANDROID)
2183 // If the platform is Android, force the distillability service on.
2184 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2185#endif
2186
[email protected]47c7ec82012-01-18 03:29:212187 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512188 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192189 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412190 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302191#if defined(OS_CHROMEOS)
2192 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2193#endif
brettw00899e62016-11-12 02:10:172194#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512195 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272196 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172197 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512198 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272199 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172200 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172201 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282202#endif
estark4b003b332015-02-14 01:07:052203 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512204 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482205 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512206 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502207 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572208 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462209 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302210 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512211 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172212#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242213 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482214 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552215#endif
[email protected]ce304ce2013-02-22 21:54:452216 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172217#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592218 switches::kForcePNaClSubzero,
2219#endif
Marc Treibad33cf942017-08-24 11:19:002220 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512221 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102222 switches::kEnableExperimentalWebAssemblyFeatures,
iclelland79237e92016-06-23 12:03:512223 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552224 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022225 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512226 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512227 switches::kPpapiFlashPath,
2228 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032229 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092230 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512231 };
2232
2233 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372234 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172235 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172236#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382237 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442238 extensions::switches::kAllowHTTPBackgroundPage,
2239 extensions::switches::kEnableExperimentalExtensionApis,
2240 extensions::switches::kExtensionsOnChromeURLs,
2241 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382242 };
2243
2244 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372245 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282246#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372247 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132248 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512249 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512250 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502251 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172252#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242253 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582254 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592255 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412256 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552257#endif
[email protected]4287a3d2011-06-13 23:56:512258 switches::kPpapiFlashPath,
2259 switches::kPpapiFlashVersion,
2260 };
2261
2262 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372263 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112264 } else if (process_type == switches::kGpuProcess) {
2265 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2266 // because GPU is expected to be unreliable.
2267 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2268 !command_line->HasSwitch(switches::kDisableBreakpad))
2269 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302270 }
[email protected]6f08af82011-09-15 01:19:032271
Ian Barkley-Yeung550aae052019-07-11 00:11:112272#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302273 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112274 static const char* const kSwitchNames[] = {
2275 switches::kCrashLoopBefore,
2276 };
2277 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2278 base::size(kSwitchNames));
2279 }
2280#endif
2281
wittman832321f52016-10-10 18:18:382282 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442283 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342284
2285#if defined(OS_LINUX)
2286 // Processes may only query perf_event_open with the BPF sandbox disabled.
2287 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2288 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2289 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2290 }
2291#endif
[email protected]b80f68432011-05-02 17:22:302292}
2293
Scott Violet776edf82017-09-29 02:03:012294void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
2295 const service_manager::Identity& identity,
2296 base::CommandLine* command_line) {
Guido Urdaneta191635e2018-05-09 16:00:532297#if defined(OS_MACOSX)
Ken Rockot2f8c1dd22019-07-23 21:56:022298 // On Mac, the audio service requires a CFRunLoop, provided by a UI message
2299 // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581.
2300 if (identity.name() == audio::mojom::kServiceName)
Guido Urdaneta191635e2018-05-09 16:00:532301 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2302#endif
Scott Violet776edf82017-09-29 02:03:012303}
2304
Olivier Yiptong0daa93f2019-08-22 19:40:082305std::string
2306ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2307 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2308}
2309
[email protected]b80f68432011-05-02 17:22:302310std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432311 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332312 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302313 return g_browser_process->GetApplicationLocale();
2314}
2315
[email protected]597a867b2011-11-18 18:31:202316std::string ChromeContentBrowserClient::GetAcceptLangs(
2317 content::BrowserContext* context) {
2318 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202319 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082320}
2321
Dana Fried34d580002019-04-24 20:05:482322gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492323 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482324 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082325}
2326
bengre8a146f2016-03-10 01:20:222327bool ChromeContentBrowserClient::IsDataSaverEnabled(
2328 content::BrowserContext* browser_context) {
Robert Ogdenc995d4fe2019-03-25 19:18:372329 Profile* profile = Profile::FromBrowserContext(browser_context);
2330 return profile && data_reduction_proxy::DataReductionProxySettings::
2331 IsDataSaverEnabledByUser(profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222332}
2333
Kenichi Ishibashi46329872018-07-17 09:43:402334void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2335 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192336 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402337 DCHECK(browser_context);
2338 DCHECK(out_prefs);
2339 renderer_preferences_util::UpdateFromSystemSettings(
2340 out_prefs, Profile::FromBrowserContext(browser_context));
2341}
2342
Clark DuVall5690e742019-07-17 18:26:172343bool ChromeContentBrowserClient::AllowAppCache(
2344 const GURL& manifest_url,
2345 const GURL& first_party,
2346 content::BrowserContext* context) {
2347 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2348 return CookieSettingsFactory::GetForProfile(
2349 Profile::FromBrowserContext(context))
2350 ->IsCookieAccessAllowed(manifest_url, first_party);
2351}
2352
Matt Falkenhagen7b509e52019-08-15 23:11:412353bool ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072354 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542355 const GURL& site_for_cookies,
2356 const base::Optional<url::Origin>& top_frame_origin,
David Bertoni3b3597d82019-06-22 02:29:362357 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202358 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342359 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522360 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Christian Dullweber2a2f2182019-09-25 15:44:542361 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
rdevlin.croninf5863da2015-09-10 19:21:452362
brettw00899e62016-11-12 02:10:172363#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452364 // Check if this is an extension-related service worker, and, if so, if it's
2365 // allowed (this can return false if, e.g., the extension is disabled).
2366 // If it's not allowed, return immediately. We deliberately do *not* report
2367 // to the TabSpecificContentSettings, since the service worker is blocked
2368 // because of the extension, rather than because of the user's content
2369 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022370 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362371 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452372 return false;
2373 }
2374#endif
2375
falken3dbc36e2014-10-10 16:48:072376 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202377
shimazuce8af88122016-10-06 23:49:212378 // Check if JavaScript is allowed.
2379 content_settings::SettingInfo info;
2380 std::unique_ptr<base::Value> value =
2381 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
2382 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2383 std::string(), &info);
2384 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2385 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2386
2387 // Check if cookies are allowed.
Christian Dullweber2a2f2182019-09-25 15:44:542388 bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed(
2389 scope, site_for_cookies, top_frame_origin);
falken4a22dce2015-04-30 08:25:202390 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242391 // Only post the task if this is for a specific tab.
2392 if (!wc_getter.is_null()) {
Sami Kyostila5e1306d2019-08-14 11:01:292393 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:282394 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512395 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342396 std::move(wc_getter), scope, !allow_javascript,
Christian Dullweber2a2f2182019-09-25 15:44:542397 !allow_cookies));
rdevlin.croninf5863da2015-09-10 19:21:452398 }
Christian Dullweber2a2f2182019-09-25 15:44:542399 return allow_javascript && allow_cookies;
falken3dbc36e2014-10-10 16:48:072400}
2401
Matt Falkenhagen7b509e52019-08-15 23:11:412402bool ChromeContentBrowserClient::AllowServiceWorkerOnUI(
2403 const GURL& scope,
Christian Dullweber2a2f2182019-09-25 15:44:542404 const GURL& site_for_cookies,
2405 const base::Optional<url::Origin>& top_frame_origin,
Matt Falkenhagen7b509e52019-08-15 23:11:412406 const GURL& script_url,
2407 content::BrowserContext* context,
2408 base::RepeatingCallback<content::WebContents*()> wc_getter) {
2409 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Christian Dullweber2a2f2182019-09-25 15:44:542410 GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL();
Matt Falkenhagen7b509e52019-08-15 23:11:412411
2412#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022413 // Check if this is an extension-related service worker, and, if so, if it's
2414 // allowed (this can return false if, e.g., the extension is disabled).
2415 // If it's not allowed, return immediately. We deliberately do *not* report
2416 // to the TabSpecificContentSettings, since the service worker is blocked
2417 // because of the extension, rather than because of the user's content
2418 // settings.
2419 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2420 scope, first_party_url, script_url, context)) {
2421 return false;
2422 }
Matt Falkenhagen7b509e52019-08-15 23:11:412423#endif
2424
2425 Profile* profile = Profile::FromBrowserContext(context);
2426
2427 // Check if JavaScript is allowed.
2428 content_settings::SettingInfo info;
2429 std::unique_ptr<base::Value> value =
2430 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
2431 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2432 std::string(), &info);
2433 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2434 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2435
2436 // Check if cookies are allowed.
2437 bool allow_cookies =
2438 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
Christian Dullweber2a2f2182019-09-25 15:44:542439 scope, site_for_cookies, top_frame_origin);
Matt Falkenhagen7b509e52019-08-15 23:11:412440
2441 // Record access to database for potential display in UI.
2442 // Only post the task if this is for a specific tab.
2443 if (!wc_getter.is_null()) {
2444 TabSpecificContentSettings::ServiceWorkerAccessed(
2445 std::move(wc_getter), scope, !allow_javascript, !allow_cookies);
2446 }
2447 return allow_javascript && allow_cookies;
2448}
2449
Jochen Eisinger0ff7645c2017-11-28 08:11:262450bool ChromeContentBrowserClient::AllowSharedWorker(
2451 const GURL& worker_url,
Christian Dullweber2a2f2182019-09-25 15:44:542452 const GURL& site_for_cookies,
2453 const base::Optional<url::Origin>& top_frame_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262454 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372455 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262456 content::BrowserContext* context,
2457 int render_process_id,
2458 int render_frame_id) {
2459 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2460
2461 // Check if cookies are allowed.
2462 bool allow =
2463 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
Christian Dullweber2a2f2182019-09-25 15:44:542464 ->IsCookieAccessAllowed(worker_url, site_for_cookies,
2465 top_frame_origin);
Jochen Eisinger0ff7645c2017-11-28 08:11:262466
2467 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372468 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2469 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262470 return allow;
2471}
2472
Patrick Monette6cb099a2019-09-18 19:31:272473bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2474 const std::string& scheme) {
2475#if BUILDFLAG(ENABLE_EXTENSIONS)
2476 // Extensions are allowed to start cross-origin shared workers.
2477 if (scheme == extensions::kExtensionScheme)
2478 return true;
2479#endif
2480
2481 return false;
2482}
2483
Clark DuVallab63d142019-07-23 04:24:362484bool ChromeContentBrowserClient::AllowSignedExchange(
2485 content::BrowserContext* browser_context) {
2486 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2487 Profile* profile = Profile::FromBrowserContext(browser_context);
2488 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2489}
2490
[email protected]f917df22014-07-10 07:45:492491void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352492 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572493 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172494 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572495 base::OnceCallback<void(bool)> callback) {
2496 Profile* profile = Profile::FromBrowserContext(browser_context);
2497 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002498 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352499
brettw00899e62016-11-12 02:10:172500#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572501 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492502#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572503 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492504#endif
2505}
2506
brettw00899e62016-11-12 02:10:172507#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492508void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2509 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172510 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572511 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492512 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492514 std::map<int, int> process_map;
2515 std::map<int, int>::const_iterator it;
2516 bool has_web_view_guest = false;
2517 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172518 for (const auto& it : render_frames) {
2519 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492520 continue;
2521
Lukasz Anforowicz09060bdf72018-08-23 15:53:172522 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492523
Lukasz Anforowicz09060bdf72018-08-23 15:53:172524 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492525 has_web_view_guest = true;
2526 }
2527 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572528 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492529 return;
2530 }
[email protected]dffb9fc2014-07-16 04:14:022531 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492532 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492533
[email protected]140d6cd92014-08-12 18:26:462534 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572535 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2536 web_view_permission_helper->RequestFileSystemPermission(
2537 url, allow,
2538 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2539 weak_factory_.GetWeakPtr(), url, render_frames,
2540 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492541}
2542#endif
2543
2544void ChromeContentBrowserClient::FileSystemAccessed(
2545 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172546 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572547 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492548 bool allow) {
[email protected]62151052012-02-01 18:40:482549 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172550 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572551 TabSpecificContentSettings::FileSystemAccessed(
2552 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352553 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572554 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352555}
2556
[email protected]7c5ff9a2012-03-02 07:42:492557bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2558 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572559 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172560 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572561 Profile* profile = Profile::FromBrowserContext(browser_context);
2562 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2563
falken71691402017-01-27 03:38:002564 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492565
2566 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172567 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572568 TabSpecificContentSettings::IndexedDBAccessed(
2569 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492570 }
2571
2572 return allow;
2573}
2574
Ben Kelly6b2e61c2019-03-14 16:06:292575bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2576 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572577 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292578 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572579 Profile* profile = Profile::FromBrowserContext(browser_context);
2580 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292581 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2582
2583 // Record access to CacheStorage for potential display in UI.
2584 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572585 TabSpecificContentSettings::CacheStorageAccessed(
2586 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292587 }
2588
2589 return allow;
2590}
2591
jyasskinc993ce8d2016-03-31 00:38:342592ChromeContentBrowserClient::AllowWebBluetoothResult
2593ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452594 content::BrowserContext* browser_context,
2595 const url::Origin& requesting_origin,
2596 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342597 // TODO(crbug.com/598890): Don't disable if
2598 // base::CommandLine::ForCurrentProcess()->
2599 // HasSwitch(switches::kEnableWebBluetooth) is true.
2600 if (variations::GetVariationParamValue(
2601 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2602 "Bluetooth") ==
2603 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2604 // The kill switch is enabled for this permission. Block requests.
2605 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2606 }
2607
jyasskin98bdd3992016-02-26 20:25:452608 const HostContentSettingsMap* const content_settings =
2609 HostContentSettingsMapFactory::GetForProfile(
2610 Profile::FromBrowserContext(browser_context));
2611
csharrisonaec2c542016-10-12 19:40:362612 if (content_settings->GetContentSetting(
2613 requesting_origin.GetURL(), embedding_origin.GetURL(),
2614 CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD,
2615 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342616 return AllowWebBluetoothResult::BLOCK_POLICY;
2617 }
2618 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452619}
2620
beaufort.francois01135bf2016-11-23 14:37:362621std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2622 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2623 "blocklist_additions");
scheib74250322016-04-07 03:32:212624}
2625
John Abd-El-Malek21bca7c2018-10-26 22:13:332626#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522627void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072628 content::BrowserContext* browser_context) {
2629 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2630 if (user_manager) {
2631 const user_manager::User* user =
2632 chromeos::ProfileHelper::Get()->GetUserByProfile(
2633 Profile::FromBrowserContext(browser_context));
2634 if (user && !user->username_hash().empty()) {
2635 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2636 user->username_hash());
2637 }
2638 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332639}
2640#endif
2641
Reilly Grant19aaccd2018-07-16 22:06:372642scoped_refptr<network::SharedURLLoaderFactory>
2643ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2645 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2646
2647 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372648 return nullptr;
2649
Min Qinda0d55b2018-10-12 18:30:052650 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372651 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042652}
2653
Sean Gilhulyda1ee4b2018-11-13 21:56:092654network::mojom::NetworkContext*
2655ChromeContentBrowserClient::GetSystemNetworkContext() {
2656 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2657 DCHECK(g_browser_process->system_network_context_manager());
2658 return g_browser_process->system_network_context_manager()->GetContext();
2659}
2660
Andrew Moylan17329fc2017-09-25 07:43:302661std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2662 return google_apis::GetAPIKey();
2663}
2664
Ke He21ee87f2018-05-30 02:35:322665#if defined(OS_ANDROID)
2666bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2667 // Indicate that Chrome uses the GMS core location provider.
2668 return true;
2669}
2670#endif
2671
Yeolf3dc22ca2019-04-18 17:25:322672scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412673ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2674 return new ChromeQuotaPermissionContext();
2675}
2676
michaeln10e5fc352017-02-07 02:07:582677void ChromeContentBrowserClient::GetQuotaSettings(
2678 content::BrowserContext* context,
2679 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452680 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582681 if (g_default_quota_settings) {
2682 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452683 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582684 return;
2685 }
taptede6d878e2017-06-24 01:53:452686 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062687 partition->GetPath(), context->IsOffTheRecord(),
2688 storage::GetDefaultDiskInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512689}
2690
Mythri Alle0b8de0d2018-10-22 11:06:222691content::GeneratedCodeCacheSettings
2692ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2693 content::BrowserContext* context) {
2694 base::FilePath cache_path;
2695 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2696 // If we pass 0 for size, disk_cache will pick a default size using the
2697 // heuristics based on available disk size. These are implemented in
2698 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162699 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132700 DCHECK(g_browser_process);
2701 PrefService* local_state = g_browser_process->local_state();
2702 if (local_state) {
2703 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2704 base::FilePath disk_cache_dir =
2705 local_state->GetFilePath(prefs::kDiskCacheDir);
2706 if (!disk_cache_dir.empty())
2707 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2708 }
Mythri Ab2486572019-06-13 14:48:162709 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222710}
2711
[email protected]848dd042011-06-04 18:24:032712void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262713 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172714 int cert_error,
2715 const net::SSLInfo& ssl_info,
2716 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232717 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222718 bool strict_enforcement,
estark719dde52016-08-09 03:14:272719 const base::Callback<void(content::CertificateRequestResultType)>&
2720 callback) {
clamy0d32d6d2015-11-24 11:16:262721 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232722 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142723 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022724 // have a context for making the right decision, so block the
2725 // request hard, without an info bar to allow showing the insecure
2726 // content.
estark719dde52016-08-09 03:14:272727 if (!callback.is_null())
2728 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022729 return;
2730 }
2731
[email protected]f9034cf2011-07-21 12:43:412732 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572733 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262734 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572735 if (prerender_contents) {
2736 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272737 if (!callback.is_null()) {
2738 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
2739 }
[email protected]09667f02014-01-06 15:37:572740 return;
[email protected]f9034cf2011-07-21 12:43:412741 }
2742
Carlos IL5a9e7512019-06-13 22:35:282743 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2744 return;
[email protected]848dd042011-06-04 18:24:032745}
2746
Alexander Hendrichbcf2616e2018-05-18 08:21:102747namespace {
2748
Pavol Markob211ab22019-01-23 20:03:042749certificate_matching::CertificatePrincipalPattern
2750ParseCertificatePrincipalPattern(const base::Value* pattern) {
2751 return certificate_matching::CertificatePrincipalPattern::
2752 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2753}
2754
Alexander Hendrichbcf2616e2018-05-18 08:21:102755// Attempts to auto-select a client certificate according to the value of
2756// |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for
2757// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2758std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2759 Profile* profile,
2760 const GURL& requesting_url,
2761 net::ClientCertIdentityList& client_certs) {
2762 HostContentSettingsMap* host_content_settings_map =
2763 HostContentSettingsMapFactory::GetForProfile(profile);
2764 std::unique_ptr<base::Value> setting =
2765 host_content_settings_map->GetWebsiteSetting(
2766 requesting_url, requesting_url,
Aran Gilmanf010bdd2019-08-28 19:55:442767 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(),
2768 nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102769
Pavol Markob211ab22019-01-23 20:03:042770 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102771 return nullptr;
2772
Alexander Hendrichbcf2616e2018-05-18 08:21:102773 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042774 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2775 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102776 // |setting_dict| has the wrong format (e.g. single filter instead of a
2777 // list of filters). This content setting is only provided by
2778 // the |PolicyProvider|, which should always set it to a valid format.
2779 // Therefore, delete the invalid value.
2780 host_content_settings_map->SetWebsiteSettingDefaultScope(
2781 requesting_url, requesting_url,
2782 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042783 return nullptr;
2784 }
2785
2786 for (const base::Value& filter : filters->GetList()) {
2787 DCHECK(filter.is_dict());
2788
2789 auto issuer_pattern = ParseCertificatePrincipalPattern(
2790 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2791 auto subject_pattern = ParseCertificatePrincipalPattern(
2792 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2793 // Use the first certificate that is matched by the filter.
2794 for (auto& client_cert : client_certs) {
2795 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2796 subject_pattern.Matches(client_cert->certificate()->subject())) {
2797 return std::move(client_cert);
2798 }
2799 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102800 }
2801
2802 return nullptr;
2803}
2804
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182805void AddDataReductionProxyReceiver(
Clark DuVall812e07d2019-08-26 18:34:562806 int render_process_id,
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182807 mojo::PendingReceiver<data_reduction_proxy::mojom::DataReductionProxy>
2808 receiver) {
Clark DuVall0e901722019-08-14 23:31:372809 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Clark DuVall812e07d2019-08-26 18:34:562810 auto* rph = content::RenderProcessHost::FromID(render_process_id);
2811 if (!rph)
2812 return;
2813
Clark DuVall0e901722019-08-14 23:31:372814 auto* drp_settings =
2815 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
Clark DuVall812e07d2019-08-26 18:34:562816 rph->GetBrowserContext());
Clark DuVall0e901722019-08-14 23:31:372817 if (!drp_settings)
2818 return;
2819
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182820 drp_settings->data_reduction_proxy_service()->Clone(std::move(receiver));
Eric Romana00cf682018-11-01 20:09:112821}
2822
Alexander Hendrichbcf2616e2018-05-18 08:21:102823} // namespace
2824
Daniel McArdle85735f52019-06-25 03:27:062825base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192826 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402827 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082828 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352829 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022830 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192831 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022832 if (prerender_contents) {
2833 prerender_contents->Destroy(
2834 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062835 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452836 }
2837
[email protected]791879c2013-12-17 07:22:412838 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2839 DCHECK(requesting_url.is_valid())
2840 << "Invalid URL string: https://"
2841 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452842
Pavol Marko230ea2c92017-12-03 22:35:442843 bool may_show_cert_selection = true;
2844
davidben3b8455ae72015-03-11 19:42:192845 Profile* profile =
2846 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442847#if defined(OS_CHROMEOS)
2848 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2849 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2850 // and remove the command-line flag after prototype phase when the
2851 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2852 may_show_cert_selection =
2853 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2854
2855 content::StoragePartition* storage_partition =
2856 content::BrowserContext::GetStoragePartition(
2857 profile, web_contents->GetSiteInstance());
2858 chromeos::login::SigninPartitionManager* signin_partition_manager =
2859 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2860 profile);
2861
2862 // On the sign-in profile, only allow client certs in the context of the
2863 // sign-in frame.
2864 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2865 storage_partition)) {
2866 LOG(WARNING)
2867 << "Client cert requested in sign-in profile in wrong context.";
2868 // Continue without client certificate. We do this to mimic the case of no
2869 // client certificate being present in the profile's certificate store.
2870 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062871 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442872 }
2873 VLOG(1) << "Client cert requested in sign-in profile.";
2874 }
2875#endif // defined(OS_CHROMEOS)
2876
Alexander Hendrichbcf2616e2018-05-18 08:21:102877 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2878 AutoSelectCertificate(profile, requesting_url, client_certs);
2879 if (auto_selected_identity) {
2880 // The callback will own |auto_selected_identity| and |delegate|, keeping
2881 // them alive until after ContinueWithCertificate is called.
2882 scoped_refptr<net::X509Certificate> cert =
2883 auto_selected_identity->certificate();
2884 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2885 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582886 base::BindOnce(
2887 &content::ClientCertificateDelegate::ContinueWithCertificate,
2888 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322889 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062890 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452891 }
2892
Pavol Marko230ea2c92017-12-03 22:35:442893 if (!may_show_cert_selection) {
2894 LOG(WARNING) << "No client cert matched by policy and user selection is "
2895 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322896 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442897 // Continue without client certificate. We do this to mimic the case of no
2898 // client certificate being present in the profile's certificate store.
2899 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062900 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442901 }
2902
Daniel McArdle85735f52019-06-25 03:27:062903 return chrome::ShowSSLClientCertificateSelector(
2904 web_contents, cert_request_info, std::move(client_certs),
2905 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452906}
2907
[email protected]dc73a7b2012-03-25 15:27:182908content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562909 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182910}
2911
peterc26c6c62014-12-10 14:13:592912content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022913ChromeContentBrowserClient::GetPlatformNotificationService(
2914 content::BrowserContext* browser_context) {
2915 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2916 Profile* profile = Profile::FromBrowserContext(browser_context);
2917 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042918}
2919
[email protected]9f3fba52011-06-08 20:37:192920bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352921 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352922 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572923 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352924 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032925 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232926 const GURL& target_url,
2927 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212928 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232929 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482930 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232931 bool user_gesture,
2932 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012933 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352934 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2935 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012936
csharrison95f01e922017-04-24 18:52:352937 content::WebContents* web_contents =
2938 content::WebContents::FromRenderFrameHost(opener);
2939 Profile* profile =
2940 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2941 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012942 *no_javascript_access = false;
2943
[email protected]9f3fba52011-06-08 20:37:192944 // If the opener is trying to create a background window but doesn't have
2945 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032946 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172947#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352948 auto* process_map = extensions::ProcessMap::Get(profile);
2949 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172950 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2951 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012952 return false;
2953 }
2954
[email protected]7b54ca02012-03-02 18:06:532955 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2956 // return a recently installed Extension even if this CanCreateWindow call
2957 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012958 // because the permission check above would have caused an early return
2959 // already. We must use the full URL to find hosted apps, though, and not
2960 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552961 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352962 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292963 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012964 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022965#endif
[email protected]190e5e22013-07-27 05:59:232966
2967 return true;
[email protected]9f3fba52011-06-08 20:37:192968 }
[email protected]056efdc2013-04-06 00:14:532969
brettw00899e62016-11-12 02:10:172970#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462971 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352972 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232973 return true;
lazyboy04b75d32016-02-25 03:12:182974 }
2975
nick0fbc3922016-12-16 20:52:072976 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352977 // Intentionally duplicating |registry| code from above because we want to
2978 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2979 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182980 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352981 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142982 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532983 UMA_HISTOGRAM_ENUMERATION(
2984 "Extensions.AppLoadedInTab",
2985 ClassifyAppLoadedInTabSource(opener_url, extension),
2986 APP_LOADED_IN_TAB_SOURCE_MAX);
2987
2988 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162989 return false;
lazyboy5d5fede02016-03-10 04:10:142990 }
lazyboy04b75d32016-02-25 03:12:182991 }
[email protected]5940b0d2014-07-01 00:18:262992#endif
[email protected]190e5e22013-07-27 05:59:232993
Charles Harrisonaf2acd02017-08-18 22:46:022994#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232995 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352996 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582997 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2998 content_settings, opener_top_level_frame_url, target_url,
2999 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353000 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3001 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583002 return false;
3003 }
3004#endif
3005
Charles Harrisonaf2acd02017-08-18 22:46:023006 // Don't let prerenders open popups.
3007 if (auto* prerender_contents =
3008 prerender::PrerenderContents::FromWebContents(web_contents)) {
3009 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
3010 return false;
3011 }
3012
Nasko Oskove9f19782019-01-04 18:32:353013 BlockedWindowParams blocked_params(target_url, source_origin, referrer,
3014 frame_name, disposition, features,
3015 user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133016 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Lei Zhang31c778f2019-09-23 20:32:193017 return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url,
3018 &nav_params, nullptr /*=open_url_params*/,
3019 blocked_params.features());
[email protected]9f3fba52011-06-08 20:37:193020}
3021
[email protected]c52b2892012-03-07 11:01:023022content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443023ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003024 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513025}
3026
Katie D840d9532018-11-27 06:20:483027content::TtsControllerDelegate*
3028ChromeContentBrowserClient::GetTtsControllerDelegate() {
3029 TtsControllerDelegateImpl* delegate =
3030 TtsControllerDelegateImpl::GetInstance();
3031#if !defined(OS_ANDROID)
3032 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3033 delegate->SetTtsEngineDelegate(tts_extension_engine);
3034#endif
3035 return delegate;
3036}
3037
Katie D4713ee42018-11-30 01:48:273038content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3039#ifdef OS_CHROMEOS
3040 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273041#else
3042 return nullptr;
3043#endif
3044}
3045
[email protected]64d69de42012-02-06 00:19:543046void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443047 RenderViewHost* rvh,
3048 WebPreferences* web_prefs) {
3049 Profile* profile =
3050 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063051 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063052
aelias0df335a2017-03-02 23:43:513053// Fill font preferences. These are not registered on Android
3054// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453055#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193056 FontFamilyCache::FillFontFamilyMap(profile,
3057 prefs::kWebKitStandardFontFamilyMap,
3058 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443059 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193060 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443061 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193062 &web_prefs->serif_font_family_map);
3063 FontFamilyCache::FillFontFamilyMap(profile,
3064 prefs::kWebKitSansSerifFontFamilyMap,
3065 &web_prefs->sans_serif_font_family_map);
3066 FontFamilyCache::FillFontFamilyMap(profile,
3067 prefs::kWebKitCursiveFontFamilyMap,
3068 &web_prefs->cursive_font_family_map);
3069 FontFamilyCache::FillFontFamilyMap(profile,
3070 prefs::kWebKitFantasyFontFamilyMap,
3071 &web_prefs->fantasy_font_family_map);
3072 FontFamilyCache::FillFontFamilyMap(profile,
3073 prefs::kWebKitPictographFontFamilyMap,
3074 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063075
[email protected]64d69de42012-02-06 00:19:543076 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403077 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543078 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403079 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543080 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403081 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543082 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403083 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513084#endif
[email protected]f3986f82012-01-03 20:00:063085
[email protected]ddf72142012-05-22 04:52:403086 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063087
[email protected]64d69de42012-02-06 00:19:543088 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063089 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213090 web_prefs->javascript_can_access_clipboard =
3091 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543092 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063093
[email protected]ddf72142012-05-22 04:52:403094 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543095 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573096
Avi Drissman1aa6cb92019-01-23 15:58:383097 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543098 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573099
[email protected]ddf72142012-05-22 04:52:403100 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543101 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543102 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403103 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063104
Zhenyao Moa3fda9972017-09-16 01:34:403105 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3106 web_prefs->webgl1_enabled = false;
3107 web_prefs->webgl2_enabled = false;
3108 }
[email protected]f3986f82012-01-03 20:00:063109
[email protected]64d69de42012-02-06 00:19:543110 web_prefs->allow_running_insecure_content =
3111 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323112#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053113 web_prefs->font_scale_factor =
3114 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3115 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323116 web_prefs->force_enable_zoom =
3117 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493118#endif
Becky Zhoubbfbde32019-02-20 17:07:593119 web_prefs->force_dark_mode_enabled =
3120 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393121
[email protected]af4256d52013-06-04 20:39:073122#if defined(OS_ANDROID)
3123 web_prefs->password_echo_enabled =
3124 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3125#else
[email protected]9d06d88d2012-02-23 22:37:083126 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073127#endif
3128
[email protected]64d69de42012-02-06 00:19:543129 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063130 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543131 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063132 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3133
brettw00899e62016-11-12 02:10:173134#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053135 std::string image_animation_policy =
3136 prefs->GetString(prefs::kAnimationPolicy);
3137 if (image_animation_policy == kAnimationPolicyOnce)
3138 web_prefs->animation_policy =
3139 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3140 else if (image_animation_policy == kAnimationPolicyNone)
3141 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3142 else
3143 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3144#endif
3145
[email protected]f3986f82012-01-03 20:00:063146 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153147 web_prefs->default_encoding =
3148 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543149 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403150 prefs->ClearPref(prefs::kDefaultCharset);
3151 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063152 }
[email protected]64d69de42012-02-06 00:19:543153 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063154
mkwst05544102015-01-10 20:26:163155 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3156 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073157 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163158 web_prefs->strict_mixed_content_checking = true;
3159 web_prefs->strict_powerful_feature_restrictions = true;
3160 }
3161
Robert Ogdencf2872d2019-03-19 18:59:373162 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213163
Tarun Bansal333819e2018-05-15 16:38:423164 web_prefs->data_saver_holdback_web_api_enabled =
3165 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3166 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423167
Jinsuk Kima3d393ce2019-05-27 00:57:423168 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133169 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533170#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423171 auto* delegate = TabAndroid::FromWebContents(contents)
3172 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3173 contents->GetDelegate())
3174 : nullptr;
3175 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133176 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423177 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133178
Mounir Lamouri9c99a1602018-07-05 15:01:443179 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423180 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383181
3182 web_prefs->preferred_color_scheme =
Jinsuk Kima3d393ce2019-05-27 00:57:423183 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3184 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113185 }
Ian Vollick6243dfe02018-03-08 01:08:533186#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533187
Mounir Lamouri6926107f2019-01-31 18:17:433188 // web_app_scope value is platform specific.
3189#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423190 if (delegate)
3191 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433192#elif BUILDFLAG(ENABLE_EXTENSIONS)
3193 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253194 web_prefs->web_app_scope = GURL();
3195 // Set |web_app_scope| based on the app associated with the app window if
3196 // any. Note that the app associated with the window never changes, even
3197 // if the app navigates off scope. This is not a problem because we still
3198 // want to use the scope of the app associated with the window, not the
3199 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433200 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233201 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443202 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273203 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443204 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253205 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053206 // for profiles that support them, so we should always be able to
3207 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253208 //
3209 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123210 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253211 web_prefs->web_app_scope =
3212 web_app::WebAppProvider::Get(profile)
3213 ->registrar()
Alan Cutterf25cfe42019-07-16 02:40:123214 .GetAppScope(*browser->app_controller()->GetAppId())
3215 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433216 }
Mounir Lamouri6926107f2019-01-31 18:17:433217 }
3218#endif
3219
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533220#if BUILDFLAG(ENABLE_EXTENSIONS)
3221 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443222 if (browser && browser->app_controller() &&
3223 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533224 web_prefs->strict_mixed_content_checking = true;
3225 }
3226#endif
3227
Ian Vollick6243dfe02018-03-08 01:08:533228 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113229 }
zqzhang93e959d12017-03-16 13:10:203230
Ian Vollick6243dfe02018-03-08 01:08:533231#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143232 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113233#endif // defined(OS_ANDROID)
3234
Tarun Bansal73d67f02018-01-17 05:56:253235 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3236 // Obtain the maximum effective connection type at which the feature is
3237 // enabled.
3238 std::string effective_connection_type_param =
3239 base::GetFieldTrialParamValueByFeature(
3240 features::kLowPriorityIframes,
3241 "max_effective_connection_type_threshold");
3242
3243 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3244 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3245 if (effective_connection_type) {
3246 web_prefs->low_priority_iframes_threshold =
3247 effective_connection_type.value();
3248 }
3249 }
3250
rajendrant0521cee2019-07-29 06:09:263251 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3252 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003253
Scott Little878f7d6702018-05-31 22:09:063254 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3255 const char* param_name =
3256 web_prefs->data_saver_enabled
3257 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3258 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3259 "saver_enabled";
3260
3261 base::StringPairs pairs;
3262 base::SplitStringIntoKeyValuePairs(
3263 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3264 param_name),
3265 ':', ',', &pairs);
3266
3267 for (const auto& pair : pairs) {
3268 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3269 net::GetEffectiveConnectionTypeForName(pair.first);
3270 int value = 0;
3271 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3272 web_prefs->lazy_frame_loading_distance_thresholds_px
3273 [effective_connection_type.value()] = value;
3274 }
3275 }
3276 }
3277
rajendrantd8026342018-08-29 08:08:393278 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3279 const char* param_name =
3280 web_prefs->data_saver_enabled
3281 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3282 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3283 "saver_enabled";
3284
3285 base::StringPairs pairs;
3286 base::SplitStringIntoKeyValuePairs(
3287 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3288 param_name),
3289 ':', ',', &pairs);
3290
3291 for (const auto& pair : pairs) {
3292 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3293 net::GetEffectiveConnectionTypeForName(pair.first);
3294 int value = 0;
3295 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3296 web_prefs->lazy_image_loading_distance_thresholds_px
3297 [effective_connection_type.value()] = value;
3298 }
3299 }
rajendrant3daeae292019-09-20 07:57:543300
3301 pairs.clear();
3302 base::SplitStringIntoKeyValuePairs(
3303 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3304 "lazy_image_first_k_fully_load"),
3305 ':', ',', &pairs);
3306
3307 for (const auto& pair : pairs) {
3308 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3309 net::GetEffectiveConnectionTypeForName(pair.first);
3310 int value = 0;
3311 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3312 web_prefs
3313 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3314 value;
3315 }
3316 }
rajendrantd8026342018-08-29 08:08:393317 }
3318
Tarun Bansald10f17a02018-09-13 00:23:173319 if (base::FeatureList::IsEnabled(
3320 features::kNetworkQualityEstimatorWebHoldback)) {
3321 std::string effective_connection_type_param =
3322 base::GetFieldTrialParamValueByFeature(
3323 features::kNetworkQualityEstimatorWebHoldback,
3324 "web_effective_connection_type_override");
3325
3326 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3327 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3328 DCHECK(effective_connection_type_param.empty() ||
3329 effective_connection_type);
3330 if (effective_connection_type) {
3331 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3332 effective_connection_type.value());
3333 web_prefs->network_quality_estimator_web_holdback =
3334 effective_connection_type.value();
3335 }
3336 }
3337
Dan Beamf0a7e112019-06-07 18:40:583338 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103339#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563340 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593341 // If autoplay is allowed by policy then force the no user gesture required
3342 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103343 web_prefs->autoplay_policy =
3344 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553345 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593346 web_prefs->autoplay_policy ==
3347 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553348 // If the autoplay disable settings feature is enabled and the autoplay
3349 // policy is set to using the unified policy then set the default autoplay
3350 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593351 web_prefs->autoplay_policy =
3352 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3353 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3354 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103355 }
Alison Maher67fd4d9f2019-07-12 18:34:213356#if !defined(OS_MACOSX)
3357 // Mac has a concept of high contrast that does not relate to forced colors.
Alison Maherbe15c072019-07-08 18:12:393358 web_prefs->forced_colors = native_theme->UsesHighContrastColors()
3359 ? blink::ForcedColors::kActive
3360 : blink::ForcedColors::kNone;
Alison Maher67fd4d9f2019-07-12 18:34:213361#endif // !defined(OS_MACOSX)
3362
3363 switch (native_theme->GetPreferredColorScheme()) {
3364 case ui::NativeTheme::PreferredColorScheme::kDark:
3365 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3366 break;
3367 case ui::NativeTheme::PreferredColorScheme::kLight:
3368 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3369 break;
3370 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3371 web_prefs->preferred_color_scheme =
3372 blink::PreferredColorScheme::kNoPreference;
3373 }
François Beaufort4f8107d2018-03-05 12:12:103374#endif // !defined(OS_ANDROID)
3375
Dave Tapuskac6627e12018-08-30 15:07:193376 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493377
Dan Beam836c02a2019-06-15 01:58:273378 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3379 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3380 // explicitly uses light (instead of not dark), which is why we don't reset
3381 // back to no-preference. https://crbug.com/965811
3382 if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3383 bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme);
3384#if BUILDFLAG(ENABLE_EXTENSIONS)
3385 if (!force_light) {
3386 force_light =
3387 contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
3388 contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
3389 }
3390#endif
3391 if (force_light)
3392 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
Dan Beamf0a7e112019-06-07 18:40:583393 }
3394
Elly Fong-Jonesf92897392019-01-24 16:05:493395 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213396 base::Optional<ui::CaptionStyle> style;
3397
3398 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3399 ::switches::kForceCaptionStyle)) {
3400 style = ui::CaptionStyle::FromSpec(
3401 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3402 switches::kForceCaptionStyle));
3403 }
3404
3405 // Apply system caption style.
3406 if (!style) {
3407 style = native_theme->GetSystemCaptionStyle();
3408 }
3409
3410 // Apply caption style from preferences if system caption style is undefined.
3411 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
evliubc2aa0472019-08-09 20:19:193412 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
Evan Liu7cdbf8872019-06-19 16:47:213413 }
3414
3415 if (style) {
3416 web_prefs->text_track_background_color = style->background_color;
3417 web_prefs->text_track_text_color = style->text_color;
3418 web_prefs->text_track_text_size = style->text_size;
3419 web_prefs->text_track_text_shadow = style->text_shadow;
3420 web_prefs->text_track_font_family = style->font_family;
3421 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563422 web_prefs->text_track_window_color = style->window_color;
3423 web_prefs->text_track_window_padding = style->window_padding;
3424 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213425 }
Elly Fong-Jonesf92897392019-01-24 16:05:493426
[email protected]a48ab7112014-08-01 16:48:033427 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503428 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363429}
3430
[email protected]b8148ac2011-07-13 22:03:253431void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3432 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033433 for (size_t i = 0; i < extra_parts_.size(); ++i)
3434 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253435
[email protected]b3adbd02011-11-30 22:23:273436 // about: handler. Must come before chrome: handler, since it will
3437 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053438 // actually handle them. Also relies on a preliminary fixup phase.
3439 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253440 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3441 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033442
madfbd10852017-01-20 03:15:333443 // The group policy NTP URL handler must be registered before the other NTP
3444 // URL handlers below.
3445 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3446 BrowserURLHandler::null_handler());
3447
zpengdb4a58e2017-01-10 17:40:323448#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033449 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353450 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033451 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453452#if BUILDFLAG(DFMIFY_DEV_UI)
3453 // Handler to rewrite chrome:// URLs in the DevUI DFM, if not installed.
3454 handler->AddHandlerPair(&chrome::android::HandleDfmifiedDevUiPageURL,
3455 BrowserURLHandler::null_handler());
3456#endif // BUILDFLAG(DFMIFY_DEV_UI)
3457
3458#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033459 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133460 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3461 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453462#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033463
[email protected]b8148ac2011-07-13 22:03:253464 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313465 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3466 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063467
3468 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3469 // the user.
Robert Ogden0f4d88682019-09-24 22:27:523470 handler->AddHandlerPair(
3471 &previews::HandlePreviewsLitePageRedirectURLRewrite,
3472 &previews::HandlePreviewsLitePageRedirectURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253473}
3474
[email protected]650b2d52013-02-10 03:41:453475base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493476 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323477}
3478
[email protected]c9b6eb62011-10-18 20:49:393479std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3480 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3481}
3482
Dominik Röttsches47347832019-03-12 17:45:013483base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3484 base::FilePath user_data_dir;
3485 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3486 DCHECK(!user_data_dir.empty());
3487 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3488}
3489
jmadill57b52d42015-08-21 18:16:133490base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3491 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523492 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133493 DCHECK(!user_data_dir.empty());
3494 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3495}
3496
Khushal7ca0b782018-07-20 05:53:273497base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3498 base::FilePath user_data_dir;
3499 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3500 DCHECK(!user_data_dir.empty());
3501 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3502}
3503
[email protected]b7631cc2012-09-15 05:08:383504void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3505 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163506#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553507 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543508#endif
[email protected]b7631cc2012-09-15 05:08:383509}
3510
[email protected]0c7193742012-11-07 19:05:033511content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443512ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173513#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553514 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033515 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443516 nacl::NaClProcessHost* host =
3517 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3518 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033519 // Found the plugin.
3520 return host->browser_ppapi_host();
3521 }
3522 ++iter;
3523 }
[email protected]a56f8322014-07-16 21:13:553524#endif
Aran Gilmanf010bdd2019-08-28 19:55:443525 return nullptr;
[email protected]0c7193742012-11-07 19:05:033526}
3527
[email protected]38cd8f7f2012-06-15 22:06:073528bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583529 content::BrowserContext* browser_context,
3530 const GURL& url,
[email protected]dda54822013-06-15 01:26:393531 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123532 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163533#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553534 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3535 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403536#else
[email protected]a658d452012-03-02 12:45:293537 return false;
[email protected]93f72062013-05-29 20:29:403538#endif
[email protected]e461da2f2012-02-16 19:06:403539}
3540
adrian.belgund54465ba2016-05-18 10:03:583541bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3542 content::BrowserContext* browser_context,
3543 const GURL& url) {
brettw4b461082016-11-19 18:55:163544#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583545 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3546 browser_context, url);
3547#else
3548 return false;
3549#endif
3550}
3551
adrian.belgun5b341c72016-06-22 22:24:083552std::unique_ptr<content::VpnServiceProxy>
3553ChromeContentBrowserClient::GetVpnServiceProxy(
3554 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173555#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083556 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3557 browser_context);
3558#else
3559 return nullptr;
3560#endif
3561}
3562
Brett Wilson804e83c2017-08-18 22:57:333563std::unique_ptr<ui::SelectFilePolicy>
3564ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3565 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433566}
3567
[email protected]7d9424702013-04-14 13:14:163568void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3569 std::vector<std::string>* additional_allowed_schemes) {
3570 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3571 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483572 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293573 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033574 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3575 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3576 additional_allowed_schemes);
3577 }
[email protected]7d9424702013-04-14 13:14:163578}
3579
falkenad185092016-06-16 06:10:023580void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3581 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043582 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023583}
3584
[email protected]c79859b82014-03-20 22:43:553585void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313586 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033587 for (size_t i = 0; i < extra_parts_.size(); ++i)
3588 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553589}
3590
nzolghadrd87a308d2016-12-07 15:45:563591::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3592 return g_browser_process->rappor_service();
3593}
3594
[email protected]f19bbf62013-07-09 01:22:323595void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313596 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533597 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003598 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3599 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313600#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313601 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313602 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313603 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093604 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093605 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3606 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473607 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093608 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3609 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053610 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3611 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473612 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323613 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313614 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003615 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313616#endif
[email protected]445b7db2013-08-02 04:58:273617
[email protected]a48ab7112014-08-01 16:48:033618 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3619 extra_parts_[i]->GetAdditionalFileSystemBackends(
3620 browser_context, storage_partition_path, additional_backends);
3621 }
[email protected]02250952013-04-24 23:52:533622}
3623
jcivellie6f550742017-01-06 19:29:123624#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183625void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173626 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383627 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203628 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123629#if defined(OS_ANDROID)
3630 base::MemoryMappedFile::Region region;
3631 int fd = ui::GetMainAndroidPackFd(&region);
3632 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003633
Samuel Huang31eadf082019-08-28 19:50:433634 // For Android: Native resources for DFMs should only be used by the browser
3635 // process. Their file descriptors and memory mapped file regions are not
3636 // passed to child processes.
3637
jcivellie6f550742017-01-06 19:29:123638 fd = ui::GetCommonResourcesPackFd(&region);
3639 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393640
jcivellie6f550742017-01-06 19:29:123641 fd = ui::GetLocalePackFd(&region);
3642 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383643
zpeng368afac82017-07-17 18:47:453644 // Optional secondary locale .pak file.
3645 fd = ui::GetSecondaryLocalePackFd(&region);
3646 if (fd != -1) {
3647 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3648 }
3649
[email protected]09560f7f2014-06-10 18:40:283650 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523651 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283652 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023653#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383654 int crash_signal_fd = GetCrashSignalFD(command_line);
3655 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133656 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383657 }
jcivellie6f550742017-01-06 19:29:123658}
3659#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303660
[email protected]4a65826d2011-08-25 16:04:013661#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033662base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:523663 int sandbox_type) {
wfh182da09c2015-06-24 19:23:033664 // TODO(wfh): Add support for more process types here. crbug.com/499523
3665 switch (sandbox_type) {
Tom Sepez15d4e5202017-09-27 23:59:053666 case service_manager::SANDBOX_TYPE_RENDERER:
Jerry Lina0de7ce2018-06-22 15:18:363667 return base::string16(install_static::GetSandboxSidPrefix()) +
3668 L"129201922";
Tom Sepez15d4e5202017-09-27 23:59:053669 case service_manager::SANDBOX_TYPE_UTILITY:
wfh182da09c2015-06-24 19:23:033670 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053671 case service_manager::SANDBOX_TYPE_GPU:
wfh182da09c2015-06-24 19:23:033672 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053673 case service_manager::SANDBOX_TYPE_PPAPI:
Jerry Lina0de7ce2018-06-22 15:18:363674 return base::string16(install_static::GetSandboxSidPrefix()) +
3675 L"129201925";
Nico Weberaf3b00b2017-09-11 17:58:173676#if BUILDFLAG(ENABLE_NACL)
wfh182da09c2015-06-24 19:23:033677 case PROCESS_TYPE_NACL_LOADER:
3678 return base::string16();
3679 case PROCESS_TYPE_NACL_BROKER:
3680 return base::string16();
3681#endif
3682 }
3683
3684 // Should never reach here.
3685 CHECK(0);
3686 return base::string16();
3687}
3688
Will Harris956e0ca2019-08-23 20:47:393689bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3690 RendererSpawnFlags flags) {
[email protected]34f48682013-03-20 00:30:183691 // Allow the server side of a pipe restricted to the "chrome.nacl."
3692 // namespace so that it cannot impersonate other system or other chrome
Will Harrisc196ed942019-08-03 03:45:303693 // service pipes. This is also done in nacl_broker_listener.cc.
3694 sandbox::ResultCode result =
3695 policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
3696 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
3697 L"\\\\.\\pipe\\chrome.nacl.*");
rickyz50109312015-11-11 00:37:083698 if (result != sandbox::SBOX_ALL_OK)
3699 return false;
Will Harrisc196ed942019-08-03 03:45:303700
Will Harris1b9b4152019-08-21 22:33:503701// Does not work under component build because all the component DLLs would need
3702// to be manually added and maintained. Does not work under ASAN build because
3703// ASAN has not yet fully initialized its instrumentation by the time the CIG
3704// intercepts run.
3705#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393706 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3707 return true;
Will Harrisc196ed942019-08-03 03:45:303708 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3709 return true;
3710
3711 // Only enable signing mitigation if launching from chrome.exe.
3712 base::FilePath exe_path;
3713 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3714 return true;
3715 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3716 return true;
3717
3718 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3719 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
3720 result = policy->SetProcessMitigations(mitigations);
3721 if (result != sandbox::SBOX_ALL_OK)
3722 return false;
3723
Aran Gilmanf010bdd2019-08-28 19:55:443724 // Allow loading Chrome's DLLs. The name of this depends on whether
3725 // is_multi_dll_chrome is defined or not. For multi-DLL Chrome,
3726 // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the
3727 // same DLL as the browser process.
Will Harrisc196ed942019-08-03 03:45:303728#if defined(CHROME_MULTIPLE_DLL_BROWSER)
3729 constexpr auto* child_dll_path = chrome::kChildDll;
3730#else
3731 constexpr auto* child_dll_path = chrome::kBrowserResourcesDll;
3732#endif
3733 for (const auto* dll : {child_dll_path, chrome::kElfDll}) {
3734 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3735 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3736 GetModulePath(dll).value().c_str());
3737 if (result != sandbox::SBOX_ALL_OK)
3738 return false;
3739 }
Will Harris1b9b4152019-08-21 22:33:503740#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303741
3742 return true;
[email protected]34f48682013-03-20 00:30:183743}
Will Harris956e0ca2019-08-23 20:47:393744
3745bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3746 PrefService* local_state = g_browser_process->local_state();
3747 if (local_state &&
3748 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3749 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3750 return false;
3751 return true;
3752}
3753
wfhc91e9672016-01-27 00:14:203754#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013755
bend1dd50f52016-06-26 22:10:483756void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
bena06f7d62017-04-04 20:48:523757 service_manager::BinderRegistry* registry,
Sam McNally52e50282017-11-29 00:54:023758 blink::AssociatedInterfaceRegistry* associated_registry,
leon.han0b618792016-06-16 01:53:513759 content::RenderProcessHost* render_process_host) {
nigeltaobeff0a102017-04-29 09:30:373760 // The CacheStatsRecorder is an associated binding, instead of a
3761 // non-associated one, because the sender (in the renderer process) posts the
3762 // message after a time delay, in order to rate limit. The association
3763 // protects against the render process host ID being recycled in that time
3764 // gap between the preparation and the execution of that IPC.
3765 associated_registry->AddInterface(
3766 base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID()));
3767
ben5be0b9132016-08-03 00:17:183768 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
Sami Kyostila5e1306d2019-08-14 11:01:293769 base::CreateSingleThreadTaskRunner({content::BrowserThread::UI});
Aran Gilmanf010bdd2019-08-28 19:55:443770 registry->AddInterface(base::Bind(&rappor::RapporRecorderImpl::Create,
3771 g_browser_process->rappor_service()),
3772 ui_task_runner);
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183773 registry->AddInterface(
Mike Wittman16fa5362018-09-04 17:27:303774 base::BindRepeating(&metrics::CallStackProfileCollector::Create));
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183775
dvallet233f57ab2016-12-21 03:17:103776 if (NetBenchmarking::CheckBenchmarkingEnabled()) {
3777 Profile* profile =
3778 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Alexandr Ilin4909ec82018-06-06 10:22:483779 auto* loading_predictor =
3780 predictors::LoadingPredictorFactory::GetForProfile(profile);
Robbie McElrathb0f248c2018-07-24 19:44:163781 registry->AddInterface(
3782 base::BindRepeating(
3783 &NetBenchmarking::Create,
3784 loading_predictor ? loading_predictor->GetWeakPtr() : nullptr,
Robbie McElrathb0f248c2018-07-24 19:44:163785 render_process_host->GetID()),
3786 ui_task_runner);
dvallet233f57ab2016-12-21 03:17:103787 }
yzshen2d8fb422017-06-01 20:29:403788
Nico Weberbc5b06f2019-07-26 14:00:133789#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Adam Rice41b89592017-07-28 10:33:443790 if (safe_browsing_service_) {
Yuzhu Shencb3011f62018-02-08 02:51:503791 content::ResourceContext* resource_context =
3792 render_process_host->GetBrowserContext()->GetResourceContext();
yzshen2d8fb422017-06-01 20:29:403793 registry->AddInterface(
Yuzhu Shen44094e22017-07-18 22:52:353794 base::Bind(
3795 &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
Yuzhu Shencb3011f62018-02-08 02:51:503796 render_process_host->GetID(), resource_context,
Yuzhu Shen44094e22017-07-18 22:52:353797 base::Bind(
3798 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Yuzhu Shencb3011f62018-02-08 02:51:503799 base::Unretained(this), resource_context)),
Sami Kyostila5e1306d2019-08-14 11:01:293800 base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
yzshen2d8fb422017-06-01 20:29:403801 }
Nico Weberbc5b06f2019-07-26 14:00:133802#endif
yzshen2d8fb422017-06-01 20:29:403803
Eric Romana00cf682018-11-01 20:09:113804 if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Julie Jeongeun Kimaaf568f2019-09-20 03:33:183805 registry->AddInterface(base::BindRepeating(&AddDataReductionProxyReceiver,
Clark DuVall812e07d2019-08-26 18:34:563806 render_process_host->GetID()),
3807 ui_task_runner);
Eric Romana00cf682018-11-01 20:09:113808 }
3809
chrisha927d8fe2017-01-18 23:09:513810#if defined(OS_WIN)
Patrick Monette9a10ae22018-06-14 22:18:183811 // Add the ModuleEventSink interface. This is the interface used by renderer
3812 // processes to notify the browser of modules in their address space. The
3813 // process handle is not yet available at this point so pass in a callback
3814 // to allow to retrieve a duplicate at the time the interface is actually
Ken Rockot15253a482019-08-23 17:44:593815 // created.
Patrick Monette9a10ae22018-06-14 22:18:183816 auto get_process = base::BindRepeating(
Ken Rockot15253a482019-08-23 17:44:593817 [](int id) -> base::Process {
3818 auto* host = content::RenderProcessHost::FromID(id);
3819 if (host)
3820 return host->GetProcess().Duplicate();
3821 return base::Process();
Patrick Monette9a10ae22018-06-14 22:18:183822 },
Ken Rockot15253a482019-08-23 17:44:593823 render_process_host->GetID());
Patrick Monette9a10ae22018-06-14 22:18:183824 registry->AddInterface(
Patrick Monetteaa2ec562019-03-20 23:37:453825 base::BindRepeating(
3826 &ModuleEventSinkImpl::Create, std::move(get_process),
3827 content::PROCESS_TYPE_RENDERER,
3828 base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)),
Patrick Monette9a10ae22018-06-14 22:18:183829 ui_task_runner);
chrisha927d8fe2017-01-18 23:09:513830#endif
Dan Harrington964d48c2018-08-03 15:52:243831#if defined(OS_ANDROID)
Carlos Knippschild63b3f042018-11-20 22:55:043832 Profile* profile =
3833 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Dan Harrington964d48c2018-08-03 15:52:243834 registry->AddInterface(
3835 base::BindRepeating(&android::AvailableOfflineContentProvider::Create,
Carlos Knippschild63b3f042018-11-20 22:55:043836 profile),
Sami Kyostila5e1306d2019-08-14 11:01:293837 base::CreateSingleThreadTaskRunner({BrowserThread::UI}));
Dan Harrington964d48c2018-08-03 15:52:243838#endif
chrisha927d8fe2017-01-18 23:09:513839
Nicholas Verneb5df4f72017-11-08 09:12:073840 for (auto* ep : extra_parts_) {
3841 ep->ExposeInterfacesToRenderer(registry, associated_registry,
3842 render_process_host);
3843 }
sammc335844522016-06-09 10:15:593844}
3845
bendd157e1a2016-07-22 03:15:573846void ChromeContentBrowserClient::ExposeInterfacesToMediaService(
ben8408b132017-05-01 23:48:503847 service_manager::BinderRegistry* registry,
xhwang9ab96482015-05-11 22:02:333848 content::RenderFrameHost* render_frame_host) {
Xiaohan Wang15303d0c2017-10-06 05:22:443849#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3850 registry->AddInterface(
3851 base::Bind(&OutputProtectionImpl::Create, render_frame_host));
ben155ecf82016-06-21 22:43:263852 registry->AddInterface(
John Rummell1b5da6102017-11-02 02:15:453853 base::Bind(&PlatformVerificationImpl::Create, render_frame_host));
Xiaohan Wang15303d0c2017-10-06 05:22:443854#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:493855
xhwangdb24d602017-05-20 06:32:243856#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
cm.sanchiad3f42a62017-11-07 11:33:353857 registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host));
xhwang116acb92017-04-03 18:27:203858#endif
xhwang9ab96482015-05-11 22:02:333859}
3860
Oksana Zhuravlova4dd171e82019-08-16 20:54:003861void ChromeContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
3862 service_manager::BinderMapWithContext<content::RenderFrameHost*>* map) {
3863 chrome::internal::PopulateChromeFrameBinders(map);
3864}
3865
Ben Goodger6a695c012017-06-20 20:21:203866void ChromeContentBrowserClient::BindInterfaceRequestFromFrame(
3867 content::RenderFrameHost* render_frame_host,
Ben Goodger6a695c012017-06-20 20:21:203868 const std::string& interface_name,
3869 mojo::ScopedMessagePipeHandle interface_pipe) {
Sam McNallyfaf9a402017-10-31 03:06:313870 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3871 !worker_interfaces_parameterized_) {
3872 InitWebContextInterfaces();
3873 }
Ben Goodger6a695c012017-06-20 20:21:203874
Ben Goodger272e0632017-07-19 23:27:003875 if (!frame_interfaces_parameterized_->TryBindInterface(
3876 interface_name, &interface_pipe, render_frame_host)) {
3877 frame_interfaces_->TryBindInterface(interface_name, &interface_pipe);
juncai1bf9f7c2016-03-22 20:46:563878 }
rockot0fa66a82015-06-11 17:25:453879}
3880
Mario Sanchez Prada39dee4a2019-07-09 07:15:403881void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113882 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403883 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3884 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113885 render_frame_host);
3886}
3887
Julie Jeongeun Kimdb52a622019-09-18 00:20:203888bool ChromeContentBrowserClient::BindAssociatedReceiverFromFrame(
Ken Rockot0aad7ec2018-07-31 15:58:443889 content::RenderFrameHost* render_frame_host,
3890 const std::string& interface_name,
3891 mojo::ScopedInterfaceEndpointHandle* handle) {
3892 if (interface_name == autofill::mojom::AutofillDriver::Name_) {
3893 autofill::ContentAutofillDriverFactory::BindAutofillDriver(
Shimi Zhang6b72d292019-07-12 20:52:423894 mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>(
3895 std::move(*handle)),
Ken Rockot0aad7ec2018-07-31 15:58:443896 render_frame_host);
3897 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583898 }
3899 if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) {
Shimi Zhang6b72d292019-07-12 20:52:423900 password_manager::ContentPasswordManagerDriverFactory::
3901 BindPasswordManagerDriver(
Julie Jeongeun Kimdb52a622019-09-18 00:20:203902 mojo::PendingAssociatedReceiver<
3903 autofill::mojom::PasswordManagerDriver>(std::move(*handle)),
Shimi Zhang6b72d292019-07-12 20:52:423904 render_frame_host);
Dominic Battre97d5edf2019-03-26 13:41:383905 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583906 }
3907 if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) {
Tao Bai02ab4dd42019-03-06 00:30:373908 content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver(
Shimi Zhang8ee32332019-07-12 17:59:363909 mojo::PendingAssociatedReceiver<
3910 content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)),
Tao Bai02ab4dd42019-03-06 00:30:373911 render_frame_host);
3912 return true;
Ken Rockot0aad7ec2018-07-31 15:58:443913 }
3914
3915 return false;
3916}
3917
Sam McNallyfaf9a402017-10-31 03:06:313918void ChromeContentBrowserClient::BindInterfaceRequestFromWorker(
3919 content::RenderProcessHost* render_process_host,
3920 const url::Origin& origin,
3921 const std::string& interface_name,
3922 mojo::ScopedMessagePipeHandle interface_pipe) {
3923 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3924 !worker_interfaces_parameterized_) {
3925 InitWebContextInterfaces();
3926 }
3927
3928 worker_interfaces_parameterized_->BindInterface(
3929 interface_name, std::move(interface_pipe), render_process_host, origin);
3930}
3931
Ken Rockot251bc6e02019-09-17 21:46:333932void ChromeContentBrowserClient::BindGpuHostReceiver(
3933 mojo::GenericPendingReceiver receiver) {
3934 if (auto r = receiver.As<metrics::mojom::CallStackProfileCollector>())
3935 metrics::CallStackProfileCollector::Create(std::move(r));
wittman757af872016-08-16 00:13:463936}
3937
Ken Rockotc185b2a2019-08-01 22:19:483938void ChromeContentBrowserClient::BindHostReceiverForRenderer(
3939 content::RenderProcessHost* render_process_host,
3940 mojo::GenericPendingReceiver receiver) {
3941#if BUILDFLAG(ENABLE_SPELLCHECK)
3942 if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) {
3943 SpellCheckHostChromeImpl::Create(render_process_host->GetID(),
3944 std::move(host_receiver));
3945 return;
3946 }
3947
3948#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
3949 if (auto panel_host_receiver =
3950 receiver.As<spellcheck::mojom::SpellCheckPanelHost>()) {
3951 SpellCheckPanelHostImpl::Create(render_process_host->GetID(),
3952 std::move(panel_host_receiver));
3953 return;
3954 }
3955#endif // BUILDFLAG(HAS_SPELLCHECK_PANEL)
3956#endif // BUILDFLAG(ENABLE_SPELLCHECK)
3957}
3958
Ken Rockot7c6275b2019-08-02 20:00:233959void ChromeContentBrowserClient::BindHostReceiverForRendererOnIOThread(
3960 int render_process_id,
3961 mojo::GenericPendingReceiver* receiver) {
3962 if (auto host_receiver =
3963 receiver->As<startup_metric_utils::mojom::StartupMetricHost>()) {
3964 startup_metric_utils::StartupMetricHostImpl::Create(
3965 std::move(host_receiver));
3966 return;
3967 }
3968}
3969
Ken Rockotfa5d57112019-05-29 20:57:143970void ChromeContentBrowserClient::WillStartServiceManager() {
John Abd-El-Malek27b3ebd22019-02-12 18:59:183971#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:053972 if (startup_data_) {
3973 auto* chrome_feature_list_creator =
3974 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183975 // This has to run very early before ServiceManagerContext is created.
3976 const base::Value* force_network_in_process_value =
Xi Han85079c22019-04-18 21:43:053977 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183978 ->GetPolicyService()
3979 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
3980 std::string()))
3981 .GetValue(policy::key::kForceNetworkInProcess);
3982 bool force_network_in_process = false;
3983 if (force_network_in_process_value)
3984 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3985 if (force_network_in_process)
3986 content::ForceInProcessNetworkService(true);
3987 }
3988#endif
xhwang5e630462015-10-30 03:18:483989}
3990
Ken Rockot06fd2832019-05-24 17:24:443991void ChromeContentBrowserClient::RunServiceInstance(
3992 const service_manager::Identity& identity,
3993 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
3994 const std::string& service_name = identity.name();
Ken Rockot91c40da82019-08-12 20:07:113995 ALLOW_UNUSED_LOCAL(service_name);
Ken Rockot3d8be742018-11-22 08:59:383996#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
3997 if (service_name == media::mojom::kMediaServiceName) {
Ken Rockotd80eb102018-11-29 14:55:163998 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443999 media::CreateMediaService(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414000 return;
Ken Rockot3d8be742018-11-22 08:59:384001 }
4002#endif
Ken Rockote116c202018-11-30 01:52:504003
4004#if defined(OS_CHROMEOS)
Ken Rockot06fd2832019-05-24 17:24:444005 auto service = ash_service_registry::HandleServiceRequest(
4006 service_name, std::move(*receiver));
Ken Rockotc15f34992018-12-01 21:27:574007 if (service)
4008 service_manager::Service::RunAsyncUntilTermination(std::move(service));
Lei Zhang194fcd32019-05-23 16:19:414009#endif // defined(OS_CHROMEOS)
Ken Rockot3d8be742018-11-22 08:59:384010}
4011
Ken Rockot8f39a272018-12-21 23:38:354012base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174013ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:584014 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:584015 return GetChromeContentBrowserOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584016 if (name == content::mojom::kGpuServiceName)
Ken Rockot341089f2019-01-11 23:11:584017 return GetChromeContentGpuOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584018 if (name == content::mojom::kRendererServiceName)
4019 return GetChromeContentRendererOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:584020 return base::nullopt;
benc70c0e32016-09-22 03:50:374021}
4022
Ken Rockot69aade02019-01-23 21:19:514023std::vector<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174024ChromeContentBrowserClient::GetExtraServiceManifests() {
Ken Rockot06fd2832019-05-24 17:24:444025 auto manifests = GetChromeBuiltinServiceManifests();
Ken Rockot06fd2832019-05-24 17:24:444026
Nico Weberaf3b00b2017-09-11 17:58:174027#if BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444028 manifests.push_back(GetNaClLoaderManifest());
Ken Rockot69aade02019-01-23 21:19:514029#if defined(OS_WIN) && defined(ARCH_CPU_X86)
Ken Rockot06fd2832019-05-24 17:24:444030 manifests.push_back(GetNaClBrokerManifest());
sammc2b0375b2016-12-22 01:26:174031#endif // defined(OS_WIN)
Nico Weberaf3b00b2017-09-11 17:58:174032#endif // BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444033
4034 return manifests;
sammc2b0375b2016-12-22 01:26:174035}
4036
peterbbcccc12015-02-11 22:23:334037void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:374038 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:334039 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:294040 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:084041 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:374042 DCHECK(ShouldAllowOpenURL(site_instance, params.url));
4043
4044 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:084045
zpengdb4a58e2017-01-10 17:40:324046#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:224047 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:294048 std::move(callback));
jam1c5a91492016-02-24 20:47:534049#else
cm.sanchi2522bc92017-12-04 08:04:134050 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
4051 params.url, params.transition);
4052 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:084053 nav_params.user_gesture = params.user_gesture;
4054
4055 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:294056 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:334057#endif
mlamourieb40d552015-02-05 00:57:084058}
4059
zhaobinf3704f82017-01-12 07:19:364060content::ControllerPresentationServiceDelegate*
4061ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
4062 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:464063 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:094064 return media_router::PresentationServiceDelegateImpl::
4065 GetOrCreateForWebContents(web_contents);
4066 }
haibinlu9e605a92015-06-06 03:45:094067 return nullptr;
4068}
4069
zhaobinf3704f82017-01-12 07:19:364070content::ReceiverPresentationServiceDelegate*
4071ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
4072 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:364073 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
4074 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
4075 // created for offscreen presentations. The WebContents must belong to
4076 // an incognito profile.
4077 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
4078 FromWebContents(web_contents)) {
4079 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
4080 return impl;
4081 }
4082 }
zhaobinf3704f82017-01-12 07:19:364083 return nullptr;
4084}
4085
horo48d4d3e2015-02-27 03:04:004086void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
4087 const GURL& url) {
mathp46284f32015-03-11 13:06:414088 if (url.is_valid()) {
4089 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
4090 metric, url);
4091 }
horo48d4d3e2015-02-27 03:04:004092}
4093
Matt Falkenhagen8479b202017-07-14 04:35:314094std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
4095 // Don't change these returned strings. They are written (in hashed form) into
4096 // UMA logs. If you add more strings, you must update histograms.xml and get
4097 // histograms review. Only Google domains should be here for privacy purposes.
4098 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
4099 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194100 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:314101 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194102 if (url.host() == "docs.google.com")
4103 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:314104 return std::string();
4105}
4106
avid6d88b912017-01-13 00:16:004107std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:474108ChromeContentBrowserClient::CreateThrottlesForNavigation(
4109 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:004110 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:274111
bmcquadeb4556552017-03-24 22:24:374112 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
4113 // that may delay or cancel navigations, so only NavigationThrottles that
4114 // don't delay or cancel navigations (e.g. throttles that are only observing
4115 // callbacks without affecting navigation behavior) should be added before
4116 // MetricsNavigationThrottle.
4117 if (handle->IsInMainFrame()) {
4118 throttles.push_back(
4119 page_load_metrics::MetricsNavigationThrottle::Create(handle));
4120 }
4121
brettw4b461082016-11-19 18:55:164122#if BUILDFLAG(ENABLE_PLUGINS)
tommycliae590f1602016-11-02 03:59:234123 std::unique_ptr<content::NavigationThrottle> flash_url_throttle =
4124 FlashDownloadInterception::MaybeCreateThrottleFor(handle);
4125 if (flash_url_throttle)
4126 throttles.push_back(std::move(flash_url_throttle));
trizzofo8ddaeb72016-09-01 23:18:274127#endif
4128
mmenkedb2637ff2017-03-30 23:59:424129#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4130 std::unique_ptr<content::NavigationThrottle> supervised_user_throttle =
4131 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle);
4132 if (supervised_user_throttle)
4133 throttles.push_back(std::move(supervised_user_throttle));
4134#endif
4135
clamy40c9e142015-09-29 11:18:474136#if defined(OS_ANDROID)
4137 // TODO(davidben): This is insufficient to integrate with prerender properly.
4138 // https://crbug.com/370595
4139 prerender::PrerenderContents* prerender_contents =
4140 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
4141 if (!prerender_contents && handle->IsInMainFrame()) {
4142 throttles.push_back(
4143 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304144 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474145 }
Min Qin0ab0e162017-11-14 21:57:194146 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574147#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474148 if (handle->IsInMainFrame()) {
4149 // Redirect some navigations to apps that have registered matching URL
4150 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574151 auto url_to_app_throttle =
4152 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:474153 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:094154 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:474155 }
4156#endif
clamy49678312015-10-22 21:59:004157
4158#if defined(OS_CHROMEOS)
4159 // Check if we need to add merge session throttle. This throttle will postpone
4160 // loading of main frames.
4161 if (handle->IsInMainFrame()) {
4162 // Add interstitial page while merge session process (cookie reconstruction
4163 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4164 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024165 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4166 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004167 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4168 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4169 }
Maggie Caia2f03f52019-04-02 02:13:284170 }
4171#endif
djacobo21e56e02016-07-02 01:14:314172
Maggie Caia2f03f52019-04-02 02:13:284173#if !defined(OS_ANDROID)
4174 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:154175 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:284176#if defined(OS_CHROMEOS)
4177 chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
4178#else
4179 apps::AppsNavigationThrottle::MaybeCreate(handle);
4180#endif
Dominick Ng7c289942018-03-27 05:57:154181 if (url_to_apps_throttle)
4182 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004183 }
4184#endif
4185
brettw00899e62016-11-12 02:10:174186#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004187 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094188 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514189
4190 std::unique_ptr<content::NavigationThrottle> user_script_throttle =
4191 extensions::ExtensionsBrowserClient::Get()
4192 ->GetUserScriptListener()
4193 ->CreateNavigationThrottle(handle);
4194 if (user_script_throttle)
4195 throttles.push_back(std::move(user_script_throttle));
naskob9164c42016-06-07 01:21:354196#endif
4197
bauerb8f9c37742017-03-30 15:04:124198#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4199 std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle =
4200 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle);
4201 if (supervised_user_nav_throttle)
4202 throttles.push_back(std::move(supervised_user_nav_throttle));
4203#endif
4204
csharrisone985ebc2017-04-04 17:05:034205 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:104206 if (auto* subresource_filter_client =
4207 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
4208 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
4209 &throttles);
csharrisone985ebc2017-04-04 17:05:034210 }
4211
zhenw6edd49c2017-07-12 05:49:454212#if !defined(OS_ANDROID)
4213 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4214 // enabled on non-Android platforms.
4215 std::unique_ptr<content::NavigationThrottle>
4216 background_tab_navigation_throttle = resource_coordinator::
4217 BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle);
4218 if (background_tab_navigation_throttle)
4219 throttles.push_back(std::move(background_tab_navigation_throttle));
4220#endif
4221
Nico Weberbc5b06f2019-07-26 14:00:134222#if BUILDFLAG(FULL_SAFE_BROWSING)
Jialiu Linbdbb81d2017-10-11 21:29:094223 std::unique_ptr<content::NavigationThrottle>
4224 password_protection_navigation_throttle =
4225 safe_browsing::MaybeCreateNavigationThrottle(handle);
4226 if (password_protection_navigation_throttle) {
4227 throttles.push_back(std::move(password_protection_navigation_throttle));
4228 }
4229#endif
4230
Joe DeBlasio6e8409a2019-02-20 23:08:274231 std::unique_ptr<content::NavigationThrottle>
Mustafa Emre Acere14f6262019-04-02 00:19:314232 lookalike_url_navigation_throttle = lookalikes::
Joe DeBlasio6e8409a2019-02-20 23:08:274233 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle);
4234 if (lookalike_url_navigation_throttle)
4235 throttles.push_back(std::move(lookalike_url_navigation_throttle));
Joe DeBlasio6e8409a2019-02-20 23:08:274236
Amber Wonf56d8f42017-08-31 22:29:404237 std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle =
4238 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle);
4239 if (pdf_iframe_throttle)
4240 throttles.push_back(std::move(pdf_iframe_throttle));
Amber Won6b5edc752017-08-17 19:23:544241
Charles Harrison6dd11d282017-10-03 06:14:514242 std::unique_ptr<content::NavigationThrottle> tab_under_throttle =
4243 TabUnderNavigationThrottle::MaybeCreate(handle);
4244 if (tab_under_throttle)
4245 throttles.push_back(std::move(tab_under_throttle));
4246
Jeremy Romanec48d7a2018-03-01 17:35:094247 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534248 handle, handle->GetWebContents()->GetBrowserContext()));
4249
Carlos IL5a9e7512019-06-13 22:35:284250 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4251 handle,
4252 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
4253 base::Bind(&SSLErrorHandler::HandleSSLError)));
Lucas Garron94b16052017-11-11 01:58:124254
Emily Starkd6896cd32019-08-21 04:55:544255 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4256
Christopher Thompson4137cec2017-12-19 05:34:234257 std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle =
4258 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle);
4259 if (https_upgrade_timing_throttle)
4260 throttles.push_back(std::move(https_upgrade_timing_throttle));
4261
Dmitry Gozman57b92ce2017-12-28 22:24:544262#if !defined(OS_ANDROID)
4263 std::unique_ptr<content::NavigationThrottle> devtools_throttle =
4264 DevToolsWindow::MaybeCreateNavigationThrottle(handle);
4265 if (devtools_throttle)
4266 throttles.push_back(std::move(devtools_throttle));
Conley Owensaafcf122018-02-26 18:53:514267
4268 std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle =
4269 NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle);
4270 if (new_tab_page_throttle)
4271 throttles.push_back(std::move(new_tab_page_throttle));
jdoerrie4f9376f2018-12-12 18:26:204272
4273 std::unique_ptr<content::NavigationThrottle>
4274 google_password_manager_throttle =
4275 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(
4276 handle);
4277 if (google_password_manager_throttle)
4278 throttles.push_back(std::move(google_password_manager_throttle));
Dmitry Gozman57b92ce2017-12-28 22:24:544279#endif
4280
Carlos IL4ee307e2018-12-22 03:19:004281 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
4282 throttles.push_back(
4283 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
4284 handle));
4285 }
Robert Ogdenafd250b2018-07-25 22:21:034286
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334287#if defined(OS_WIN) || defined(OS_MACOSX) || \
4288 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134289 std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle =
Robert Ogden4308eb12019-09-18 18:42:374290 browser_switcher::BrowserSwitcherNavigationThrottle::
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134291 MaybeCreateThrottleFor(handle);
4292 if (browser_switcher_throttle)
4293 throttles.push_back(std::move(browser_switcher_throttle));
4294#endif
4295
dchenge73d8520c2015-12-27 01:19:094296 return throttles;
clamy40c9e142015-09-29 11:18:474297}
4298
clamy1e5574e2016-09-29 16:48:444299std::unique_ptr<content::NavigationUIData>
4300ChromeContentBrowserClient::GetNavigationUIData(
4301 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094302 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444303}
4304
Xiaohan Wanga4e41842018-06-26 18:45:104305void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4306 const std::string& key_system,
4307 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4308 base::flat_set<media::VideoCodec>* video_codecs,
4309 base::flat_set<media::EncryptionMode>* encryption_schemes) {
4310#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264311 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104312 if (key_system == kWidevineKeySystem) {
4313 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4314 encryption_schemes);
4315 }
4316#endif
4317}
4318
[email protected]487974a2014-06-13 16:49:014319content::DevToolsManagerDelegate*
4320ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354321#if defined(OS_ANDROID)
4322 return new DevToolsManagerDelegateAndroid();
4323#else
[email protected]487974a2014-06-13 16:49:014324 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354325#endif
[email protected]487974a2014-06-13 16:49:014326}
4327
Rayan Kanso411e84e2019-02-13 15:27:404328void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4329 content::BrowserContext* browser_context,
4330 int service,
4331 base::Time expiration_time) {
4332 Profile* profile = Profile::FromBrowserContext(browser_context);
4333 DCHECK(profile);
4334
4335 auto* pref_service = profile->GetPrefs();
4336 DCHECK(pref_service);
4337
4338 DictionaryPrefUpdate pref_update(
4339 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4340 base::DictionaryValue* exp_dict = pref_update.Get();
4341
4342 // Convert |expiration_time| to minutes since that is the most granular
4343 // option that returns an int. base::Value does not accept int64.
4344 int expiration_time_minutes =
4345 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4346 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4347}
4348
4349base::flat_map<int, base::Time>
4350ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4351 content::BrowserContext* browser_context) {
4352 Profile* profile = Profile::FromBrowserContext(browser_context);
4353 DCHECK(profile);
4354
4355 auto* pref_service = profile->GetPrefs();
4356 DCHECK(pref_service);
4357
4358 auto* expiration_dict = pref_service->GetDictionary(
4359 prefs::kDevToolsBackgroundServicesExpirationDict);
4360 DCHECK(expiration_dict);
4361
4362 base::flat_map<int, base::Time> expiration_times;
4363 for (const auto& it : *expiration_dict) {
4364 // key.
4365 int service = 0;
4366 bool did_convert = base::StringToInt(it.first, &service);
4367 DCHECK(did_convert);
4368
4369 // value.
4370 DCHECK(it.second->is_int());
4371 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4372 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4373
4374 expiration_times[service] = expiration_time;
4375 }
4376
4377 return expiration_times;
4378}
4379
oysteinec563c582015-02-13 19:19:524380content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524381 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524382}
4383
[email protected]a6868c22013-10-09 02:50:294384bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4385 content::BrowserContext* browser_context,
4386 const GURL& url) {
brettw4b461082016-11-19 18:55:164387#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554388 return ChromeContentBrowserClientPluginsPart::
4389 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4390 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294391#else
4392 return false;
4393#endif
4394}
4395
[email protected]aec5ed52014-06-20 07:51:424396bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4397 content::BrowserContext* browser_context,
4398 const GURL& url) {
brettw4b461082016-11-19 18:55:164399#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554400 return ChromeContentBrowserClientPluginsPart::
4401 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4402 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064403#else
4404 return false;
4405#endif
4406}
4407
mlamourif8c23a2002015-01-27 13:10:104408void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014409 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434410 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524411 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104412
4413 WebContents* web_contents =
4414 WebContents::FromRenderFrameHost(render_frame_host);
4415 DCHECK(web_contents);
4416
mlamourif8c23a2002015-01-27 13:10:104417 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374418 prerender::PrerenderManagerFactory::GetForBrowserContext(
4419 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104420 if (prerender_manager &&
4421 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
danakj0018a29a2018-12-01 01:03:434422 *visibility_state = content::PageVisibilityState::kPrerender;
mlamourif8c23a2002015-01-27 13:10:104423 }
4424}
4425
Sam McNallyfaf9a402017-10-31 03:06:314426void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094427 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4428 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014429 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Sam McNallyfaf9a402017-10-31 03:06:314430 worker_interfaces_parameterized_ =
Jeremy Romanec48d7a2018-03-01 17:35:094431 std::make_unique<service_manager::BinderRegistryWithArgs<
Sam McNallyfaf9a402017-10-31 03:06:314432 content::RenderProcessHost*, const url::Origin&>>();
Ben Goodger6a695c012017-06-20 20:21:204433
Michael Martis4a542f52017-07-28 01:51:444434 // Register mojo ContentTranslateDriver interface only for main frame.
Anthony Vallee-Duboise2432137a2019-01-17 20:06:014435 frame_interfaces_parameterized_->AddInterface(
4436 base::BindRepeating(&language::BindContentTranslateDriver));
Ben Goodger6a695c012017-06-20 20:21:204437
4438 frame_interfaces_parameterized_->AddInterface(
Ken Rockotd480bee2019-08-27 18:54:484439 base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver));
Ben Goodger6a695c012017-06-20 20:21:204440
4441#if defined(OS_ANDROID)
4442 frame_interfaces_parameterized_->AddInterface(base::Bind(
Matt Giucaee4aefb2017-08-04 03:11:554443 &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>));
Ben Goodger6a695c012017-06-20 20:21:204444 frame_interfaces_parameterized_->AddInterface(
4445 base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>));
Kim Paulhamus3d33e442018-03-29 23:04:144446 frame_interfaces_parameterized_->AddInterface(
Amos Limdddb6992018-07-19 22:14:324447 base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>));
Michael Thiessen909ba032019-03-26 23:47:434448#if defined(BROWSER_MEDIA_CONTROLS_MENU)
4449 frame_interfaces_parameterized_->AddInterface(base::Bind(
4450 &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>));
4451#endif
Ben Goodger6a695c012017-06-20 20:21:204452#else
4453 if (base::FeatureList::IsEnabled(features::kWebPayments)) {
4454 frame_interfaces_parameterized_->AddInterface(
4455 base::Bind(&payments::CreatePaymentRequest));
4456 }
4457#endif
4458
Ben Goodger6a695c012017-06-20 20:21:204459#if defined(OS_ANDROID)
Matt Giuca00e993602017-06-23 05:17:544460 frame_interfaces_parameterized_->AddInterface(base::Bind(
4461 &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>));
Michael Thiessen07c444c2019-04-26 03:53:114462#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
4463 frame_interfaces_parameterized_->AddInterface(base::Bind(
4464 &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>));
4465#endif
Ben Goodger6a695c012017-06-20 20:21:204466#endif
Reilly Grant8e5c85c2017-07-07 16:35:064467
4468 frame_interfaces_parameterized_->AddInterface(
Lu Chen5bec7a302018-06-26 18:52:324469 base::BindRepeating(&NavigationPredictor::Create));
Dan Harringtonbc87c062018-10-31 15:21:244470
4471#if defined(OS_ANDROID)
4472 frame_interfaces_parameterized_->AddInterface(
Dan Harringtonf60bd502019-09-05 17:30:334473 base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create));
Dan Harringtonbc87c062018-10-31 15:21:244474#endif
Ben Goodger6a695c012017-06-20 20:21:204475}
4476
Robert Sesek466e43e2019-08-19 22:02:024477void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4478 base::FilePath user_data_dir;
4479 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4480 DCHECK(!user_data_dir.empty());
4481 network_contexts_parent_directory_.push_back(user_data_dir);
4482
4483 base::FilePath cache_dir;
4484 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4485 DCHECK(!cache_dir.empty());
4486 // On some platforms, the cache is a child of the user_data_dir so only
4487 // return the one path.
4488 if (!user_data_dir.IsParent(cache_dir))
4489 network_contexts_parent_directory_.push_back(cache_dir);
4490
4491 // If the cache location has been overridden by a switch or preference,
4492 // include that as well.
4493 if (auto* local_state = g_browser_process->local_state()) {
4494 base::FilePath pref_cache_dir =
4495 local_state->GetFilePath(prefs::kDiskCacheDir);
4496 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4497 network_contexts_parent_directory_.push_back(pref_cache_dir);
4498 }
4499}
4500
[email protected]30335fdf02014-02-26 19:51:274501void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174502 base::CommandLine* to_command_line,
4503 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544504 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274505#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544506 const version_info::Channel kMaxDisableEncryptionChannel =
4507 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274508#else
sdefresne6e883e42015-07-30 08:05:544509 const version_info::Channel kMaxDisableEncryptionChannel =
4510 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274511#endif
4512 if (channel <= kMaxDisableEncryptionChannel) {
4513 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444514 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274515 };
Avi Drissmand251e912018-12-26 15:46:374516 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4517 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274518 }
4519}
bashi933629552016-10-13 23:32:404520
miu54dca6c2016-11-17 10:59:384521#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4522void ChromeContentBrowserClient::CreateMediaRemoter(
4523 content::RenderFrameHost* render_frame_host,
4524 media::mojom::RemotingSourcePtr source,
4525 media::mojom::RemoterRequest request) {
miu54dca6c2016-11-17 10:59:384526 CastRemotingConnector::CreateMediaRemoter(
4527 render_frame_host, std::move(source), std::move(request));
miu54dca6c2016-11-17 10:59:384528}
4529#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464530
Michael Giuffrida6802ffe2017-09-29 03:40:254531base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4532 const base::CommandLine& command_line) {
4533 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164534}
4535
John Abd-El-Malek8efa11f2019-01-06 00:51:534536namespace {
4537// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024538class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534539 public:
4540 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174541 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534542 : protocol_handler_registry_(protocol_handler_registry) {}
4543 ~ProtocolHandlerThrottle() override = default;
4544
4545 void WillStartRequest(network::ResourceRequest* request,
4546 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294547 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534548 }
4549
4550 void WillRedirectRequest(net::RedirectInfo* redirect_info,
4551 const network::ResourceResponseHead& response_head,
4552 bool* defer,
4553 std::vector<std::string>* to_be_removed_headers,
4554 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294555 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534556 }
4557
4558 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294559 void TranslateUrl(GURL* url) {
4560 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4561 return;
4562 GURL translated_url = protocol_handler_registry_->Translate(*url);
4563 if (!translated_url.is_empty())
4564 *url = translated_url;
4565 }
4566
Clark DuValla411bda2019-08-02 03:09:174567 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534568};
4569} // namespace
4570
Minggang Wangf6840ecf2019-07-29 05:15:024571std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194572ChromeContentBrowserClient::CreateURLLoaderThrottles(
4573 const network::ResourceRequest& request,
4574 content::BrowserContext* browser_context,
4575 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4576 content::NavigationUIData* navigation_ui_data,
4577 int frame_tree_node_id) {
4578 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4579
Minggang Wangf6840ecf2019-07-29 05:15:024580 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194581
4582 Profile* profile = Profile::FromBrowserContext(browser_context);
4583
4584 ChromeNavigationUIData* chrome_navigation_ui_data =
4585 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4586
Clark DuVall68eb997f2019-06-28 05:42:284587 auto* drp_settings =
4588 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4589 browser_context);
4590 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4591 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4592 drp_settings) {
4593 if (!data_reduction_proxy_throttle_manager_) {
4594 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4595 data_reduction_proxy::DataReductionProxyThrottleManager,
4596 base::OnTaskRunnerDeleter>(
4597 new data_reduction_proxy::DataReductionProxyThrottleManager(
4598 drp_settings->data_reduction_proxy_service(),
4599 data_reduction_proxy::DataReductionProxyThrottleManager::
Clark DuVall0e901722019-08-14 23:31:374600 CreateConfig(drp_settings->data_reduction_proxy_service()
4601 ->config()
4602 ->GetProxiesForHttp())),
Clark DuVall68eb997f2019-06-28 05:42:284603 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4604 }
4605 net::HttpRequestHeaders headers;
4606 data_reduction_proxy::DataReductionProxyRequestOptions::
4607 AddPageIDRequestHeader(
4608 &headers,
4609 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4610 result.push_back(std::make_unique<
4611 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4612 headers, data_reduction_proxy_throttle_manager_.get()));
4613 }
4614
Nico Weberbc5b06f2019-07-26 14:00:134615#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564616 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4617 request.url, *profile->GetPrefs());
4618 if (!matches_enterprise_whitelist) {
4619 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4620 base::BindOnce(
4621 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4622 base::Unretained(this)),
4623 wc_getter, frame_tree_node_id, profile->GetResourceContext()));
4624 }
Nico Weberbc5b06f2019-07-26 14:00:134625#endif
Clark DuVall5497288d2019-07-17 00:17:564626
Clark DuVallfffa41e2019-06-25 20:27:194627 if (chrome_navigation_ui_data &&
4628 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4629 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4630 chrome_navigation_ui_data->prerender_mode(),
4631 chrome_navigation_ui_data->prerender_histogram_prefix(),
4632 base::BindOnce(GetPrerenderCanceller, wc_getter),
Sami Kyostila5e1306d2019-08-14 11:01:294633 base::CreateSingleThreadTaskRunner({BrowserThread::UI})));
Clark DuVallfffa41e2019-06-25 20:27:194634 }
4635
David Rogere8e83f3c2019-09-12 10:56:234636 signin::IdentityManager* identity_manager =
4637 IdentityManagerFactory::GetForProfile(profile);
4638 bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount();
Clark DuVallfffa41e2019-06-25 20:27:194639
4640 chrome::mojom::DynamicParams dynamic_params = {
4641 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4642 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4643 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4644 variations::VariationsHttpHeaderProvider::GetInstance()
4645 ->GetClientDataHeader(is_signed_in)};
4646 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
David Rogere8e83f3c2019-09-12 10:56:234647 profile->IsOffTheRecord(), std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194648
Clark DuValla411bda2019-08-02 03:09:174649 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4650 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214651
Clark DuVall39c2cfc2019-06-25 21:49:284652#if BUILDFLAG(ENABLE_PLUGINS)
4653 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464654 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284655#endif
4656
Robbie McElrath127ad2b2019-07-22 22:38:114657 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404658 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
Robbie McElrath127ad2b2019-07-22 22:38:114659 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4660 std::move(delegate), navigation_ui_data, wc_getter);
4661 if (signin_throttle)
4662 result.push_back(std::move(signin_throttle));
4663
Clark DuVallfffa41e2019-06-25 20:27:194664 return result;
4665}
4666
Ken Rockot6414c4d92017-11-08 19:58:324667void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464668 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324669 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414670#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464671 content::WebContents* web_contents =
4672 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414673#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324674 factories->emplace(
4675 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574676 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464677 web_contents->GetBrowserContext(),
4678 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414679#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4680#if defined(OS_CHROMEOS)
4681 Profile* profile =
4682 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304683 factories->emplace(content::kExternalFileScheme,
4684 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4685 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414686#endif // defined(OS_CHROMEOS)
4687#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324688}
4689
Ting Shao2dc60582019-07-15 04:43:364690void ChromeContentBrowserClient::
4691 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4692 content::BrowserContext* browser_context,
4693 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114694#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364695 DCHECK(browser_context);
4696 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364697 factories->emplace(
4698 extensions::kExtensionScheme,
4699 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4700 browser_context));
4701#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364702}
4703
Jay Civelli2578ebe2018-06-05 18:44:314704namespace {
4705
4706// The FileURLLoaderFactory provided to the extension background pages.
4707// Checks with the ChildProcessSecurityPolicy to validate the file access.
4708class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4709 public:
4710 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4711
4712 private:
4713 // network::mojom::URLLoaderFactory:
4714 void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
4715 int32_t routing_id,
4716 int32_t request_id,
4717 uint32_t options,
4718 const network::ResourceRequest& request,
4719 network::mojom::URLLoaderClientPtr client,
4720 const net::MutableNetworkTrafficAnnotationTag&
4721 traffic_annotation) override {
4722 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4723 child_id_, request.url)) {
4724 client->OnComplete(
4725 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
4726 return;
4727 }
4728 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454729 /*observer=*/nullptr,
4730 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314731 }
4732
4733 void Clone(network::mojom::URLLoaderFactoryRequest loader) override {
4734 bindings_.AddBinding(this, std::move(loader));
4735 }
4736
4737 int child_id_;
4738 mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
4739 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4740};
4741
4742} // namespace
4743
Ken Rockot6414c4d92017-11-08 19:58:324744void ChromeContentBrowserClient::
4745 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464746 int render_process_id,
4747 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324748 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414749#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4750 content::RenderFrameHost* frame_host =
4751 RenderFrameHost::FromID(render_process_id, render_frame_id);
4752 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4753#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4754
4755#if defined(OS_CHROMEOS)
4756 if (web_contents) {
4757 Profile* profile =
4758 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304759 factories->emplace(content::kExternalFileScheme,
4760 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4761 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414762 }
4763#endif // defined(OS_CHROMEOS)
4764
Ken Rockot6414c4d92017-11-08 19:58:324765#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464766 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4767 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324768 if (factory)
4769 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234770
4771 // This logic should match
4772 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314773 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234774 return;
Jay Civellic9bbf72d2018-03-24 01:58:314775
4776 Profile* profile =
4777 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4778 InstantService* instant_service =
4779 InstantServiceFactory::GetForProfile(profile);
4780 // The test below matches what's done by ShouldServiceRequestIOThread in
4781 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464782 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314783 factories->emplace(
4784 chrome::kChromeSearchScheme,
4785 content::CreateWebUIURLLoader(
4786 frame_host, chrome::kChromeSearchScheme,
4787 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234788 }
Jay Civellic9bbf72d2018-03-24 01:58:314789
Chris Mumfordbae8a742018-03-01 23:02:234790 extensions::ChromeExtensionWebContentsObserver* web_observer =
4791 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4792 web_contents);
4793
Karan Bhatia91928572018-03-06 01:18:074794 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4795 // to the |web_contents|.
4796 if (!web_observer)
4797 return;
4798
Chris Mumfordbae8a742018-03-01 23:02:234799 const Extension* extension =
4800 web_observer->GetExtensionFromFrame(frame_host, false);
4801 if (!extension)
4802 return;
4803
Sam McNally7414eeb72018-09-03 04:05:304804 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234805 // Support for chrome:// scheme if appropriate.
4806 if ((extension->is_extension() || extension->is_platform_app()) &&
4807 Manifest::IsComponentLocation(extension->location())) {
4808 // Components of chrome that are implemented as extensions or platform apps
4809 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304810 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4811 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4812 }
4813 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4814 (extension->is_platform_app() &&
4815 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234816 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024817 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4818 // URLs. Hosted apps are not allowed because they are served via web servers
4819 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304820 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4821 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024822 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304823 }
4824 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234825 factories->emplace(
4826 content::kChromeUIScheme,
4827 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4828 std::move(allowed_webui_hosts)));
4829 }
Jay Civelli2578ebe2018-06-05 18:44:314830
4831 // Extension with a background page get file access that gets approval from
4832 // ChildProcessSecurityPolicy.
4833 extensions::ExtensionHost* host =
4834 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4835 ->GetBackgroundHostForExtension(extension->id());
4836 if (host) {
4837 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4838 render_process_id));
4839 }
Chris Mumfordbae8a742018-03-01 23:02:234840#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324841}
4842
Ken Rockota0dfaca12018-02-15 07:26:254843bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214844 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254845 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384846 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444847 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264848 const url::Origin& request_initiator,
Dominic Farolino1be897a2019-07-20 08:11:424849 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184850 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4851 header_client,
Clark DuVall8dc4e502018-09-07 01:51:124852 bool* bypass_redirect_checks) {
Reilly Grant24bf8332018-08-27 21:55:014853 bool use_proxy = false;
4854
Ken Rockota0dfaca12018-02-15 07:26:254855#if BUILDFLAG(ENABLE_EXTENSIONS)
4856 auto* web_request_api =
4857 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214858 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254859
4860 // NOTE: Some unit test environments do not initialize
4861 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014862 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124863 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384864 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia4a834b32019-08-16 22:26:444865 browser_context, frame, render_process_id, type, factory_receiver,
4866 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124867 if (bypass_redirect_checks)
4868 *bypass_redirect_checks = use_proxy_for_web_request;
4869 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014870 }
Ken Rockota0dfaca12018-02-15 07:26:254871#endif
Reilly Grant24bf8332018-08-27 21:55:014872
Reilly Grantcc22e602018-09-07 15:25:204873 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444874 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4875 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014876
4877 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254878}
4879
Jian Lide7b43792018-06-01 23:22:134880std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4881ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4882 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144883 int frame_tree_node_id,
4884 const scoped_refptr<network::SharedURLLoaderFactory>&
4885 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134886 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4887 interceptors;
4888#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234889 interceptors.push_back(
4890 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4891 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134892#endif
Ryan Sturmaf523742019-01-16 00:15:454893
Robert Ogden3d5d5b42019-04-22 05:13:114894 ChromeNavigationUIData* chrome_navigation_ui_data =
4895 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4896
Ryan Sturm27d93f412019-02-15 21:30:144897 // TODO(ryansturm): Once this is on the UI thread, stop passing
4898 // |network_loader_factory| and have interceptors create one themselves.
4899 // https://crbug.com/931786
John Abd-El-Malek7577f262019-06-10 21:23:234900 if (base::FeatureList::IsEnabled(
Robert Ogdene5830c52019-09-23 21:42:234901 previews::features::kLitePageServerPreviews)) {
Ryan Sturmaf523742019-01-16 00:15:454902 interceptors.push_back(
Robert Ogden0f4d88682019-09-24 22:27:524903 std::make_unique<
4904 previews::PreviewsLitePageRedirectURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114905 network_loader_factory,
4906 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4907 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454908 }
4909
Jian Lide7b43792018-06-01 23:22:134910 return interceptors;
4911}
4912
Yutaka Hirano8e0b4d432019-07-04 07:12:384913bool ChromeContentBrowserClient::WillInterceptWebSocket(
4914 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334915#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384916 if (!frame) {
4917 return false;
4918 }
4919 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334920 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4921 frame->GetProcess()->GetBrowserContext());
4922
4923 // NOTE: Some unit test environments do not initialize
4924 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4925 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384926 return false;
Yutaka Hirano36c94952018-05-30 21:33:334927
Yutaka Hirano8e0b4d432019-07-04 07:12:384928 return web_request_api->MayHaveProxies();
4929#else
4930 return false;
4931#endif
4932}
4933
4934void ChromeContentBrowserClient::CreateWebSocket(
4935 content::RenderFrameHost* frame,
4936 WebSocketFactory factory,
4937 const GURL& url,
4938 const GURL& site_for_cookies,
4939 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404940 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4941 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384942#if BUILDFLAG(ENABLE_EXTENSIONS)
4943 if (!frame) {
4944 return;
4945 }
4946 auto* web_request_api =
4947 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4948 frame->GetProcess()->GetBrowserContext());
4949
4950 DCHECK(web_request_api);
4951 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
4952 site_for_cookies, user_agent,
4953 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334954#endif
4955}
4956
Maks Orlovich710d5e32019-07-09 20:16:454957bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464958 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454959 content::BrowserContext* browser_context,
4960 const url::Origin& origin,
4961 bool is_service_worker,
4962 int process_id,
4963 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034964 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454965 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4966#if BUILDFLAG(ENABLE_EXTENSIONS)
4967 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464968 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454969 extensions::ChromeExtensionCookies::Get(browser_context)
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034970 ->CreateRestrictedCookieManager(origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454971 return true;
4972 }
4973#endif
4974 return false;
4975}
4976
Matt Menkeae4fdb12018-06-02 06:32:544977void ChromeContentBrowserClient::OnNetworkServiceCreated(
4978 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534979 PrefService* local_state;
4980 if (g_browser_process) {
4981 DCHECK(g_browser_process->local_state());
4982 local_state = g_browser_process->local_state();
4983 } else {
Xi Han85079c22019-04-18 21:43:054984 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4985 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534986 }
4987
4988 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4989 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4990
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494991 // Create SystemNetworkContextManager if it has not been created yet. We need
4992 // to set up global NetworkService state before anything else uses it and this
4993 // is the first opportunity to initialize SystemNetworkContextManager with the
4994 // NetworkService.
4995 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534996 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074997
Min Qin8caab1d2018-10-03 17:28:134998 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544999 network_service);
5000}
5001
Julie Jeongeun Kim5984e992019-09-11 11:00:465002mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:255003ChromeContentBrowserClient::CreateNetworkContext(
5004 content::BrowserContext* context,
5005 bool in_memory,
5006 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:505007 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:455008 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:255009}
5010
Robert Sesek34f68f312019-01-14 20:25:115011std::vector<base::FilePath>
5012ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:025013 DCHECK(!network_contexts_parent_directory_.empty());
5014 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:115015}
5016
Min Qin75ed6df2017-12-01 20:39:155017bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135018 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155019#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5020 // It is OK to load the saved offline copy, in MHTML format.
5021 ChromeNavigationUIData* chrome_navigation_ui_data =
5022 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5023 if (!chrome_navigation_ui_data)
5024 return false;
5025 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5026 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5027 return offline_page_data && offline_page_data->is_offline_page();
5028#else
5029 return false;
5030#endif
5031}
5032
Min Qin30a78a12017-12-06 01:29:135033bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5034 const GURL& url,
5035 const std::string& mime_type) {
5036#if BUILDFLAG(ENABLE_EXTENSIONS)
5037 // Special-case user scripts to get downloaded instead of viewed.
5038 return extensions::UserScript::IsURLUserScript(url, mime_type);
5039#else
5040 return false;
5041#endif
5042}
5043
Donna Wu838ac362018-08-10 10:36:335044void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345045 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:045046 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grantc31b8192017-12-15 19:54:345047 if (!base::FeatureList::IsEnabled(features::kWebUsb))
5048 return;
5049
Reilly Grantc31b8192017-12-15 19:54:345050 WebContents* web_contents =
5051 WebContents::FromRenderFrameHost(render_frame_host);
5052 if (!web_contents) {
5053 NOTREACHED();
5054 return;
5055 }
5056
5057 UsbTabHelper* tab_helper =
5058 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Miyoung Shin62622152019-08-27 05:13:045059 tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:345060}
5061
Reilly Grant0d282322019-01-29 02:42:585062#if !defined(OS_ANDROID)
5063content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5064 if (!serial_delegate_)
5065 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5066 return serial_delegate_.get();
5067}
Matt Reynolds93616f9b2019-06-07 01:28:525068
5069content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5070 if (!hid_delegate_)
5071 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5072 return hid_delegate_.get();
5073}
Reilly Grant0d282322019-01-29 02:42:585074
Balazs Engedya7ff70982018-06-04 18:14:475075std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5076ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:225077 content::RenderFrameHost* render_frame_host,
5078 const std::string& relying_party_id) {
5079 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
5080 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:475081}
Nina Satragno8c832df2019-07-29 15:59:395082#endif
Balazs Engedya7ff70982018-06-04 18:14:475083
Jun Cai9409ded2018-01-30 00:19:465084std::unique_ptr<net::ClientCertStore>
5085ChromeContentBrowserClient::CreateClientCertStore(
5086 content::ResourceContext* resource_context) {
5087 if (!resource_context)
5088 return nullptr;
5089 return ProfileIOData::FromResourceContext(resource_context)
5090 ->CreateClientCertStore();
5091}
5092
David Benjamineced01fc2019-02-27 18:29:025093std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395094ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585095 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025096 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035097 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245098 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395099 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035100 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395101 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565102 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:035103 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:025104 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:205105 std::move(response_headers), LoginHandler::PRE_COMMIT,
5106 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:395107}
5108
John Abd-El-Maleka67add82018-03-09 18:22:015109bool ChromeContentBrowserClient::HandleExternalProtocol(
5110 const GURL& url,
John Abd-El-Malek92bf3602019-07-31 02:25:485111 content::WebContents::Getter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015112 int child_id,
5113 content::NavigationUIData* navigation_data,
5114 bool is_main_frame,
5115 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455116 bool has_user_gesture,
Clark DuVallb6042ed32019-07-15 17:20:455117 network::mojom::URLLoaderFactoryPtr* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015118#if BUILDFLAG(ENABLE_EXTENSIONS)
5119 // External protocols are disabled for guests. An exception is made for the
5120 // "mailto" protocol, so that pages that utilize it work properly in a
5121 // WebView.
5122 ChromeNavigationUIData* chrome_data =
5123 static_cast<ChromeNavigationUIData*>(navigation_data);
5124 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5125 (chrome_data &&
5126 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5127 !url.SchemeIs(url::kMailToScheme)) {
5128 return false;
5129 }
5130#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5131
5132#if defined(OS_ANDROID)
5133 // Main frame external protocols are handled by
5134 // InterceptNavigationResourceThrottle.
5135 if (is_main_frame)
5136 return false;
5137#endif // defined(ANDROID)
5138
Sami Kyostila5e1306d2019-08-14 11:01:295139 base::PostTask(FROM_HERE, {BrowserThread::UI},
5140 base::BindOnce(&LaunchURL, url, web_contents_getter,
5141 page_transition, has_user_gesture));
John Abd-El-Maleka67add82018-03-09 18:22:015142 return true;
5143}
5144
Jennifer Apacible4f854a82018-04-06 22:22:115145std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285146ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5147 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115148 // Note: content::OverlayWindow::Create() is defined by platform-specific
5149 // implementation in chrome/browser/ui/views. This layering hack, which goes
5150 // through //content and ContentBrowserClient, allows us to work around the
5151 // dependency constraints that disallow directly calling
5152 // chrome/browser/ui/views code either from here or from other code in
5153 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285154 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115155}
5156
Clark DuVallfffa41e2019-06-25 20:27:195157bool ChromeContentBrowserClient::IsSafeRedirectTarget(
5158 const GURL& url,
5159 content::BrowserContext* context) {
5160#if BUILDFLAG(ENABLE_EXTENSIONS)
5161 if (url.SchemeIs(extensions::kExtensionScheme)) {
5162 const Extension* extension = extensions::ExtensionRegistry::Get(context)
5163 ->enabled_extensions()
5164 .GetByID(url.host());
5165 if (!extension)
5166 return false;
5167 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5168 extension, url.path());
5169 }
5170#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5171 return true;
5172}
5173
Kunihiko Sakamoto19aa7082019-02-25 03:14:435174void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565175 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115176 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565177 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435178 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5179 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565180}
5181
dbeam25472e0c2017-06-23 19:02:315182// Static; handles rewriting Web UI URLs.
5183bool ChromeContentBrowserClient::HandleWebUI(
5184 GURL* url,
5185 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:395186 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315187 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395188 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315189 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5190 chrome::kChromeUIHelpHost);
5191 return true; // Return true to update the displayed URL.
5192 }
5193
Hector Carmona566a20b2019-09-13 22:44:425194#if defined(OS_WIN)
5195 // TODO(crbug.com/1003960): Remove when issue is resolved.
5196 if (url->SchemeIs(content::kChromeUIScheme) &&
5197 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5198 url::Replacements<char> replacements;
5199 replacements.SetHost(
5200 chrome::kChromeUIWelcomeHost,
5201 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5202 *url = url->ReplaceComponents(replacements);
5203 return true;
5204 }
5205#endif // defined(OS_WIN)
5206
dbeam25472e0c2017-06-23 19:02:315207 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5208 browser_context, *url)) {
5209 return false;
5210 }
5211
5212#if defined(OS_CHROMEOS)
5213 // Special case : in ChromeOS in Guest mode bookmarks and history are
5214 // disabled for security reasons. New tab page explains the reasons, so
5215 // we redirect user to new tab page.
5216 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5217 if (url->SchemeIs(content::kChromeUIScheme) &&
5218 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5219 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5220 // Rewrite with new tab URL
5221 *url = GURL(chrome::kChromeUINewTabURL);
5222 }
5223 }
5224#endif
5225
5226 return true;
5227}
5228
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065229bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5230 content::BrowserContext* browser_context,
5231 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325232 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065233#if defined(OS_ANDROID)
5234 return false;
5235#else
5236 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5237 ->GetForBrowserContext(browser_context)
5238 ->ShowPaymentHandlerWindow(url, std::move(callback));
5239 return true;
5240#endif
5241}
5242
Dan Beam141c48932019-08-22 02:29:395243// static
dbeam25472e0c2017-06-23 19:02:315244bool ChromeContentBrowserClient::HandleWebUIReverse(
5245 GURL* url,
5246 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425247#if defined(OS_WIN)
5248 // TODO(crbug.com/1003960): Remove when issue is resolved.
5249 // No need to actually reverse-rewrite the URL, but return true to update the
5250 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5251 if (url->SchemeIs(content::kChromeUIScheme) &&
5252 url->host() == chrome::kChromeUIWelcomeHost) {
5253 return true;
5254 }
5255#endif // defined(OS_WIN)
5256
dbeam25472e0c2017-06-23 19:02:315257 // No need to actually reverse-rewrite the URL, but return true to update the
5258 // displayed URL when rewriting chrome://help to chrome://settings/help.
5259 return url->SchemeIs(content::kChromeUIScheme) &&
5260 url->host() == chrome::kChromeUISettingsHost;
5261}
5262
Dan Beamf0a7e112019-06-07 18:40:585263const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
5264 return ui::NativeTheme::GetInstanceForWeb();
5265}
5266
scottmgde42fb92017-02-10 17:56:035267// static
michaeln10e5fc352017-02-07 02:07:585268void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
5269 const storage::QuotaSettings* settings) {
5270 g_default_quota_settings = settings;
5271}
Yuzhu Shen44094e22017-07-18 22:52:355272
Clark DuVall5497288d2019-07-17 00:17:565273scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505274ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
5275 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:355276 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5277
Yuzhu Shencb3011f62018-02-08 02:51:505278 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
5279 if (!io_data->safe_browsing_enabled()->GetValue())
5280 return nullptr;
5281
Yuzhu Shen44094e22017-07-18 22:52:355282 // |safe_browsing_service_| may be unavailable in tests.
5283 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5284 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435285 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355286 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435287 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355288 }
5289
Clark DuVall5497288d2019-07-17 00:17:565290 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355291}
Daniel Vogelheim6008f572018-09-24 14:35:145292
5293base::Optional<std::string>
5294ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:265295 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185296 content::NavigationHandle* handle) {
5297 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5298 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145299}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525300
Takashi Toyoshima5af383aa2019-07-22 15:24:225301bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525302 // We require --user-data-dir flag too so that no dangerous changes are made
5303 // in the user's regular profile.
5304 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5305 switches::kUserDataDir);
5306}
rajendrantfeea8592018-10-19 18:26:065307
5308void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5309 int32_t network_traffic_annotation_id_hash,
5310 int64_t recv_bytes,
5311 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035312 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5313 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5314 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5315 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065316 }
5317}
Ryan Sturmaa05092f2018-10-21 03:56:545318
5319content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5320 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395321 content::NavigationHandle* navigation_handle,
5322 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135323 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5324 initial_state, navigation_handle, current_navigation_url);
5325
5326 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5327}
5328
5329content::PreviewsState
5330ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5331 content::PreviewsState initial_state,
5332 content::NavigationHandle* navigation_handle,
5333 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295335 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215336
Ryan Sturmaa05092f2018-10-21 03:56:545337 // If this is not a main frame, return the initial state. If there are no
5338 // previews in the state, return the state as is.
5339 if (!navigation_handle->IsInMainFrame() ||
5340 navigation_handle->IsSameDocument()) {
5341 return initial_state;
5342 }
5343
Robert Ogdena994eb42019-02-14 19:15:085344 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395345 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085346
Doug Arnettb3b99bc2019-08-09 16:55:565347 // Check if initial state specifies no previews should be considered.
5348 if (initial_state == content::PREVIEWS_OFF)
5349 return initial_state;
5350
Robert Ogdena994eb42019-02-14 19:15:085351 // Do not allow previews on POST navigations since the primary opt-out
5352 // mechanism is to reload the page. Because POST navigations are not
5353 // idempotent, we do not want to show a preview on a POST navigation where
5354 // opting out would cause another navigation, i.e.: a reload.
5355 if (navigation_handle->IsPost())
5356 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395357
5358 content::WebContents* web_contents = navigation_handle->GetWebContents();
5359 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5360
Ryan Sturmda2a0e02018-10-25 01:52:215361 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545362
5363 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5364 Profile::FromBrowserContext(browser_context));
5365 auto* data_reduction_proxy_settings =
5366 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5367 browser_context);
5368 // If the profile does not support previews or Data Saver, do not turn on
5369 // Previews.
5370 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355371 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545372 return content::PREVIEWS_OFF;
5373 }
5374
5375 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215376 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545377 // If this tab does not have a PreviewsUITabHelper, no preview should be
5378 // served.
5379 if (!ui_tab_helper)
5380 return content::PREVIEWS_OFF;
5381
5382 DCHECK(!browser_context->IsOffTheRecord());
5383
5384 // Other previews objects should all exist and be initialized if we have made
5385 // it past earlier checks.
5386 previews::PreviewsDeciderImpl* previews_decider_impl =
5387 previews_service->previews_ui_service()->previews_decider_impl();
5388 DCHECK(previews_decider_impl);
5389
Ryan Sturm647d1d92018-11-07 15:41:395390 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545391 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5392
Ryan Sturm647d1d92018-11-07 15:41:395393 previews::PreviewsUserData* previews_data =
5394 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5395
5396 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315397 // previews) and cannot re-evaluate PreviewsState once previews triggering
5398 // logic has already been run, so they should not change. Assume that
5399 // previews triggering logic has run when PreviewsUserData already exists and
5400 // a Lite Page Redirect preview is not being attempted, since it may also
5401 // create a previews_data before this point.
5402 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395403 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315404 previews_triggering_logic_already_ran =
5405 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395406 } else {
5407 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5408 navigation_handle, previews_decider_impl->GeneratePageId());
5409 }
5410
5411 DCHECK(previews_data);
5412
Robert Ogden01770b362019-05-22 17:36:435413 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5414 previews::switches::kForceEnablePreviews)) {
Sophie Changacd9e2d2019-08-22 22:05:095415 previews_decider_impl->LoadPageHints(navigation_handle);
Robert Ogden01770b362019-05-22 17:36:435416 return content::ALL_SUPPORTED_PREVIEWS;
5417 }
5418
Ryan Sturmaa05092f2018-10-21 03:56:545419 bool is_reload =
5420 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5421
Ryan Sturm647d1d92018-11-07 15:41:395422 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515423 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395424
5425 // For now, treat server previews types as a single decision, and do not
5426 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5427 // header, nor does the plumbing exist to modify the PreviewsState within the
5428 // URLLoader.
Seanac57e9b92019-04-29 19:19:315429 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395430 // Copy the server state that was used before the redirect for the initial
5431 // URL.
Robert Ogden869986f2019-06-20 19:12:055432 previews_state |=
5433 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395434 } else {
Doug Arnetta3dc71582018-11-08 00:25:105435 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215436 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305437 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395438 previews_state |= server_previews_enabled_state;
5439 }
Ryan Sturmaa05092f2018-10-21 03:56:545440 }
5441
Robert Ogden198d6572019-06-26 15:15:335442 // Evaluate Offline, NoScript, and ResourceBlocking previews.
Ryan Sturmaa05092f2018-10-21 03:56:545443 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315444 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355445 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5446 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545447
5448 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395449 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545450 return content::PREVIEWS_OFF;
5451 }
5452
5453 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395454 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545455 return content::PREVIEWS_NO_TRANSFORM;
5456 }
5457
5458 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395459 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5460 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545461 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395462 }
5463
5464 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5465 if (delegate) {
5466 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5467 }
Ryan Sturmaa05092f2018-10-21 03:56:545468
5469 // If the allowed previews are limited by the embedder, ensure previews honors
5470 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395471 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5472 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545473 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5474 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5475 previews_state = content::PREVIEWS_OFF;
5476 }
Ryan Sturm647d1d92018-11-07 15:41:395477 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545478 return previews_state;
5479}
5480
5481// static
5482content::PreviewsState
5483ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5484 const GURL& url,
5485 data_reduction_proxy::DataReductionProxyData* drp_data,
5486 previews::PreviewsUserData* previews_user_data,
5487 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055488 content::PreviewsState initial_state,
5489 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545490 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5491 if (!previews::HasEnabledPreviews(initial_state))
5492 return content::PREVIEWS_OFF;
5493
5494 // Check if the server sent a preview directive.
5495 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555496 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545497
Ryan Sturmaa05092f2018-10-21 03:56:545498 // Check the various other client previews types.
5499 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055500 previews_user_data, url, previews_state, previews_decider,
5501 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545502}
5503
5504content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5505 content::PreviewsState initial_state,
5506 content::NavigationHandle* navigation_handle,
5507 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135508 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5509 initial_state, navigation_handle, response_headers);
5510
5511 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5512}
5513
5514content::PreviewsState
5515ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5516 content::PreviewsState initial_state,
5517 content::NavigationHandle* navigation_handle,
5518 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5520 // Only support HTTP and HTTPS.
5521 if (navigation_handle->IsErrorPage() ||
5522 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5523 return content::PREVIEWS_OFF;
5524 }
5525
5526 // If this is not a main frame, return the initial state. If there are no
5527 // previews in the state, return the state as is.
5528 if (!previews::HasEnabledPreviews(initial_state) ||
5529 !navigation_handle->IsInMainFrame() ||
5530 navigation_handle->IsSameDocument()) {
5531 return initial_state;
5532 }
5533
5534 // WebContents that don't have a PreviewsUITabHelper are not supported.
5535 PreviewsUITabHelper* ui_tab_helper =
5536 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5537 if (!ui_tab_helper)
5538 return content::PREVIEWS_OFF;
5539
5540 // If we did not previously create a PreviewsUserData, do not go any further.
5541 previews::PreviewsUserData* previews_user_data =
5542 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5543 if (!previews_user_data)
5544 return content::PREVIEWS_OFF;
5545
5546 PreviewsService* previews_service =
5547 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5548 navigation_handle->GetWebContents()->GetBrowserContext()));
5549
5550 if (!previews_service || !previews_service->previews_ui_service())
5551 return content::PREVIEWS_OFF;
5552
5553// Check if offline previews are being used and set it in the user data.
5554#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5555 offline_pages::OfflinePageTabHelper* tab_helper =
5556 offline_pages::OfflinePageTabHelper::FromWebContents(
5557 navigation_handle->GetWebContents());
5558
Ryan Sturmfc7d92f2019-02-12 02:24:235559 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5560 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5561
5562 // If this is an offline page, but not a preview, then we should not attempt
5563 // any previews or surface the previews UI.
5564 if (is_offline_page && !is_offline_preview)
5565 return content::PREVIEWS_OFF;
5566
5567 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545568#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5569
5570 // Annotate request if no-transform directive found in response headers.
5571 if (response_headers &&
5572 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265573 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545574 }
5575
5576 previews::PreviewsDeciderImpl* previews_decider_impl =
5577 previews_service->previews_ui_service()->previews_decider_impl();
5578 DCHECK(previews_decider_impl);
5579
Clark DuVall9c5a72cc2018-10-25 01:29:215580 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5581 auto* settings =
5582 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5583 navigation_handle->GetWebContents()->GetBrowserContext());
5584 if (settings) {
5585 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5586 // does not yet have all the response information.
5587 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5588 response_headers);
5589 }
Ryan Sturmaa05092f2018-10-21 03:56:545590
5591 // Determine effective PreviewsState for this committed main frame response.
5592 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215593 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055594 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545595
5596 // Double check that we never serve a preview when we have a
5597 // cache-control:no-transform directive.
5598 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5599 !previews::HasEnabledPreviews(committed_state));
5600
Robert Ogdended292c6f2019-05-03 22:44:515601 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545602 previews_user_data->set_committed_previews_state(committed_state);
5603
5604 previews::PreviewsType committed_type =
5605 previews::GetMainFramePreviewsType(committed_state);
5606
5607 // Capture committed previews type, if any, in PreviewsUserData.
5608 // Note: this is for the subset of previews types that are decided upon
5609 // navigation commit. Previews types that are determined prior to
5610 // navigation (such as for offline pages or for redirecting to another
5611 // url), are not set here.
5612 previews_user_data->SetCommittedPreviewsType(committed_type);
5613
5614 // Log the commit decision.
5615 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5616 previews_decider_impl->LogPreviewDecisionMade(
5617 (previews_user_data->cache_control_no_transform_directive()
5618 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5619 : previews::PreviewsEligibilityReason::COMMITTED),
5620 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055621 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055622 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545623
5624 return committed_state;
5625}
Charlie Harrison650e11422018-12-04 00:37:265626
5627void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5628 content::RenderFrameHost* render_frame_host,
5629 blink::mojom::WebFeature feature) {
5630 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5631 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5632 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5633 render_frame_host, new_features);
5634}
Yutaka Hirano968d6252018-12-04 05:09:315635
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525636std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315637 return ::GetProduct();
5638}
5639
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525640std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315641 return ::GetUserAgent();
5642}
Sam McNallyd54e23f92019-01-16 04:42:395643
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525644blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175645 return ::GetUserAgentMetadata();
5646}
5647
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525648base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275649 // This icon is available on Android, but adds 19KiB to the APK. Since it
5650 // isn't used on Android we exclude it to avoid bloat.
5651#if !defined(OS_ANDROID)
5652 return base::Optional<gfx::ImageSkia>(
5653 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5654 IDR_PRODUCT_LOGO_256));
5655#else
5656 return base::nullopt;
5657#endif
5658}
5659
Sam McNallyd54e23f92019-01-16 04:42:395660bool ChromeContentBrowserClient::IsBuiltinComponent(
5661 content::BrowserContext* browser_context,
5662 const url::Origin& origin) {
5663#if BUILDFLAG(ENABLE_EXTENSIONS)
5664 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5665 browser_context, origin);
5666#else
5667 return false;
5668#endif
5669}
Oleg Davydov2cc0167b2019-02-05 14:32:485670
5671bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5672 const GURL& url,
5673 content::BrowserContext* context) {
5674 PolicyBlacklistService* service =
5675 PolicyBlacklistFactory::GetForBrowserContext(context);
5676
5677 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5678 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5679 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5680}
Dominic Mazzoni21fb0282019-02-13 18:32:475681
5682ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5683 content::BrowserContext* browser_context) {
5684 Profile* profile = Profile::FromBrowserContext(browser_context);
5685 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5686}
Eric Karld6cd75b2019-03-14 22:01:365687
5688#if defined(OS_ANDROID)
5689content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525690ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365691 if (features::UseDisplayWideColorGamut()) {
5692 return WideColorGamutHeuristic::kUseDisplay;
5693 }
5694 return WideColorGamutHeuristic::kNone;
5695}
5696#endif
Ehsan Karamad91413d72019-03-22 16:37:485697
5698base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435699ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465700 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485701 base::flat_set<std::string> mime_types;
5702#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465703 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485704 for (const auto& pair : map)
5705 mime_types.insert(pair.first);
5706#endif
5707 return mime_types;
5708}
Yao Xiaod06607b2019-05-02 23:16:365709
5710void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5711 const content::WebContents* web_contents,
5712 const content::RenderFrameHost* frame_host,
5713 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525714 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365715 const ChromeSubresourceFilterClient* client =
5716 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5717 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045718 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365719 if (!user_gesture) {
5720 if (base::FeatureList::IsEnabled(
5721 blink::features::
5722 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5723 download_policy->SetDisallowed(
5724 content::NavigationDownloadType::kAdFrameNoGesture);
5725 } else {
5726 download_policy->SetAllowed(
5727 content::NavigationDownloadType::kAdFrameNoGesture);
5728 }
Yao Xiaod06607b2019-05-02 23:16:365729 }
5730 }
5731}
Jun Cai732a05e32019-05-29 19:34:195732
5733bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5734 content::BrowserContext* browser_context,
5735 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525736 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195737 const HostContentSettingsMap* const content_settings =
5738 HostContentSettingsMapFactory::GetForProfile(
5739 Profile::FromBrowserContext(browser_context));
5740
5741 if (content_settings->GetContentSetting(
5742 requesting_origin.GetURL(), embedding_origin.GetURL(),
5743 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING,
5744 std::string()) == CONTENT_SETTING_BLOCK) {
5745 return true;
5746 }
5747
5748 return false;
5749}
5750
5751void ChromeContentBrowserClient::BlockBluetoothScanning(
5752 content::BrowserContext* browser_context,
5753 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525754 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195755 HostContentSettingsMap* const content_settings =
5756 HostContentSettingsMapFactory::GetForProfile(
5757 Profile::FromBrowserContext(browser_context));
5758
5759 content_settings->SetContentSettingDefaultScope(
5760 requesting_origin.GetURL(), embedding_origin.GetURL(),
5761 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(),
5762 CONTENT_SETTING_BLOCK);
5763}