blob: 10bc86fe6880142655cb8fd9bc4ba39b180bf7c0 [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 Ogdenafd250b2018-07-25 22:21:03102#include "chrome/browser/previews/previews_lite_page_decider.h"
Robert Ogdene7fdca92018-10-12 17:53:06103#include "chrome/browser/previews/previews_lite_page_navigation_throttle.h"
Ryan Sturmaf523742019-01-16 00:15:45104#include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h"
Ryan Sturmaa05092f2018-10-21 03:56:54105#include "chrome/browser/previews/previews_service.h"
106#include "chrome/browser/previews/previews_service_factory.h"
107#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03108#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14109#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32110#include "chrome/browser/profiles/profile_io_data.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06111#include "chrome/browser/profiles/renderer_updater.h"
112#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56113#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
114#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44115#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]05fcf982011-04-19 00:44:14116#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:38117#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40118#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45119#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31120#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
121#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Carlos IL4ee307e2018-12-22 03:19:00122#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40123#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35124#include "chrome/browser/safe_browsing/ui_manager.h"
125#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43126#include "chrome/browser/search/search.h"
Jay Civelli2578ebe2018-06-05 18:44:31127#include "chrome/browser/sessions/session_tab_helper.h"
Reilly Grantcc22e602018-09-07 15:25:20128#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35129#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Robbie McElrath38f47af2019-09-19 21:51:40130#include "chrome/browser/signin/header_modification_delegate_impl.h"
David Rogere8e83f3c2019-09-12 10:56:23131#include "chrome/browser/signin/identity_manager_factory.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28132#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02133#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48134#include "chrome/browser/speech/tts_controller_delegate_impl.h"
Eric Lawrenced0acf2a7c2017-07-20 18:02:48135#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
[email protected]848dd042011-06-04 18:24:03136#include "chrome/browser/ssl/ssl_blocking_page.h"
estark3ba11132015-04-10 01:38:33137#include "chrome/browser/ssl/ssl_cert_reporter.h"
Joe DeBlasio9b996292019-01-31 05:09:32138#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07139#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35140#include "chrome/browser/ssl/ssl_error_handler.h"
Lucas Garron94b16052017-11-11 01:58:12141#include "chrome/browser/ssl/ssl_error_navigation_throttle.h"
Christopher Thompson4137cec2017-12-19 05:34:23142#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10143#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35144#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45145#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52146#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19147#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44148#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38149#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51150#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08151#include "chrome/browser/ui/browser_navigator.h"
152#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43153#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39154#include "chrome/browser/ui/login/login_handler.h"
Emily Starkd6896cd32019-08-21 04:55:54155#include "chrome/browser/ui/login/login_navigation_throttle.h"
Makoto Shimazuc7502932018-08-15 02:12:56156#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25157#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44158#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58159#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50160#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01161#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25162#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53163#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25164#include "chrome/browser/web_applications/components/app_registrar.h"
165#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23166#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22167#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01168#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51169#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14170#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22171#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30172#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:02173#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50174#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34175#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37176#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12177#include "chrome/common/pref_names.h"
evliubc2aa0472019-08-09 20:19:19178#include "chrome/common/pref_names_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:12179#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22180#include "chrome/common/prerender_util.h"
[email protected]3e69bc82011-05-26 23:22:38181#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28182#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02183#include "chrome/common/secure_origin_whitelist.h"
wittman832321f52016-10-10 18:18:38184#include "chrome/common/stack_sampling_configuration.h"
[email protected]c5dbef02011-05-13 05:06:09185#include "chrome/common/url_constants.h"
Peter Boström8e9b1632019-08-22 23:12:47186#include "chrome/common/webui_url_constants.h"
benc70c0e32016-09-22 03:50:37187#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18188#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30189#include "chrome/installer/util/google_update_settings.h"
leon.han04b276e2016-06-01 01:34:16190#include "components/autofill/content/browser/content_autofill_driver_factory.h"
brettwf1958912015-10-07 19:43:12191#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53192#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44193#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04194#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48195#include "components/cloud_devices/common/cloud_devices_switches.h"
Tao Bai02ab4dd42019-03-06 00:30:37196#include "components/content_capture/browser/content_capture_receiver_manager.h"
mukai8eaec822014-10-25 17:53:16197#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09198#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16199#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52200#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45201#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08202#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03203#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09204#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Clark DuVall0e901722019-08-14 23:31:37205#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
Ryan Sturmaa05092f2018-10-21 03:56:54206#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28207#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43208#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09209#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32210#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03211#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24212#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43213#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01214#include "components/feature_engagement/public/feature_constants.h"
215#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39216#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20217#include "components/language/core/browser/pref_names.h"
wittmane16da2782016-09-21 16:43:04218#include "components/metrics/call_stack_profile_collector.h"
[email protected]8e885de2014-07-22 23:36:53219#include "components/metrics/client_info.h"
Scott Violet9ae82892018-03-01 18:38:12220#include "components/nacl/common/buildflags.h"
sammc2b0375b2016-12-22 01:26:17221#include "components/nacl/common/nacl_constants.h"
drogerc690e8802015-09-21 14:29:16222#include "components/net_log/chrome_net_log.h"
Tao Baib827b202019-09-19 21:22:12223#include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
224#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
225#include "components/page_load_metrics/browser/page_load_metrics_util.h"
leon.han97e8f752016-09-06 06:13:20226#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06227#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53228#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54229#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18230#include "components/policy/core/common/policy_service.h"
231#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26232#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54233#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08234#include "components/prefs/pref_service.h"
235#include "components/prefs/scoped_user_pref_update.h"
Sophie Changff1fc382019-08-21 16:30:21236#include "components/previews/content/previews_decider.h"
Ryan Sturmaa05092f2018-10-21 03:56:54237#include "components/previews/content/previews_decider_impl.h"
238#include "components/previews/content/previews_ui_service.h"
239#include "components/previews/content/previews_user_data.h"
Ryan Sturmaa05092f2018-10-21 03:56:54240#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45241#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43242#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56243#include "components/rappor/public/rappor_utils.h"
nigeltao2f673762016-10-14 03:27:28244#include "components/rappor/rappor_recorder_impl.h"
nzolghadrd87a308d2016-12-07 15:45:56245#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35246#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
247#include "components/safe_browsing/browser/mojo_safe_browsing_impl.h"
248#include "components/safe_browsing/browser/url_checker_delegate.h"
Nico Weberbc5b06f2019-07-26 14:00:13249#include "components/safe_browsing/buildflags.h"
timvolodine89cf11712017-05-15 18:05:07250#include "components/safe_browsing/common/safe_browsing_prefs.h"
Tim Volodinee45938472017-09-21 10:08:22251#include "components/safe_browsing/db/database_manager.h"
Yuzhu Shencb3011f62018-02-08 02:51:50252#include "components/safe_browsing/features.h"
Jialiu Linbdbb81d2017-10-11 21:29:09253#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14254#include "components/security_interstitials/content/origin_policy_ui.h"
David Rogere8e83f3c2019-09-12 10:56:23255#include "components/signin/public/identity_manager/identity_manager.h"
Scott Violetd7983c52018-03-03 00:24:41256#include "components/spellcheck/spellcheck_buildflags.h"
Ken Rockot7c6275b2019-08-02 20:00:23257#include "components/startup_metric_utils/browser/startup_metric_host_impl.h"
csharrisone985ebc2017-04-04 17:05:03258#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17259#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21260#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28261#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33262#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46263#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22264#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43265#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30266#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38267#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28268#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03269#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31270#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41271#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09272#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03273#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59274#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19275#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31276#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35277#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47278#include "content/public/browser/navigation_handle.h"
279#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11280#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50281#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30282#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33283#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05284#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34285#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48286#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27287#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13288#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08289#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19290#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21291#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23292#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43293#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18294#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56295#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40296#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18297#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58298#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57299#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23300#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44301#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31302#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05303#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56304#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43305#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59306#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48307#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30308#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28309#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04310#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31311#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44312#include "media/media_buildflags.h"
313#include "media/mojo/buildflags.h"
Jay Civelli2578ebe2018-06-05 18:44:31314#include "mojo/public/cpp/bindings/binding_set.h"
Shimi Zhang6b72d292019-07-12 20:52:42315#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Ken Rockot40a1df792019-05-08 22:15:52316#include "mojo/public/cpp/bindings/pending_receiver.h"
317#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot0adc1e42019-05-24 08:20:08318#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53319#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51320#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58321#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23322#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46323#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57324#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14325#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38326#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19327#include "printing/buildflags/buildflags.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37328#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50329#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50330#include "services/network/public/cpp/resource_request.h"
Jay Civelli668c097f2018-05-16 20:44:13331#include "services/service_manager/embedder/switches.h"
Tom Sepez15d4e5202017-09-27 23:59:05332#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34333#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03334#include "services/strings/grit/services_strings.h"
pilgrime92c5fcd2014-09-10 23:31:23335#include "storage/browser/fileapi/external_mount_points.h"
John Delaneyac24e572019-04-30 19:47:02336#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02337#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Julie Jeongeun Kimd3d00a12019-03-25 01:46:25338#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h"
Leon Hanc819dc62019-01-28 04:30:19339#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17340#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Eric Willigers3eeae17c2019-03-13 17:32:10341#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21342#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26343#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18344#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39345#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08346#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35347#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21348#include "ui/base/ui_base_switches.h"
349#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49350#include "ui/native_theme/caption_style.h"
351#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57352#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45353#include "url/gurl.h"
354#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26355
Ken Rockot69aade02019-01-23 21:19:51356#if BUILDFLAG(ENABLE_NACL)
357#include "components/nacl/loader/nacl_loader_manifest.h"
358#if defined(OS_WIN) && defined(ARCH_CPU_X86)
359#include "components/nacl/broker/nacl_broker_manifest.h"
360#endif
361#endif
362
[email protected]b48c9182011-10-26 18:03:30363#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20364#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38365#include "chrome/browser/chrome_browser_main_win.h"
Patrick Monettebb543942019-05-17 17:45:32366#include "chrome/browser/win/conflicts/module_database.h"
367#include "chrome/browser/win/conflicts/module_event_sink_impl.h"
Jerry Lina0de7ce2018-06-22 15:18:36368#include "chrome/install_static/install_util.h"
[email protected]34f48682013-03-20 00:30:18369#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38370#elif defined(OS_MACOSX)
371#include "chrome/browser/chrome_browser_main_mac.h"
Guido Urdaneta1a2917432018-05-10 18:32:32372#include "services/audio/public/mojom/constants.mojom.h"
[email protected]b48c9182011-10-26 18:03:30373#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:42374#include "ash/public/cpp/tablet_mode.h"
Miyoung Shin7e1b1b12019-08-02 12:23:50375#include "ash/public/mojom/constants.mojom.h"
Joshua Peraza30d8fc72019-08-19 17:24:30376#include "chrome/app/chrome_crash_reporter_client.h"
Scott Violet47f00e52018-05-04 22:50:31377#include "chrome/browser/ash_service_registry.h"
hashimotoa53e7e82016-10-26 06:30:47378#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17379#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30380#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24381#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Sam McNallyd8b7d822018-08-21 03:18:18382#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08383#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48384#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41385#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32386#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58387#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00388#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
389#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44390#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39391#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31392#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33393#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44394#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10395#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36396#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27397#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
djacobo21e56e02016-07-02 01:14:31398#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10399#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21400#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10401#include "chromeos/constants/chromeos_switches.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11402#include "components/crash/content/app/breakpad_linux.h"
John Abd-El-Malek35bfaa52019-08-20 16:22:07403#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:58404#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50405#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26406#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30407#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09408#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35409#include "base/android/application_status_listener.h"
Samuel Huange63048d2019-09-03 20:35:45410#include "chrome/android/features/dev_ui/buildflags.h"
zqzhang93e959d12017-03-16 13:10:20411#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36412#include "chrome/browser/android/chrome_context_util.h"
413#include "chrome/browser/android/devtools_manager_delegate_android.h"
Dan Harrington964d48c2018-08-03 15:52:24414#include "chrome/browser/android/download/available_offline_content_provider.h"
Min Qin0ab0e162017-11-14 21:57:19415#include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h"
Scott Violetef765b92017-06-09 21:26:36416#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
417#include "chrome/browser/android/service_tab_launcher.h"
418#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42419#include "chrome/browser/android/tab_web_contents_delegate_android.h"
[email protected]81054f812012-08-30 00:47:09420#include "chrome/browser/chrome_browser_main_android.h"
Dan Harrington954c8822019-01-09 18:40:48421#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07422#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38423#include "chrome/common/chrome_descriptors.h"
Joshua Peraza934e5592018-07-18 23:43:11424#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07425#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47426#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36427#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54428#include "services/service_manager/public/cpp/interface_provider.h"
Han Leonabbe7c902018-08-30 02:08:10429#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Julie Jeongeun Kimb6a0a1f2019-03-21 05:08:26430#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
agrieve05398f52015-06-24 18:59:00431#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36432#include "ui/base/ui_base_paths.h"
Samuel Huange63048d2019-09-03 20:35:45433#if BUILDFLAG(DFMIFY_DEV_UI)
434#include "chrome/browser/android/dev_ui/dev_ui_url_handler.h"
435#endif // BUILDFLAG(DFMIFY_DEV_UI)
[email protected]b48c9182011-10-26 18:03:30436#elif defined(OS_POSIX)
437#include "chrome/browser/chrome_browser_main_posix.h"
438#endif
439
tmartinofb341882017-02-10 19:36:53440#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40441#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36442#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54443#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59444#include "chrome/browser/media/unified_autoplay_config.h"
mathpf709499d2017-01-09 20:48:36445#include "chrome/browser/payments/payment_request_factory.h"
Marc Treib7895941d2017-11-28 12:37:02446#include "chrome/browser/search/instant_service.h"
447#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46448#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51449#include "chrome/browser/ui/browser.h"
450#include "chrome/browser/ui/browser_finder.h"
451#include "chrome/browser/ui/browser_list.h"
452#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20453#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51454#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39455#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
456#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43457#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27458#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28459#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36460
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33461#if defined(OS_WIN) || defined(OS_MACOSX) || \
462 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52463#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
464#endif
465
[email protected]a220b5932013-09-21 03:47:44466#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02467#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02468#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13469#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02470#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13471#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43472#endif
[email protected]b80f68432011-05-02 17:22:30473
Maggie Caia2f03f52019-04-02 02:13:28474// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
475// single navigation throttle to display the intent picker on all platforms.
476#if !defined(OS_ANDROID)
477#if defined(OS_CHROMEOS)
478#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
479#else
480#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
481#endif
482#endif
483
[email protected]e8b6ca02013-07-10 18:00:51484#if defined(TOOLKIT_VIEWS)
485#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
486#endif
487
estaded3aa0e82016-02-17 22:55:21488#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22489#if defined(USE_X11)
490#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
491#else
estaded3aa0e82016-02-17 22:55:21492#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22493#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51494#endif
495
Mohsen Izadif1958f22019-01-18 20:29:31496#if defined(USE_OZONE)
497#include "ui/ozone/public/ozone_platform.h"
498#endif
499
[email protected]e8b6ca02013-07-10 18:00:51500#if defined(USE_X11)
501#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
502#endif
503
brettwab78fef2016-10-12 02:56:05504#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19505#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
506#endif
507
Nico Weberaf3b00b2017-09-11 17:58:17508#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55509#include "components/nacl/browser/nacl_browser.h"
510#include "components/nacl/browser/nacl_host_message_filter.h"
511#include "components/nacl/browser/nacl_process_host.h"
512#include "components/nacl/common/nacl_process_type.h"
513#include "components/nacl/common/nacl_switches.h"
514#endif
515
brettw00899e62016-11-12 02:10:17516#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05517#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20518#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27519#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23520#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Pavol Marko41c37b12019-08-07 10:56:32521#include "chrome/browser/extensions/extension_util.h"
Clark DuVall2cf99249e2018-09-19 19:11:51522#include "chrome/browser/extensions/user_script_listener.h"
523#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28524#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Eric Willigers007ef302019-08-29 09:58:46525#include "chrome/browser/ui/web_applications/app_browser_controller.h"
fsamuel8dfa19a2015-05-05 01:00:39526#include "components/guest_view/browser/guest_view_base.h"
527#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25528#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31529#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35530#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32531#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12532#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57533#include "extensions/browser/extension_system.h"
hanxi0d0a1e92014-08-26 18:39:48534#include "extensions/browser/guest_view/web_view/web_view_guest.h"
535#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
536#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31537#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27538#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28539#include "extensions/common/extension.h"
540#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13541#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28542#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33543#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28544#include "extensions/common/permissions/permissions_data.h"
545#include "extensions/common/permissions/socket_permission.h"
546#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34547#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25548
brettw4b461082016-11-19 18:55:16549#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55550#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27551#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39552#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55553#endif
554
bauerb8f9c37742017-03-30 15:04:12555#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
556#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
557#endif
558
thakis678822e2017-04-20 17:20:34559#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38560#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09561#endif
562
weilifabbf7572017-05-22 19:05:16563#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21564#include "chrome/browser/printing/printing_message_filter.h"
weilifabbf7572017-05-22 19:05:16565#endif
Lei Zhanga2fa14c2018-05-15 00:05:21566
Xiaohan Wanga4e41842018-06-26 18:45:10567#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49568#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wanga4e41842018-06-26 18:45:10569#include "chrome/browser/media/platform_verification_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26570#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10571#include "chrome/browser/media/widevine_hardware_caps_win.h"
572#include "third_party/widevine/cdm/widevine_cdm_common.h"
573#endif
574#endif
575
xhwangdb24d602017-05-20 06:32:24576#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
xhwang116acb92017-04-03 18:27:20577#include "chrome/browser/media/android/cdm/media_drm_storage_factory.h"
578#endif
xhwangc86d76e42016-03-14 23:38:49579
xhwangdb24d602017-05-20 06:32:24580#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
Aran Gilmanf010bdd2019-08-28 19:55:44581#include "media/mojo/mojom/constants.mojom.h" // nogncheck
xhwangb1d65fd2016-10-19 20:55:52582#include "media/mojo/services/media_service_factory.h" // nogncheck
alokp6ecb2382016-01-27 00:40:00583#endif
584
mmenkedb2637ff2017-03-30 23:59:42585#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
586#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
587#endif
588
Nico Weberbc5b06f2019-07-26 14:00:13589#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35590#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
591#endif
592
Jian Lide7b43792018-06-01 23:22:13593#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54594#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13595#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
596#endif
597
Will Cassella40837ba2019-07-01 21:32:00598#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43599#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
600#endif
601
Ken Rockotc185b2a2019-08-01 22:19:48602#if BUILDFLAG(ENABLE_SPELLCHECK)
603#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
604#include "components/spellcheck/common/spellcheck.mojom.h"
605#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
606#include "chrome/browser/spellchecker/spell_check_panel_host_impl.h"
607#endif
608#endif
609
Michael Thiessen909ba032019-03-26 23:47:43610#if defined(BROWSER_MEDIA_CONTROLS_MENU)
611#include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h"
612#endif
613
Michael Thiessen07c444c2019-04-26 03:53:11614#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
615#include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h"
616#endif
617
[email protected]c7abd422012-09-25 00:20:08618using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39619using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31620using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13621using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59622using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00623using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02624using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11625using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07626using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33627using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13628using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05629using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38630using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39631
[email protected]0daaebfe2014-03-15 00:09:05632#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20633using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05634#endif
635
brettw00899e62016-11-12 02:10:17636#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28637using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27638using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28639using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28640using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27641#endif
642
brettw4b461082016-11-19 18:55:16643#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55644using plugins::ChromeContentBrowserClientPluginsPart;
645#endif
646
[email protected]c5dbef02011-05-13 05:06:09647namespace {
648
michaeln10e5fc352017-02-07 02:07:58649const storage::QuotaSettings* g_default_quota_settings;
650
brettw4b461082016-11-19 18:55:16651#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42652// TODO(teravest): Add renderer-side API-specific checking for these APIs so
653// that blanket permission isn't granted to all dev channel APIs for these.
654// http://crbug.com/386743
655const char* const kPredefinedAllowedDevChannelOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44656 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
657 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
[email protected]aec5ed52014-06-20 07:51:42658};
659
[email protected]9de4da52014-05-24 12:26:50660const char* const kPredefinedAllowedFileHandleOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44661 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
662 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
[email protected]10c39222013-11-13 20:09:25663};
664
[email protected]9de4da52014-05-24 12:26:50665const char* const kPredefinedAllowedSocketOrigins[] = {
Aran Gilmanf010bdd2019-08-28 19:55:44666 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
667 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
668 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
669 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
670 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
671 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
672 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
673 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
674 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
675 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
676 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
677 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
678 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
679 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
680 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
681 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
682 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
683 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
684 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
685 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
686 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
687 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40688};
[email protected]93f72062013-05-29 20:29:40689#endif
[email protected]e461da2f2012-02-16 19:06:40690
Will Harris1b9b4152019-08-21 22:33:50691#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30692// Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when
693// running on Windows 10 1511 and above. See
694// https://blogs.windows.com/blog/tag/code-integrity-guard/.
695const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity",
Will Harris6dd1f842019-08-05 21:01:33696 base::FEATURE_ENABLED_BY_DEFAULT};
Will Harris1b9b4152019-08-21 22:33:50697#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
698 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:30699
lazyboy5d5fede02016-03-10 04:10:14700enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53701 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14702 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53703
704 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14705 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53706
707 // An extension or app tried to load a resource of a different platform app in
708 // a tab.
709 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
710
711 // A non-app and non-extension page tried to load a platform app in a tab.
712 APP_LOADED_IN_TAB_SOURCE_OTHER,
713
lazyboy5d5fede02016-03-10 04:10:14714 APP_LOADED_IN_TAB_SOURCE_MAX
715};
716
Lei Zhang2cfceac2018-11-14 19:36:33717// Cached version of the locale so we can return the locale on the I/O
718// thread.
719std::string& GetIOThreadApplicationLocale() {
720 static base::NoDestructor<std::string> s;
721 return *s;
722}
723
[email protected]f8f93eb2012-09-25 03:06:24724// Returns a copy of the given url with its host set to given host and path set
725// to given path. Other parts of the url will be the same.
726GURL ReplaceURLHostAndPath(const GURL& url,
727 const std::string& host,
728 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05729 url::Replacements<char> replacements;
730 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
731 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24732 return url.ReplaceComponents(replacements);
733}
734
madfbd10852017-01-20 03:15:33735// Handles the rewriting of the new tab page URL based on group policy.
736bool HandleNewTabPageLocationOverride(
737 GURL* url,
738 content::BrowserContext* browser_context) {
739 if (!url->SchemeIs(content::kChromeUIScheme) ||
740 url->host() != chrome::kChromeUINewTabHost)
741 return false;
742
743 Profile* profile = Profile::FromBrowserContext(browser_context);
744 std::string ntp_location =
745 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
746 if (ntp_location.empty())
747 return false;
748
749 *url = GURL(ntp_location);
750 return true;
751}
752
Becca Hughesfe8c32c2018-03-21 13:36:56753#if !defined(OS_ANDROID)
754// Check if the current url is whitelisted based on a list of whitelisted urls.
755bool IsURLWhitelisted(const GURL& current_url,
Jan Wilken Dörrie53e009b2019-09-09 14:17:41756 base::span<const base::Value> whitelisted_urls) {
Becca Hughesfe8c32c2018-03-21 13:36:56757 // Only check on HTTP and HTTPS pages.
758 if (!current_url.SchemeIsHTTPOrHTTPS())
759 return false;
760
761 for (auto const& value : whitelisted_urls) {
762 ContentSettingsPattern pattern =
763 ContentSettingsPattern::FromString(value.GetString());
764 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
765 continue;
766 if (pattern.Matches(current_url))
767 return true;
768 }
769
770 return false;
771}
772
773// Check if autoplay is allowed by policy configuration.
774bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
775 PrefService* prefs) {
776 DCHECK(prefs);
777
778 // Check if we have globally allowed autoplay by policy.
779 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
780 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
781 return true;
782 }
783
784 if (!contents)
785 return false;
786
787 // Check if the current URL matches a URL pattern on the whitelist.
788 const base::ListValue* autoplay_whitelist =
789 prefs->GetList(prefs::kAutoplayWhitelist);
790 return autoplay_whitelist &&
791 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
792 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
793}
794#endif
795
Joshua Perazaf890e4b2019-01-03 19:19:02796#if defined(OS_ANDROID)
797int GetCrashSignalFD(const base::CommandLine& command_line) {
798 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
799}
800#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03801breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
802 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02803 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52804 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02805 {
806 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31807 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03808 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50809 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02810 crash_handler->StartUploaderThread();
811 return crash_handler;
812 }
813}
814
avi3ef9ec9e2014-12-22 22:50:17815int GetCrashSignalFD(const base::CommandLine& command_line) {
[email protected]9de4da52014-05-24 12:26:50816 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39817 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31818 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02819 if (!crash_handler)
820 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18821 return crash_handler->GetDeathSignalSocket();
822 }
823
824 std::string process_type =
825 command_line.GetSwitchValueASCII(switches::kProcessType);
826
[email protected]779dd282013-10-19 15:57:02827 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31828 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02829 if (!crash_handler)
830 crash_handler = CreateCrashHandlerHost(process_type);
831 return crash_handler->GetDeathSignalSocket();
832 }
[email protected]a1733df2012-06-22 11:24:18833
[email protected]779dd282013-10-19 15:57:02834 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31835 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02836 if (!crash_handler)
837 crash_handler = CreateCrashHandlerHost(process_type);
838 return crash_handler->GetDeathSignalSocket();
839 }
[email protected]a1733df2012-06-22 11:24:18840
[email protected]779dd282013-10-19 15:57:02841 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31842 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02843 if (!crash_handler)
844 crash_handler = CreateCrashHandlerHost(process_type);
845 return crash_handler->GetDeathSignalSocket();
846 }
[email protected]a1733df2012-06-22 11:24:18847
James Cook9207cc12017-10-19 17:08:39848 if (process_type == switches::kUtilityProcess) {
849 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
850 if (!crash_handler)
851 crash_handler = CreateCrashHandlerHost(process_type);
852 return crash_handler->GetDeathSignalSocket();
853 }
854
[email protected]a1733df2012-06-22 11:24:18855 return -1;
856}
Joshua Perazaf890e4b2019-01-03 19:19:02857#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18858
[email protected]eabbfb12013-04-05 23:28:35859void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52860 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33861 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35862}
863
estark3ba11132015-04-10 01:38:33864// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31865// SSLErrorHandler. Uses CertificateReportingService to send reports. The
866// service handles queueing and re-sending of failed reports. Each certificate
867// error creates a new instance of this class.
868class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33869 public:
meacerf43117a2016-12-27 21:02:31870 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12871 content::WebContents* web_contents)
872 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
873 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31874 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33875
876 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55877 void ReportInvalidCertificateChain(
878 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31879 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33880 }
881
882 private:
meacerf43117a2016-12-27 21:02:31883 CertificateReportingService* service_;
884
885 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33886};
887
bshe4f53ce42015-11-30 16:56:31888#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05889float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59890 static const float kMinFSM = 1.05f;
891 static const int kWidthForMinFSM = 320;
892 static const float kMaxFSM = 1.3f;
893 static const int kWidthForMaxFSM = 800;
894
boliu21c5afa2017-01-11 19:34:23895 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59896
897 if (minWidth <= kWidthForMinFSM)
898 return kMinFSM;
899 if (minWidth >= kWidthForMaxFSM)
900 return kMaxFSM;
901
902 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
903 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
Aran Gilmanf010bdd2019-08-28 19:55:44904 (kWidthForMaxFSM - kWidthForMinFSM);
[email protected]b255a8e0e82013-10-22 04:03:59905 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
906}
zpengdb4a58e2017-01-10 17:40:32907
[email protected]916615b2013-09-11 18:19:44908#endif // defined(OS_ANDROID)
909
brettw00899e62016-11-12 02:10:17910#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53911
912AppLoadedInTabSource ClassifyAppLoadedInTabSource(
913 const GURL& opener_url,
914 const extensions::Extension* target_platform_app) {
915 if (opener_url.SchemeIs(extensions::kExtensionScheme)) {
916 if (opener_url.host_piece() == target_platform_app->id()) {
917 // This platform app was trying to window.open() one of its own URLs.
918 if (opener_url ==
919 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
920 // Source was the background page.
921 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
922 } else {
923 // Source was a different page inside the app.
924 return APP_LOADED_IN_TAB_SOURCE_APP;
925 }
926 }
927 // The forbidden app URL was being opened by a different app or extension.
928 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
929 }
930 // The forbidden app URL was being opened by a non-extension page (e.g. http).
931 return APP_LOADED_IN_TAB_SOURCE_OTHER;
932}
[email protected]9c7656382014-08-08 21:02:30933
Charles Harrison34f67862017-08-22 01:04:17934// Returns true if there is is an extension matching |url| in
935// |opener_render_process_id| with APIPermission::kBackground.
936//
937// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
938// hosted app, even though normal extensions just use the host.
939bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35940 extensions::ProcessMap* process_map,
941 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17942 const GURL& url,
csharrison95f01e922017-04-24 18:52:35943 int opener_render_process_id) {
944 // Note: includes web URLs that are part of an extension's web extent.
945 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17946 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35947 return extension &&
948 extension->permissions_data()->HasAPIPermission(
949 APIPermission::kBackground) &&
950 process_map->Contains(extension->id(), opener_render_process_id);
951}
Kevin Marshall32f99d7e2017-07-11 23:17:46952
csharrison95f01e922017-04-24 18:52:35953#endif
954
John Abd-El-Malekd2377982018-01-08 22:23:12955chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
956 const base::Callback<content::WebContents*()>& wc_getter) {
957 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
958 auto* web_contents = wc_getter.Run();
959 if (!web_contents)
960 return nullptr;
961
962 return prerender::PrerenderContents::FromWebContents(web_contents);
963}
964
John Abd-El-Malek92bf3602019-07-31 02:25:48965void LaunchURL(const GURL& url,
966 const content::WebContents::Getter& web_contents_getter,
967 ui::PageTransition page_transition,
968 bool has_user_gesture) {
John Abd-El-Maleka67add82018-03-09 18:22:01969 // If there is no longer a WebContents, the request may have raced with tab
970 // closing. Don't fire the external request. (It may have been a prerender.)
971 content::WebContents* web_contents = web_contents_getter.Run();
972 if (!web_contents)
973 return;
974
975 // Do not launch external requests attached to unswapped prerenders.
976 prerender::PrerenderContents* prerender_contents =
977 prerender::PrerenderContents::FromWebContents(web_contents);
978 if (prerender_contents) {
979 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
980 prerender::ReportPrerenderExternalURL();
981 return;
982 }
983
Robbie McElrath1294d242019-05-31 20:46:22984 // Do not launch external requests for schemes that have a handler registered.
985 ProtocolHandlerRegistry* protocol_handler_registry =
986 ProtocolHandlerRegistryFactory::GetForBrowserContext(
987 web_contents->GetBrowserContext());
988 if (protocol_handler_registry &&
989 protocol_handler_registry->IsHandledProtocol(url.scheme()))
990 return;
991
John Abd-El-Maleka67add82018-03-09 18:22:01992 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:01993 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:19994 PolicyBlacklistFactory::GetForBrowserContext(
995 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:01996 if (service) {
997 const policy::URLBlacklist::URLBlacklistState url_state =
998 service->GetURLBlacklistState(url);
999 is_whitelisted =
1000 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1001 }
1002
1003 // If the URL is in whitelist, we launch it without asking the user and
1004 // without any additional security checks. Since the URL is whitelisted,
1005 // we assume it can be executed.
1006 if (is_whitelisted) {
1007 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1008 } else {
1009 ExternalProtocolHandler::LaunchUrl(
1010 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1011 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
1012 has_user_gesture);
1013 }
1014}
1015
Yutaka Hirano968d6252018-12-04 05:09:311016std::string GetProduct() {
1017 return version_info::GetProductNameAndVersionForUserAgent();
1018}
1019
Lukasz Anforowicz60d1253d2019-05-08 16:31:371020void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1021 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1022 // For renderer and utility (e.g. NetworkService) processes the switch is the
1023 // only available source, so below the combined (pref/policy + cmdline)
1024 // allowlist of secure origins is injected into |cmdline| for these other
1025 // processes.
1026 std::vector<std::string> allowlist =
1027 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1028 if (!allowlist.empty()) {
1029 cmdline->AppendSwitchASCII(
1030 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1031 base::JoinString(allowlist, ","));
1032 }
1033}
1034
Will Harris1b9b4152019-08-21 22:33:501035#if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301036// Returns the full path to |module_name|. Both dev builds (where |module_name|
1037// is in the current executable's directory) and proper installs (where
1038// |module_name| is in a versioned sub-directory of the current executable's
1039// directory) are supported. The identified file is not guaranteed to exist.
1040base::FilePath GetModulePath(base::StringPiece16 module_name) {
1041 base::FilePath exe_dir;
1042 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
1043 DCHECK(has_path);
1044
1045 // Look for the module in a versioned sub-directory of the current
1046 // executable's directory and return the path if it can be read. This is the
1047 // expected location of modules for proper installs.
1048 const base::FilePath module_path =
1049 exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
1050 if (base::PathExists(module_path))
1051 return module_path;
1052
1053 // Otherwise, return the path to the module in the current executable's
1054 // directory. This is the expected location of modules for dev builds.
1055 return exe_dir.Append(module_name);
1056}
Will Harris1b9b4152019-08-21 22:33:501057#endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) &&
1058 // !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:301059
[email protected]9dbfff12011-07-01 19:37:071060} // namespace
[email protected]c5dbef02011-05-13 05:06:091061
Yutaka Hirano968d6252018-12-04 05:09:311062std::string GetUserAgent() {
1063 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1064 if (command_line->HasSwitch(switches::kUserAgent)) {
1065 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1066 if (net::HttpUtil::IsValidHeaderValue(ua))
1067 return ua;
1068 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1069 }
1070
John Delaneyac24e572019-04-30 19:47:021071 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1072 return content::GetFrozenUserAgent(
1073 command_line->HasSwitch(switches::kUseMobileUserAgent))
1074 .as_string();
1075 }
1076
Yutaka Hirano968d6252018-12-04 05:09:311077 std::string product = GetProduct();
1078#if defined(OS_ANDROID)
1079 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1080 product += " Mobile";
1081#endif
1082 return content::BuildUserAgentFromProduct(product);
1083}
1084
Mike West6e4cbb32019-02-13 09:40:171085blink::UserAgentMetadata GetUserAgentMetadata() {
1086 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171087 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301088 metadata.full_version = version_info::GetVersionNumber();
1089 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171090 metadata.platform = version_info::GetOSType();
1091
1092 // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces.
1093 metadata.architecture = "";
1094 metadata.model = "";
1095
1096 return metadata;
1097}
1098
Ran Jia96d43d42018-05-02 17:14:531099ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051100 StartupData* startup_data)
Wojciech Dzierżanowski45380802019-04-29 14:50:321101 : data_reduction_proxy_throttle_manager_(
1102 nullptr,
1103 base::OnTaskRunnerDeleter(nullptr)),
Jeremy Roman495db682019-07-12 16:03:241104 startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161105#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371106 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421107 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371108 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251109 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371110 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401111 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551112
1113 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401114#endif
[email protected]1deace22013-05-22 06:14:461115
Ahmed Fakhryd70bf37b2018-04-04 17:07:241116#if defined(OS_CHROMEOS)
1117 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1118#endif // defined(OS_CHROMEOS)
1119
brettw00899e62016-11-12 02:10:171120#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131121 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271122#endif
bena06f7d62017-04-04 20:48:521123
Sigurdur Asgeirsson70696672019-02-08 16:14:511124 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
[email protected]e461da2f2012-02-16 19:06:401125}
1126
1127ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031128 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1129 delete extra_parts_[i];
1130 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401131}
1132
[email protected]bca18382012-06-25 19:15:231133// static
Chris Palmerac7d75642017-11-22 20:12:541134void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1135 PrefRegistrySimple* registry) {
Greg Thompson8c9227562019-08-05 17:47:131136 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
1137 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
Chris Palmerac7d75642017-11-22 20:12:541138 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1139 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Chris Hamilton8206aad2018-07-18 01:00:031140 registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true);
Julian Pastarmovfac28002018-02-01 11:17:451141 registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies,
1142 false);
Chris Palmerac7d75642017-11-22 20:12:541143}
1144
1145// static
[email protected]37ca3fe02013-07-05 15:32:441146void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341147 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251148 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1149 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1150 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281151 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1152 // user policy in addition to the same named ones in Local State (which are
1153 // used for mapping the command-line flags).
1154 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1155 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571156 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401157 registry->RegisterDictionaryPref(
1158 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041159 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101160#if !defined(OS_ANDROID)
1161 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561162 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101163#endif
[email protected]bca18382012-06-25 19:15:231164}
1165
[email protected]eabbfb12013-04-05 23:28:351166// static
1167void ChromeContentBrowserClient::SetApplicationLocale(
1168 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481169 // The common case is that this function is called early in Chrome startup
1170 // before any threads are created or registered. When there are no threads,
1171 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001172 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331173 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481174 return;
1175 }
1176
1177 // Otherwise we're being called to change the locale. In this case set it on
1178 // the IO thread.
thestig00844cea2015-09-08 21:44:521179 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351180
Sami Kyostila5e1306d2019-08-14 11:01:291181 base::PostTask(FROM_HERE, {BrowserThread::IO},
1182 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351183}
1184
Patrick Monette61dfef92019-05-30 23:06:271185std::unique_ptr<content::BrowserMainParts>
1186ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311187 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271188 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301189 // Construct the Main browser parts based on the OS type.
1190#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051191 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271192 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1193#elif defined(OS_MACOSX)
1194 main_parts =
1195 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1196#elif defined(OS_CHROMEOS)
1197 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1198 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261199#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271200 main_parts =
1201 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141202#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271203 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1204 startup_data_);
[email protected]b48c9182011-10-26 18:03:301205#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271206 main_parts =
1207 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041208#else
[email protected]b48c9182011-10-26 18:03:301209 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271210 main_parts =
1211 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301212#endif
1213
Xi Han9fd44002019-04-30 17:39:361214 bool add_profiles_extra_parts = true;
1215#if defined(OS_ANDROID)
1216 if (startup_data_->HasBuiltProfilePrefService())
1217 add_profiles_extra_parts = false;
1218#endif
1219 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271220 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031221
Xi Han9fd44002019-04-30 17:39:361222 // Construct additional browser parts. Stages are called in the order in
1223 // which they are added.
[email protected]c7480942011-11-08 19:18:271224#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221225#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1226#if defined(USE_X11)
1227 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1228#else
estaded3aa0e82016-02-17 22:55:211229 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221230#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211231#else
riajiang7d6ec5c2017-01-25 16:40:331232 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351233#endif
1234#endif
1235
1236#if defined(OS_CHROMEOS)
1237 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331238 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221239#endif
[email protected]dc04be7c2012-03-15 23:57:491240
[email protected]e8b6ca02013-07-10 18:00:511241#if defined(USE_X11)
1242 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241243#endif
1244
Sigurdur Asgeirsson54b72702019-04-12 14:18:541245 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001246
Albert J. Wong59d85acb2017-08-10 00:50:571247 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571248
Patrick Monette61dfef92019-05-30 23:06:271249 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041250
[email protected]50462bf02011-11-21 19:13:311251 return main_parts;
[email protected]f967b722011-09-07 00:58:041252}
1253
michaeln96f887e22015-04-13 23:58:311254void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091255 const base::Location& from_here,
michaeln96f887e22015-04-13 23:58:311256 const scoped_refptr<base::TaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211257 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121258 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291259
Robert Sesek466e43e2019-08-19 22:02:021260 InitNetworkContextsParentDirectory();
1261
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291262 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1263 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311264}
1265
falkenb09d443f2016-04-07 12:36:121266bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1267 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1268}
1269
Gabriel Charettec8cca992017-08-10 18:21:491270void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1271 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1272}
1273
John Abd-El-Malek9d57f9c2019-02-20 18:50:041274bool ChromeContentBrowserClient::IsShuttingDown() {
1275 return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID;
1276}
1277
[email protected]e94bbcb2012-09-07 05:33:571278std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191279 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571280 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531281 std::string partition_id;
1282
1283 // The partition ID for webview guest processes is the string value of its
1284 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451285 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531286 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171287#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501288 // The partition ID for extensions with isolated storage is treated similarly
1289 // to the above.
1290 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1291 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1292 partition_id = site.spec();
1293#endif
[email protected]1bc28312012-11-08 08:31:531294
[email protected]056efdc2013-04-06 00:14:531295 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531296 return partition_id;
1297}
1298
1299bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1300 content::BrowserContext* browser_context,
1301 const std::string& partition_id) {
1302 // The default ID is empty and is always valid.
1303 if (partition_id.empty())
1304 return true;
1305
1306 return GURL(partition_id).is_valid();
1307}
1308
1309void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1310 content::BrowserContext* browser_context,
1311 const GURL& site,
[email protected]14acc642012-11-17 12:20:101312 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531313 std::string* partition_domain,
1314 std::string* partition_name,
1315 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101316 // Default to the browser-wide storage partition and override based on |site|
1317 // below.
1318 partition_domain->clear();
1319 partition_name->clear();
1320 *in_memory = false;
1321
brettw00899e62016-11-12 02:10:171322#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451323 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331324 site, partition_domain, partition_name, in_memory);
1325
1326 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101327 // If |can_be_default| is false, the caller is stating that the |site|
1328 // should be parsed as if it had isolated storage. In particular it is
1329 // important to NOT check ExtensionService for the is_storage_isolated()
1330 // attribute because this code path is run during Extension uninstall
1331 // to do cleanup after the Extension has already been unloaded from the
1332 // ExtensionService.
1333 bool is_isolated = !can_be_default;
1334 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341335 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1336 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101337 }
[email protected]1bc28312012-11-08 08:31:531338
[email protected]14acc642012-11-17 12:20:101339 if (is_isolated) {
1340 CHECK(site.has_host());
1341 // For extensions with isolated storage, the the host of the |site| is
1342 // the |partition_domain|. The |in_memory| and |partition_name| are only
1343 // used in guest schemes so they are cleared here.
1344 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531345 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101346 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531347 }
[email protected]1df3d972014-06-11 04:55:181348 success = true;
1349 }
1350#endif
1351
[email protected]14acc642012-11-17 12:20:101352 // Assert that if |can_be_default| is false, the code above must have found a
1353 // non-default partition. If this fails, the caller has a serious logic
1354 // error about which StoragePartition they expect to be in and it is not
1355 // safe to continue.
1356 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441357}
1358
[email protected]38b098f2012-03-14 21:11:571359content::WebContentsViewDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:441360ChromeContentBrowserClient::GetWebContentsViewDelegate(
1361 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101362 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321363}
1364
Bo Liu4ade6b1b22017-11-28 02:26:351365bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1366#if defined(OS_ANDROID)
1367 const base::android::ApplicationState app_state =
1368 base::android::ApplicationStatusListener::GetState();
1369 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1370 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1371 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1372#else
1373 return true;
1374#endif
1375}
1376
[email protected]6f2862742013-12-20 07:53:191377void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ken Rockot7c6275b2019-08-02 20:00:231378 content::RenderProcessHost* host) {
[email protected]f3b1a082011-11-18 00:34:301379 int id = host->GetID();
1380 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
horo062ef5352017-03-29 08:16:071381 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
thakis678822e2017-04-20 17:20:341382#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491383 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061384#endif
Brett Wilson65f951c2016-11-03 22:06:121385#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401386 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031387#endif
[email protected]ba780c12013-10-01 17:07:061388 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
Darin Fisher8c84328c2019-07-23 02:50:001389
Darin Fisher09aa7222019-08-29 09:27:361390 WebRtcLoggingController::AttachToRenderProcessHost(
Darin Fisher8c84328c2019-07-23 02:50:001391 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021392
grunell086a4112017-03-02 09:23:041393 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1394 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021395 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121396 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021397 host->SetUserData(
1398 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091399 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021400 audio_debug_recordings_handler));
1401
Nico Weberaf3b00b2017-09-11 17:58:171402#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031403 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1404 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351405#endif
jeremyim364ac1182015-03-03 18:49:431406
Xiaohan Wang9b34281b2017-09-08 23:48:331407#if defined(OS_ANDROID)
1408 // Data cannot be persisted if the profile is off the record.
1409 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061410 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071411
1412 // Register CrashMemoryMetricsCollector to report oom related metrics.
1413 host->SetUserData(
1414 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1415 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331416#endif
1417
Jun Caidb3f93cc2018-07-09 21:54:551418 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061419 RendererUpdaterFactory::GetForProfile(original_profile)
1420 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071421
[email protected]a48ab7112014-08-01 16:48:031422 for (size_t i = 0; i < extra_parts_.size(); ++i)
1423 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]05fcf982011-04-19 00:44:141424}
1425
[email protected]3d7474ff2011-07-27 17:47:371426GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571427 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301428 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371429 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521430 if (!profile)
1431 return url;
1432
Marc Treib7d467b792017-12-04 13:31:031433#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291434 // If the input |url| should be assigned to the Instant renderer, make its
1435 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311436 // This needs to happen even if |url| corresponds to an isolated origin; see
1437 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131438 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1439 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031440#endif
[email protected]b3cb3a32013-07-31 01:32:291441
brettw00899e62016-11-12 02:10:171442#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301443 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1444 url);
[email protected]d5a74be2014-08-08 01:01:271445#else
1446 return url;
1447#endif
[email protected]36fb2c7c2011-04-04 15:49:081448}
1449
Alexander Yashkin6aedc6e2018-08-15 08:58:451450bool ChromeContentBrowserClient::
1451 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1452 content::BrowserContext* browser_context,
1453 content::SiteInstance* candidate_site_instance,
1454 bool is_main_frame,
1455 const GURL& candidate_url,
1456 const GURL& destination_url) {
1457 DCHECK(browser_context);
1458 DCHECK(candidate_site_instance);
1459#if BUILDFLAG(ENABLE_EXTENSIONS)
1460 return ChromeContentBrowserClientExtensionsPart::
1461 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1462 browser_context, candidate_site_instance, is_main_frame,
1463 candidate_url, destination_url);
1464#else
1465 return true;
1466#endif
1467}
1468
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521469bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411470#if defined(OS_ANDROID)
1471 return true;
1472#elif defined(OS_CHROMEOS)
Xiyuan Xiafc9f38132019-08-02 00:51:421473 return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode();
Ahmed Fakhrye6a2c642018-06-20 02:58:411474#else
1475 return false;
1476#endif // defined(OS_ANDROID)
1477}
1478
[email protected]056ad2a2011-07-12 02:13:551479bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
Aran Gilmanf010bdd2019-08-28 19:55:441480 content::BrowserContext* browser_context,
1481 const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521482 Profile* profile = Profile::FromBrowserContext(browser_context);
1483 if (!profile)
1484 return false;
1485
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301486 // NTP should use process-per-site. This is a performance optimization to
1487 // reduce process count associated with NTP tabs.
1488 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1489 return true;
Peter Boström8e9b1632019-08-22 23:12:471490
1491 // The web footer experiment should share its renderer to not effectively
1492 // instantiate one per window. See https://crbug.com/993502.
1493 if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL))
1494 return true;
1495
Marc Treib7d467b792017-12-04 13:31:031496#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131497 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521498 return true;
Marc Treib7d467b792017-12-04 13:31:031499#endif
[email protected]c5dec6292013-01-25 04:54:521500
brettw00899e62016-11-12 02:10:171501#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301502 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1503 profile, effective_url))
1504 return true;
[email protected]d5a74be2014-08-08 01:01:271505#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301506
1507 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1508 // (rather than process-per-site).
1509 return false;
[email protected]056ad2a2011-07-12 02:13:551510}
1511
Lukasz Anforowicz32d27122018-04-09 21:48:331512bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1513 content::BrowserContext* browser_context,
1514 const GURL& site_url) {
1515 Profile* profile = Profile::FromBrowserContext(browser_context);
1516 if (!profile)
1517 return false;
1518
1519#if !defined(OS_ANDROID)
1520 // Instant renderers should not use a spare process, because they require
1521 // passing switches::kInstantProcess to the renderer process when it
1522 // launches. A spare process is launched earlier, before it is known which
1523 // navigation will use it, so it lacks this flag.
1524 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1525 return false;
1526#endif
1527
1528#if BUILDFLAG(ENABLE_EXTENSIONS)
1529 return ChromeContentBrowserClientExtensionsPart::
1530 ShouldUseSpareRenderProcessHost(profile, site_url);
1531#else
1532 return true;
1533#endif
1534}
1535
nickcc0d9142015-10-14 16:27:101536bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421537 content::BrowserContext* browser_context,
nickcc0d9142015-10-14 16:27:101538 const GURL& effective_site_url) {
Clark DuVall4e1f0a72019-08-07 22:41:421539 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
brettw00899e62016-11-12 02:10:171540#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101541 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Clark DuVall4e1f0a72019-08-07 22:41:421542 browser_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101543 return true;
1544 }
1545#endif
1546 return false;
1547}
1548
nick7d0984c2015-08-29 00:13:461549// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1550// origin-lock enforcement, where we don't have a way to efficiently know
1551// effective URLs on the IO thread, and wind up killing processes that e.g.
1552// request cookies for their actual URL. This whole function (and its
1553// ExtensionsPart) should be removed once we add that ability to the IO thread.
1554bool ChromeContentBrowserClient::ShouldLockToOrigin(
1555 content::BrowserContext* browser_context,
1556 const GURL& effective_site_url) {
1557 // Origin lock to the search scheme would kill processes upon legitimate
1558 // requests for cookies from the search engine's domain.
1559 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1560 return false;
1561
brettw00899e62016-11-12 02:10:171562#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461563 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1564 browser_context, effective_site_url)) {
1565 return false;
1566 }
1567#endif
1568 return true;
creise5d6d1732015-08-25 19:47:061569}
1570
Lukasz Anforowicz05f356e2018-03-13 20:26:111571const char*
Lukasz Anforowiczce869f0b2018-08-06 18:33:371572ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() {
Charles Reis358baf472017-12-06 05:30:431573#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz05f356e2018-03-13 20:26:111574 // Don't block responses for extension processes or for content scripts.
1575 // TODO(creis): When every extension fetch (including content scripts) has
1576 // been made to go through an extension-specific URLLoaderFactory, this
1577 // mechanism ought to work by enumerating the host permissions from the
1578 // extension manifest, and forwarding them on to the network service while
1579 // brokering the URLLoaderFactory.
1580 return extensions::kExtensionScheme;
1581#else
1582 return nullptr;
Charles Reis358baf472017-12-06 05:30:431583#endif
Charles Reis358baf472017-12-06 05:30:431584}
1585
Maks Orlovich0e23e312019-07-16 13:13:561586bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
1587 base::StringPiece scheme) {
1588#if BUILDFLAG(ENABLE_EXTENSIONS)
1589 return scheme == extensions::kExtensionScheme;
1590#else
1591 return false;
1592#endif
1593}
1594
Lukasz Anforowicz2f810162018-10-03 21:38:071595network::mojom::URLLoaderFactoryPtrInfo
1596ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests(
1597 content::RenderProcessHost* process,
1598 network::mojom::NetworkContext* network_context,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:181599 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
1600 header_client,
Lukasz Anforowicz2f810162018-10-03 21:38:071601 const url::Origin& request_initiator) {
1602#if BUILDFLAG(ENABLE_EXTENSIONS)
1603 return ChromeContentBrowserClientExtensionsPart::
Clark DuValla5e25b752018-11-27 22:08:161604 CreateURLLoaderFactoryForNetworkRequests(
1605 process, network_context, header_client, request_initiator);
Lukasz Anforowicz2f810162018-10-03 21:38:071606#else
1607 return network::mojom::URLLoaderFactoryPtrInfo();
1608#endif
1609}
1610
[email protected]73b718f2014-01-27 02:59:461611// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1612// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411613void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1614 std::vector<std::string>* additional_schemes) {
1615 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241616 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351617 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061618}
1619
alexmos94875b3b2017-03-16 22:19:011620void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1621 std::vector<std::string>* additional_schemes) {
1622 GetAdditionalWebUISchemes(additional_schemes);
1623
1624#if BUILDFLAG(ENABLE_EXTENSIONS)
1625 additional_schemes->push_back(extensions::kExtensionScheme);
1626#endif
1627}
1628
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521629bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011630 return webui::LogWebUIUrl(web_ui_url);
1631}
1632
John Abd-El-Malek04bfa8532018-07-12 05:28:221633bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1634 const url::Origin& origin) {
1635 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1636 origin);
1637}
1638
[email protected]46fb9442011-12-09 17:57:471639bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1640 return ProfileIOData::IsHandledURL(url);
1641}
1642
[email protected]c4365fa42013-05-14 01:08:241643bool ChromeContentBrowserClient::CanCommitURL(
1644 content::RenderProcessHost* process_host,
1645 const GURL& url) {
brettw00899e62016-11-12 02:10:171646#if BUILDFLAG(ENABLE_EXTENSIONS)
Aran Gilmanf010bdd2019-08-28 19:55:441647 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host,
1648 url);
[email protected]d5a74be2014-08-08 01:01:271649#else
1650 return true;
1651#endif
[email protected]c4365fa42013-05-14 01:08:241652}
1653
[email protected]9a60d1602013-09-11 04:09:121654bool ChromeContentBrowserClient::ShouldAllowOpenURL(
Aran Gilmanf010bdd2019-08-28 19:55:441655 content::SiteInstance* site_instance,
1656 const GURL& url) {
brettw00899e62016-11-12 02:10:171657#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131658 bool result;
1659 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
alexmos1c3da4f2016-11-03 06:06:111660 site_instance, url, &result))
[email protected]f7daaa32014-08-02 07:58:131661 return result;
[email protected]d5a74be2014-08-08 01:01:271662#endif
[email protected]879816a92014-04-29 00:53:541663
1664 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1665 // the signin page may host untrusted web content.
alexmos1c3da4f2016-11-03 06:06:111666 GURL from_url = site_instance->GetSiteURL();
[email protected]879816a92014-04-29 00:53:541667 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
1668 url.SchemeIs(content::kChromeUIScheme) &&
brettwb65cd5c2016-01-23 00:46:381669 url.host_piece() != chrome::kChromeUIChromeSigninHost) {
[email protected]879816a92014-04-29 00:53:541670 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
1671 << chrome::kChromeUIChromeSigninURL;
1672 return false;
1673 }
1674
[email protected]9a60d1602013-09-11 04:09:121675 return true;
1676}
1677
rdevlin.cronina32a0902016-11-09 15:50:201678void ChromeContentBrowserClient::OverrideNavigationParams(
1679 SiteInstance* site_instance,
1680 ui::PageTransition* transition,
1681 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581682 content::Referrer* referrer,
1683 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201684 DCHECK(transition);
1685 DCHECK(is_renderer_initiated);
1686 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471687 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1688 // use for making security decisions 99.44% of the time, for detecting the NTP
1689 // it is reliable and the correct way. See http://crbug.com/624410.
1690 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201691 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581692 // Clicks on tiles of the new tab page should be treated as if a user
1693 // clicked on a bookmark. This is consistent with native implementations
1694 // like Android's. This also helps ensure that security features (like
1695 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1696 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201697 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1698 *is_renderer_initiated = false;
1699 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581700 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421701 }
rdevlin.cronina32a0902016-11-09 15:50:201702
brettw00899e62016-11-12 02:10:171703#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.cronina32a0902016-11-09 15:50:201704 ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams(
Lukasz Anforowicz63f3b9432019-05-30 05:42:581705 site_instance, transition, is_renderer_initiated, referrer,
1706 initiator_origin);
rdevlin.cronina32a0902016-11-09 15:50:201707#endif
mastiza77db6992016-06-30 09:48:421708}
1709
Charles Reis29e9dd12017-09-28 00:59:151710bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1711 const GURL& url,
1712 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471713 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1714 // use for making security decisions 99.44% of the time, for detecting the NTP
1715 // it is reliable and the correct way. See http://crbug.com/624410.
1716 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1717 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151718}
1719
[email protected]2a5221b2011-09-27 23:07:311720bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301721 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311722 const GURL& site_url) {
1723 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301724 Profile::FromBrowserContext(process_host->GetBrowserContext());
Aran Gilmanf010bdd2019-08-28 19:55:441725 // This may be nullptr during tests. In that case, just assume any site can
[email protected]c5dec6292013-01-25 04:54:521726 // share any host.
1727 if (!profile)
1728 return true;
1729
Marc Treib7895941d2017-11-28 12:37:021730#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141731 // Instant URLs should only be in the instant process and instant process
1732 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521733 InstantService* instant_service =
1734 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141735 if (instant_service) {
Aran Gilmanf010bdd2019-08-28 19:55:441736 bool is_instant_process =
1737 instant_service->IsInstantProcess(process_host->GetID());
[email protected]d43f99fe2013-04-03 00:20:141738 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131739 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141740 if (is_instant_process || should_be_in_instant_process)
1741 return is_instant_process && should_be_in_instant_process;
1742 }
Marc Treib7895941d2017-11-28 12:37:021743#endif
[email protected]c5dec6292013-01-25 04:54:521744
brettw00899e62016-11-12 02:10:171745#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131746 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1747 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271748#else
1749 return true;
1750#endif
[email protected]2a5221b2011-09-27 23:07:311751}
1752
[email protected]28c5d0b72014-05-13 08:19:591753bool ChromeContentBrowserClient::MayReuseHost(
1754 content::RenderProcessHost* process_host) {
1755 // If there is currently a prerender in progress for the host provided,
1756 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041757 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591758 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371759 prerender::PrerenderManagerFactory::GetForBrowserContext(
1760 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591761 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491762 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591763 return false;
1764 }
1765
1766 return true;
1767}
1768
[email protected]76411f412012-02-22 18:56:061769bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
Aran Gilmanf010bdd2019-08-28 19:55:441770 content::BrowserContext* browser_context,
1771 const GURL& url) {
[email protected]76411f412012-02-22 18:56:061772 // It has to be a valid URL for us to check for an extension.
1773 if (!url.is_valid())
1774 return false;
1775
brettw00899e62016-11-12 02:10:171776#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061777 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131778 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441779 ShouldTryToUseExistingProcessHost(profile, url);
[email protected]d5a74be2014-08-08 01:01:271780#else
1781 return false;
1782#endif
[email protected]76411f412012-02-22 18:56:061783}
1784
Alex Moshchuk9c9e3882018-11-02 19:57:031785bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1786 content::RenderFrameHost* main_frame) {
1787#if BUILDFLAG(ENABLE_EXTENSIONS)
1788 return ChromeContentBrowserClientExtensionsPart::
1789 ShouldSubframesTryToReuseExistingProcess(main_frame);
1790#else
1791 return true;
1792#endif
1793}
1794
[email protected]6f371442011-11-09 06:45:461795void ChromeContentBrowserClient::SiteInstanceGotProcess(
1796 SiteInstance* site_instance) {
1797 CHECK(site_instance->HasProcess());
1798
Aran Gilmanf010bdd2019-08-28 19:55:441799 Profile* profile =
1800 Profile::FromBrowserContext(site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521801 if (!profile)
1802 return;
1803
Marc Treib7895941d2017-11-28 12:37:021804#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521805 // Remember the ID of the Instant process to signal the renderer process
1806 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131807 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1808 profile)) {
[email protected]c5dec6292013-01-25 04:54:521809 InstantService* instant_service =
1810 InstantServiceFactory::GetForProfile(profile);
1811 if (instant_service)
1812 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1813 }
Marc Treib7895941d2017-11-28 12:37:021814#endif
[email protected]c5dec6292013-01-25 04:54:521815
[email protected]a48ab7112014-08-01 16:48:031816 for (size_t i = 0; i < extra_parts_.size(); ++i)
1817 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461818}
1819
1820void ChromeContentBrowserClient::SiteInstanceDeleting(
1821 SiteInstance* site_instance) {
1822 if (!site_instance->HasProcess())
1823 return;
1824
[email protected]a48ab7112014-08-01 16:48:031825 for (size_t i = 0; i < extra_parts_.size(); ++i)
1826 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461827}
1828
[email protected]453f5432013-11-26 19:43:001829bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141830 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081831 const GURL& current_url,
1832 const GURL& new_url) {
brettw00899e62016-11-12 02:10:171833#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131834 return ChromeContentBrowserClientExtensionsPart::
Aran Gilmanf010bdd2019-08-28 19:55:441835 ShouldSwapBrowsingInstancesForNavigation(site_instance, current_url,
1836 new_url);
[email protected]d5a74be2014-08-08 01:01:271837#else
1838 return false;
1839#endif
[email protected]e3daf3c2011-10-05 21:17:081840}
1841
Nasko Oskovd83b5712018-05-04 04:50:571842bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1843 // TODO(nasko): Consider supporting error page isolation in subframes if
1844 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381845 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571846}
1847
[email protected]3d831992013-07-04 01:13:291848bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1849 return !url.SchemeIs(chrome::kChromeNativeScheme);
1850}
1851
Alex Moshchukd252c192017-07-17 22:03:481852std::vector<url::Origin>
1853ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1854 std::vector<url::Origin> isolated_origin_list;
1855
Alex Moshchuk89352a72017-10-25 20:25:591856// Sign-in process isolation is not needed on Android, see
1857// https://crbug.com/739418.
1858#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381859 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121860 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591861#endif
Alex Moshchukd252c192017-07-17 22:03:481862
Alex Moshchuk81d2a29e2019-07-16 01:14:381863#if BUILDFLAG(ENABLE_EXTENSIONS)
1864 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1865 GetOriginsRequiringDedicatedProcess();
1866 std::move(std::begin(origins_from_extensions),
1867 std::end(origins_from_extensions),
1868 std::back_inserter(isolated_origin_list));
1869#endif
1870
Alex Moshchukd252c192017-07-17 22:03:481871 return isolated_origin_list;
1872}
1873
Lukasz Anforowicz5e201abd2018-03-24 00:41:061874bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341875 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1876}
1877
1878bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Lukasz Anforowicz0711a0f2019-03-28 18:15:311879 // Using 1077 rather than 1024 because 1) it helps ensure that devices with
1880 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one
1881 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2.
1882 // See also https://crbug.com/844118.
1883 constexpr int kDefaultMemoryThresholdMb = 1077;
Aaron Colwell25617f72018-11-27 20:56:341884
1885 // TODO(acolwell): Rename feature since it now affects more than just the
1886 // site-per-process case.
Lukasz Anforowicz46275d92018-04-12 14:57:381887 if (base::FeatureList::IsEnabled(
1888 features::kSitePerProcessOnlyForHighMemoryClients)) {
Lukasz Anforowicz46275d92018-04-12 14:57:381889 int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
1890 features::kSitePerProcessOnlyForHighMemoryClients,
1891 features::kSitePerProcessOnlyForHighMemoryClientsParamName,
1892 kDefaultMemoryThresholdMb);
Aaron Colwell25617f72018-11-27 20:56:341893 return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb;
Lukasz Anforowicz46275d92018-04-12 14:57:381894 }
1895
Aaron Colwell25617f72018-11-27 20:56:341896#if defined(OS_ANDROID)
1897 if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) {
1898 return true;
1899 }
1900#endif
1901
1902 return false;
Lukasz Anforowicz5e201abd2018-03-24 00:41:061903}
1904
Alex Moshchuk082b5f82019-03-14 01:34:161905std::vector<std::string>
1906ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1907 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1908 return {"Isolate Password Sites"};
1909 else
1910 return {};
1911}
1912
Alex Moshchuke256d562019-04-26 21:43:571913void ChromeContentBrowserClient::PersistIsolatedOrigin(
1914 content::BrowserContext* context,
1915 const url::Origin& origin) {
1916 DCHECK(!context->IsOffTheRecord());
1917 Profile* profile = Profile::FromBrowserContext(context);
1918 ListPrefUpdate update(profile->GetPrefs(),
1919 prefs::kUserTriggeredIsolatedOrigins);
1920 base::ListValue* list = update.Get();
1921 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361922 if (!base::Contains(list->GetList(), value))
Jan Wilken Dörrie91e4ef02019-09-11 08:22:121923 list->Append(std::move(value));
Alex Moshchuke256d562019-04-26 21:43:571924}
1925
Ken Rockot314714c2017-11-05 23:36:241926bool ChromeContentBrowserClient::IsFileAccessAllowed(
1927 const base::FilePath& path,
1928 const base::FilePath& absolute_path,
1929 const base::FilePath& profile_path) {
1930 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1931 profile_path);
1932}
1933
[email protected]d2e1a0a2014-06-16 15:49:371934namespace {
1935
1936bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171937 const base::CommandLine& browser_command_line =
1938 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351939 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371940 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351941 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371942 return false;
[email protected]9ef49b42014-08-07 16:44:241943 return true;
[email protected]d2e1a0a2014-06-16 15:49:371944}
1945
bmcquade5d2d9cf32015-06-19 17:42:281946void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1947 const base::CommandLine& browser_command_line,
1948 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521949 // List of field trials that modify the blink-settings command line flag. No
1950 // two field trials in the list should specify the same keys, otherwise one
1951 // field trial may overwrite another. See Source/core/frame/Settings.in in
1952 // Blink for the list of valid keys.
1953 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161954 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1955 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1956 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1957 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521958 };
1959
1960 std::vector<std::string> blink_settings;
1961 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1962 // Each blink-settings field trial should include a forcing_flag group,
1963 // to make sure that clients that specify the blink-settings flag on the
1964 // command line are excluded from the experiment groups. To make
1965 // sure we assign clients that specify this flag to the forcing_flag
1966 // group, we must call GetVariationParams for each field trial first
1967 // (for example, before checking HasSwitch() and returning), since
1968 // GetVariationParams has the side-effect of assigning the client to
1969 // a field trial group.
1970 std::map<std::string, std::string> params;
1971 if (variations::GetVariationParams(field_trial_name, &params)) {
1972 for (const auto& param : params) {
1973 blink_settings.push_back(base::StringPrintf(
1974 "%s=%s", param.first.c_str(), param.second.c_str()));
1975 }
1976 }
1977 }
pmeenan9ac669682015-08-17 14:57:031978
bmcquade9dd54cc2015-06-22 16:56:521979 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:281980 return;
1981 }
1982
1983 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
1984 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:031985 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:521986 // blink-settings flag into a group with no params, and we return
1987 // above if no params were specified, so it's an error if we reach
1988 // this point.
bmcquade5d2d9cf32015-06-19 17:42:281989 LOG(WARNING) << "Received field trial params, "
1990 "but blink-settings switch already specified.";
1991 return;
1992 }
1993
bmcquade5d2d9cf32015-06-19 17:42:281994 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:261995 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:281996}
1997
zpengdb4a58e2017-01-10 17:40:321998#if defined(OS_ANDROID)
Ben Goodger6a695c012017-06-20 20:21:201999template <typename Interface>
Aran Gilmanf010bdd2019-08-28 19:55:442000void ForwardToJavaFrameRegistry(mojo::InterfaceRequest<Interface> request,
2001 content::RenderFrameHost* render_frame_host) {
Ben Goodger6a695c012017-06-20 20:21:202002 render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request));
mgiuca3d9a1962017-04-07 05:25:442003}
2004
Ben Goodger6a695c012017-06-20 20:21:202005template <typename Interface>
2006void ForwardToJavaWebContentsRegistry(
Ben Goodger6a695c012017-06-20 20:21:202007 mojo::InterfaceRequest<Interface> request,
2008 content::RenderFrameHost* render_frame_host) {
2009 content::WebContents* contents =
2010 content::WebContents::FromRenderFrameHost(render_frame_host);
2011 if (contents)
2012 contents->GetJavaInterfaces()->GetInterface(std::move(request));
sammc0285a442016-10-04 23:03:562013}
2014#endif
2015
[email protected]d2e1a0a2014-06-16 15:49:372016} // namespace
2017
[email protected]b80f68432011-05-02 17:22:302018void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172019 base::CommandLine* command_line,
2020 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062021#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352022 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062023 GoogleUpdateSettings::LoadMetricsClientInfo();
2024 if (client_info) {
2025 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2026 client_info->client_id);
2027 }
2028#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022029#if defined(OS_ANDROID)
2030 bool enable_crash_reporter = true;
2031#else
2032 bool enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2033#endif
2034 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512035 std::string switch_value;
dcheng4af48582016-04-19 00:29:352036 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532037 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512038 if (client_info)
2039 switch_value = client_info->client_id;
2040 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252041 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302042 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512043 switch_value);
[email protected]b80f68432011-05-02 17:22:302044 }
Mark Mentovaic67fa64f2015-03-24 14:00:062045#endif
[email protected]b80f68432011-05-02 17:22:302046
[email protected]f1933792011-06-14 00:49:342047 if (logging::DialogsAreSuppressed())
2048 command_line->AppendSwitch(switches::kNoErrorDialogs);
2049
[email protected]b80f68432011-05-02 17:22:302050 std::string process_type =
2051 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172052 const base::CommandLine& browser_command_line =
2053 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322054
[email protected]7c9b6f92013-09-10 18:11:352055 static const char* const kCommonSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442056 switches::kUserAgent,
2057 switches::kUserDataDir, // Make logs go to the right file.
[email protected]7c9b6f92013-09-10 18:11:352058 };
2059 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372060 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322061
fqj15ff3f72015-10-09 19:20:022062 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432063 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312064 };
fqj15ff3f72015-10-09 19:20:022065 command_line->CopySwitchesFrom(browser_command_line,
2066 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372067 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312068
fqj15ff3f72015-10-09 19:20:022069#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332070 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2071 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522072 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332073 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2074 homedir.value().c_str());
2075#endif
2076
[email protected]718eab62011-10-05 21:16:522077 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032078 content::RenderProcessHost* process =
2079 content::RenderProcessHost::FromID(child_process_id);
2080 Profile* profile =
2081 process ? Profile::FromBrowserContext(process->GetBrowserContext())
Aran Gilmanf010bdd2019-08-28 19:55:442082 : nullptr;
[email protected]a48ab7112014-08-01 16:48:032083 for (size_t i = 0; i < extra_parts_.size(); ++i) {
Aran Gilmanf010bdd2019-08-28 19:55:442084 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line,
2085 process, profile);
[email protected]a48ab7112014-08-01 16:48:032086 }
2087
[email protected]b80f68432011-05-02 17:22:302088#if defined(OS_CHROMEOS)
Aran Gilmanf010bdd2019-08-28 19:55:442089 const std::string& login_profile = browser_command_line.GetSwitchValueASCII(
2090 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302091 if (!login_profile.empty())
Aran Gilmanf010bdd2019-08-28 19:55:442092 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
2093 login_profile);
[email protected]b80f68432011-05-02 17:22:302094#endif
2095
Aran Gilmanf010bdd2019-08-28 19:55:442096 MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line,
sdefresne9fb67692015-08-03 18:48:222097 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372098 if (process) {
[email protected]a8d851f82011-12-21 00:32:372099 PrefService* prefs = profile->GetPrefs();
2100 // Currently this pref is only registered if applied via a policy.
2101 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2102 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2103 // Turn this policy into a command line switch.
2104 command_line->AppendSwitch(switches::kDisable3DAPIs);
2105 }
[email protected]718eab62011-10-05 21:16:522106
[email protected]1733b782014-06-19 18:51:552107 const base::ListValue* switches =
2108 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2109 if (switches) {
2110 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112111 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552112 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142113 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552114 command_line->AppendSwitch(switch_to_enable);
2115 }
2116 }
2117
[email protected]a8d851f82011-12-21 00:32:372118 // Disable client-side phishing detection in the renderer if it is
2119 // disabled in the Profile preferences or the browser process.
2120 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2121 !g_browser_process->safe_browsing_detection_service()) {
2122 command_line->AppendSwitch(
2123 switches::kDisableClientSidePhishingDetection);
2124 }
[email protected]0045b0f42012-07-26 11:52:082125
vitalybukaa7ae5052014-09-26 04:11:132126 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2127 command_line->AppendSwitch(switches::kDisablePrintPreview);
2128
Marc Treib7895941d2017-11-28 12:37:022129#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522130 InstantService* instant_service =
2131 InstantServiceFactory::GetForProfile(profile);
2132 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542133 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522134 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542135 }
Marc Treib7895941d2017-11-28 12:37:022136#endif
fqjba8749c2015-10-29 15:33:072137
fqj38306f7b2015-11-02 16:59:062138 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542139 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432140 command_line->AppendSwitch(
2141 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542142 }
Daniel Vogelheim976f1c22017-11-22 16:26:032143
Lukasz Anforowicz60d1253d2019-05-08 16:31:372144 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2145
Amr Aboelkherb04cbf32019-04-29 15:17:102146 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2147 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292148 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102149 }
Katie Dillonc25ee5c92019-09-12 17:05:422150
2151 if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) &&
2152 prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) {
2153 command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal);
2154 }
[email protected]47c7ec82012-01-18 03:29:212155 }
[email protected]4287a3d2011-06-13 23:56:512156
[email protected]d2e1a0a2014-06-16 15:49:372157 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352158 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042159
Aran Gilmanf010bdd2019-08-28 19:55:442160 MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line,
2161 command_line);
bmcquade5d2d9cf32015-06-19 17:42:282162
mdjonesa6b9e172016-09-23 16:24:302163#if defined(OS_ANDROID)
2164 // If the platform is Android, force the distillability service on.
2165 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2166#endif
2167
[email protected]47c7ec82012-01-18 03:29:212168 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512169 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192170 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412171 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302172#if defined(OS_CHROMEOS)
2173 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2174#endif
brettw00899e62016-11-12 02:10:172175#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512176 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272177 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172178 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512179 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272180 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172181 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172182 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282183#endif
estark4b003b332015-02-14 01:07:052184 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512185 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482186 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512187 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502188 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572189 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462190 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302191 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512192 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172193#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242194 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482195 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552196#endif
[email protected]ce304ce2013-02-22 21:54:452197 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172198#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592199 switches::kForcePNaClSubzero,
2200#endif
Marc Treibad33cf942017-08-24 11:19:002201 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512202 switches::kJavaScriptHarmony,
Andreas Haasb400d912019-08-28 18:54:102203 switches::kEnableExperimentalWebAssemblyFeatures,
iclelland79237e92016-06-23 12:03:512204 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552205 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022206 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512207 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512208 switches::kPpapiFlashPath,
2209 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032210 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092211 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512212 };
2213
2214 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372215 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172216 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172217#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382218 static const char* const kSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:442219 extensions::switches::kAllowHTTPBackgroundPage,
2220 extensions::switches::kEnableExperimentalExtensionApis,
2221 extensions::switches::kExtensionsOnChromeURLs,
2222 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382223 };
2224
2225 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372226 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282227#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372228 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132229 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512230 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512231 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502232 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172233#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242234 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582235 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592236 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412237 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552238#endif
[email protected]4287a3d2011-06-13 23:56:512239 switches::kPpapiFlashPath,
2240 switches::kPpapiFlashVersion,
2241 };
2242
2243 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372244 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112245 } else if (process_type == switches::kGpuProcess) {
2246 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2247 // because GPU is expected to be unreliable.
2248 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2249 !command_line->HasSwitch(switches::kDisableBreakpad))
2250 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302251 }
[email protected]6f08af82011-09-15 01:19:032252
Ian Barkley-Yeung550aae052019-07-11 00:11:112253#if defined(OS_CHROMEOS)
Joshua Peraza30d8fc72019-08-19 17:24:302254 if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) {
Ian Barkley-Yeung550aae052019-07-11 00:11:112255 static const char* const kSwitchNames[] = {
2256 switches::kCrashLoopBefore,
2257 };
2258 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2259 base::size(kSwitchNames));
2260 }
2261#endif
2262
wittman832321f52016-10-10 18:18:382263 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
Aran Gilmanf010bdd2019-08-28 19:55:442264 process_type, command_line);
Andrew Comminos66057672019-05-01 00:03:342265
2266#if defined(OS_LINUX)
2267 // Processes may only query perf_event_open with the BPF sandbox disabled.
2268 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2269 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2270 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2271 }
2272#endif
[email protected]b80f68432011-05-02 17:22:302273}
2274
Scott Violet776edf82017-09-29 02:03:012275void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
2276 const service_manager::Identity& identity,
2277 base::CommandLine* command_line) {
Guido Urdaneta191635e2018-05-09 16:00:532278#if defined(OS_MACOSX)
Ken Rockot2f8c1dd22019-07-23 21:56:022279 // On Mac, the audio service requires a CFRunLoop, provided by a UI message
2280 // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581.
2281 if (identity.name() == audio::mojom::kServiceName)
Guido Urdaneta191635e2018-05-09 16:00:532282 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2283#endif
Scott Violet776edf82017-09-29 02:03:012284}
2285
Olivier Yiptong0daa93f2019-08-22 19:40:082286std::string
2287ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() {
2288 return std::string(chrome::kApplicationClientIDStringForAVScanning);
2289}
2290
[email protected]b80f68432011-05-02 17:22:302291std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432292 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332293 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302294 return g_browser_process->GetApplicationLocale();
2295}
2296
[email protected]597a867b2011-11-18 18:31:202297std::string ChromeContentBrowserClient::GetAcceptLangs(
2298 content::BrowserContext* context) {
2299 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202300 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082301}
2302
Dana Fried34d580002019-04-24 20:05:482303gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492304 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482305 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082306}
2307
bengre8a146f2016-03-10 01:20:222308bool ChromeContentBrowserClient::IsDataSaverEnabled(
2309 content::BrowserContext* browser_context) {
Robert Ogdenc995d4fe2019-03-25 19:18:372310 Profile* profile = Profile::FromBrowserContext(browser_context);
2311 return profile && data_reduction_proxy::DataReductionProxySettings::
2312 IsDataSaverEnabledByUser(profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222313}
2314
Kenichi Ishibashi46329872018-07-17 09:43:402315void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2316 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192317 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402318 DCHECK(browser_context);
2319 DCHECK(out_prefs);
2320 renderer_preferences_util::UpdateFromSystemSettings(
2321 out_prefs, Profile::FromBrowserContext(browser_context));
2322}
2323
Clark DuVall5690e742019-07-17 18:26:172324bool ChromeContentBrowserClient::AllowAppCache(
2325 const GURL& manifest_url,
2326 const GURL& first_party,
2327 content::BrowserContext* context) {
2328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2329 return CookieSettingsFactory::GetForProfile(
2330 Profile::FromBrowserContext(context))
2331 ->IsCookieAccessAllowed(manifest_url, first_party);
2332}
2333
Matt Falkenhagen7b509e52019-08-15 23:11:412334bool ChromeContentBrowserClient::AllowServiceWorkerOnIO(
falken3dbc36e2014-10-10 16:48:072335 const GURL& scope,
2336 const GURL& first_party_url,
David Bertoni3b3597d82019-06-22 02:29:362337 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202338 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342339 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522340 DCHECK_CURRENTLY_ON(BrowserThread::IO);
rdevlin.croninf5863da2015-09-10 19:21:452341
brettw00899e62016-11-12 02:10:172342#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452343 // Check if this is an extension-related service worker, and, if so, if it's
2344 // allowed (this can return false if, e.g., the extension is disabled).
2345 // If it's not allowed, return immediately. We deliberately do *not* report
2346 // to the TabSpecificContentSettings, since the service worker is blocked
2347 // because of the extension, rather than because of the user's content
2348 // settings.
Matt Falkenhagena59e1cce2019-08-22 23:45:022349 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO(
David Bertoni3b3597d82019-06-22 02:29:362350 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452351 return false;
2352 }
2353#endif
2354
falken3dbc36e2014-10-10 16:48:072355 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202356
shimazuce8af88122016-10-06 23:49:212357 // Check if JavaScript is allowed.
2358 content_settings::SettingInfo info;
2359 std::unique_ptr<base::Value> value =
2360 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
2361 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2362 std::string(), &info);
2363 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2364 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2365
2366 // Check if cookies are allowed.
2367 bool allow_serviceworker =
falken71691402017-01-27 03:38:002368 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope,
2369 first_party_url);
falken4a22dce2015-04-30 08:25:202370 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242371 // Only post the task if this is for a specific tab.
2372 if (!wc_getter.is_null()) {
Sami Kyostila5e1306d2019-08-14 11:01:292373 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:282374 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512375 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342376 std::move(wc_getter), scope, !allow_javascript,
tzik29ea5c72017-04-20 02:16:512377 !allow_serviceworker));
rdevlin.croninf5863da2015-09-10 19:21:452378 }
shimazuce8af88122016-10-06 23:49:212379 return allow_javascript && allow_serviceworker;
falken3dbc36e2014-10-10 16:48:072380}
2381
Matt Falkenhagen7b509e52019-08-15 23:11:412382bool ChromeContentBrowserClient::AllowServiceWorkerOnUI(
2383 const GURL& scope,
2384 const GURL& first_party_url,
2385 const GURL& script_url,
2386 content::BrowserContext* context,
2387 base::RepeatingCallback<content::WebContents*()> wc_getter) {
2388 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2389
2390#if BUILDFLAG(ENABLE_EXTENSIONS)
Matt Falkenhagena59e1cce2019-08-22 23:45:022391 // Check if this is an extension-related service worker, and, if so, if it's
2392 // allowed (this can return false if, e.g., the extension is disabled).
2393 // If it's not allowed, return immediately. We deliberately do *not* report
2394 // to the TabSpecificContentSettings, since the service worker is blocked
2395 // because of the extension, rather than because of the user's content
2396 // settings.
2397 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI(
2398 scope, first_party_url, script_url, context)) {
2399 return false;
2400 }
Matt Falkenhagen7b509e52019-08-15 23:11:412401#endif
2402
2403 Profile* profile = Profile::FromBrowserContext(context);
2404
2405 // Check if JavaScript is allowed.
2406 content_settings::SettingInfo info;
2407 std::unique_ptr<base::Value> value =
2408 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
2409 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2410 std::string(), &info);
2411 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2412 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2413
2414 // Check if cookies are allowed.
2415 bool allow_cookies =
2416 CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed(
2417 scope, first_party_url);
2418
2419 // Record access to database for potential display in UI.
2420 // Only post the task if this is for a specific tab.
2421 if (!wc_getter.is_null()) {
2422 TabSpecificContentSettings::ServiceWorkerAccessed(
2423 std::move(wc_getter), scope, !allow_javascript, !allow_cookies);
2424 }
2425 return allow_javascript && allow_cookies;
2426}
2427
Jochen Eisinger0ff7645c2017-11-28 08:11:262428bool ChromeContentBrowserClient::AllowSharedWorker(
2429 const GURL& worker_url,
2430 const GURL& main_frame_url,
2431 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372432 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262433 content::BrowserContext* context,
2434 int render_process_id,
2435 int render_frame_id) {
2436 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2437
2438 // Check if cookies are allowed.
2439 bool allow =
2440 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
2441 ->IsCookieAccessAllowed(worker_url, main_frame_url);
2442
2443 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372444 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2445 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262446 return allow;
2447}
2448
Patrick Monette6cb099a2019-09-18 19:31:272449bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker(
2450 const std::string& scheme) {
2451#if BUILDFLAG(ENABLE_EXTENSIONS)
2452 // Extensions are allowed to start cross-origin shared workers.
2453 if (scheme == extensions::kExtensionScheme)
2454 return true;
2455#endif
2456
2457 return false;
2458}
2459
Clark DuVallab63d142019-07-23 04:24:362460bool ChromeContentBrowserClient::AllowSignedExchange(
2461 content::BrowserContext* browser_context) {
2462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2463 Profile* profile = Profile::FromBrowserContext(browser_context);
2464 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2465}
2466
[email protected]f917df22014-07-10 07:45:492467void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352468 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572469 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172470 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572471 base::OnceCallback<void(bool)> callback) {
2472 Profile* profile = Profile::FromBrowserContext(browser_context);
2473 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
falken71691402017-01-27 03:38:002474 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352475
brettw00899e62016-11-12 02:10:172476#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malek2a18d98d2019-08-08 04:31:572477 GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492478#else
John Abd-El-Malek2a18d98d2019-08-08 04:31:572479 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492480#endif
2481}
2482
brettw00899e62016-11-12 02:10:172483#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492484void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2485 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172486 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572487 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492488 bool allow) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572489 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]f917df22014-07-10 07:45:492490 std::map<int, int> process_map;
2491 std::map<int, int>::const_iterator it;
2492 bool has_web_view_guest = false;
2493 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172494 for (const auto& it : render_frames) {
2495 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492496 continue;
2497
Lukasz Anforowicz09060bdf72018-08-23 15:53:172498 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492499
Lukasz Anforowicz09060bdf72018-08-23 15:53:172500 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492501 has_web_view_guest = true;
2502 }
2503 if (!has_web_view_guest) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572504 FileSystemAccessed(url, render_frames, std::move(callback), allow);
[email protected]f917df22014-07-10 07:45:492505 return;
2506 }
[email protected]dffb9fc2014-07-16 04:14:022507 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492508 it = process_map.begin();
[email protected]f917df22014-07-10 07:45:492509
[email protected]140d6cd92014-08-12 18:26:462510 extensions::WebViewPermissionHelper* web_view_permission_helper =
John Abd-El-Malek2a18d98d2019-08-08 04:31:572511 extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second);
2512 web_view_permission_helper->RequestFileSystemPermission(
2513 url, allow,
2514 base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed,
2515 weak_factory_.GetWeakPtr(), url, render_frames,
2516 std::move(callback)));
[email protected]f917df22014-07-10 07:45:492517}
2518#endif
2519
2520void ChromeContentBrowserClient::FileSystemAccessed(
2521 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172522 const std::vector<content::GlobalFrameRoutingId>& render_frames,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572523 base::OnceCallback<void(bool)> callback,
[email protected]f917df22014-07-10 07:45:492524 bool allow) {
[email protected]62151052012-02-01 18:40:482525 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172526 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572527 TabSpecificContentSettings::FileSystemAccessed(
2528 it.child_id, it.frame_routing_id, url, !allow);
[email protected]5c5a88e2011-11-12 00:45:352529 }
John Abd-El-Malek2a18d98d2019-08-08 04:31:572530 std::move(callback).Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352531}
2532
[email protected]7c5ff9a2012-03-02 07:42:492533bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2534 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572535 content::BrowserContext* browser_context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172536 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572537 Profile* profile = Profile::FromBrowserContext(browser_context);
2538 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
2539
falken71691402017-01-27 03:38:002540 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492541
2542 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172543 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572544 TabSpecificContentSettings::IndexedDBAccessed(
2545 it.child_id, it.frame_routing_id, url, !allow);
[email protected]7c5ff9a2012-03-02 07:42:492546 }
2547
2548 return allow;
2549}
2550
Ben Kelly6b2e61c2019-03-14 16:06:292551bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2552 const GURL& url,
John Abd-El-Malek2a18d98d2019-08-08 04:31:572553 content::BrowserContext* browser_context,
Ben Kelly6b2e61c2019-03-14 16:06:292554 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572555 Profile* profile = Profile::FromBrowserContext(browser_context);
2556 auto cookie_settings = CookieSettingsFactory::GetForProfile(profile);
Ben Kelly6b2e61c2019-03-14 16:06:292557 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2558
2559 // Record access to CacheStorage for potential display in UI.
2560 for (const auto& it : render_frames) {
John Abd-El-Malek2a18d98d2019-08-08 04:31:572561 TabSpecificContentSettings::CacheStorageAccessed(
2562 it.child_id, it.frame_routing_id, url, !allow);
Ben Kelly6b2e61c2019-03-14 16:06:292563 }
2564
2565 return allow;
2566}
2567
jyasskinc993ce8d2016-03-31 00:38:342568ChromeContentBrowserClient::AllowWebBluetoothResult
2569ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452570 content::BrowserContext* browser_context,
2571 const url::Origin& requesting_origin,
2572 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342573 // TODO(crbug.com/598890): Don't disable if
2574 // base::CommandLine::ForCurrentProcess()->
2575 // HasSwitch(switches::kEnableWebBluetooth) is true.
2576 if (variations::GetVariationParamValue(
2577 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2578 "Bluetooth") ==
2579 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2580 // The kill switch is enabled for this permission. Block requests.
2581 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2582 }
2583
jyasskin98bdd3992016-02-26 20:25:452584 const HostContentSettingsMap* const content_settings =
2585 HostContentSettingsMapFactory::GetForProfile(
2586 Profile::FromBrowserContext(browser_context));
2587
csharrisonaec2c542016-10-12 19:40:362588 if (content_settings->GetContentSetting(
2589 requesting_origin.GetURL(), embedding_origin.GetURL(),
2590 CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD,
2591 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342592 return AllowWebBluetoothResult::BLOCK_POLICY;
2593 }
2594 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452595}
2596
beaufort.francois01135bf2016-11-23 14:37:362597std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2598 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2599 "blocklist_additions");
scheib74250322016-04-07 03:32:212600}
2601
John Abd-El-Malek21bca7c2018-10-26 22:13:332602#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522603void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek35bfaa52019-08-20 16:22:072604 content::BrowserContext* browser_context) {
2605 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
2606 if (user_manager) {
2607 const user_manager::User* user =
2608 chromeos::ProfileHelper::Get()->GetUserByProfile(
2609 Profile::FromBrowserContext(browser_context));
2610 if (user && !user->username_hash().empty()) {
2611 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(
2612 user->username_hash());
2613 }
2614 }
John Abd-El-Malek21bca7c2018-10-26 22:13:332615}
2616#endif
2617
Reilly Grant19aaccd2018-07-16 22:06:372618scoped_refptr<network::SharedURLLoaderFactory>
2619ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2621 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2622
2623 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372624 return nullptr;
2625
Min Qinda0d55b2018-10-12 18:30:052626 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372627 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042628}
2629
Sean Gilhulyda1ee4b2018-11-13 21:56:092630network::mojom::NetworkContext*
2631ChromeContentBrowserClient::GetSystemNetworkContext() {
2632 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2633 DCHECK(g_browser_process->system_network_context_manager());
2634 return g_browser_process->system_network_context_manager()->GetContext();
2635}
2636
Andrew Moylan17329fc2017-09-25 07:43:302637std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2638 return google_apis::GetAPIKey();
2639}
2640
Ke He21ee87f2018-05-30 02:35:322641#if defined(OS_ANDROID)
2642bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2643 // Indicate that Chrome uses the GMS core location provider.
2644 return true;
2645}
2646#endif
2647
Yeolf3dc22ca2019-04-18 17:25:322648scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412649ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2650 return new ChromeQuotaPermissionContext();
2651}
2652
michaeln10e5fc352017-02-07 02:07:582653void ChromeContentBrowserClient::GetQuotaSettings(
2654 content::BrowserContext* context,
2655 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452656 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582657 if (g_default_quota_settings) {
2658 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452659 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582660 return;
2661 }
taptede6d878e2017-06-24 01:53:452662 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062663 partition->GetPath(), context->IsOffTheRecord(),
2664 storage::GetDefaultDiskInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512665}
2666
Mythri Alle0b8de0d2018-10-22 11:06:222667content::GeneratedCodeCacheSettings
2668ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2669 content::BrowserContext* context) {
2670 base::FilePath cache_path;
2671 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2672 // If we pass 0 for size, disk_cache will pick a default size using the
2673 // heuristics based on available disk size. These are implemented in
2674 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162675 int64_t size_in_bytes = 0;
Greg Thompson8c9227562019-08-05 17:47:132676 DCHECK(g_browser_process);
2677 PrefService* local_state = g_browser_process->local_state();
2678 if (local_state) {
2679 size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize);
2680 base::FilePath disk_cache_dir =
2681 local_state->GetFilePath(prefs::kDiskCacheDir);
2682 if (!disk_cache_dir.empty())
2683 cache_path = disk_cache_dir.Append(cache_path.BaseName());
2684 }
Mythri Ab2486572019-06-13 14:48:162685 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222686}
2687
[email protected]848dd042011-06-04 18:24:032688void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262689 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172690 int cert_error,
2691 const net::SSLInfo& ssl_info,
2692 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232693 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222694 bool strict_enforcement,
estark719dde52016-08-09 03:14:272695 const base::Callback<void(content::CertificateRequestResultType)>&
2696 callback) {
clamy0d32d6d2015-11-24 11:16:262697 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232698 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142699 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022700 // have a context for making the right decision, so block the
2701 // request hard, without an info bar to allow showing the insecure
2702 // content.
estark719dde52016-08-09 03:14:272703 if (!callback.is_null())
2704 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022705 return;
2706 }
2707
[email protected]f9034cf2011-07-21 12:43:412708 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572709 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262710 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572711 if (prerender_contents) {
2712 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272713 if (!callback.is_null()) {
2714 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
2715 }
[email protected]09667f02014-01-06 15:37:572716 return;
[email protected]f9034cf2011-07-21 12:43:412717 }
2718
Carlos IL5a9e7512019-06-13 22:35:282719 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2720 return;
[email protected]848dd042011-06-04 18:24:032721}
2722
Alexander Hendrichbcf2616e2018-05-18 08:21:102723namespace {
2724
Pavol Markob211ab22019-01-23 20:03:042725certificate_matching::CertificatePrincipalPattern
2726ParseCertificatePrincipalPattern(const base::Value* pattern) {
2727 return certificate_matching::CertificatePrincipalPattern::
2728 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2729}
2730
Alexander Hendrichbcf2616e2018-05-18 08:21:102731// Attempts to auto-select a client certificate according to the value of
2732// |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for
2733// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2734std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2735 Profile* profile,
2736 const GURL& requesting_url,
2737 net::ClientCertIdentityList& client_certs) {
2738 HostContentSettingsMap* host_content_settings_map =
2739 HostContentSettingsMapFactory::GetForProfile(profile);
2740 std::unique_ptr<base::Value> setting =
2741 host_content_settings_map->GetWebsiteSetting(
2742 requesting_url, requesting_url,
Aran Gilmanf010bdd2019-08-28 19:55:442743 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(),
2744 nullptr);
Alexander Hendrichbcf2616e2018-05-18 08:21:102745
Pavol Markob211ab22019-01-23 20:03:042746 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102747 return nullptr;
2748
Alexander Hendrichbcf2616e2018-05-18 08:21:102749 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042750 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2751 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102752 // |setting_dict| has the wrong format (e.g. single filter instead of a
2753 // list of filters). This content setting is only provided by
2754 // the |PolicyProvider|, which should always set it to a valid format.
2755 // Therefore, delete the invalid value.
2756 host_content_settings_map->SetWebsiteSettingDefaultScope(
2757 requesting_url, requesting_url,
2758 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042759 return nullptr;
2760 }
2761
2762 for (const base::Value& filter : filters->GetList()) {
2763 DCHECK(filter.is_dict());
2764
2765 auto issuer_pattern = ParseCertificatePrincipalPattern(
2766 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2767 auto subject_pattern = ParseCertificatePrincipalPattern(
2768 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2769 // Use the first certificate that is matched by the filter.
2770 for (auto& client_cert : client_certs) {
2771 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2772 subject_pattern.Matches(client_cert->certificate()->subject())) {
2773 return std::move(client_cert);
2774 }
2775 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102776 }
2777
2778 return nullptr;
2779}
2780
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182781void AddDataReductionProxyReceiver(
Clark DuVall812e07d2019-08-26 18:34:562782 int render_process_id,
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182783 mojo::PendingReceiver<data_reduction_proxy::mojom::DataReductionProxy>
2784 receiver) {
Clark DuVall0e901722019-08-14 23:31:372785 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Clark DuVall812e07d2019-08-26 18:34:562786 auto* rph = content::RenderProcessHost::FromID(render_process_id);
2787 if (!rph)
2788 return;
2789
Clark DuVall0e901722019-08-14 23:31:372790 auto* drp_settings =
2791 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
Clark DuVall812e07d2019-08-26 18:34:562792 rph->GetBrowserContext());
Clark DuVall0e901722019-08-14 23:31:372793 if (!drp_settings)
2794 return;
2795
Julie Jeongeun Kimaaf568f2019-09-20 03:33:182796 drp_settings->data_reduction_proxy_service()->Clone(std::move(receiver));
Eric Romana00cf682018-11-01 20:09:112797}
2798
Alexander Hendrichbcf2616e2018-05-18 08:21:102799} // namespace
2800
Daniel McArdle85735f52019-06-25 03:27:062801base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192802 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402803 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082804 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352805 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022806 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192807 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022808 if (prerender_contents) {
2809 prerender_contents->Destroy(
2810 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062811 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452812 }
2813
[email protected]791879c2013-12-17 07:22:412814 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2815 DCHECK(requesting_url.is_valid())
2816 << "Invalid URL string: https://"
2817 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452818
Pavol Marko230ea2c92017-12-03 22:35:442819 bool may_show_cert_selection = true;
2820
davidben3b8455ae72015-03-11 19:42:192821 Profile* profile =
2822 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442823#if defined(OS_CHROMEOS)
2824 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2825 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2826 // and remove the command-line flag after prototype phase when the
2827 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2828 may_show_cert_selection =
2829 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2830
2831 content::StoragePartition* storage_partition =
2832 content::BrowserContext::GetStoragePartition(
2833 profile, web_contents->GetSiteInstance());
2834 chromeos::login::SigninPartitionManager* signin_partition_manager =
2835 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2836 profile);
2837
2838 // On the sign-in profile, only allow client certs in the context of the
2839 // sign-in frame.
2840 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2841 storage_partition)) {
2842 LOG(WARNING)
2843 << "Client cert requested in sign-in profile in wrong context.";
2844 // Continue without client certificate. We do this to mimic the case of no
2845 // client certificate being present in the profile's certificate store.
2846 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062847 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442848 }
2849 VLOG(1) << "Client cert requested in sign-in profile.";
2850 }
2851#endif // defined(OS_CHROMEOS)
2852
Alexander Hendrichbcf2616e2018-05-18 08:21:102853 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2854 AutoSelectCertificate(profile, requesting_url, client_certs);
2855 if (auto_selected_identity) {
2856 // The callback will own |auto_selected_identity| and |delegate|, keeping
2857 // them alive until after ContinueWithCertificate is called.
2858 scoped_refptr<net::X509Certificate> cert =
2859 auto_selected_identity->certificate();
2860 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2861 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582862 base::BindOnce(
2863 &content::ClientCertificateDelegate::ContinueWithCertificate,
2864 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322865 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062866 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452867 }
2868
Pavol Marko230ea2c92017-12-03 22:35:442869 if (!may_show_cert_selection) {
2870 LOG(WARNING) << "No client cert matched by policy and user selection is "
2871 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322872 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442873 // Continue without client certificate. We do this to mimic the case of no
2874 // client certificate being present in the profile's certificate store.
2875 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062876 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442877 }
2878
Daniel McArdle85735f52019-06-25 03:27:062879 return chrome::ShowSSLClientCertificateSelector(
2880 web_contents, cert_request_info, std::move(client_certs),
2881 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452882}
2883
[email protected]dc73a7b2012-03-25 15:27:182884content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562885 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182886}
2887
peterc26c6c62014-12-10 14:13:592888content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022889ChromeContentBrowserClient::GetPlatformNotificationService(
2890 content::BrowserContext* browser_context) {
2891 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2892 Profile* profile = Profile::FromBrowserContext(browser_context);
2893 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042894}
2895
[email protected]9f3fba52011-06-08 20:37:192896bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352897 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352898 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572899 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352900 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032901 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232902 const GURL& target_url,
2903 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212904 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232905 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482906 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232907 bool user_gesture,
2908 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012909 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352910 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2911 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012912
csharrison95f01e922017-04-24 18:52:352913 content::WebContents* web_contents =
2914 content::WebContents::FromRenderFrameHost(opener);
2915 Profile* profile =
2916 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2917 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012918 *no_javascript_access = false;
2919
[email protected]9f3fba52011-06-08 20:37:192920 // If the opener is trying to create a background window but doesn't have
2921 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032922 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172923#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352924 auto* process_map = extensions::ProcessMap::Get(profile);
2925 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172926 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2927 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012928 return false;
2929 }
2930
[email protected]7b54ca02012-03-02 18:06:532931 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2932 // return a recently installed Extension even if this CanCreateWindow call
2933 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012934 // because the permission check above would have caused an early return
2935 // already. We must use the full URL to find hosted apps, though, and not
2936 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552937 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352938 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292939 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012940 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022941#endif
[email protected]190e5e22013-07-27 05:59:232942
2943 return true;
[email protected]9f3fba52011-06-08 20:37:192944 }
[email protected]056efdc2013-04-06 00:14:532945
brettw00899e62016-11-12 02:10:172946#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462947 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352948 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232949 return true;
lazyboy04b75d32016-02-25 03:12:182950 }
2951
nick0fbc3922016-12-16 20:52:072952 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352953 // Intentionally duplicating |registry| code from above because we want to
2954 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2955 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182956 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352957 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142958 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532959 UMA_HISTOGRAM_ENUMERATION(
2960 "Extensions.AppLoadedInTab",
2961 ClassifyAppLoadedInTabSource(opener_url, extension),
2962 APP_LOADED_IN_TAB_SOURCE_MAX);
2963
2964 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162965 return false;
lazyboy5d5fede02016-03-10 04:10:142966 }
lazyboy04b75d32016-02-25 03:12:182967 }
[email protected]5940b0d2014-07-01 00:18:262968#endif
[email protected]190e5e22013-07-27 05:59:232969
Charles Harrisonaf2acd02017-08-18 22:46:022970#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232971 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352972 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582973 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2974 content_settings, opener_top_level_frame_url, target_url,
2975 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352976 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2977 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582978 return false;
2979 }
2980#endif
2981
Charles Harrisonaf2acd02017-08-18 22:46:022982 // Don't let prerenders open popups.
2983 if (auto* prerender_contents =
2984 prerender::PrerenderContents::FromWebContents(web_contents)) {
2985 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2986 return false;
2987 }
2988
Nasko Oskove9f19782019-01-04 18:32:352989 BlockedWindowParams blocked_params(target_url, source_origin, referrer,
2990 frame_name, disposition, features,
2991 user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132992 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Charlie Harrison804659a2018-10-16 16:43:382993 if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params,
2994 nullptr /*=open_url_params*/,
2995 blocked_params.features())) {
Charles Harrisonaf2acd02017-08-18 22:46:022996 return false;
[email protected]916615b2013-09-11 18:19:442997 }
[email protected]9f3fba52011-06-08 20:37:192998 return true;
2999}
3000
[email protected]c52b2892012-03-07 11:01:023001content::SpeechRecognitionManagerDelegate*
Aran Gilmanf010bdd2019-08-28 19:55:443002ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003003 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513004}
3005
Katie D840d9532018-11-27 06:20:483006content::TtsControllerDelegate*
3007ChromeContentBrowserClient::GetTtsControllerDelegate() {
3008 TtsControllerDelegateImpl* delegate =
3009 TtsControllerDelegateImpl::GetInstance();
3010#if !defined(OS_ANDROID)
3011 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3012 delegate->SetTtsEngineDelegate(tts_extension_engine);
3013#endif
3014 return delegate;
3015}
3016
Katie D4713ee42018-11-30 01:48:273017content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3018#ifdef OS_CHROMEOS
3019 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273020#else
3021 return nullptr;
3022#endif
3023}
3024
[email protected]64d69de42012-02-06 00:19:543025void ChromeContentBrowserClient::OverrideWebkitPrefs(
Aran Gilmanf010bdd2019-08-28 19:55:443026 RenderViewHost* rvh,
3027 WebPreferences* web_prefs) {
3028 Profile* profile =
3029 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063030 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063031
aelias0df335a2017-03-02 23:43:513032// Fill font preferences. These are not registered on Android
3033// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453034#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193035 FontFamilyCache::FillFontFamilyMap(profile,
3036 prefs::kWebKitStandardFontFamilyMap,
3037 &web_prefs->standard_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443038 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193039 &web_prefs->fixed_font_family_map);
Aran Gilmanf010bdd2019-08-28 19:55:443040 FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
[email protected]354de9e2014-08-07 03:27:193041 &web_prefs->serif_font_family_map);
3042 FontFamilyCache::FillFontFamilyMap(profile,
3043 prefs::kWebKitSansSerifFontFamilyMap,
3044 &web_prefs->sans_serif_font_family_map);
3045 FontFamilyCache::FillFontFamilyMap(profile,
3046 prefs::kWebKitCursiveFontFamilyMap,
3047 &web_prefs->cursive_font_family_map);
3048 FontFamilyCache::FillFontFamilyMap(profile,
3049 prefs::kWebKitFantasyFontFamilyMap,
3050 &web_prefs->fantasy_font_family_map);
3051 FontFamilyCache::FillFontFamilyMap(profile,
3052 prefs::kWebKitPictographFontFamilyMap,
3053 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063054
[email protected]64d69de42012-02-06 00:19:543055 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403056 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543057 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403058 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543059 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403060 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543061 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403062 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513063#endif
[email protected]f3986f82012-01-03 20:00:063064
[email protected]ddf72142012-05-22 04:52:403065 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063066
[email protected]64d69de42012-02-06 00:19:543067 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063068 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213069 web_prefs->javascript_can_access_clipboard =
3070 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543071 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063072
[email protected]ddf72142012-05-22 04:52:403073 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543074 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573075
Avi Drissman1aa6cb92019-01-23 15:58:383076 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543077 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573078
[email protected]ddf72142012-05-22 04:52:403079 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543080 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543081 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403082 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063083
Zhenyao Moa3fda9972017-09-16 01:34:403084 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3085 web_prefs->webgl1_enabled = false;
3086 web_prefs->webgl2_enabled = false;
3087 }
[email protected]f3986f82012-01-03 20:00:063088
[email protected]64d69de42012-02-06 00:19:543089 web_prefs->allow_running_insecure_content =
3090 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323091#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053092 web_prefs->font_scale_factor =
3093 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3094 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323095 web_prefs->force_enable_zoom =
3096 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Aran Gilman5e9672bed2019-08-02 19:07:493097#endif
Becky Zhoubbfbde32019-02-20 17:07:593098 web_prefs->force_dark_mode_enabled =
3099 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]5c915252013-05-07 13:15:393100
[email protected]af4256d52013-06-04 20:39:073101#if defined(OS_ANDROID)
3102 web_prefs->password_echo_enabled =
3103 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3104#else
[email protected]9d06d88d2012-02-23 22:37:083105 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073106#endif
3107
[email protected]64d69de42012-02-06 00:19:543108 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063109 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543110 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063111 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3112
brettw00899e62016-11-12 02:10:173113#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053114 std::string image_animation_policy =
3115 prefs->GetString(prefs::kAnimationPolicy);
3116 if (image_animation_policy == kAnimationPolicyOnce)
3117 web_prefs->animation_policy =
3118 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3119 else if (image_animation_policy == kAnimationPolicyNone)
3120 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3121 else
3122 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3123#endif
3124
[email protected]f3986f82012-01-03 20:00:063125 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153126 web_prefs->default_encoding =
3127 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543128 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403129 prefs->ClearPref(prefs::kDefaultCharset);
3130 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063131 }
[email protected]64d69de42012-02-06 00:19:543132 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063133
mkwst05544102015-01-10 20:26:163134 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3135 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073136 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163137 web_prefs->strict_mixed_content_checking = true;
3138 web_prefs->strict_powerful_feature_restrictions = true;
3139 }
3140
Robert Ogdencf2872d2019-03-19 18:59:373141 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213142
Tarun Bansal333819e2018-05-15 16:38:423143 web_prefs->data_saver_holdback_web_api_enabled =
3144 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3145 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423146
Jinsuk Kima3d393ce2019-05-27 00:57:423147 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133148 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533149#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423150 auto* delegate = TabAndroid::FromWebContents(contents)
3151 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3152 contents->GetDelegate())
3153 : nullptr;
3154 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133155 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423156 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133157
Mounir Lamouri9c99a1602018-07-05 15:01:443158 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423159 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383160
3161 web_prefs->preferred_color_scheme =
Jinsuk Kima3d393ce2019-05-27 00:57:423162 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3163 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113164 }
Ian Vollick6243dfe02018-03-08 01:08:533165#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533166
Mounir Lamouri6926107f2019-01-31 18:17:433167 // web_app_scope value is platform specific.
3168#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423169 if (delegate)
3170 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433171#elif BUILDFLAG(ENABLE_EXTENSIONS)
3172 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253173 web_prefs->web_app_scope = GURL();
3174 // Set |web_app_scope| based on the app associated with the app window if
3175 // any. Note that the app associated with the window never changes, even
3176 // if the app navigates off scope. This is not a problem because we still
3177 // want to use the scope of the app associated with the window, not the
3178 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433179 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233180 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443181 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273182 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443183 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253184 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053185 // for profiles that support them, so we should always be able to
3186 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253187 //
3188 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123189 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253190 web_prefs->web_app_scope =
3191 web_app::WebAppProvider::Get(profile)
3192 ->registrar()
Alan Cutterf25cfe42019-07-16 02:40:123193 .GetAppScope(*browser->app_controller()->GetAppId())
3194 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433195 }
Mounir Lamouri6926107f2019-01-31 18:17:433196 }
3197#endif
3198
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533199#if BUILDFLAG(ENABLE_EXTENSIONS)
3200 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443201 if (browser && browser->app_controller() &&
3202 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533203 web_prefs->strict_mixed_content_checking = true;
3204 }
3205#endif
3206
Ian Vollick6243dfe02018-03-08 01:08:533207 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113208 }
zqzhang93e959d12017-03-16 13:10:203209
Ian Vollick6243dfe02018-03-08 01:08:533210#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143211 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113212#endif // defined(OS_ANDROID)
3213
Tarun Bansal73d67f02018-01-17 05:56:253214 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3215 // Obtain the maximum effective connection type at which the feature is
3216 // enabled.
3217 std::string effective_connection_type_param =
3218 base::GetFieldTrialParamValueByFeature(
3219 features::kLowPriorityIframes,
3220 "max_effective_connection_type_threshold");
3221
3222 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3223 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3224 if (effective_connection_type) {
3225 web_prefs->low_priority_iframes_threshold =
3226 effective_connection_type.value();
3227 }
3228 }
3229
rajendrant0521cee2019-07-29 06:09:263230 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3231 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003232
Scott Little878f7d6702018-05-31 22:09:063233 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3234 const char* param_name =
3235 web_prefs->data_saver_enabled
3236 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3237 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3238 "saver_enabled";
3239
3240 base::StringPairs pairs;
3241 base::SplitStringIntoKeyValuePairs(
3242 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3243 param_name),
3244 ':', ',', &pairs);
3245
3246 for (const auto& pair : pairs) {
3247 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3248 net::GetEffectiveConnectionTypeForName(pair.first);
3249 int value = 0;
3250 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3251 web_prefs->lazy_frame_loading_distance_thresholds_px
3252 [effective_connection_type.value()] = value;
3253 }
3254 }
3255 }
3256
rajendrantd8026342018-08-29 08:08:393257 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3258 const char* param_name =
3259 web_prefs->data_saver_enabled
3260 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3261 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3262 "saver_enabled";
3263
3264 base::StringPairs pairs;
3265 base::SplitStringIntoKeyValuePairs(
3266 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3267 param_name),
3268 ':', ',', &pairs);
3269
3270 for (const auto& pair : pairs) {
3271 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3272 net::GetEffectiveConnectionTypeForName(pair.first);
3273 int value = 0;
3274 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3275 web_prefs->lazy_image_loading_distance_thresholds_px
3276 [effective_connection_type.value()] = value;
3277 }
3278 }
rajendrant3daeae292019-09-20 07:57:543279
3280 pairs.clear();
3281 base::SplitStringIntoKeyValuePairs(
3282 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3283 "lazy_image_first_k_fully_load"),
3284 ':', ',', &pairs);
3285
3286 for (const auto& pair : pairs) {
3287 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3288 net::GetEffectiveConnectionTypeForName(pair.first);
3289 int value = 0;
3290 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3291 web_prefs
3292 ->lazy_image_first_k_fully_load[effective_connection_type.value()] =
3293 value;
3294 }
3295 }
rajendrantd8026342018-08-29 08:08:393296 }
3297
Tarun Bansald10f17a02018-09-13 00:23:173298 if (base::FeatureList::IsEnabled(
3299 features::kNetworkQualityEstimatorWebHoldback)) {
3300 std::string effective_connection_type_param =
3301 base::GetFieldTrialParamValueByFeature(
3302 features::kNetworkQualityEstimatorWebHoldback,
3303 "web_effective_connection_type_override");
3304
3305 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3306 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3307 DCHECK(effective_connection_type_param.empty() ||
3308 effective_connection_type);
3309 if (effective_connection_type) {
3310 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3311 effective_connection_type.value());
3312 web_prefs->network_quality_estimator_web_holdback =
3313 effective_connection_type.value();
3314 }
3315 }
3316
Dan Beamf0a7e112019-06-07 18:40:583317 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103318#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563319 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593320 // If autoplay is allowed by policy then force the no user gesture required
3321 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103322 web_prefs->autoplay_policy =
3323 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553324 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593325 web_prefs->autoplay_policy ==
3326 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553327 // If the autoplay disable settings feature is enabled and the autoplay
3328 // policy is set to using the unified policy then set the default autoplay
3329 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593330 web_prefs->autoplay_policy =
3331 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3332 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3333 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103334 }
Alison Maher67fd4d9f2019-07-12 18:34:213335#if !defined(OS_MACOSX)
3336 // Mac has a concept of high contrast that does not relate to forced colors.
Alison Maherbe15c072019-07-08 18:12:393337 web_prefs->forced_colors = native_theme->UsesHighContrastColors()
3338 ? blink::ForcedColors::kActive
3339 : blink::ForcedColors::kNone;
Alison Maher67fd4d9f2019-07-12 18:34:213340#endif // !defined(OS_MACOSX)
3341
3342 switch (native_theme->GetPreferredColorScheme()) {
3343 case ui::NativeTheme::PreferredColorScheme::kDark:
3344 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3345 break;
3346 case ui::NativeTheme::PreferredColorScheme::kLight:
3347 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3348 break;
3349 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3350 web_prefs->preferred_color_scheme =
3351 blink::PreferredColorScheme::kNoPreference;
3352 }
François Beaufort4f8107d2018-03-05 12:12:103353#endif // !defined(OS_ANDROID)
3354
Dave Tapuskac6627e12018-08-30 15:07:193355 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493356
Dan Beam836c02a2019-06-15 01:58:273357 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3358 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3359 // explicitly uses light (instead of not dark), which is why we don't reset
3360 // back to no-preference. https://crbug.com/965811
3361 if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3362 bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme);
3363#if BUILDFLAG(ENABLE_EXTENSIONS)
3364 if (!force_light) {
3365 force_light =
3366 contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
3367 contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
3368 }
3369#endif
3370 if (force_light)
3371 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
Dan Beamf0a7e112019-06-07 18:40:583372 }
3373
Elly Fong-Jonesf92897392019-01-24 16:05:493374 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213375 base::Optional<ui::CaptionStyle> style;
3376
3377 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3378 ::switches::kForceCaptionStyle)) {
3379 style = ui::CaptionStyle::FromSpec(
3380 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3381 switches::kForceCaptionStyle));
3382 }
3383
3384 // Apply system caption style.
3385 if (!style) {
3386 style = native_theme->GetSystemCaptionStyle();
3387 }
3388
3389 // Apply caption style from preferences if system caption style is undefined.
3390 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
evliubc2aa0472019-08-09 20:19:193391 style = pref_names_util::GetCaptionStyleFromPrefs(prefs);
Evan Liu7cdbf8872019-06-19 16:47:213392 }
3393
3394 if (style) {
3395 web_prefs->text_track_background_color = style->background_color;
3396 web_prefs->text_track_text_color = style->text_color;
3397 web_prefs->text_track_text_size = style->text_size;
3398 web_prefs->text_track_text_shadow = style->text_shadow;
3399 web_prefs->text_track_font_family = style->font_family;
3400 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563401 web_prefs->text_track_window_color = style->window_color;
3402 web_prefs->text_track_window_padding = style->window_padding;
3403 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213404 }
Elly Fong-Jonesf92897392019-01-24 16:05:493405
[email protected]a48ab7112014-08-01 16:48:033406 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503407 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363408}
3409
[email protected]b8148ac2011-07-13 22:03:253410void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3411 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033412 for (size_t i = 0; i < extra_parts_.size(); ++i)
3413 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253414
[email protected]b3adbd02011-11-30 22:23:273415 // about: handler. Must come before chrome: handler, since it will
3416 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053417 // actually handle them. Also relies on a preliminary fixup phase.
3418 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253419 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3420 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033421
madfbd10852017-01-20 03:15:333422 // The group policy NTP URL handler must be registered before the other NTP
3423 // URL handlers below.
3424 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3425 BrowserURLHandler::null_handler());
3426
zpengdb4a58e2017-01-10 17:40:323427#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033428 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353429 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033430 BrowserURLHandler::null_handler());
Samuel Huange63048d2019-09-03 20:35:453431#if BUILDFLAG(DFMIFY_DEV_UI)
3432 // Handler to rewrite chrome:// URLs in the DevUI DFM, if not installed.
3433 handler->AddHandlerPair(&chrome::android::HandleDfmifiedDevUiPageURL,
3434 BrowserURLHandler::null_handler());
3435#endif // BUILDFLAG(DFMIFY_DEV_UI)
3436
3437#else // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033438 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133439 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3440 &search::HandleNewTabURLReverseRewrite);
Samuel Huange63048d2019-09-03 20:35:453441#endif // defined(OS_ANDROID)
[email protected]231dba22013-07-25 23:53:033442
[email protected]b8148ac2011-07-13 22:03:253443 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313444 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3445 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063446
3447 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3448 // the user.
3449 handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite,
3450 &HandlePreviewsLitePageURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253451}
3452
[email protected]650b2d52013-02-10 03:41:453453base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493454 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323455}
3456
[email protected]c9b6eb62011-10-18 20:49:393457std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3458 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3459}
3460
Dominik Röttsches47347832019-03-12 17:45:013461base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3462 base::FilePath user_data_dir;
3463 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3464 DCHECK(!user_data_dir.empty());
3465 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3466}
3467
jmadill57b52d42015-08-21 18:16:133468base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3469 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523470 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133471 DCHECK(!user_data_dir.empty());
3472 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3473}
3474
Khushal7ca0b782018-07-20 05:53:273475base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3476 base::FilePath user_data_dir;
3477 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3478 DCHECK(!user_data_dir.empty());
3479 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3480}
3481
[email protected]b7631cc2012-09-15 05:08:383482void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3483 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163484#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553485 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543486#endif
[email protected]b7631cc2012-09-15 05:08:383487}
3488
[email protected]0c7193742012-11-07 19:05:033489content::BrowserPpapiHost*
Aran Gilmanf010bdd2019-08-28 19:55:443490ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173491#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553492 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033493 while (!iter.Done()) {
Aran Gilmanf010bdd2019-08-28 19:55:443494 nacl::NaClProcessHost* host =
3495 static_cast<nacl::NaClProcessHost*>(iter.GetDelegate());
3496 if (host->process() && host->process()->GetData().id == plugin_process_id) {
[email protected]0c7193742012-11-07 19:05:033497 // Found the plugin.
3498 return host->browser_ppapi_host();
3499 }
3500 ++iter;
3501 }
[email protected]a56f8322014-07-16 21:13:553502#endif
Aran Gilmanf010bdd2019-08-28 19:55:443503 return nullptr;
[email protected]0c7193742012-11-07 19:05:033504}
3505
[email protected]38cd8f7f2012-06-15 22:06:073506bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583507 content::BrowserContext* browser_context,
3508 const GURL& url,
[email protected]dda54822013-06-15 01:26:393509 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123510 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163511#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553512 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3513 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403514#else
[email protected]a658d452012-03-02 12:45:293515 return false;
[email protected]93f72062013-05-29 20:29:403516#endif
[email protected]e461da2f2012-02-16 19:06:403517}
3518
adrian.belgund54465ba2016-05-18 10:03:583519bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3520 content::BrowserContext* browser_context,
3521 const GURL& url) {
brettw4b461082016-11-19 18:55:163522#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583523 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3524 browser_context, url);
3525#else
3526 return false;
3527#endif
3528}
3529
adrian.belgun5b341c72016-06-22 22:24:083530std::unique_ptr<content::VpnServiceProxy>
3531ChromeContentBrowserClient::GetVpnServiceProxy(
3532 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173533#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083534 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3535 browser_context);
3536#else
3537 return nullptr;
3538#endif
3539}
3540
Brett Wilson804e83c2017-08-18 22:57:333541std::unique_ptr<ui::SelectFilePolicy>
3542ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3543 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433544}
3545
[email protected]7d9424702013-04-14 13:14:163546void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3547 std::vector<std::string>* additional_allowed_schemes) {
3548 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3549 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483550 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293551 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033552 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3553 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3554 additional_allowed_schemes);
3555 }
[email protected]7d9424702013-04-14 13:14:163556}
3557
falkenad185092016-06-16 06:10:023558void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3559 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043560 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023561}
3562
[email protected]c79859b82014-03-20 22:43:553563void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313564 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033565 for (size_t i = 0; i < extra_parts_.size(); ++i)
3566 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553567}
3568
nzolghadrd87a308d2016-12-07 15:45:563569::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3570 return g_browser_process->rappor_service();
3571}
3572
[email protected]f19bbf62013-07-09 01:22:323573void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313574 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533575 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003576 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3577 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313578#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313579 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313580 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313581 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093582 auto backend = std::make_unique<chromeos::FileSystemBackend>(
Jeremy Romanec48d7a2018-03-01 17:35:093583 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3584 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473585 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093586 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3587 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053588 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3589 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473590 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323591 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313592 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003593 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313594#endif
[email protected]445b7db2013-08-02 04:58:273595
[email protected]a48ab7112014-08-01 16:48:033596 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3597 extra_parts_[i]->GetAdditionalFileSystemBackends(
3598 browser_context, storage_partition_path, additional_backends);
3599 }
[email protected]02250952013-04-24 23:52:533600}
3601
jcivellie6f550742017-01-06 19:29:123602#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183603void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173604 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383605 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203606 PosixFileDescriptorInfo* mappings) {
jcivellie6f550742017-01-06 19:29:123607#if defined(OS_ANDROID)
3608 base::MemoryMappedFile::Region region;
3609 int fd = ui::GetMainAndroidPackFd(&region);
3610 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003611
Samuel Huang31eadf082019-08-28 19:50:433612 // For Android: Native resources for DFMs should only be used by the browser
3613 // process. Their file descriptors and memory mapped file regions are not
3614 // passed to child processes.
3615
jcivellie6f550742017-01-06 19:29:123616 fd = ui::GetCommonResourcesPackFd(&region);
3617 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393618
jcivellie6f550742017-01-06 19:29:123619 fd = ui::GetLocalePackFd(&region);
3620 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383621
zpeng368afac82017-07-17 18:47:453622 // Optional secondary locale .pak file.
3623 fd = ui::GetSecondaryLocalePackFd(&region);
3624 if (fd != -1) {
3625 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3626 }
3627
[email protected]09560f7f2014-06-10 18:40:283628 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523629 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283630 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023631#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383632 int crash_signal_fd = GetCrashSignalFD(command_line);
3633 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133634 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383635 }
jcivellie6f550742017-01-06 19:29:123636}
3637#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303638
[email protected]4a65826d2011-08-25 16:04:013639#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033640base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:523641 int sandbox_type) {
wfh182da09c2015-06-24 19:23:033642 // TODO(wfh): Add support for more process types here. crbug.com/499523
3643 switch (sandbox_type) {
Tom Sepez15d4e5202017-09-27 23:59:053644 case service_manager::SANDBOX_TYPE_RENDERER:
Jerry Lina0de7ce2018-06-22 15:18:363645 return base::string16(install_static::GetSandboxSidPrefix()) +
3646 L"129201922";
Tom Sepez15d4e5202017-09-27 23:59:053647 case service_manager::SANDBOX_TYPE_UTILITY:
wfh182da09c2015-06-24 19:23:033648 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053649 case service_manager::SANDBOX_TYPE_GPU:
wfh182da09c2015-06-24 19:23:033650 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053651 case service_manager::SANDBOX_TYPE_PPAPI:
Jerry Lina0de7ce2018-06-22 15:18:363652 return base::string16(install_static::GetSandboxSidPrefix()) +
3653 L"129201925";
Nico Weberaf3b00b2017-09-11 17:58:173654#if BUILDFLAG(ENABLE_NACL)
wfh182da09c2015-06-24 19:23:033655 case PROCESS_TYPE_NACL_LOADER:
3656 return base::string16();
3657 case PROCESS_TYPE_NACL_BROKER:
3658 return base::string16();
3659#endif
3660 }
3661
3662 // Should never reach here.
3663 CHECK(0);
3664 return base::string16();
3665}
3666
Will Harris956e0ca2019-08-23 20:47:393667bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
3668 RendererSpawnFlags flags) {
[email protected]34f48682013-03-20 00:30:183669 // Allow the server side of a pipe restricted to the "chrome.nacl."
3670 // namespace so that it cannot impersonate other system or other chrome
Will Harrisc196ed942019-08-03 03:45:303671 // service pipes. This is also done in nacl_broker_listener.cc.
3672 sandbox::ResultCode result =
3673 policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
3674 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
3675 L"\\\\.\\pipe\\chrome.nacl.*");
rickyz50109312015-11-11 00:37:083676 if (result != sandbox::SBOX_ALL_OK)
3677 return false;
Will Harrisc196ed942019-08-03 03:45:303678
Will Harris1b9b4152019-08-21 22:33:503679// Does not work under component build because all the component DLLs would need
3680// to be manually added and maintained. Does not work under ASAN build because
3681// ASAN has not yet fully initialized its instrumentation by the time the CIG
3682// intercepts run.
3683#if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harris956e0ca2019-08-23 20:47:393684 if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0)
3685 return true;
Will Harrisc196ed942019-08-03 03:45:303686 if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity))
3687 return true;
3688
3689 // Only enable signing mitigation if launching from chrome.exe.
3690 base::FilePath exe_path;
3691 if (!base::PathService::Get(base::FILE_EXE, &exe_path))
3692 return true;
3693 if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value())
3694 return true;
3695
3696 sandbox::MitigationFlags mitigations = policy->GetProcessMitigations();
3697 mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS;
3698 result = policy->SetProcessMitigations(mitigations);
3699 if (result != sandbox::SBOX_ALL_OK)
3700 return false;
3701
Aran Gilmanf010bdd2019-08-28 19:55:443702 // Allow loading Chrome's DLLs. The name of this depends on whether
3703 // is_multi_dll_chrome is defined or not. For multi-DLL Chrome,
3704 // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the
3705 // same DLL as the browser process.
Will Harrisc196ed942019-08-03 03:45:303706#if defined(CHROME_MULTIPLE_DLL_BROWSER)
3707 constexpr auto* child_dll_path = chrome::kChildDll;
3708#else
3709 constexpr auto* child_dll_path = chrome::kBrowserResourcesDll;
3710#endif
3711 for (const auto* dll : {child_dll_path, chrome::kElfDll}) {
3712 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY,
3713 sandbox::TargetPolicy::SIGNED_ALLOW_LOAD,
3714 GetModulePath(dll).value().c_str());
3715 if (result != sandbox::SBOX_ALL_OK)
3716 return false;
3717 }
Will Harris1b9b4152019-08-21 22:33:503718#endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER)
Will Harrisc196ed942019-08-03 03:45:303719
3720 return true;
[email protected]34f48682013-03-20 00:30:183721}
Will Harris956e0ca2019-08-23 20:47:393722
3723bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() {
3724 PrefService* local_state = g_browser_process->local_state();
3725 if (local_state &&
3726 local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) &&
3727 !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled))
3728 return false;
3729 return true;
3730}
3731
wfhc91e9672016-01-27 00:14:203732#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013733
bend1dd50f52016-06-26 22:10:483734void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
bena06f7d62017-04-04 20:48:523735 service_manager::BinderRegistry* registry,
Sam McNally52e50282017-11-29 00:54:023736 blink::AssociatedInterfaceRegistry* associated_registry,
leon.han0b618792016-06-16 01:53:513737 content::RenderProcessHost* render_process_host) {
nigeltaobeff0a102017-04-29 09:30:373738 // The CacheStatsRecorder is an associated binding, instead of a
3739 // non-associated one, because the sender (in the renderer process) posts the
3740 // message after a time delay, in order to rate limit. The association
3741 // protects against the render process host ID being recycled in that time
3742 // gap between the preparation and the execution of that IPC.
3743 associated_registry->AddInterface(
3744 base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID()));
3745
ben5be0b9132016-08-03 00:17:183746 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
Sami Kyostila5e1306d2019-08-14 11:01:293747 base::CreateSingleThreadTaskRunner({content::BrowserThread::UI});
Aran Gilmanf010bdd2019-08-28 19:55:443748 registry->AddInterface(base::Bind(&rappor::RapporRecorderImpl::Create,
3749 g_browser_process->rappor_service()),
3750 ui_task_runner);
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183751 registry->AddInterface(
Mike Wittman16fa5362018-09-04 17:27:303752 base::BindRepeating(&metrics::CallStackProfileCollector::Create));
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183753
dvallet233f57ab2016-12-21 03:17:103754 if (NetBenchmarking::CheckBenchmarkingEnabled()) {
3755 Profile* profile =
3756 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Alexandr Ilin4909ec82018-06-06 10:22:483757 auto* loading_predictor =
3758 predictors::LoadingPredictorFactory::GetForProfile(profile);
Robbie McElrathb0f248c2018-07-24 19:44:163759 registry->AddInterface(
3760 base::BindRepeating(
3761 &NetBenchmarking::Create,
3762 loading_predictor ? loading_predictor->GetWeakPtr() : nullptr,
Robbie McElrathb0f248c2018-07-24 19:44:163763 render_process_host->GetID()),
3764 ui_task_runner);
dvallet233f57ab2016-12-21 03:17:103765 }
yzshen2d8fb422017-06-01 20:29:403766
Nico Weberbc5b06f2019-07-26 14:00:133767#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Adam Rice41b89592017-07-28 10:33:443768 if (safe_browsing_service_) {
Yuzhu Shencb3011f62018-02-08 02:51:503769 content::ResourceContext* resource_context =
3770 render_process_host->GetBrowserContext()->GetResourceContext();
yzshen2d8fb422017-06-01 20:29:403771 registry->AddInterface(
Yuzhu Shen44094e22017-07-18 22:52:353772 base::Bind(
3773 &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
Yuzhu Shencb3011f62018-02-08 02:51:503774 render_process_host->GetID(), resource_context,
Yuzhu Shen44094e22017-07-18 22:52:353775 base::Bind(
3776 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Yuzhu Shencb3011f62018-02-08 02:51:503777 base::Unretained(this), resource_context)),
Sami Kyostila5e1306d2019-08-14 11:01:293778 base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
yzshen2d8fb422017-06-01 20:29:403779 }
Nico Weberbc5b06f2019-07-26 14:00:133780#endif
yzshen2d8fb422017-06-01 20:29:403781
Eric Romana00cf682018-11-01 20:09:113782 if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Julie Jeongeun Kimaaf568f2019-09-20 03:33:183783 registry->AddInterface(base::BindRepeating(&AddDataReductionProxyReceiver,
Clark DuVall812e07d2019-08-26 18:34:563784 render_process_host->GetID()),
3785 ui_task_runner);
Eric Romana00cf682018-11-01 20:09:113786 }
3787
chrisha927d8fe2017-01-18 23:09:513788#if defined(OS_WIN)
Patrick Monette9a10ae22018-06-14 22:18:183789 // Add the ModuleEventSink interface. This is the interface used by renderer
3790 // processes to notify the browser of modules in their address space. The
3791 // process handle is not yet available at this point so pass in a callback
3792 // to allow to retrieve a duplicate at the time the interface is actually
Ken Rockot15253a482019-08-23 17:44:593793 // created.
Patrick Monette9a10ae22018-06-14 22:18:183794 auto get_process = base::BindRepeating(
Ken Rockot15253a482019-08-23 17:44:593795 [](int id) -> base::Process {
3796 auto* host = content::RenderProcessHost::FromID(id);
3797 if (host)
3798 return host->GetProcess().Duplicate();
3799 return base::Process();
Patrick Monette9a10ae22018-06-14 22:18:183800 },
Ken Rockot15253a482019-08-23 17:44:593801 render_process_host->GetID());
Patrick Monette9a10ae22018-06-14 22:18:183802 registry->AddInterface(
Patrick Monetteaa2ec562019-03-20 23:37:453803 base::BindRepeating(
3804 &ModuleEventSinkImpl::Create, std::move(get_process),
3805 content::PROCESS_TYPE_RENDERER,
3806 base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)),
Patrick Monette9a10ae22018-06-14 22:18:183807 ui_task_runner);
chrisha927d8fe2017-01-18 23:09:513808#endif
Dan Harrington964d48c2018-08-03 15:52:243809#if defined(OS_ANDROID)
Carlos Knippschild63b3f042018-11-20 22:55:043810 Profile* profile =
3811 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Dan Harrington964d48c2018-08-03 15:52:243812 registry->AddInterface(
3813 base::BindRepeating(&android::AvailableOfflineContentProvider::Create,
Carlos Knippschild63b3f042018-11-20 22:55:043814 profile),
Sami Kyostila5e1306d2019-08-14 11:01:293815 base::CreateSingleThreadTaskRunner({BrowserThread::UI}));
Dan Harrington964d48c2018-08-03 15:52:243816#endif
chrisha927d8fe2017-01-18 23:09:513817
Nicholas Verneb5df4f72017-11-08 09:12:073818 for (auto* ep : extra_parts_) {
3819 ep->ExposeInterfacesToRenderer(registry, associated_registry,
3820 render_process_host);
3821 }
sammc335844522016-06-09 10:15:593822}
3823
bendd157e1a2016-07-22 03:15:573824void ChromeContentBrowserClient::ExposeInterfacesToMediaService(
ben8408b132017-05-01 23:48:503825 service_manager::BinderRegistry* registry,
xhwang9ab96482015-05-11 22:02:333826 content::RenderFrameHost* render_frame_host) {
Xiaohan Wang15303d0c2017-10-06 05:22:443827#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3828 registry->AddInterface(
3829 base::Bind(&OutputProtectionImpl::Create, render_frame_host));
ben155ecf82016-06-21 22:43:263830 registry->AddInterface(
John Rummell1b5da6102017-11-02 02:15:453831 base::Bind(&PlatformVerificationImpl::Create, render_frame_host));
Xiaohan Wang15303d0c2017-10-06 05:22:443832#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:493833
xhwangdb24d602017-05-20 06:32:243834#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
cm.sanchiad3f42a62017-11-07 11:33:353835 registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host));
xhwang116acb92017-04-03 18:27:203836#endif
xhwang9ab96482015-05-11 22:02:333837}
3838
Oksana Zhuravlova4dd171e82019-08-16 20:54:003839void ChromeContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
3840 service_manager::BinderMapWithContext<content::RenderFrameHost*>* map) {
3841 chrome::internal::PopulateChromeFrameBinders(map);
3842}
3843
Ben Goodger6a695c012017-06-20 20:21:203844void ChromeContentBrowserClient::BindInterfaceRequestFromFrame(
3845 content::RenderFrameHost* render_frame_host,
Ben Goodger6a695c012017-06-20 20:21:203846 const std::string& interface_name,
3847 mojo::ScopedMessagePipeHandle interface_pipe) {
Sam McNallyfaf9a402017-10-31 03:06:313848 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3849 !worker_interfaces_parameterized_) {
3850 InitWebContextInterfaces();
3851 }
Ben Goodger6a695c012017-06-20 20:21:203852
Ben Goodger272e0632017-07-19 23:27:003853 if (!frame_interfaces_parameterized_->TryBindInterface(
3854 interface_name, &interface_pipe, render_frame_host)) {
3855 frame_interfaces_->TryBindInterface(interface_name, &interface_pipe);
juncai1bf9f7c2016-03-22 20:46:563856 }
rockot0fa66a82015-06-11 17:25:453857}
3858
Mario Sanchez Prada39dee4a2019-07-09 07:15:403859void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113860 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403861 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3862 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113863 render_frame_host);
3864}
3865
Julie Jeongeun Kimdb52a622019-09-18 00:20:203866bool ChromeContentBrowserClient::BindAssociatedReceiverFromFrame(
Ken Rockot0aad7ec2018-07-31 15:58:443867 content::RenderFrameHost* render_frame_host,
3868 const std::string& interface_name,
3869 mojo::ScopedInterfaceEndpointHandle* handle) {
3870 if (interface_name == autofill::mojom::AutofillDriver::Name_) {
3871 autofill::ContentAutofillDriverFactory::BindAutofillDriver(
Shimi Zhang6b72d292019-07-12 20:52:423872 mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>(
3873 std::move(*handle)),
Ken Rockot0aad7ec2018-07-31 15:58:443874 render_frame_host);
3875 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583876 }
3877 if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) {
Shimi Zhang6b72d292019-07-12 20:52:423878 password_manager::ContentPasswordManagerDriverFactory::
3879 BindPasswordManagerDriver(
Julie Jeongeun Kimdb52a622019-09-18 00:20:203880 mojo::PendingAssociatedReceiver<
3881 autofill::mojom::PasswordManagerDriver>(std::move(*handle)),
Shimi Zhang6b72d292019-07-12 20:52:423882 render_frame_host);
Dominic Battre97d5edf2019-03-26 13:41:383883 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583884 }
3885 if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) {
Tao Bai02ab4dd42019-03-06 00:30:373886 content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver(
Shimi Zhang8ee32332019-07-12 17:59:363887 mojo::PendingAssociatedReceiver<
3888 content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)),
Tao Bai02ab4dd42019-03-06 00:30:373889 render_frame_host);
3890 return true;
Ken Rockot0aad7ec2018-07-31 15:58:443891 }
3892
3893 return false;
3894}
3895
Sam McNallyfaf9a402017-10-31 03:06:313896void ChromeContentBrowserClient::BindInterfaceRequestFromWorker(
3897 content::RenderProcessHost* render_process_host,
3898 const url::Origin& origin,
3899 const std::string& interface_name,
3900 mojo::ScopedMessagePipeHandle interface_pipe) {
3901 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3902 !worker_interfaces_parameterized_) {
3903 InitWebContextInterfaces();
3904 }
3905
3906 worker_interfaces_parameterized_->BindInterface(
3907 interface_name, std::move(interface_pipe), render_process_host, origin);
3908}
3909
Ken Rockot251bc6e02019-09-17 21:46:333910void ChromeContentBrowserClient::BindGpuHostReceiver(
3911 mojo::GenericPendingReceiver receiver) {
3912 if (auto r = receiver.As<metrics::mojom::CallStackProfileCollector>())
3913 metrics::CallStackProfileCollector::Create(std::move(r));
wittman757af872016-08-16 00:13:463914}
3915
Ken Rockotc185b2a2019-08-01 22:19:483916void ChromeContentBrowserClient::BindHostReceiverForRenderer(
3917 content::RenderProcessHost* render_process_host,
3918 mojo::GenericPendingReceiver receiver) {
3919#if BUILDFLAG(ENABLE_SPELLCHECK)
3920 if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) {
3921 SpellCheckHostChromeImpl::Create(render_process_host->GetID(),
3922 std::move(host_receiver));
3923 return;
3924 }
3925
3926#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
3927 if (auto panel_host_receiver =
3928 receiver.As<spellcheck::mojom::SpellCheckPanelHost>()) {
3929 SpellCheckPanelHostImpl::Create(render_process_host->GetID(),
3930 std::move(panel_host_receiver));
3931 return;
3932 }
3933#endif // BUILDFLAG(HAS_SPELLCHECK_PANEL)
3934#endif // BUILDFLAG(ENABLE_SPELLCHECK)
3935}
3936
Ken Rockot7c6275b2019-08-02 20:00:233937void ChromeContentBrowserClient::BindHostReceiverForRendererOnIOThread(
3938 int render_process_id,
3939 mojo::GenericPendingReceiver* receiver) {
3940 if (auto host_receiver =
3941 receiver->As<startup_metric_utils::mojom::StartupMetricHost>()) {
3942 startup_metric_utils::StartupMetricHostImpl::Create(
3943 std::move(host_receiver));
3944 return;
3945 }
3946}
3947
Ken Rockotfa5d57112019-05-29 20:57:143948void ChromeContentBrowserClient::WillStartServiceManager() {
John Abd-El-Malek27b3ebd22019-02-12 18:59:183949#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:053950 if (startup_data_) {
3951 auto* chrome_feature_list_creator =
3952 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183953 // This has to run very early before ServiceManagerContext is created.
3954 const base::Value* force_network_in_process_value =
Xi Han85079c22019-04-18 21:43:053955 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183956 ->GetPolicyService()
3957 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
3958 std::string()))
3959 .GetValue(policy::key::kForceNetworkInProcess);
3960 bool force_network_in_process = false;
3961 if (force_network_in_process_value)
3962 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3963 if (force_network_in_process)
3964 content::ForceInProcessNetworkService(true);
3965 }
3966#endif
xhwang5e630462015-10-30 03:18:483967}
3968
Ken Rockot06fd2832019-05-24 17:24:443969void ChromeContentBrowserClient::RunServiceInstance(
3970 const service_manager::Identity& identity,
3971 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
3972 const std::string& service_name = identity.name();
Ken Rockot91c40da82019-08-12 20:07:113973 ALLOW_UNUSED_LOCAL(service_name);
Ken Rockot3d8be742018-11-22 08:59:383974#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
3975 if (service_name == media::mojom::kMediaServiceName) {
Ken Rockotd80eb102018-11-29 14:55:163976 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443977 media::CreateMediaService(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413978 return;
Ken Rockot3d8be742018-11-22 08:59:383979 }
3980#endif
Ken Rockote116c202018-11-30 01:52:503981
3982#if defined(OS_CHROMEOS)
Ken Rockot06fd2832019-05-24 17:24:443983 auto service = ash_service_registry::HandleServiceRequest(
3984 service_name, std::move(*receiver));
Ken Rockotc15f34992018-12-01 21:27:573985 if (service)
3986 service_manager::Service::RunAsyncUntilTermination(std::move(service));
Lei Zhang194fcd32019-05-23 16:19:413987#endif // defined(OS_CHROMEOS)
Ken Rockot3d8be742018-11-22 08:59:383988}
3989
Ken Rockot8f39a272018-12-21 23:38:353990base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:173991ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:583992 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:583993 return GetChromeContentBrowserOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:583994 if (name == content::mojom::kGpuServiceName)
Ken Rockot341089f2019-01-11 23:11:583995 return GetChromeContentGpuOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:583996 if (name == content::mojom::kRendererServiceName)
3997 return GetChromeContentRendererOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:583998 return base::nullopt;
benc70c0e32016-09-22 03:50:373999}
4000
Ken Rockot69aade02019-01-23 21:19:514001std::vector<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174002ChromeContentBrowserClient::GetExtraServiceManifests() {
Ken Rockot06fd2832019-05-24 17:24:444003 auto manifests = GetChromeBuiltinServiceManifests();
Ken Rockot06fd2832019-05-24 17:24:444004
Nico Weberaf3b00b2017-09-11 17:58:174005#if BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444006 manifests.push_back(GetNaClLoaderManifest());
Ken Rockot69aade02019-01-23 21:19:514007#if defined(OS_WIN) && defined(ARCH_CPU_X86)
Ken Rockot06fd2832019-05-24 17:24:444008 manifests.push_back(GetNaClBrokerManifest());
sammc2b0375b2016-12-22 01:26:174009#endif // defined(OS_WIN)
Nico Weberaf3b00b2017-09-11 17:58:174010#endif // BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444011
4012 return manifests;
sammc2b0375b2016-12-22 01:26:174013}
4014
peterbbcccc12015-02-11 22:23:334015void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:374016 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:334017 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:294018 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:084019 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:374020 DCHECK(ShouldAllowOpenURL(site_instance, params.url));
4021
4022 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:084023
zpengdb4a58e2017-01-10 17:40:324024#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:224025 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:294026 std::move(callback));
jam1c5a91492016-02-24 20:47:534027#else
cm.sanchi2522bc92017-12-04 08:04:134028 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
4029 params.url, params.transition);
4030 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:084031 nav_params.user_gesture = params.user_gesture;
4032
4033 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:294034 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:334035#endif
mlamourieb40d552015-02-05 00:57:084036}
4037
zhaobinf3704f82017-01-12 07:19:364038content::ControllerPresentationServiceDelegate*
4039ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
4040 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:464041 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:094042 return media_router::PresentationServiceDelegateImpl::
4043 GetOrCreateForWebContents(web_contents);
4044 }
haibinlu9e605a92015-06-06 03:45:094045 return nullptr;
4046}
4047
zhaobinf3704f82017-01-12 07:19:364048content::ReceiverPresentationServiceDelegate*
4049ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
4050 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:364051 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
4052 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
4053 // created for offscreen presentations. The WebContents must belong to
4054 // an incognito profile.
4055 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
4056 FromWebContents(web_contents)) {
4057 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
4058 return impl;
4059 }
4060 }
zhaobinf3704f82017-01-12 07:19:364061 return nullptr;
4062}
4063
horo48d4d3e2015-02-27 03:04:004064void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
4065 const GURL& url) {
mathp46284f32015-03-11 13:06:414066 if (url.is_valid()) {
4067 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
4068 metric, url);
4069 }
horo48d4d3e2015-02-27 03:04:004070}
4071
Matt Falkenhagen8479b202017-07-14 04:35:314072std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
4073 // Don't change these returned strings. They are written (in hashed form) into
4074 // UMA logs. If you add more strings, you must update histograms.xml and get
4075 // histograms review. Only Google domains should be here for privacy purposes.
4076 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
4077 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194078 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:314079 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194080 if (url.host() == "docs.google.com")
4081 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:314082 return std::string();
4083}
4084
avid6d88b912017-01-13 00:16:004085std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:474086ChromeContentBrowserClient::CreateThrottlesForNavigation(
4087 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:004088 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:274089
bmcquadeb4556552017-03-24 22:24:374090 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
4091 // that may delay or cancel navigations, so only NavigationThrottles that
4092 // don't delay or cancel navigations (e.g. throttles that are only observing
4093 // callbacks without affecting navigation behavior) should be added before
4094 // MetricsNavigationThrottle.
4095 if (handle->IsInMainFrame()) {
4096 throttles.push_back(
4097 page_load_metrics::MetricsNavigationThrottle::Create(handle));
4098 }
4099
brettw4b461082016-11-19 18:55:164100#if BUILDFLAG(ENABLE_PLUGINS)
tommycliae590f1602016-11-02 03:59:234101 std::unique_ptr<content::NavigationThrottle> flash_url_throttle =
4102 FlashDownloadInterception::MaybeCreateThrottleFor(handle);
4103 if (flash_url_throttle)
4104 throttles.push_back(std::move(flash_url_throttle));
trizzofo8ddaeb72016-09-01 23:18:274105#endif
4106
mmenkedb2637ff2017-03-30 23:59:424107#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4108 std::unique_ptr<content::NavigationThrottle> supervised_user_throttle =
4109 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle);
4110 if (supervised_user_throttle)
4111 throttles.push_back(std::move(supervised_user_throttle));
4112#endif
4113
clamy40c9e142015-09-29 11:18:474114#if defined(OS_ANDROID)
4115 // TODO(davidben): This is insufficient to integrate with prerender properly.
4116 // https://crbug.com/370595
4117 prerender::PrerenderContents* prerender_contents =
4118 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
4119 if (!prerender_contents && handle->IsInMainFrame()) {
4120 throttles.push_back(
4121 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304122 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474123 }
Min Qin0ab0e162017-11-14 21:57:194124 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574125#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474126 if (handle->IsInMainFrame()) {
4127 // Redirect some navigations to apps that have registered matching URL
4128 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574129 auto url_to_app_throttle =
4130 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:474131 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:094132 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:474133 }
4134#endif
clamy49678312015-10-22 21:59:004135
4136#if defined(OS_CHROMEOS)
4137 // Check if we need to add merge session throttle. This throttle will postpone
4138 // loading of main frames.
4139 if (handle->IsInMainFrame()) {
4140 // Add interstitial page while merge session process (cookie reconstruction
4141 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4142 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024143 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4144 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004145 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4146 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4147 }
Maggie Caia2f03f52019-04-02 02:13:284148 }
4149#endif
djacobo21e56e02016-07-02 01:14:314150
Maggie Caia2f03f52019-04-02 02:13:284151#if !defined(OS_ANDROID)
4152 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:154153 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:284154#if defined(OS_CHROMEOS)
4155 chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
4156#else
4157 apps::AppsNavigationThrottle::MaybeCreate(handle);
4158#endif
Dominick Ng7c289942018-03-27 05:57:154159 if (url_to_apps_throttle)
4160 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004161 }
4162#endif
4163
brettw00899e62016-11-12 02:10:174164#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004165 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094166 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514167
4168 std::unique_ptr<content::NavigationThrottle> user_script_throttle =
4169 extensions::ExtensionsBrowserClient::Get()
4170 ->GetUserScriptListener()
4171 ->CreateNavigationThrottle(handle);
4172 if (user_script_throttle)
4173 throttles.push_back(std::move(user_script_throttle));
naskob9164c42016-06-07 01:21:354174#endif
4175
bauerb8f9c37742017-03-30 15:04:124176#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4177 std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle =
4178 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle);
4179 if (supervised_user_nav_throttle)
4180 throttles.push_back(std::move(supervised_user_nav_throttle));
4181#endif
4182
csharrisone985ebc2017-04-04 17:05:034183 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:104184 if (auto* subresource_filter_client =
4185 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
4186 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
4187 &throttles);
csharrisone985ebc2017-04-04 17:05:034188 }
4189
zhenw6edd49c2017-07-12 05:49:454190#if !defined(OS_ANDROID)
4191 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4192 // enabled on non-Android platforms.
4193 std::unique_ptr<content::NavigationThrottle>
4194 background_tab_navigation_throttle = resource_coordinator::
4195 BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle);
4196 if (background_tab_navigation_throttle)
4197 throttles.push_back(std::move(background_tab_navigation_throttle));
4198#endif
4199
Nico Weberbc5b06f2019-07-26 14:00:134200#if BUILDFLAG(FULL_SAFE_BROWSING)
Jialiu Linbdbb81d2017-10-11 21:29:094201 std::unique_ptr<content::NavigationThrottle>
4202 password_protection_navigation_throttle =
4203 safe_browsing::MaybeCreateNavigationThrottle(handle);
4204 if (password_protection_navigation_throttle) {
4205 throttles.push_back(std::move(password_protection_navigation_throttle));
4206 }
4207#endif
4208
Joe DeBlasio6e8409a2019-02-20 23:08:274209 std::unique_ptr<content::NavigationThrottle>
Mustafa Emre Acere14f6262019-04-02 00:19:314210 lookalike_url_navigation_throttle = lookalikes::
Joe DeBlasio6e8409a2019-02-20 23:08:274211 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle);
4212 if (lookalike_url_navigation_throttle)
4213 throttles.push_back(std::move(lookalike_url_navigation_throttle));
Joe DeBlasio6e8409a2019-02-20 23:08:274214
Amber Wonf56d8f42017-08-31 22:29:404215 std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle =
4216 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle);
4217 if (pdf_iframe_throttle)
4218 throttles.push_back(std::move(pdf_iframe_throttle));
Amber Won6b5edc752017-08-17 19:23:544219
Charles Harrison6dd11d282017-10-03 06:14:514220 std::unique_ptr<content::NavigationThrottle> tab_under_throttle =
4221 TabUnderNavigationThrottle::MaybeCreate(handle);
4222 if (tab_under_throttle)
4223 throttles.push_back(std::move(tab_under_throttle));
4224
Jeremy Romanec48d7a2018-03-01 17:35:094225 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534226 handle, handle->GetWebContents()->GetBrowserContext()));
4227
Carlos IL5a9e7512019-06-13 22:35:284228 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4229 handle,
4230 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
4231 base::Bind(&SSLErrorHandler::HandleSSLError)));
Lucas Garron94b16052017-11-11 01:58:124232
Emily Starkd6896cd32019-08-21 04:55:544233 throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle));
4234
Christopher Thompson4137cec2017-12-19 05:34:234235 std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle =
4236 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle);
4237 if (https_upgrade_timing_throttle)
4238 throttles.push_back(std::move(https_upgrade_timing_throttle));
4239
Dmitry Gozman57b92ce2017-12-28 22:24:544240#if !defined(OS_ANDROID)
4241 std::unique_ptr<content::NavigationThrottle> devtools_throttle =
4242 DevToolsWindow::MaybeCreateNavigationThrottle(handle);
4243 if (devtools_throttle)
4244 throttles.push_back(std::move(devtools_throttle));
Conley Owensaafcf122018-02-26 18:53:514245
4246 std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle =
4247 NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle);
4248 if (new_tab_page_throttle)
4249 throttles.push_back(std::move(new_tab_page_throttle));
jdoerrie4f9376f2018-12-12 18:26:204250
4251 std::unique_ptr<content::NavigationThrottle>
4252 google_password_manager_throttle =
4253 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(
4254 handle);
4255 if (google_password_manager_throttle)
4256 throttles.push_back(std::move(google_password_manager_throttle));
Dmitry Gozman57b92ce2017-12-28 22:24:544257#endif
4258
Carlos IL4ee307e2018-12-22 03:19:004259 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
4260 throttles.push_back(
4261 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
4262 handle));
4263 }
Robert Ogdenafd250b2018-07-25 22:21:034264
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334265#if defined(OS_WIN) || defined(OS_MACOSX) || \
4266 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134267 std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle =
Robert Ogden4308eb12019-09-18 18:42:374268 browser_switcher::BrowserSwitcherNavigationThrottle::
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134269 MaybeCreateThrottleFor(handle);
4270 if (browser_switcher_throttle)
4271 throttles.push_back(std::move(browser_switcher_throttle));
4272#endif
4273
dchenge73d8520c2015-12-27 01:19:094274 return throttles;
clamy40c9e142015-09-29 11:18:474275}
4276
clamy1e5574e2016-09-29 16:48:444277std::unique_ptr<content::NavigationUIData>
4278ChromeContentBrowserClient::GetNavigationUIData(
4279 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094280 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444281}
4282
Xiaohan Wanga4e41842018-06-26 18:45:104283void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4284 const std::string& key_system,
4285 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4286 base::flat_set<media::VideoCodec>* video_codecs,
4287 base::flat_set<media::EncryptionMode>* encryption_schemes) {
4288#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264289 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104290 if (key_system == kWidevineKeySystem) {
4291 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4292 encryption_schemes);
4293 }
4294#endif
4295}
4296
[email protected]487974a2014-06-13 16:49:014297content::DevToolsManagerDelegate*
4298ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354299#if defined(OS_ANDROID)
4300 return new DevToolsManagerDelegateAndroid();
4301#else
[email protected]487974a2014-06-13 16:49:014302 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354303#endif
[email protected]487974a2014-06-13 16:49:014304}
4305
Rayan Kanso411e84e2019-02-13 15:27:404306void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4307 content::BrowserContext* browser_context,
4308 int service,
4309 base::Time expiration_time) {
4310 Profile* profile = Profile::FromBrowserContext(browser_context);
4311 DCHECK(profile);
4312
4313 auto* pref_service = profile->GetPrefs();
4314 DCHECK(pref_service);
4315
4316 DictionaryPrefUpdate pref_update(
4317 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4318 base::DictionaryValue* exp_dict = pref_update.Get();
4319
4320 // Convert |expiration_time| to minutes since that is the most granular
4321 // option that returns an int. base::Value does not accept int64.
4322 int expiration_time_minutes =
4323 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4324 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4325}
4326
4327base::flat_map<int, base::Time>
4328ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4329 content::BrowserContext* browser_context) {
4330 Profile* profile = Profile::FromBrowserContext(browser_context);
4331 DCHECK(profile);
4332
4333 auto* pref_service = profile->GetPrefs();
4334 DCHECK(pref_service);
4335
4336 auto* expiration_dict = pref_service->GetDictionary(
4337 prefs::kDevToolsBackgroundServicesExpirationDict);
4338 DCHECK(expiration_dict);
4339
4340 base::flat_map<int, base::Time> expiration_times;
4341 for (const auto& it : *expiration_dict) {
4342 // key.
4343 int service = 0;
4344 bool did_convert = base::StringToInt(it.first, &service);
4345 DCHECK(did_convert);
4346
4347 // value.
4348 DCHECK(it.second->is_int());
4349 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4350 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4351
4352 expiration_times[service] = expiration_time;
4353 }
4354
4355 return expiration_times;
4356}
4357
oysteinec563c582015-02-13 19:19:524358content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524359 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524360}
4361
[email protected]a6868c22013-10-09 02:50:294362bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4363 content::BrowserContext* browser_context,
4364 const GURL& url) {
brettw4b461082016-11-19 18:55:164365#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554366 return ChromeContentBrowserClientPluginsPart::
4367 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4368 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294369#else
4370 return false;
4371#endif
4372}
4373
[email protected]aec5ed52014-06-20 07:51:424374bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4375 content::BrowserContext* browser_context,
4376 const GURL& url) {
brettw4b461082016-11-19 18:55:164377#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554378 return ChromeContentBrowserClientPluginsPart::
4379 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4380 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064381#else
4382 return false;
4383#endif
4384}
4385
mlamourif8c23a2002015-01-27 13:10:104386void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014387 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434388 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524389 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104390
4391 WebContents* web_contents =
4392 WebContents::FromRenderFrameHost(render_frame_host);
4393 DCHECK(web_contents);
4394
mlamourif8c23a2002015-01-27 13:10:104395 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374396 prerender::PrerenderManagerFactory::GetForBrowserContext(
4397 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104398 if (prerender_manager &&
4399 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
danakj0018a29a2018-12-01 01:03:434400 *visibility_state = content::PageVisibilityState::kPrerender;
mlamourif8c23a2002015-01-27 13:10:104401 }
4402}
4403
Sam McNallyfaf9a402017-10-31 03:06:314404void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094405 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4406 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014407 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Sam McNallyfaf9a402017-10-31 03:06:314408 worker_interfaces_parameterized_ =
Jeremy Romanec48d7a2018-03-01 17:35:094409 std::make_unique<service_manager::BinderRegistryWithArgs<
Sam McNallyfaf9a402017-10-31 03:06:314410 content::RenderProcessHost*, const url::Origin&>>();
Ben Goodger6a695c012017-06-20 20:21:204411
Michael Martis4a542f52017-07-28 01:51:444412 // Register mojo ContentTranslateDriver interface only for main frame.
Anthony Vallee-Duboise2432137a2019-01-17 20:06:014413 frame_interfaces_parameterized_->AddInterface(
4414 base::BindRepeating(&language::BindContentTranslateDriver));
Ben Goodger6a695c012017-06-20 20:21:204415
4416 frame_interfaces_parameterized_->AddInterface(
Ken Rockotd480bee2019-08-27 18:54:484417 base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver));
Ben Goodger6a695c012017-06-20 20:21:204418
4419#if defined(OS_ANDROID)
4420 frame_interfaces_parameterized_->AddInterface(base::Bind(
Matt Giucaee4aefb2017-08-04 03:11:554421 &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>));
Ben Goodger6a695c012017-06-20 20:21:204422 frame_interfaces_parameterized_->AddInterface(
4423 base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>));
Kim Paulhamus3d33e442018-03-29 23:04:144424 frame_interfaces_parameterized_->AddInterface(
Amos Limdddb6992018-07-19 22:14:324425 base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>));
Michael Thiessen909ba032019-03-26 23:47:434426#if defined(BROWSER_MEDIA_CONTROLS_MENU)
4427 frame_interfaces_parameterized_->AddInterface(base::Bind(
4428 &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>));
4429#endif
Ben Goodger6a695c012017-06-20 20:21:204430#else
4431 if (base::FeatureList::IsEnabled(features::kWebPayments)) {
4432 frame_interfaces_parameterized_->AddInterface(
4433 base::Bind(&payments::CreatePaymentRequest));
4434 }
4435#endif
4436
Ben Goodger6a695c012017-06-20 20:21:204437#if defined(OS_ANDROID)
Matt Giuca00e993602017-06-23 05:17:544438 frame_interfaces_parameterized_->AddInterface(base::Bind(
4439 &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>));
Michael Thiessen07c444c2019-04-26 03:53:114440#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
4441 frame_interfaces_parameterized_->AddInterface(base::Bind(
4442 &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>));
4443#endif
Ben Goodger6a695c012017-06-20 20:21:204444#endif
Reilly Grant8e5c85c2017-07-07 16:35:064445
Jay Harris5a42aa21b2018-11-28 01:23:554446#if !defined(OS_ANDROID)
Eric Stevenson1d074a972018-12-07 14:16:454447 frame_interfaces_parameterized_->AddInterface(
Ken Rockotd480bee2019-08-27 18:54:484448 base::BindRepeating(&badging::BadgeManager::BindRequest));
Eric Stevensonc3b18052018-10-01 22:22:004449#endif
4450
Reilly Grant8e5c85c2017-07-07 16:35:064451 frame_interfaces_parameterized_->AddInterface(
Lu Chen5bec7a302018-06-26 18:52:324452 base::BindRepeating(&NavigationPredictor::Create));
Dan Harringtonbc87c062018-10-31 15:21:244453
4454#if defined(OS_ANDROID)
4455 frame_interfaces_parameterized_->AddInterface(
Dan Harringtonf60bd502019-09-05 17:30:334456 base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create));
Dan Harringtonbc87c062018-10-31 15:21:244457#endif
Ben Goodger6a695c012017-06-20 20:21:204458}
4459
Robert Sesek466e43e2019-08-19 22:02:024460void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() {
4461 base::FilePath user_data_dir;
4462 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
4463 DCHECK(!user_data_dir.empty());
4464 network_contexts_parent_directory_.push_back(user_data_dir);
4465
4466 base::FilePath cache_dir;
4467 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
4468 DCHECK(!cache_dir.empty());
4469 // On some platforms, the cache is a child of the user_data_dir so only
4470 // return the one path.
4471 if (!user_data_dir.IsParent(cache_dir))
4472 network_contexts_parent_directory_.push_back(cache_dir);
4473
4474 // If the cache location has been overridden by a switch or preference,
4475 // include that as well.
4476 if (auto* local_state = g_browser_process->local_state()) {
4477 base::FilePath pref_cache_dir =
4478 local_state->GetFilePath(prefs::kDiskCacheDir);
4479 if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir))
4480 network_contexts_parent_directory_.push_back(pref_cache_dir);
4481 }
4482}
4483
[email protected]30335fdf02014-02-26 19:51:274484void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174485 base::CommandLine* to_command_line,
4486 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544487 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274488#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544489 const version_info::Channel kMaxDisableEncryptionChannel =
4490 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274491#else
sdefresne6e883e42015-07-30 08:05:544492 const version_info::Channel kMaxDisableEncryptionChannel =
4493 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274494#endif
4495 if (channel <= kMaxDisableEncryptionChannel) {
4496 static const char* const kWebRtcDevSwitchNames[] = {
Aran Gilmanf010bdd2019-08-28 19:55:444497 switches::kDisableWebRtcEncryption,
[email protected]30335fdf02014-02-26 19:51:274498 };
Avi Drissmand251e912018-12-26 15:46:374499 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4500 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274501 }
4502}
bashi933629552016-10-13 23:32:404503
miu54dca6c2016-11-17 10:59:384504#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4505void ChromeContentBrowserClient::CreateMediaRemoter(
4506 content::RenderFrameHost* render_frame_host,
4507 media::mojom::RemotingSourcePtr source,
4508 media::mojom::RemoterRequest request) {
miu54dca6c2016-11-17 10:59:384509 CastRemotingConnector::CreateMediaRemoter(
4510 render_frame_host, std::move(source), std::move(request));
miu54dca6c2016-11-17 10:59:384511}
4512#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464513
Michael Giuffrida6802ffe2017-09-29 03:40:254514base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4515 const base::CommandLine& command_line) {
4516 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164517}
4518
John Abd-El-Malek8efa11f2019-01-06 00:51:534519namespace {
4520// TODO(jam): move this to a separate file.
Minggang Wangf6840ecf2019-07-29 05:15:024521class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534522 public:
4523 explicit ProtocolHandlerThrottle(
Clark DuValla411bda2019-08-02 03:09:174524 ProtocolHandlerRegistry* protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534525 : protocol_handler_registry_(protocol_handler_registry) {}
4526 ~ProtocolHandlerThrottle() override = default;
4527
4528 void WillStartRequest(network::ResourceRequest* request,
4529 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294530 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534531 }
4532
4533 void WillRedirectRequest(net::RedirectInfo* redirect_info,
4534 const network::ResourceResponseHead& response_head,
4535 bool* defer,
4536 std::vector<std::string>* to_be_removed_headers,
4537 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294538 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534539 }
4540
4541 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294542 void TranslateUrl(GURL* url) {
4543 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4544 return;
4545 GURL translated_url = protocol_handler_registry_->Translate(*url);
4546 if (!translated_url.is_empty())
4547 *url = translated_url;
4548 }
4549
Clark DuValla411bda2019-08-02 03:09:174550 ProtocolHandlerRegistry* protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534551};
4552} // namespace
4553
Minggang Wangf6840ecf2019-07-29 05:15:024554std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194555ChromeContentBrowserClient::CreateURLLoaderThrottles(
4556 const network::ResourceRequest& request,
4557 content::BrowserContext* browser_context,
4558 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4559 content::NavigationUIData* navigation_ui_data,
4560 int frame_tree_node_id) {
4561 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4562
Minggang Wangf6840ecf2019-07-29 05:15:024563 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194564
4565 Profile* profile = Profile::FromBrowserContext(browser_context);
4566
4567 ChromeNavigationUIData* chrome_navigation_ui_data =
4568 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4569
Clark DuVall68eb997f2019-06-28 05:42:284570 auto* drp_settings =
4571 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4572 browser_context);
4573 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4574 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4575 drp_settings) {
4576 if (!data_reduction_proxy_throttle_manager_) {
4577 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4578 data_reduction_proxy::DataReductionProxyThrottleManager,
4579 base::OnTaskRunnerDeleter>(
4580 new data_reduction_proxy::DataReductionProxyThrottleManager(
4581 drp_settings->data_reduction_proxy_service(),
4582 data_reduction_proxy::DataReductionProxyThrottleManager::
Clark DuVall0e901722019-08-14 23:31:374583 CreateConfig(drp_settings->data_reduction_proxy_service()
4584 ->config()
4585 ->GetProxiesForHttp())),
Clark DuVall68eb997f2019-06-28 05:42:284586 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4587 }
4588 net::HttpRequestHeaders headers;
4589 data_reduction_proxy::DataReductionProxyRequestOptions::
4590 AddPageIDRequestHeader(
4591 &headers,
4592 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4593 result.push_back(std::make_unique<
4594 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4595 headers, data_reduction_proxy_throttle_manager_.get()));
4596 }
4597
Nico Weberbc5b06f2019-07-26 14:00:134598#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564599 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4600 request.url, *profile->GetPrefs());
4601 if (!matches_enterprise_whitelist) {
4602 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4603 base::BindOnce(
4604 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4605 base::Unretained(this)),
4606 wc_getter, frame_tree_node_id, profile->GetResourceContext()));
4607 }
Nico Weberbc5b06f2019-07-26 14:00:134608#endif
Clark DuVall5497288d2019-07-17 00:17:564609
Clark DuVallfffa41e2019-06-25 20:27:194610 if (chrome_navigation_ui_data &&
4611 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4612 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4613 chrome_navigation_ui_data->prerender_mode(),
4614 chrome_navigation_ui_data->prerender_histogram_prefix(),
4615 base::BindOnce(GetPrerenderCanceller, wc_getter),
Sami Kyostila5e1306d2019-08-14 11:01:294616 base::CreateSingleThreadTaskRunner({BrowserThread::UI})));
Clark DuVallfffa41e2019-06-25 20:27:194617 }
4618
David Rogere8e83f3c2019-09-12 10:56:234619 signin::IdentityManager* identity_manager =
4620 IdentityManagerFactory::GetForProfile(profile);
4621 bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount();
Clark DuVallfffa41e2019-06-25 20:27:194622
4623 chrome::mojom::DynamicParams dynamic_params = {
4624 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4625 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4626 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4627 variations::VariationsHttpHeaderProvider::GetInstance()
4628 ->GetClientDataHeader(is_signed_in)};
4629 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
David Rogere8e83f3c2019-09-12 10:56:234630 profile->IsOffTheRecord(), std::move(dynamic_params)));
Clark DuVallfffa41e2019-06-25 20:27:194631
Clark DuValla411bda2019-08-02 03:09:174632 result.push_back(std::make_unique<ProtocolHandlerThrottle>(
4633 ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
Clark DuVall8512cee62019-06-26 01:14:214634
Clark DuVall39c2cfc2019-06-25 21:49:284635#if BUILDFLAG(ENABLE_PLUGINS)
4636 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
Clark DuVall1df2052b2019-08-05 19:58:464637 request.resource_type, frame_tree_node_id));
Clark DuVall39c2cfc2019-06-25 21:49:284638#endif
4639
Robbie McElrath127ad2b2019-07-22 22:38:114640 auto delegate =
Robbie McElrath38f47af2019-09-19 21:51:404641 std::make_unique<signin::HeaderModificationDelegateImpl>(profile);
Robbie McElrath127ad2b2019-07-22 22:38:114642 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4643 std::move(delegate), navigation_ui_data, wc_getter);
4644 if (signin_throttle)
4645 result.push_back(std::move(signin_throttle));
4646
Clark DuVallfffa41e2019-06-25 20:27:194647 return result;
4648}
4649
Ken Rockot6414c4d92017-11-08 19:58:324650void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464651 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324652 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414653#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464654 content::WebContents* web_contents =
4655 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414656#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324657 factories->emplace(
4658 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574659 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464660 web_contents->GetBrowserContext(),
4661 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414662#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4663#if defined(OS_CHROMEOS)
4664 Profile* profile =
4665 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304666 factories->emplace(content::kExternalFileScheme,
4667 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4668 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414669#endif // defined(OS_CHROMEOS)
4670#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324671}
4672
Ting Shao2dc60582019-07-15 04:43:364673void ChromeContentBrowserClient::
4674 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4675 content::BrowserContext* browser_context,
4676 NonNetworkURLLoaderFactoryMap* factories) {
Hiroki Nakagawad5e7e89d82019-09-11 09:42:114677#if BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364678 DCHECK(browser_context);
4679 DCHECK(factories);
Ting Shao2dc60582019-07-15 04:43:364680 factories->emplace(
4681 extensions::kExtensionScheme,
4682 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4683 browser_context));
4684#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ting Shao2dc60582019-07-15 04:43:364685}
4686
Jay Civelli2578ebe2018-06-05 18:44:314687namespace {
4688
4689// The FileURLLoaderFactory provided to the extension background pages.
4690// Checks with the ChildProcessSecurityPolicy to validate the file access.
4691class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4692 public:
4693 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4694
4695 private:
4696 // network::mojom::URLLoaderFactory:
4697 void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
4698 int32_t routing_id,
4699 int32_t request_id,
4700 uint32_t options,
4701 const network::ResourceRequest& request,
4702 network::mojom::URLLoaderClientPtr client,
4703 const net::MutableNetworkTrafficAnnotationTag&
4704 traffic_annotation) override {
4705 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4706 child_id_, request.url)) {
4707 client->OnComplete(
4708 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
4709 return;
4710 }
4711 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454712 /*observer=*/nullptr,
4713 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314714 }
4715
4716 void Clone(network::mojom::URLLoaderFactoryRequest loader) override {
4717 bindings_.AddBinding(this, std::move(loader));
4718 }
4719
4720 int child_id_;
4721 mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
4722 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4723};
4724
4725} // namespace
4726
Ken Rockot6414c4d92017-11-08 19:58:324727void ChromeContentBrowserClient::
4728 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464729 int render_process_id,
4730 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324731 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414732#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4733 content::RenderFrameHost* frame_host =
4734 RenderFrameHost::FromID(render_process_id, render_frame_id);
4735 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4736#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4737
4738#if defined(OS_CHROMEOS)
4739 if (web_contents) {
4740 Profile* profile =
4741 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304742 factories->emplace(content::kExternalFileScheme,
4743 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4744 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414745 }
4746#endif // defined(OS_CHROMEOS)
4747
Ken Rockot6414c4d92017-11-08 19:58:324748#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464749 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4750 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324751 if (factory)
4752 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234753
4754 // This logic should match
4755 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314756 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234757 return;
Jay Civellic9bbf72d2018-03-24 01:58:314758
4759 Profile* profile =
4760 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4761 InstantService* instant_service =
4762 InstantServiceFactory::GetForProfile(profile);
4763 // The test below matches what's done by ShouldServiceRequestIOThread in
4764 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464765 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314766 factories->emplace(
4767 chrome::kChromeSearchScheme,
4768 content::CreateWebUIURLLoader(
4769 frame_host, chrome::kChromeSearchScheme,
4770 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234771 }
Jay Civellic9bbf72d2018-03-24 01:58:314772
Chris Mumfordbae8a742018-03-01 23:02:234773 extensions::ChromeExtensionWebContentsObserver* web_observer =
4774 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4775 web_contents);
4776
Karan Bhatia91928572018-03-06 01:18:074777 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4778 // to the |web_contents|.
4779 if (!web_observer)
4780 return;
4781
Chris Mumfordbae8a742018-03-01 23:02:234782 const Extension* extension =
4783 web_observer->GetExtensionFromFrame(frame_host, false);
4784 if (!extension)
4785 return;
4786
Sam McNally7414eeb72018-09-03 04:05:304787 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234788 // Support for chrome:// scheme if appropriate.
4789 if ((extension->is_extension() || extension->is_platform_app()) &&
4790 Manifest::IsComponentLocation(extension->location())) {
4791 // Components of chrome that are implemented as extensions or platform apps
4792 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304793 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4794 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4795 }
4796 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4797 (extension->is_platform_app() &&
4798 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234799 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024800 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4801 // URLs. Hosted apps are not allowed because they are served via web servers
4802 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304803 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4804 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024805 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304806 }
4807 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234808 factories->emplace(
4809 content::kChromeUIScheme,
4810 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4811 std::move(allowed_webui_hosts)));
4812 }
Jay Civelli2578ebe2018-06-05 18:44:314813
4814 // Extension with a background page get file access that gets approval from
4815 // ChildProcessSecurityPolicy.
4816 extensions::ExtensionHost* host =
4817 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4818 ->GetBackgroundHostForExtension(extension->id());
4819 if (host) {
4820 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4821 render_process_id));
4822 }
Chris Mumfordbae8a742018-03-01 23:02:234823#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324824}
4825
Ken Rockota0dfaca12018-02-15 07:26:254826bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214827 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254828 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384829 int render_process_id,
Karan Bhatia4a834b32019-08-16 22:26:444830 URLLoaderFactoryType type,
Lukasz Anforowicz762733652018-09-28 14:48:264831 const url::Origin& request_initiator,
Dominic Farolino1be897a2019-07-20 08:11:424832 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Julie Jeongeun Kim47499a0c2019-08-28 07:23:184833 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
4834 header_client,
Clark DuVall8dc4e502018-09-07 01:51:124835 bool* bypass_redirect_checks) {
Reilly Grant24bf8332018-08-27 21:55:014836 bool use_proxy = false;
4837
Ken Rockota0dfaca12018-02-15 07:26:254838#if BUILDFLAG(ENABLE_EXTENSIONS)
4839 auto* web_request_api =
4840 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214841 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254842
4843 // NOTE: Some unit test environments do not initialize
4844 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014845 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124846 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384847 web_request_api->MaybeProxyURLLoaderFactory(
Karan Bhatia4a834b32019-08-16 22:26:444848 browser_context, frame, render_process_id, type, factory_receiver,
4849 header_client);
Clark DuVall8dc4e502018-09-07 01:51:124850 if (bypass_redirect_checks)
4851 *bypass_redirect_checks = use_proxy_for_web_request;
4852 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014853 }
Ken Rockota0dfaca12018-02-15 07:26:254854#endif
Reilly Grant24bf8332018-08-27 21:55:014855
Reilly Grantcc22e602018-09-07 15:25:204856 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Karan Bhatia4a834b32019-08-16 22:26:444857 frame, type == URLLoaderFactoryType::kNavigation, request_initiator,
4858 factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014859
4860 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254861}
4862
Jian Lide7b43792018-06-01 23:22:134863std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4864ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4865 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144866 int frame_tree_node_id,
4867 const scoped_refptr<network::SharedURLLoaderFactory>&
4868 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134869 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4870 interceptors;
4871#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:234872 interceptors.push_back(
4873 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
4874 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:134875#endif
Ryan Sturmaf523742019-01-16 00:15:454876
Robert Ogden3d5d5b42019-04-22 05:13:114877 ChromeNavigationUIData* chrome_navigation_ui_data =
4878 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4879
Ryan Sturm27d93f412019-02-15 21:30:144880 // TODO(ryansturm): Once this is on the UI thread, stop passing
4881 // |network_loader_factory| and have interceptors create one themselves.
4882 // https://crbug.com/931786
John Abd-El-Malek7577f262019-06-10 21:23:234883 if (base::FeatureList::IsEnabled(
Ryan Sturmaf523742019-01-16 00:15:454884 previews::features::kHTTPSServerPreviewsUsingURLLoader)) {
4885 interceptors.push_back(
4886 std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:114887 network_loader_factory,
4888 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
4889 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:454890 }
4891
Jian Lide7b43792018-06-01 23:22:134892 return interceptors;
4893}
4894
Yutaka Hirano8e0b4d432019-07-04 07:12:384895bool ChromeContentBrowserClient::WillInterceptWebSocket(
4896 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:334897#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:384898 if (!frame) {
4899 return false;
4900 }
4901 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:334902 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4903 frame->GetProcess()->GetBrowserContext());
4904
4905 // NOTE: Some unit test environments do not initialize
4906 // BrowserContextKeyedAPI factories for e.g. WebRequest.
4907 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:384908 return false;
Yutaka Hirano36c94952018-05-30 21:33:334909
Yutaka Hirano8e0b4d432019-07-04 07:12:384910 return web_request_api->MayHaveProxies();
4911#else
4912 return false;
4913#endif
4914}
4915
4916void ChromeContentBrowserClient::CreateWebSocket(
4917 content::RenderFrameHost* frame,
4918 WebSocketFactory factory,
4919 const GURL& url,
4920 const GURL& site_for_cookies,
4921 const base::Optional<std::string>& user_agent,
Julie Jeongeun Kim3e973f92019-08-22 08:02:404922 mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
4923 handshake_client) {
Yutaka Hirano8e0b4d432019-07-04 07:12:384924#if BUILDFLAG(ENABLE_EXTENSIONS)
4925 if (!frame) {
4926 return;
4927 }
4928 auto* web_request_api =
4929 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
4930 frame->GetProcess()->GetBrowserContext());
4931
4932 DCHECK(web_request_api);
4933 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
4934 site_for_cookies, user_agent,
4935 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:334936#endif
4937}
4938
Maks Orlovich710d5e32019-07-09 20:16:454939bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:464940 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:454941 content::BrowserContext* browser_context,
4942 const url::Origin& origin,
4943 bool is_service_worker,
4944 int process_id,
4945 int routing_id,
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034946 mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
Maks Orlovich710d5e32019-07-09 20:16:454947 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4948#if BUILDFLAG(ENABLE_EXTENSIONS)
4949 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:464950 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:454951 extensions::ChromeExtensionCookies::Get(browser_context)
Julie Jeongeun Kimd20f64b2019-08-26 04:13:034952 ->CreateRestrictedCookieManager(origin, std::move(*receiver));
Maks Orlovich710d5e32019-07-09 20:16:454953 return true;
4954 }
4955#endif
4956 return false;
4957}
4958
Matt Menkeae4fdb12018-06-02 06:32:544959void ChromeContentBrowserClient::OnNetworkServiceCreated(
4960 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:534961 PrefService* local_state;
4962 if (g_browser_process) {
4963 DCHECK(g_browser_process->local_state());
4964 local_state = g_browser_process->local_state();
4965 } else {
Xi Han85079c22019-04-18 21:43:054966 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
4967 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:534968 }
4969
4970 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
4971 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
4972
Henrique Nakashimaa3b1c5d2019-07-03 19:25:494973 // Create SystemNetworkContextManager if it has not been created yet. We need
4974 // to set up global NetworkService state before anything else uses it and this
4975 // is the first opportunity to initialize SystemNetworkContextManager with the
4976 // NetworkService.
4977 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:534978 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:074979
Min Qin8caab1d2018-10-03 17:28:134980 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:544981 network_service);
4982}
4983
Julie Jeongeun Kim5984e992019-09-11 11:00:464984mojo::Remote<network::mojom::NetworkContext>
Ken Rockota0dfaca12018-02-15 07:26:254985ChromeContentBrowserClient::CreateNetworkContext(
4986 content::BrowserContext* context,
4987 bool in_memory,
4988 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:504989 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:454990 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:254991}
4992
Robert Sesek34f68f312019-01-14 20:25:114993std::vector<base::FilePath>
4994ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
Robert Sesek466e43e2019-08-19 22:02:024995 DCHECK(!network_contexts_parent_directory_.empty());
4996 return network_contexts_parent_directory_;
Robert Sesek34f68f312019-01-14 20:25:114997}
4998
Min Qin75ed6df2017-12-01 20:39:154999bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135000 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155001#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5002 // It is OK to load the saved offline copy, in MHTML format.
5003 ChromeNavigationUIData* chrome_navigation_ui_data =
5004 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5005 if (!chrome_navigation_ui_data)
5006 return false;
5007 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5008 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5009 return offline_page_data && offline_page_data->is_offline_page();
5010#else
5011 return false;
5012#endif
5013}
5014
Min Qin30a78a12017-12-06 01:29:135015bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5016 const GURL& url,
5017 const std::string& mime_type) {
5018#if BUILDFLAG(ENABLE_EXTENSIONS)
5019 // Special-case user scripts to get downloaded instead of viewed.
5020 return extensions::UserScript::IsURLUserScript(url, mime_type);
5021#else
5022 return false;
5023#endif
5024}
5025
Donna Wu838ac362018-08-10 10:36:335026void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345027 content::RenderFrameHost* render_frame_host,
Miyoung Shin62622152019-08-27 05:13:045028 mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) {
Reilly Grantc31b8192017-12-15 19:54:345029 if (!base::FeatureList::IsEnabled(features::kWebUsb))
5030 return;
5031
Reilly Grantc31b8192017-12-15 19:54:345032 WebContents* web_contents =
5033 WebContents::FromRenderFrameHost(render_frame_host);
5034 if (!web_contents) {
5035 NOTREACHED();
5036 return;
5037 }
5038
5039 UsbTabHelper* tab_helper =
5040 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Miyoung Shin62622152019-08-27 05:13:045041 tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver));
Reilly Grantc31b8192017-12-15 19:54:345042}
5043
Reilly Grant0d282322019-01-29 02:42:585044#if !defined(OS_ANDROID)
5045content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5046 if (!serial_delegate_)
5047 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5048 return serial_delegate_.get();
5049}
Matt Reynolds93616f9b2019-06-07 01:28:525050
5051content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5052 if (!hid_delegate_)
5053 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5054 return hid_delegate_.get();
5055}
Reilly Grant0d282322019-01-29 02:42:585056
Balazs Engedya7ff70982018-06-04 18:14:475057std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5058ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:225059 content::RenderFrameHost* render_frame_host,
5060 const std::string& relying_party_id) {
5061 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
5062 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:475063}
Nina Satragno8c832df2019-07-29 15:59:395064#endif
Balazs Engedya7ff70982018-06-04 18:14:475065
Jun Cai9409ded2018-01-30 00:19:465066std::unique_ptr<net::ClientCertStore>
5067ChromeContentBrowserClient::CreateClientCertStore(
5068 content::ResourceContext* resource_context) {
5069 if (!resource_context)
5070 return nullptr;
5071 return ProfileIOData::FromResourceContext(resource_context)
5072 ->CreateClientCertStore();
5073}
5074
David Benjamineced01fc2019-02-27 18:29:025075std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395076ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585077 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025078 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035079 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245080 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395081 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035082 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395083 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565084 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:035085 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:025086 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:205087 std::move(response_headers), LoginHandler::PRE_COMMIT,
5088 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:395089}
5090
John Abd-El-Maleka67add82018-03-09 18:22:015091bool ChromeContentBrowserClient::HandleExternalProtocol(
5092 const GURL& url,
John Abd-El-Malek92bf3602019-07-31 02:25:485093 content::WebContents::Getter web_contents_getter,
John Abd-El-Maleka67add82018-03-09 18:22:015094 int child_id,
5095 content::NavigationUIData* navigation_data,
5096 bool is_main_frame,
5097 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455098 bool has_user_gesture,
Clark DuVallb6042ed32019-07-15 17:20:455099 network::mojom::URLLoaderFactoryPtr* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015100#if BUILDFLAG(ENABLE_EXTENSIONS)
5101 // External protocols are disabled for guests. An exception is made for the
5102 // "mailto" protocol, so that pages that utilize it work properly in a
5103 // WebView.
5104 ChromeNavigationUIData* chrome_data =
5105 static_cast<ChromeNavigationUIData*>(navigation_data);
5106 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5107 (chrome_data &&
5108 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5109 !url.SchemeIs(url::kMailToScheme)) {
5110 return false;
5111 }
5112#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5113
5114#if defined(OS_ANDROID)
5115 // Main frame external protocols are handled by
5116 // InterceptNavigationResourceThrottle.
5117 if (is_main_frame)
5118 return false;
5119#endif // defined(ANDROID)
5120
Sami Kyostila5e1306d2019-08-14 11:01:295121 base::PostTask(FROM_HERE, {BrowserThread::UI},
5122 base::BindOnce(&LaunchURL, url, web_contents_getter,
5123 page_transition, has_user_gesture));
John Abd-El-Maleka67add82018-03-09 18:22:015124 return true;
5125}
5126
Jennifer Apacible4f854a82018-04-06 22:22:115127std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285128ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5129 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115130 // Note: content::OverlayWindow::Create() is defined by platform-specific
5131 // implementation in chrome/browser/ui/views. This layering hack, which goes
5132 // through //content and ContentBrowserClient, allows us to work around the
5133 // dependency constraints that disallow directly calling
5134 // chrome/browser/ui/views code either from here or from other code in
5135 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285136 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115137}
5138
Clark DuVallfffa41e2019-06-25 20:27:195139bool ChromeContentBrowserClient::IsSafeRedirectTarget(
5140 const GURL& url,
5141 content::BrowserContext* context) {
5142#if BUILDFLAG(ENABLE_EXTENSIONS)
5143 if (url.SchemeIs(extensions::kExtensionScheme)) {
5144 const Extension* extension = extensions::ExtensionRegistry::Get(context)
5145 ->enabled_extensions()
5146 .GetByID(url.host());
5147 if (!extension)
5148 return false;
5149 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5150 extension, url.path());
5151 }
5152#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5153 return true;
5154}
5155
Kunihiko Sakamoto19aa7082019-02-25 03:14:435156void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565157 content::BrowserContext* browser_context,
Julie Jeongeun Kim6d8b7492019-08-20 19:24:115158 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565159 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435160 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5161 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565162}
5163
dbeam25472e0c2017-06-23 19:02:315164// Static; handles rewriting Web UI URLs.
5165bool ChromeContentBrowserClient::HandleWebUI(
5166 GURL* url,
5167 content::BrowserContext* browser_context) {
Dan Beam141c48932019-08-22 02:29:395168 // Rewrite chrome://help to chrome://settings/help.
dbeam25472e0c2017-06-23 19:02:315169 if (url->SchemeIs(content::kChromeUIScheme) &&
Dan Beam141c48932019-08-22 02:29:395170 url->host() == chrome::kChromeUIHelpHost) {
dbeam25472e0c2017-06-23 19:02:315171 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5172 chrome::kChromeUIHelpHost);
5173 return true; // Return true to update the displayed URL.
5174 }
5175
Hector Carmona566a20b2019-09-13 22:44:425176#if defined(OS_WIN)
5177 // TODO(crbug.com/1003960): Remove when issue is resolved.
5178 if (url->SchemeIs(content::kChromeUIScheme) &&
5179 url->host() == chrome::kChromeUIWelcomeWin10Host) {
5180 url::Replacements<char> replacements;
5181 replacements.SetHost(
5182 chrome::kChromeUIWelcomeHost,
5183 url::Component(0, strlen(chrome::kChromeUIWelcomeHost)));
5184 *url = url->ReplaceComponents(replacements);
5185 return true;
5186 }
5187#endif // defined(OS_WIN)
5188
dbeam25472e0c2017-06-23 19:02:315189 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5190 browser_context, *url)) {
5191 return false;
5192 }
5193
5194#if defined(OS_CHROMEOS)
5195 // Special case : in ChromeOS in Guest mode bookmarks and history are
5196 // disabled for security reasons. New tab page explains the reasons, so
5197 // we redirect user to new tab page.
5198 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5199 if (url->SchemeIs(content::kChromeUIScheme) &&
5200 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5201 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5202 // Rewrite with new tab URL
5203 *url = GURL(chrome::kChromeUINewTabURL);
5204 }
5205 }
5206#endif
5207
5208 return true;
5209}
5210
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065211bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5212 content::BrowserContext* browser_context,
5213 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325214 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065215#if defined(OS_ANDROID)
5216 return false;
5217#else
5218 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5219 ->GetForBrowserContext(browser_context)
5220 ->ShowPaymentHandlerWindow(url, std::move(callback));
5221 return true;
5222#endif
5223}
5224
Dan Beam141c48932019-08-22 02:29:395225// static
dbeam25472e0c2017-06-23 19:02:315226bool ChromeContentBrowserClient::HandleWebUIReverse(
5227 GURL* url,
5228 content::BrowserContext* browser_context) {
Hector Carmona566a20b2019-09-13 22:44:425229#if defined(OS_WIN)
5230 // TODO(crbug.com/1003960): Remove when issue is resolved.
5231 // No need to actually reverse-rewrite the URL, but return true to update the
5232 // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome.
5233 if (url->SchemeIs(content::kChromeUIScheme) &&
5234 url->host() == chrome::kChromeUIWelcomeHost) {
5235 return true;
5236 }
5237#endif // defined(OS_WIN)
5238
dbeam25472e0c2017-06-23 19:02:315239 // No need to actually reverse-rewrite the URL, but return true to update the
5240 // displayed URL when rewriting chrome://help to chrome://settings/help.
5241 return url->SchemeIs(content::kChromeUIScheme) &&
5242 url->host() == chrome::kChromeUISettingsHost;
5243}
5244
Dan Beamf0a7e112019-06-07 18:40:585245const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
5246 return ui::NativeTheme::GetInstanceForWeb();
5247}
5248
scottmgde42fb92017-02-10 17:56:035249// static
michaeln10e5fc352017-02-07 02:07:585250void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
5251 const storage::QuotaSettings* settings) {
5252 g_default_quota_settings = settings;
5253}
Yuzhu Shen44094e22017-07-18 22:52:355254
Clark DuVall5497288d2019-07-17 00:17:565255scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505256ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
5257 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:355258 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5259
Yuzhu Shencb3011f62018-02-08 02:51:505260 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
5261 if (!io_data->safe_browsing_enabled()->GetValue())
5262 return nullptr;
5263
Yuzhu Shen44094e22017-07-18 22:52:355264 // |safe_browsing_service_| may be unavailable in tests.
5265 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5266 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435267 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355268 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435269 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355270 }
5271
Clark DuVall5497288d2019-07-17 00:17:565272 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355273}
Daniel Vogelheim6008f572018-09-24 14:35:145274
5275base::Optional<std::string>
5276ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:265277 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185278 content::NavigationHandle* handle) {
5279 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5280 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145281}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525282
Takashi Toyoshima5af383aa2019-07-22 15:24:225283bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525284 // We require --user-data-dir flag too so that no dangerous changes are made
5285 // in the user's regular profile.
5286 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5287 switches::kUserDataDir);
5288}
rajendrantfeea8592018-10-19 18:26:065289
5290void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5291 int32_t network_traffic_annotation_id_hash,
5292 int64_t recv_bytes,
5293 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035294 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5295 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5296 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5297 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065298 }
5299}
Ryan Sturmaa05092f2018-10-21 03:56:545300
5301content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5302 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395303 content::NavigationHandle* navigation_handle,
5304 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135305 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5306 initial_state, navigation_handle, current_navigation_url);
5307
5308 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5309}
5310
5311content::PreviewsState
5312ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5313 content::PreviewsState initial_state,
5314 content::NavigationHandle* navigation_handle,
5315 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545316 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295317 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215318
Ryan Sturmaa05092f2018-10-21 03:56:545319 // If this is not a main frame, return the initial state. If there are no
5320 // previews in the state, return the state as is.
5321 if (!navigation_handle->IsInMainFrame() ||
5322 navigation_handle->IsSameDocument()) {
5323 return initial_state;
5324 }
5325
Robert Ogdena994eb42019-02-14 19:15:085326 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395327 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085328
Doug Arnettb3b99bc2019-08-09 16:55:565329 // Check if initial state specifies no previews should be considered.
5330 if (initial_state == content::PREVIEWS_OFF)
5331 return initial_state;
5332
Robert Ogdena994eb42019-02-14 19:15:085333 // Do not allow previews on POST navigations since the primary opt-out
5334 // mechanism is to reload the page. Because POST navigations are not
5335 // idempotent, we do not want to show a preview on a POST navigation where
5336 // opting out would cause another navigation, i.e.: a reload.
5337 if (navigation_handle->IsPost())
5338 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395339
5340 content::WebContents* web_contents = navigation_handle->GetWebContents();
5341 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5342
Ryan Sturmda2a0e02018-10-25 01:52:215343 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545344
5345 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5346 Profile::FromBrowserContext(browser_context));
5347 auto* data_reduction_proxy_settings =
5348 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5349 browser_context);
5350 // If the profile does not support previews or Data Saver, do not turn on
5351 // Previews.
5352 if (!previews_service || !previews_service->previews_ui_service() ||
Owen Min08a72892019-07-31 20:03:355353 !data_reduction_proxy_settings) {
Ryan Sturmaa05092f2018-10-21 03:56:545354 return content::PREVIEWS_OFF;
5355 }
5356
5357 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215358 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545359 // If this tab does not have a PreviewsUITabHelper, no preview should be
5360 // served.
5361 if (!ui_tab_helper)
5362 return content::PREVIEWS_OFF;
5363
5364 DCHECK(!browser_context->IsOffTheRecord());
5365
5366 // Other previews objects should all exist and be initialized if we have made
5367 // it past earlier checks.
5368 previews::PreviewsDeciderImpl* previews_decider_impl =
5369 previews_service->previews_ui_service()->previews_decider_impl();
5370 DCHECK(previews_decider_impl);
5371
Ryan Sturm647d1d92018-11-07 15:41:395372 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545373 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5374
Ryan Sturm647d1d92018-11-07 15:41:395375 previews::PreviewsUserData* previews_data =
5376 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5377
5378 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315379 // previews) and cannot re-evaluate PreviewsState once previews triggering
5380 // logic has already been run, so they should not change. Assume that
5381 // previews triggering logic has run when PreviewsUserData already exists and
5382 // a Lite Page Redirect preview is not being attempted, since it may also
5383 // create a previews_data before this point.
5384 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395385 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315386 previews_triggering_logic_already_ran =
5387 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395388 } else {
5389 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5390 navigation_handle, previews_decider_impl->GeneratePageId());
5391 }
5392
5393 DCHECK(previews_data);
5394
Robert Ogden01770b362019-05-22 17:36:435395 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5396 previews::switches::kForceEnablePreviews)) {
Sophie Changacd9e2d2019-08-22 22:05:095397 previews_decider_impl->LoadPageHints(navigation_handle);
Robert Ogden01770b362019-05-22 17:36:435398 return content::ALL_SUPPORTED_PREVIEWS;
5399 }
5400
Ryan Sturmaa05092f2018-10-21 03:56:545401 bool is_reload =
5402 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5403
Ryan Sturm647d1d92018-11-07 15:41:395404 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515405 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395406
5407 // For now, treat server previews types as a single decision, and do not
5408 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5409 // header, nor does the plumbing exist to modify the PreviewsState within the
5410 // URLLoader.
Seanac57e9b92019-04-29 19:19:315411 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395412 // Copy the server state that was used before the redirect for the initial
5413 // URL.
Robert Ogden869986f2019-06-20 19:12:055414 previews_state |=
5415 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395416 } else {
Doug Arnetta3dc71582018-11-08 00:25:105417 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Sophie Changff1fc382019-08-21 16:30:215418 previews_data, navigation_handle, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305419 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395420 previews_state |= server_previews_enabled_state;
5421 }
Ryan Sturmaa05092f2018-10-21 03:56:545422 }
5423
Robert Ogden198d6572019-06-26 15:15:335424 // Evaluate Offline, NoScript, and ResourceBlocking previews.
Ryan Sturmaa05092f2018-10-21 03:56:545425 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315426 previews_data, previews_triggering_logic_already_ran,
Owen Min08a72892019-07-31 20:03:355427 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
5428 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545429
5430 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395431 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545432 return content::PREVIEWS_OFF;
5433 }
5434
5435 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395436 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545437 return content::PREVIEWS_NO_TRANSFORM;
5438 }
5439
5440 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395441 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5442 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545443 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395444 }
5445
5446 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5447 if (delegate) {
5448 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5449 }
Ryan Sturmaa05092f2018-10-21 03:56:545450
5451 // If the allowed previews are limited by the embedder, ensure previews honors
5452 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395453 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5454 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545455 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5456 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5457 previews_state = content::PREVIEWS_OFF;
5458 }
Ryan Sturm647d1d92018-11-07 15:41:395459 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545460 return previews_state;
5461}
5462
5463// static
5464content::PreviewsState
5465ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5466 const GURL& url,
5467 data_reduction_proxy::DataReductionProxyData* drp_data,
5468 previews::PreviewsUserData* previews_user_data,
5469 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055470 content::PreviewsState initial_state,
5471 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545472 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5473 if (!previews::HasEnabledPreviews(initial_state))
5474 return content::PREVIEWS_OFF;
5475
5476 // Check if the server sent a preview directive.
5477 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555478 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545479
Ryan Sturmaa05092f2018-10-21 03:56:545480 // Check the various other client previews types.
5481 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055482 previews_user_data, url, previews_state, previews_decider,
5483 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545484}
5485
5486content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5487 content::PreviewsState initial_state,
5488 content::NavigationHandle* navigation_handle,
5489 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135490 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5491 initial_state, navigation_handle, response_headers);
5492
5493 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5494}
5495
5496content::PreviewsState
5497ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5498 content::PreviewsState initial_state,
5499 content::NavigationHandle* navigation_handle,
5500 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545501 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5502 // Only support HTTP and HTTPS.
5503 if (navigation_handle->IsErrorPage() ||
5504 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5505 return content::PREVIEWS_OFF;
5506 }
5507
5508 // If this is not a main frame, return the initial state. If there are no
5509 // previews in the state, return the state as is.
5510 if (!previews::HasEnabledPreviews(initial_state) ||
5511 !navigation_handle->IsInMainFrame() ||
5512 navigation_handle->IsSameDocument()) {
5513 return initial_state;
5514 }
5515
5516 // WebContents that don't have a PreviewsUITabHelper are not supported.
5517 PreviewsUITabHelper* ui_tab_helper =
5518 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5519 if (!ui_tab_helper)
5520 return content::PREVIEWS_OFF;
5521
5522 // If we did not previously create a PreviewsUserData, do not go any further.
5523 previews::PreviewsUserData* previews_user_data =
5524 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5525 if (!previews_user_data)
5526 return content::PREVIEWS_OFF;
5527
5528 PreviewsService* previews_service =
5529 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5530 navigation_handle->GetWebContents()->GetBrowserContext()));
5531
5532 if (!previews_service || !previews_service->previews_ui_service())
5533 return content::PREVIEWS_OFF;
5534
5535// Check if offline previews are being used and set it in the user data.
5536#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5537 offline_pages::OfflinePageTabHelper* tab_helper =
5538 offline_pages::OfflinePageTabHelper::FromWebContents(
5539 navigation_handle->GetWebContents());
5540
Ryan Sturmfc7d92f2019-02-12 02:24:235541 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5542 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5543
5544 // If this is an offline page, but not a preview, then we should not attempt
5545 // any previews or surface the previews UI.
5546 if (is_offline_page && !is_offline_preview)
5547 return content::PREVIEWS_OFF;
5548
5549 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545550#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5551
5552 // Annotate request if no-transform directive found in response headers.
5553 if (response_headers &&
5554 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265555 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545556 }
5557
5558 previews::PreviewsDeciderImpl* previews_decider_impl =
5559 previews_service->previews_ui_service()->previews_decider_impl();
5560 DCHECK(previews_decider_impl);
5561
Clark DuVall9c5a72cc2018-10-25 01:29:215562 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5563 auto* settings =
5564 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5565 navigation_handle->GetWebContents()->GetBrowserContext());
5566 if (settings) {
5567 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5568 // does not yet have all the response information.
5569 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5570 response_headers);
5571 }
Ryan Sturmaa05092f2018-10-21 03:56:545572
5573 // Determine effective PreviewsState for this committed main frame response.
5574 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215575 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055576 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545577
5578 // Double check that we never serve a preview when we have a
5579 // cache-control:no-transform directive.
5580 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5581 !previews::HasEnabledPreviews(committed_state));
5582
Robert Ogdended292c6f2019-05-03 22:44:515583 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545584 previews_user_data->set_committed_previews_state(committed_state);
5585
5586 previews::PreviewsType committed_type =
5587 previews::GetMainFramePreviewsType(committed_state);
5588
5589 // Capture committed previews type, if any, in PreviewsUserData.
5590 // Note: this is for the subset of previews types that are decided upon
5591 // navigation commit. Previews types that are determined prior to
5592 // navigation (such as for offline pages or for redirecting to another
5593 // url), are not set here.
5594 previews_user_data->SetCommittedPreviewsType(committed_type);
5595
5596 // Log the commit decision.
5597 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5598 previews_decider_impl->LogPreviewDecisionMade(
5599 (previews_user_data->cache_control_no_transform_directive()
5600 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5601 : previews::PreviewsEligibilityReason::COMMITTED),
5602 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055603 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055604 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545605
5606 return committed_state;
5607}
Charlie Harrison650e11422018-12-04 00:37:265608
5609void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5610 content::RenderFrameHost* render_frame_host,
5611 blink::mojom::WebFeature feature) {
5612 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5613 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5614 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5615 render_frame_host, new_features);
5616}
Yutaka Hirano968d6252018-12-04 05:09:315617
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525618std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315619 return ::GetProduct();
5620}
5621
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525622std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315623 return ::GetUserAgent();
5624}
Sam McNallyd54e23f92019-01-16 04:42:395625
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525626blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175627 return ::GetUserAgentMetadata();
5628}
5629
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525630base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275631 // This icon is available on Android, but adds 19KiB to the APK. Since it
5632 // isn't used on Android we exclude it to avoid bloat.
5633#if !defined(OS_ANDROID)
5634 return base::Optional<gfx::ImageSkia>(
5635 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5636 IDR_PRODUCT_LOGO_256));
5637#else
5638 return base::nullopt;
5639#endif
5640}
5641
Sam McNallyd54e23f92019-01-16 04:42:395642bool ChromeContentBrowserClient::IsBuiltinComponent(
5643 content::BrowserContext* browser_context,
5644 const url::Origin& origin) {
5645#if BUILDFLAG(ENABLE_EXTENSIONS)
5646 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5647 browser_context, origin);
5648#else
5649 return false;
5650#endif
5651}
Oleg Davydov2cc0167b2019-02-05 14:32:485652
5653bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5654 const GURL& url,
5655 content::BrowserContext* context) {
5656 PolicyBlacklistService* service =
5657 PolicyBlacklistFactory::GetForBrowserContext(context);
5658
5659 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5660 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5661 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5662}
Dominic Mazzoni21fb0282019-02-13 18:32:475663
5664ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5665 content::BrowserContext* browser_context) {
5666 Profile* profile = Profile::FromBrowserContext(browser_context);
5667 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5668}
Eric Karld6cd75b2019-03-14 22:01:365669
5670#if defined(OS_ANDROID)
5671content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525672ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365673 if (features::UseDisplayWideColorGamut()) {
5674 return WideColorGamutHeuristic::kUseDisplay;
5675 }
5676 return WideColorGamutHeuristic::kNone;
5677}
5678#endif
Ehsan Karamad91413d72019-03-22 16:37:485679
5680base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435681ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Clark DuVall1df2052b2019-08-05 19:58:465682 content::BrowserContext* browser_context) {
Ehsan Karamad91413d72019-03-22 16:37:485683 base::flat_set<std::string> mime_types;
5684#if BUILDFLAG(ENABLE_PLUGINS)
Clark DuVall1df2052b2019-08-05 19:58:465685 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
Ehsan Karamad91413d72019-03-22 16:37:485686 for (const auto& pair : map)
5687 mime_types.insert(pair.first);
5688#endif
5689 return mime_types;
5690}
Yao Xiaod06607b2019-05-02 23:16:365691
5692void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5693 const content::WebContents* web_contents,
5694 const content::RenderFrameHost* frame_host,
5695 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525696 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365697 const ChromeSubresourceFilterClient* client =
5698 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5699 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045700 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365701 if (!user_gesture) {
5702 if (base::FeatureList::IsEnabled(
5703 blink::features::
5704 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5705 download_policy->SetDisallowed(
5706 content::NavigationDownloadType::kAdFrameNoGesture);
5707 } else {
5708 download_policy->SetAllowed(
5709 content::NavigationDownloadType::kAdFrameNoGesture);
5710 }
Yao Xiaod06607b2019-05-02 23:16:365711 }
5712 }
5713}
Jun Cai732a05e32019-05-29 19:34:195714
5715bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5716 content::BrowserContext* browser_context,
5717 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525718 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195719 const HostContentSettingsMap* const content_settings =
5720 HostContentSettingsMapFactory::GetForProfile(
5721 Profile::FromBrowserContext(browser_context));
5722
5723 if (content_settings->GetContentSetting(
5724 requesting_origin.GetURL(), embedding_origin.GetURL(),
5725 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING,
5726 std::string()) == CONTENT_SETTING_BLOCK) {
5727 return true;
5728 }
5729
5730 return false;
5731}
5732
5733void ChromeContentBrowserClient::BlockBluetoothScanning(
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 HostContentSettingsMap* const content_settings =
5738 HostContentSettingsMapFactory::GetForProfile(
5739 Profile::FromBrowserContext(browser_context));
5740
5741 content_settings->SetContentSettingDefaultScope(
5742 requesting_origin.GetURL(), embedding_origin.GetURL(),
5743 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(),
5744 CONTENT_SETTING_BLOCK);
5745}