blob: 1054d28c88a5175ce672c285ee37cd5cca1d6f0f [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"
morritad95714f2014-10-01 02:37:2416#include "base/files/scoped_file.h"
Marc Treibad33cf942017-08-24 11:19:0017#include "base/i18n/base_i18n_switches.h"
jinsukkim79df88a2017-01-04 06:26:1518#include "base/i18n/character_encoding.h"
Ken Rockot341089f2019-01-11 23:11:5819#include "base/macros.h"
Tarun Bansal73d67f02018-01-17 05:56:2520#include "base/metrics/field_trial_params.h"
lazyboy5d5fede02016-03-10 04:10:1421#include "base/metrics/histogram_macros.h"
Lei Zhang2cfceac2018-11-14 19:36:3322#include "base/no_destructor.h"
[email protected]29699c22012-10-03 23:57:3923#include "base/path_service.h"
Avi Drissmand251e912018-12-26 15:46:3724#include "base/stl_util.h"
[email protected]e7463412013-06-10 22:53:4625#include "base/strings/string_number_conversions.h"
markdittmer67b71ea2016-03-03 22:40:0326#include "base/strings/string_split.h"
bmcquade5d2d9cf32015-06-19 17:42:2827#include "base/strings/string_util.h"
28#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2029#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0330#include "base/system/sys_info.h"
Eric Seckler8652dcd52018-09-20 10:42:2831#include "base/task/post_task.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:3232#include "base/threading/sequenced_task_runner_handle.h"
gabb15e19072016-05-11 20:45:4133#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1834#include "build/build_config.h"
Ken Rockot06fd2832019-05-24 17:24:4435#include "chrome/app/builtin_service_manifests.h"
Ken Rockot341089f2019-01-11 23:11:5836#include "chrome/app/chrome_content_browser_overlay_manifest.h"
37#include "chrome/app/chrome_content_gpu_overlay_manifest.h"
38#include "chrome/app/chrome_content_renderer_overlay_manifest.h"
39#include "chrome/app/chrome_content_utility_overlay_manifest.h"
Ken Rockot341089f2019-01-11 23:11:5840#include "chrome/app/chrome_renderer_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"
[email protected]d5a74be2014-08-08 01:01:2749#include "chrome/browser/chrome_content_browser_client_parts.h"
[email protected]317f96c92011-05-31 06:53:4150#include "chrome/browser/chrome_quota_permission_context.h"
drogerb1716972015-06-30 09:04:0951#include "chrome/browser/content_settings/cookie_settings_factory.h"
peconn5100d432015-09-16 12:03:0852#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
[email protected]8093a542011-05-13 07:29:3253#include "chrome/browser/content_settings/tab_specific_content_settings.h"
Robbie McElrath1294d242019-05-31 20:46:2254#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
55#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
Zhuoyu Qiancb1976382018-12-13 02:18:3056#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
57#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
rajendrantfeea8592018-10-19 18:26:0658#include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h"
[email protected]9d06d88d2012-02-23 22:37:0859#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4960#include "chrome/browser/download/download_prefs.h"
Maks Orlovich710d5e32019-07-09 20:16:4561#include "chrome/browser/extensions/chrome_extension_cookies.h"
John Abd-El-Maleka67add82018-03-09 18:22:0162#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]354de9e2014-08-07 03:27:1963#include "chrome/browser/font_family_cache.h"
Matt Reynolds93616f9b2019-06-07 01:28:5264#include "chrome/browser/hid/chrome_hid_delegate.h"
Anthony Vallee-Duboise2432137a2019-01-17 20:06:0165#include "chrome/browser/language/translate_frame_binder.h"
Avi Drissmand30927342018-05-22 15:04:2766#include "chrome/browser/lifetime/browser_shutdown.h"
Joe DeBlasio6e8409a2019-02-20 23:08:2767#include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h"
thakis678822e2017-04-20 17:20:3468#include "chrome/browser/media/router/media_router_feature.h"
Derek Chengeb64b19a2018-01-02 20:20:4269#include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h"
70#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
Patrik Höglundb564859b2018-05-17 11:17:1671#include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h"
mcasasa2023ab2016-09-08 01:06:3672#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Patrik Höglundb564859b2018-05-17 11:17:1673#include "chrome/browser/media/webrtc/webrtc_logging_handler_host.h"
[email protected]95132f52013-04-12 02:19:0474#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
Xi Han85079c22019-04-18 21:43:0575#include "chrome/browser/metrics/chrome_feature_list_creator.h"
[email protected]a2b4c5c2013-10-18 02:06:0776#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
Lu Chen5bec7a302018-06-26 18:52:3277#include "chrome/browser/navigation_predictor/navigation_predictor.h"
John Abd-El-Malek7577f262019-06-10 21:23:2378#include "chrome/browser/net/chrome_network_delegate.h"
Matt Menkeae4fdb12018-06-02 06:32:5479#include "chrome/browser/net/system_network_context_manager.h"
dvallet233f57ab2016-12-21 03:17:1080#include "chrome/browser/net_benchmarking.h"
Richard Knolld0eae962019-04-04 12:34:0281#include "chrome/browser/notifications/platform_notification_service_factory.h"
peterc26c6c62014-12-10 14:13:5982#include "chrome/browser/notifications/platform_notification_service_impl.h"
csharrison4bd8a192016-08-02 18:03:1583#include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h"
Charlie Harrison650e11422018-12-04 00:37:2684#include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
Matt Falkenhagen8479b202017-07-14 04:35:3185#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
leon.han952ea3252016-04-13 02:44:5686#include "chrome/browser/password_manager/chrome_password_manager_client.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:0687#include "chrome/browser/payments/payment_request_display_manager_factory.h"
Sigurdur Asgeirsson54b72702019-04-12 14:18:5488#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"
Sigurdur Asgeirsson70696672019-02-08 16:14:5189#include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h"
Adam Langley85339f62018-02-12 22:03:5690#include "chrome/browser/permissions/attestation_permission_request.h"
jyasskinc993ce8d2016-03-31 00:38:3491#include "chrome/browser/permissions/permission_context_base.h"
Adam Langley85339f62018-02-12 22:03:5692#include "chrome/browser/permissions/permission_request_manager.h"
[email protected]0609b17f2011-05-31 20:13:4293#include "chrome/browser/platform_util.h"
Amber Won94afd8112017-08-23 17:30:1194#include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h"
Ehsan Karamad91413d72019-03-22 16:37:4895#include "chrome/browser/plugins/plugin_utils.h"
Alexandr Ilin4909ec82018-06-06 10:22:4896#include "chrome/browser/predictors/loading_predictor.h"
97#include "chrome/browser/predictors/loading_predictor_factory.h"
[email protected]190e5e22013-07-27 05:59:2398#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4199#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:50100#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:07101#include "chrome/browser/prerender/prerender_message_filter.h"
John Abd-El-Maleka67add82018-03-09 18:22:01102#include "chrome/browser/prerender/prerender_util.h"
Ryan Sturmcc5071be2019-02-16 02:15:19103#include "chrome/browser/previews/previews_content_util.h"
Robert Ogdenafd250b2018-07-25 22:21:03104#include "chrome/browser/previews/previews_lite_page_decider.h"
Robert Ogdene7fdca92018-10-12 17:53:06105#include "chrome/browser/previews/previews_lite_page_navigation_throttle.h"
Ryan Sturmaf523742019-01-16 00:15:45106#include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h"
Ryan Sturmaa05092f2018-10-21 03:56:54107#include "chrome/browser/previews/previews_service.h"
108#include "chrome/browser/previews/previews_service_factory.h"
109#include "chrome/browser/previews/previews_ui_tab_helper.h"
[email protected]7e75e4a2013-05-17 17:20:03110#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:14111#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:32112#include "chrome/browser/profiles/profile_io_data.h"
John Abd-El-Malek1f7fc912018-07-26 02:48:06113#include "chrome/browser/profiles/renderer_updater.h"
114#include "chrome/browser/profiles/renderer_updater_factory.h"
Erik Chen49bbfa22017-08-18 08:49:56115#include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h"
116#include "chrome/browser/profiling_host/profiling_process_host.h"
clamy1e5574e2016-09-29 16:48:44117#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
[email protected]05fcf982011-04-19 00:44:14118#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:38119#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
Kenichi Ishibashi46329872018-07-17 09:43:40120#include "chrome/browser/renderer_preferences_util.h"
zhenw6edd49c2017-07-12 05:49:45121#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
meacerf43117a2016-12-27 21:02:31122#include "chrome/browser/safe_browsing/certificate_reporting_service.h"
123#include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
Carlos IL4ee307e2018-12-22 03:19:00124#include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h"
yzshen2d8fb422017-06-01 20:29:40125#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Yuzhu Shen44094e22017-07-18 22:52:35126#include "chrome/browser/safe_browsing/ui_manager.h"
127#include "chrome/browser/safe_browsing/url_checker_delegate_impl.h"
[email protected]a7b8e43d2013-03-18 18:52:43128#include "chrome/browser/search/search.h"
Jay Civelli2578ebe2018-06-05 18:44:31129#include "chrome/browser/sessions/session_tab_helper.h"
Reilly Grantcc22e602018-09-07 15:25:20130#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
Reilly Grant37877802018-08-18 00:58:35131#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
Reilly Grant24bf8332018-08-27 21:55:01132#include "chrome/browser/signin/header_modification_delegate_impl.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28133#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02134#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48135#include "chrome/browser/speech/tts_controller_delegate_impl.h"
[email protected]7a06d282013-05-03 04:39:33136#include "chrome/browser/speech/tts_message_filter.h"
Eric Lawrenced0acf2a7c2017-07-20 18:02:48137#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
[email protected]848dd042011-06-04 18:24:03138#include "chrome/browser/ssl/ssl_blocking_page.h"
estark3ba11132015-04-10 01:38:33139#include "chrome/browser/ssl/ssl_cert_reporter.h"
Joe DeBlasio9b996292019-01-31 05:09:32140#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07141#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35142#include "chrome/browser/ssl/ssl_error_handler.h"
Lucas Garron94b16052017-11-11 01:58:12143#include "chrome/browser/ssl/ssl_error_navigation_throttle.h"
Christopher Thompson4137cec2017-12-19 05:34:23144#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10145#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35146#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45147#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52148#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19149#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44150#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38151#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51152#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08153#include "chrome/browser/ui/browser_navigator.h"
154#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43155#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39156#include "chrome/browser/ui/login/login_handler.h"
Makoto Shimazuc7502932018-08-15 02:12:56157#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25158#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44159#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58160#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50161#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01162#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25163#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53164#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25165#include "chrome/browser/web_applications/components/app_registrar.h"
166#include "chrome/browser/web_applications/web_app_provider.h"
Balazs Engedy5b1088762018-06-05 09:30:46167#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
Balazs Engedya7ff70982018-06-04 18:14:47168#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Scott Violet6200d332018-02-23 21:29:23169#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22170#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01171#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51172#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14173#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22174#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30175#include "chrome/common/chrome_switches.h"
Ben Goodgere25ef852017-08-11 00:17:50176#include "chrome/common/constants.mojom.h"
[email protected]779dd282013-10-19 15:57:02177#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50178#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34179#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37180#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12181#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12182#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22183#include "chrome/common/prerender_util.h"
[email protected]3e69bc82011-05-26 23:22:38184#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28185#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02186#include "chrome/common/secure_origin_whitelist.h"
wittman832321f52016-10-10 18:18:38187#include "chrome/common/stack_sampling_configuration.h"
[email protected]c5dbef02011-05-13 05:06:09188#include "chrome/common/url_constants.h"
benc70c0e32016-09-22 03:50:37189#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18190#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30191#include "chrome/installer/util/google_update_settings.h"
leon.han04b276e2016-06-01 01:34:16192#include "components/autofill/content/browser/content_autofill_driver_factory.h"
brettwf1958912015-10-07 19:43:12193#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53194#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44195#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04196#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48197#include "components/cloud_devices/common/cloud_devices_switches.h"
Tao Bai02ab4dd42019-03-06 00:30:37198#include "components/content_capture/browser/content_capture_receiver_manager.h"
mukai8eaec822014-10-25 17:53:16199#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09200#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16201#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52202#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45203#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08204#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03205#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09206#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Ryan Sturmaa05092f2018-10-21 03:56:54207#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall92335842018-10-10 16:49:09208#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28209#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43210#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09211#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32212#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03213#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24214#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43215#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01216#include "components/feature_engagement/public/feature_constants.h"
217#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39218#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20219#include "components/language/core/browser/pref_names.h"
wittmane16da2782016-09-21 16:43:04220#include "components/metrics/call_stack_profile_collector.h"
[email protected]8e885de2014-07-22 23:36:53221#include "components/metrics/client_info.h"
Xiangjun Zhang45474842018-08-17 21:07:59222#include "components/mirroring/mojom/constants.mojom.h"
223#include "components/mirroring/service/features.h"
Scott Violet9ae82892018-03-01 18:38:12224#include "components/nacl/common/buildflags.h"
sammc2b0375b2016-12-22 01:26:17225#include "components/nacl/common/nacl_constants.h"
drogerc690e8802015-09-21 14:29:16226#include "components/net_log/chrome_net_log.h"
leon.han97e8f752016-09-06 06:13:20227#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06228#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53229#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54230#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18231#include "components/policy/core/common/policy_service.h"
232#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26233#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54234#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08235#include "components/prefs/pref_service.h"
236#include "components/prefs/scoped_user_pref_update.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"
240#include "components/previews/core/previews_decider.h"
241#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45242#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43243#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56244#include "components/rappor/public/rappor_utils.h"
nigeltao2f673762016-10-14 03:27:28245#include "components/rappor/rappor_recorder_impl.h"
nzolghadrd87a308d2016-12-07 15:45:56246#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35247#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
248#include "components/safe_browsing/browser/mojo_safe_browsing_impl.h"
249#include "components/safe_browsing/browser/url_checker_delegate.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"
Alexei Filippov65c08b92019-02-02 03:41:00255#include "components/services/heap_profiling/heap_profiling_service.h"
256#include "components/services/heap_profiling/public/cpp/settings.h"
erikchen0d4a6012018-04-03 16:06:33257#include "components/services/heap_profiling/public/mojom/constants.mojom.h"
Sergey Kuznetsovae594402019-04-19 16:08:05258#include "components/services/patch/public/interfaces/constants.mojom.h"
Alexander Woolfed183c512019-05-17 01:18:03259#include "components/services/quarantine/public/mojom/quarantine.mojom.h"
260#include "components/services/quarantine/quarantine_service.h"
Colin Blundell6a897c72018-03-16 11:14:14261#include "components/services/unzip/public/interfaces/constants.mojom.h"
Colin Blundell3517170e2019-07-11 08:16:34262#include "components/signin/public/base/signin_pref_names.h"
Scott Violetd7983c52018-03-03 00:24:41263#include "components/spellcheck/spellcheck_buildflags.h"
csharrisone985ebc2017-04-04 17:05:03264#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17265#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21266#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28267#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33268#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46269#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22270#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43271#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30272#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38273#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28274#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03275#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31276#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41277#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09278#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03279#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59280#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19281#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31282#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35283#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47284#include "content/public/browser/navigation_handle.h"
285#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11286#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50287#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30288#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33289#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05290#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34291#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48292#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27293#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13294#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08295#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19296#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21297#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23298#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43299#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18300#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56301#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40302#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18303#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58304#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57305#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23306#include "content/public/common/url_constants.h"
yzshenefcb7c72017-06-16 23:12:30307#include "content/public/common/url_loader_throttle.h"
[email protected]22aa4f82013-09-24 17:01:44308#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31309#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05310#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56311#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43312#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59313#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48314#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30315#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28316#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04317#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31318#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44319#include "media/media_buildflags.h"
320#include "media/mojo/buildflags.h"
Jay Civelli2578ebe2018-06-05 18:44:31321#include "mojo/public/cpp/bindings/binding_set.h"
Shimi Zhang6b72d292019-07-12 20:52:42322#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Ken Rockot40a1df792019-05-08 22:15:52323#include "mojo/public/cpp/bindings/pending_receiver.h"
324#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot0adc1e42019-05-24 08:20:08325#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53326#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51327#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58328#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34329#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06330#include "net/cookies/cookie_options.h"
John Abd-El-Malek7577f262019-06-10 21:23:23331#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46332#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57333#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14334#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38335#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19336#include "printing/buildflags/buildflags.h"
Andrew Moylan8ed9d83c82019-01-29 20:23:52337#include "services/image_annotation/public/mojom/constants.mojom.h"
338#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37339#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50340#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50341#include "services/network/public/cpp/resource_request.h"
Sam McNallye36abbc2017-07-20 01:04:28342#include "services/preferences/public/cpp/in_process_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33343#include "services/preferences/public/mojom/preferences.mojom.h"
Ken Rockot26cf4742018-02-11 04:10:40344#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
Jay Civelli668c097f2018-05-16 20:44:13345#include "services/service_manager/embedder/switches.h"
erikchena9db3a72018-04-12 16:24:00346#include "services/service_manager/public/cpp/connector.h"
Ken Rockot543f5e32018-02-04 02:13:50347#include "services/service_manager/public/mojom/connector.mojom.h"
Tom Sepez15d4e5202017-09-27 23:59:05348#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34349#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03350#include "services/strings/grit/services_strings.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35351#include "services/viz/public/interfaces/constants.mojom.h"
pilgrime92c5fcd2014-09-10 23:31:23352#include "storage/browser/fileapi/external_mount_points.h"
John Delaneyac24e572019-04-30 19:47:02353#include "third_party/blink/public/common/features.h"
Julie Jeongeun Kimd3d00a12019-03-25 01:46:25354#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h"
Leon Hanc819dc62019-01-28 04:30:19355#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17356#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Eric Willigers3eeae17c2019-03-13 17:32:10357#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21358#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26359#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18360#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39361#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08362#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35363#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21364#include "ui/base/ui_base_switches.h"
365#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49366#include "ui/native_theme/caption_style.h"
367#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57368#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45369#include "url/gurl.h"
370#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26371
Ken Rockot69aade02019-01-23 21:19:51372#if BUILDFLAG(ENABLE_NACL)
373#include "components/nacl/loader/nacl_loader_manifest.h"
374#if defined(OS_WIN) && defined(ARCH_CPU_X86)
375#include "components/nacl/broker/nacl_broker_manifest.h"
376#endif
377#endif
378
[email protected]b48c9182011-10-26 18:03:30379#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20380#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38381#include "chrome/browser/chrome_browser_main_win.h"
Patrick Monettebb543942019-05-17 17:45:32382#include "chrome/browser/win/conflicts/module_database.h"
383#include "chrome/browser/win/conflicts/module_event_sink_impl.h"
Jerry Lina0de7ce2018-06-22 15:18:36384#include "chrome/install_static/install_util.h"
Ken Rockotc74e3792018-02-10 16:31:30385#include "chrome/services/util_win/public/mojom/constants.mojom.h"
Ken Rockotfba9e742018-02-10 16:36:20386#include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h"
Ken Rockot7c168502019-05-30 07:58:46387#include "components/services/quarantine/public/cpp/quarantine_features_win.h"
[email protected]34f48682013-03-20 00:30:18388#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38389#elif defined(OS_MACOSX)
390#include "chrome/browser/chrome_browser_main_mac.h"
Guido Urdaneta1a2917432018-05-10 18:32:32391#include "services/audio/public/mojom/constants.mojom.h"
Guido Urdaneta191635e2018-05-09 16:00:53392#include "services/video_capture/public/mojom/constants.mojom.h"
[email protected]b48c9182011-10-26 18:03:30393#elif defined(OS_CHROMEOS)
Scott Violet776edf82017-09-29 02:03:01394#include "ash/public/interfaces/constants.mojom.h"
Scott Violet47f00e52018-05-04 22:50:31395#include "chrome/browser/ash_service_registry.h"
hashimotoa53e7e82016-10-26 06:30:47396#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17397#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30398#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24399#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Scott Violetef765b92017-06-09 21:26:36400#include "chrome/browser/chromeos/chrome_service_name.h"
Sam McNallyd8b7d822018-08-21 03:18:18401#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]07fe2752014-01-29 11:21:55402#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08403#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48404#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41405#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32406#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58407#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00408#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
409#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44410#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39411#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31412#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33413#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Luum Habtemariamce0d1a92019-06-21 03:26:52414#include "chrome/browser/chromeos/printing/cups_proxy_service_delegate_impl.h"
Pavol Marko230ea2c92017-12-03 22:35:44415#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10416#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36417#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27418#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
Huanzhong Huangafa98092019-06-24 12:01:24419#include "chrome/browser/ui/ash/tablet_mode_client.h"
djacobo21e56e02016-07-02 01:14:31420#include "chrome/browser/ui/browser_dialogs.h"
Luum Habtemariamc295b4ea2019-04-24 20:18:51421#include "chrome/services/cups_proxy/cups_proxy_service.h"
422#include "chrome/services/cups_proxy/public/mojom/constants.mojom.h"
Steven Bennetts38e9bde22019-01-03 17:31:10423#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21424#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10425#include "chromeos/constants/chromeos_switches.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21426#include "chromeos/services/cellular_setup/cellular_setup_service.h"
427#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
428#include "chromeos/services/cellular_setup/public/mojom/constants.mojom.h"
Leo Zhang84ce09e92018-08-25 01:55:36429#include "chromeos/services/ime/public/mojom/constants.mojom.h"
Steven Bennetts0c565d5b2019-04-24 23:52:45430#include "chromeos/services/network_config/network_config_service.h"
431#include "chromeos/services/network_config/public/mojom/constants.mojom.h"
Ryan Hansberry9a08623c2018-06-14 21:28:05432#include "chromeos/services/secure_channel/public/mojom/constants.mojom.h"
433#include "chromeos/services/secure_channel/secure_channel_service.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11434#include "components/crash/content/app/breakpad_linux.h"
[email protected]4d390782014-08-15 09:22:58435#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50436#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26437#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30438#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09439#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35440#include "base/android/application_status_listener.h"
zqzhang93e959d12017-03-16 13:10:20441#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36442#include "chrome/browser/android/chrome_context_util.h"
443#include "chrome/browser/android/devtools_manager_delegate_android.h"
Dan Harrington964d48c2018-08-03 15:52:24444#include "chrome/browser/android/download/available_offline_content_provider.h"
Min Qin0ab0e162017-11-14 21:57:19445#include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h"
Scott Violetef765b92017-06-09 21:26:36446#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
447#include "chrome/browser/android/service_tab_launcher.h"
448#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42449#include "chrome/browser/android/tab_web_contents_delegate_android.h"
Scott Violetef765b92017-06-09 21:26:36450#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09451#include "chrome/browser/chrome_browser_main_android.h"
Dan Harrington954c8822019-01-09 18:40:48452#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07453#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38454#include "chrome/common/chrome_descriptors.h"
Xing Liu302e0652018-04-27 18:23:08455#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Joshua Peraza934e5592018-07-18 23:43:11456#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07457#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47458#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36459#include "content/public/browser/android/java_interfaces.h"
Jay Civelli2df24642017-10-09 20:22:28460#include "services/proxy_resolver/proxy_resolver_service.h"
mfomitchev220b8562017-07-13 23:08:54461#include "services/service_manager/public/cpp/interface_provider.h"
Han Leonabbe7c902018-08-30 02:08:10462#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Julie Jeongeun Kimb6a0a1f2019-03-21 05:08:26463#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
agrieve05398f52015-06-24 18:59:00464#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36465#include "ui/base/ui_base_paths.h"
[email protected]b48c9182011-10-26 18:03:30466#elif defined(OS_POSIX)
467#include "chrome/browser/chrome_browser_main_posix.h"
468#endif
469
tmartinofb341882017-02-10 19:36:53470#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40471#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36472#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54473#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59474#include "chrome/browser/media/unified_autoplay_config.h"
mathpf709499d2017-01-09 20:48:36475#include "chrome/browser/payments/payment_request_factory.h"
Marc Treib7895941d2017-11-28 12:37:02476#include "chrome/browser/search/instant_service.h"
477#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46478#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51479#include "chrome/browser/ui/browser.h"
480#include "chrome/browser/ui/browser_finder.h"
481#include "chrome/browser/ui/browser_list.h"
482#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20483#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51484#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Jay Civelli4d53be9b2017-08-31 22:01:43485#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27486#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28487#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36488
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33489#if defined(OS_WIN) || defined(OS_MACOSX) || \
490 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52491#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
492#endif
493
[email protected]a220b5932013-09-21 03:47:44494#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02495#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02496#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13497#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02498#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13499#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43500#endif
[email protected]b80f68432011-05-02 17:22:30501
Maggie Caia2f03f52019-04-02 02:13:28502// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
503// single navigation throttle to display the intent picker on all platforms.
504#if !defined(OS_ANDROID)
505#if defined(OS_CHROMEOS)
506#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
507#else
508#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
509#endif
510#endif
511
[email protected]e8b6ca02013-07-10 18:00:51512#if defined(TOOLKIT_VIEWS)
513#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
514#endif
515
estaded3aa0e82016-02-17 22:55:21516#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22517#if defined(USE_X11)
518#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
519#else
estaded3aa0e82016-02-17 22:55:21520#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22521#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51522#endif
523
Mohsen Izadif1958f22019-01-18 20:29:31524#if defined(USE_OZONE)
525#include "ui/ozone/public/ozone_platform.h"
526#endif
527
[email protected]e8b6ca02013-07-10 18:00:51528#if defined(USE_X11)
529#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
530#endif
531
brettwab78fef2016-10-12 02:56:05532#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19533#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
534#endif
535
Nico Weberaf3b00b2017-09-11 17:58:17536#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55537#include "components/nacl/browser/nacl_browser.h"
538#include "components/nacl/browser/nacl_host_message_filter.h"
539#include "components/nacl/browser/nacl_process_host.h"
540#include "components/nacl/common/nacl_process_type.h"
541#include "components/nacl/common/nacl_switches.h"
542#endif
543
brettw00899e62016-11-12 02:10:17544#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05545#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20546#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27547#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23548#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Clark DuVall2cf99249e2018-09-19 19:11:51549#include "chrome/browser/extensions/user_script_listener.h"
550#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28551#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:53552#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Ken Rockot551f7482018-02-10 11:18:46553#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Ken Rockot2ad4db32018-02-10 16:24:10554#include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h"
fsamuel8dfa19a2015-05-05 01:00:39555#include "components/guest_view/browser/guest_view_base.h"
556#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25557#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31558#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35559#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32560#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12561#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57562#include "extensions/browser/extension_system.h"
tfarina01710e32015-07-13 21:53:22563#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48564#include "extensions/browser/guest_view/web_view/web_view_guest.h"
565#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
566#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31567#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27568#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28569#include "extensions/common/extension.h"
570#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13571#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28572#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33573#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28574#include "extensions/common/permissions/permissions_data.h"
575#include "extensions/common/permissions/socket_permission.h"
576#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34577#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25578
brettw4b461082016-11-19 18:55:16579#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55580#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27581#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39582#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55583#endif
584
bauerb8f9c37742017-03-30 15:04:12585#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
586#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
587#endif
588
thakis678822e2017-04-20 17:20:34589#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38590#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09591#endif
592
weilifabbf7572017-05-22 19:05:16593#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21594#include "chrome/browser/printing/printing_message_filter.h"
Colin Blundell00b00a82018-05-24 10:22:16595#include "components/services/pdf_compositor/public/interfaces/pdf_compositor.mojom.h"
weilifabbf7572017-05-22 19:05:16596#endif
Lei Zhanga2fa14c2018-05-15 00:05:21597
598#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
599 (BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
Ken Rockoted7f41b2018-02-10 16:19:10600#include "chrome/services/printing/public/mojom/constants.mojom.h"
Jay Civelli9237eac2017-09-21 16:10:21601#endif
weilifabbf7572017-05-22 19:05:16602
Xiaohan Wanga4e41842018-06-26 18:45:10603#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49604#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wanga4e41842018-06-26 18:45:10605#include "chrome/browser/media/platform_verification_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26606#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10607#include "chrome/browser/media/widevine_hardware_caps_win.h"
608#include "third_party/widevine/cdm/widevine_cdm_common.h"
609#endif
610#endif
611
xhwangdb24d602017-05-20 06:32:24612#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
xhwang116acb92017-04-03 18:27:20613#include "chrome/browser/media/android/cdm/media_drm_storage_factory.h"
614#endif
xhwangc86d76e42016-03-14 23:38:49615
xhwangdb24d602017-05-20 06:32:24616#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
Xiaohan Wang3fcfc152017-07-06 00:51:55617#include "media/mojo/interfaces/constants.mojom.h" // nogncheck
xhwangb1d65fd2016-10-19 20:55:52618#include "media/mojo/services/media_service_factory.h" // nogncheck
alokp6ecb2382016-01-27 00:40:00619#endif
620
mmenkedb2637ff2017-03-30 23:59:42621#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
622#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
623#endif
624
Luum Habtemariam7f7c61752018-07-18 00:41:18625#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_CHROMEOS)
Luum Habtemariamc295b4ea2019-04-24 20:18:51626// TODO(crbug.com/948800): Doesn't match BUILD.gn of use_cups && is_chromeos.
Luum Habtemariam9d999932018-10-15 23:04:12627#include "chrome/services/cups_ipp_parser/public/mojom/constants.mojom.h"
Luum Habtemariam7f7c61752018-07-18 00:41:18628#endif
629
Daniel Ruberya1611e32019-04-24 21:38:35630#if defined(FULL_SAFE_BROWSING)
631#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
632#endif
633
Jay Civellid5b614332017-11-10 03:37:05634#if defined(FULL_SAFE_BROWSING) || defined(OS_CHROMEOS)
Ken Rockot3d366682018-02-10 11:13:26635#include "chrome/services/file_util/public/mojom/constants.mojom.h"
Jay Civellid5b614332017-11-10 03:37:05636#endif
637
Jian Lide7b43792018-06-01 23:22:13638#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54639#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13640#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
641#endif
642
Ken Rockot80b08e92018-08-15 04:22:02643#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
644#include "services/content/simple_browser/public/mojom/constants.mojom.h"
645#include "services/content/simple_browser/simple_browser_service.h"
646#endif
647
648#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
Ken Rockot99c5bc742018-07-12 15:36:56649#include "services/content/simple_browser/public/mojom/constants.mojom.h"
650#endif
651
Will Cassella40837ba2019-07-01 21:32:00652#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43653#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
654#endif
655
Michael Thiessen909ba032019-03-26 23:47:43656#if defined(BROWSER_MEDIA_CONTROLS_MENU)
657#include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h"
658#endif
659
Michael Thiessen07c444c2019-04-26 03:53:11660#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
661#include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h"
662#endif
663
[email protected]c7abd422012-09-25 00:20:08664using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39665using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31666using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13667using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59668using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00669using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02670using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11671using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07672using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33673using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13674using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05675using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38676using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39677
[email protected]0daaebfe2014-03-15 00:09:05678#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20679using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05680#endif
681
brettw00899e62016-11-12 02:10:17682#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28683using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27684using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28685using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28686using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27687#endif
688
brettw4b461082016-11-19 18:55:16689#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55690using plugins::ChromeContentBrowserClientPluginsPart;
691#endif
692
[email protected]c5dbef02011-05-13 05:06:09693namespace {
694
michaeln10e5fc352017-02-07 02:07:58695const storage::QuotaSettings* g_default_quota_settings;
696
brettw4b461082016-11-19 18:55:16697#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42698// TODO(teravest): Add renderer-side API-specific checking for these APIs so
699// that blanket permission isn't granted to all dev channel APIs for these.
700// http://crbug.com/386743
701const char* const kPredefinedAllowedDevChannelOrigins[] = {
702 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
703 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
704};
705
[email protected]9de4da52014-05-24 12:26:50706const char* const kPredefinedAllowedFileHandleOrigins[] = {
[email protected]10c39222013-11-13 20:09:25707 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
708 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
709};
710
[email protected]9de4da52014-05-24 12:26:50711const char* const kPredefinedAllowedSocketOrigins[] = {
Mike Frysingera9864c6a2017-12-18 22:12:31712 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
713 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
714 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
715 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
[email protected]99132682012-04-24 19:00:45716 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
717 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
718 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
719 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35720 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54721 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
722 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
723 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
724 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
725 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
726 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38727 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58728 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29729 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42730 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42731 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
732 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
733 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40734};
[email protected]93f72062013-05-29 20:29:40735#endif
[email protected]e461da2f2012-02-16 19:06:40736
lazyboy5d5fede02016-03-10 04:10:14737enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53738 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14739 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53740
741 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14742 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53743
744 // An extension or app tried to load a resource of a different platform app in
745 // a tab.
746 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
747
748 // A non-app and non-extension page tried to load a platform app in a tab.
749 APP_LOADED_IN_TAB_SOURCE_OTHER,
750
lazyboy5d5fede02016-03-10 04:10:14751 APP_LOADED_IN_TAB_SOURCE_MAX
752};
753
Lei Zhang2cfceac2018-11-14 19:36:33754// Cached version of the locale so we can return the locale on the I/O
755// thread.
756std::string& GetIOThreadApplicationLocale() {
757 static base::NoDestructor<std::string> s;
758 return *s;
759}
760
[email protected]f8f93eb2012-09-25 03:06:24761// Returns a copy of the given url with its host set to given host and path set
762// to given path. Other parts of the url will be the same.
763GURL ReplaceURLHostAndPath(const GURL& url,
764 const std::string& host,
765 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05766 url::Replacements<char> replacements;
767 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
768 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24769 return url.ReplaceComponents(replacements);
770}
771
madfbd10852017-01-20 03:15:33772// Handles the rewriting of the new tab page URL based on group policy.
773bool HandleNewTabPageLocationOverride(
774 GURL* url,
775 content::BrowserContext* browser_context) {
776 if (!url->SchemeIs(content::kChromeUIScheme) ||
777 url->host() != chrome::kChromeUINewTabHost)
778 return false;
779
780 Profile* profile = Profile::FromBrowserContext(browser_context);
781 std::string ntp_location =
782 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
783 if (ntp_location.empty())
784 return false;
785
786 *url = GURL(ntp_location);
787 return true;
788}
789
Becca Hughesfe8c32c2018-03-21 13:36:56790#if !defined(OS_ANDROID)
791// Check if the current url is whitelisted based on a list of whitelisted urls.
792bool IsURLWhitelisted(const GURL& current_url,
793 const base::Value::ListStorage& whitelisted_urls) {
794 // Only check on HTTP and HTTPS pages.
795 if (!current_url.SchemeIsHTTPOrHTTPS())
796 return false;
797
798 for (auto const& value : whitelisted_urls) {
799 ContentSettingsPattern pattern =
800 ContentSettingsPattern::FromString(value.GetString());
801 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
802 continue;
803 if (pattern.Matches(current_url))
804 return true;
805 }
806
807 return false;
808}
809
810// Check if autoplay is allowed by policy configuration.
811bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
812 PrefService* prefs) {
813 DCHECK(prefs);
814
815 // Check if we have globally allowed autoplay by policy.
816 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
817 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
818 return true;
819 }
820
821 if (!contents)
822 return false;
823
824 // Check if the current URL matches a URL pattern on the whitelist.
825 const base::ListValue* autoplay_whitelist =
826 prefs->GetList(prefs::kAutoplayWhitelist);
827 return autoplay_whitelist &&
828 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
829 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
830}
831#endif
832
Joshua Perazaf890e4b2019-01-03 19:19:02833#if defined(OS_ANDROID)
834int GetCrashSignalFD(const base::CommandLine& command_line) {
835 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
836}
837#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03838breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
839 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02840 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52841 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02842 {
843 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31844 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03845 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50846 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02847 crash_handler->StartUploaderThread();
848 return crash_handler;
849 }
850}
851
avi3ef9ec9e2014-12-22 22:50:17852int GetCrashSignalFD(const base::CommandLine& command_line) {
[email protected]9de4da52014-05-24 12:26:50853 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39854 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31855 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02856 if (!crash_handler)
857 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18858 return crash_handler->GetDeathSignalSocket();
859 }
860
James Cook783fdeb2018-05-24 22:28:46861#if defined(OS_CHROMEOS)
862 // Mash services are utility processes, but crashes are reported using the
863 // service name as the process type to make the crash console easier to read.
864 if (command_line.HasSwitch(switches::kMashServiceName)) {
865 static base::NoDestructor<
866 std::map<std::string, breakpad::CrashHandlerHostLinux*>>
867 crash_handlers;
868 std::string service_name =
869 command_line.GetSwitchValueASCII(switches::kMashServiceName);
870 auto it = crash_handlers->find(service_name);
871 if (it == crash_handlers->end()) {
Lei Zhang74f3dd3f2019-04-10 00:16:31872 auto insert_result = crash_handlers->insert(
James Cook783fdeb2018-05-24 22:28:46873 std::make_pair(service_name, CreateCrashHandlerHost(service_name)));
Lei Zhang74f3dd3f2019-04-10 00:16:31874 it = insert_result.first;
James Cook783fdeb2018-05-24 22:28:46875 }
Lei Zhang74f3dd3f2019-04-10 00:16:31876 return it->second->GetDeathSignalSocket();
James Cook783fdeb2018-05-24 22:28:46877 }
878#endif // defined(OS_CHROMEOS)
879
[email protected]a1733df2012-06-22 11:24:18880 std::string process_type =
881 command_line.GetSwitchValueASCII(switches::kProcessType);
882
[email protected]779dd282013-10-19 15:57:02883 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31884 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02885 if (!crash_handler)
886 crash_handler = CreateCrashHandlerHost(process_type);
887 return crash_handler->GetDeathSignalSocket();
888 }
[email protected]a1733df2012-06-22 11:24:18889
[email protected]779dd282013-10-19 15:57:02890 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31891 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02892 if (!crash_handler)
893 crash_handler = CreateCrashHandlerHost(process_type);
894 return crash_handler->GetDeathSignalSocket();
895 }
[email protected]a1733df2012-06-22 11:24:18896
[email protected]779dd282013-10-19 15:57:02897 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31898 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02899 if (!crash_handler)
900 crash_handler = CreateCrashHandlerHost(process_type);
901 return crash_handler->GetDeathSignalSocket();
902 }
[email protected]a1733df2012-06-22 11:24:18903
James Cook9207cc12017-10-19 17:08:39904 if (process_type == switches::kUtilityProcess) {
905 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
906 if (!crash_handler)
907 crash_handler = CreateCrashHandlerHost(process_type);
908 return crash_handler->GetDeathSignalSocket();
909 }
910
[email protected]a1733df2012-06-22 11:24:18911 return -1;
912}
Joshua Perazaf890e4b2019-01-03 19:19:02913#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18914
[email protected]eabbfb12013-04-05 23:28:35915void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52916 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33917 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35918}
919
estark3ba11132015-04-10 01:38:33920// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31921// SSLErrorHandler. Uses CertificateReportingService to send reports. The
922// service handles queueing and re-sending of failed reports. Each certificate
923// error creates a new instance of this class.
924class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33925 public:
meacerf43117a2016-12-27 21:02:31926 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12927 content::WebContents* web_contents)
928 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
929 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31930 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33931
932 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55933 void ReportInvalidCertificateChain(
934 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31935 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33936 }
937
938 private:
meacerf43117a2016-12-27 21:02:31939 CertificateReportingService* service_;
940
941 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33942};
943
bshe4f53ce42015-11-30 16:56:31944#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05945float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59946 static const float kMinFSM = 1.05f;
947 static const int kWidthForMinFSM = 320;
948 static const float kMaxFSM = 1.3f;
949 static const int kWidthForMaxFSM = 800;
950
boliu21c5afa2017-01-11 19:34:23951 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59952
953 if (minWidth <= kWidthForMinFSM)
954 return kMinFSM;
955 if (minWidth >= kWidthForMaxFSM)
956 return kMaxFSM;
957
958 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
959 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
960 (kWidthForMaxFSM - kWidthForMinFSM);
961 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
962}
zpengdb4a58e2017-01-10 17:40:32963
[email protected]916615b2013-09-11 18:19:44964#endif // defined(OS_ANDROID)
965
brettw00899e62016-11-12 02:10:17966#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53967
968AppLoadedInTabSource ClassifyAppLoadedInTabSource(
969 const GURL& opener_url,
970 const extensions::Extension* target_platform_app) {
971 if (opener_url.SchemeIs(extensions::kExtensionScheme)) {
972 if (opener_url.host_piece() == target_platform_app->id()) {
973 // This platform app was trying to window.open() one of its own URLs.
974 if (opener_url ==
975 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
976 // Source was the background page.
977 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
978 } else {
979 // Source was a different page inside the app.
980 return APP_LOADED_IN_TAB_SOURCE_APP;
981 }
982 }
983 // The forbidden app URL was being opened by a different app or extension.
984 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
985 }
986 // The forbidden app URL was being opened by a non-extension page (e.g. http).
987 return APP_LOADED_IN_TAB_SOURCE_OTHER;
988}
brettw00899e62016-11-12 02:10:17989#endif // BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]9c7656382014-08-08 21:02:30990
Ken Rockot42dfa782018-06-28 21:08:41991WebContents* GetWebContentsFromProcessAndFrameId(int render_process_id,
992 int render_frame_id) {
Clark DuVallc57280be2018-06-19 03:46:23993 if (render_process_id) {
994 RenderFrameHost* rfh =
995 RenderFrameHost::FromID(render_process_id, render_frame_id);
996 return WebContents::FromRenderFrameHost(rfh);
997 }
998 return WebContents::FromFrameTreeNodeId(render_frame_id);
jam092d3be2016-09-27 15:56:36999}
1000
csharrison95f01e922017-04-24 18:52:351001#if BUILDFLAG(ENABLE_EXTENSIONS)
Charles Harrison34f67862017-08-22 01:04:171002// Returns true if there is is an extension matching |url| in
1003// |opener_render_process_id| with APIPermission::kBackground.
1004//
1005// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
1006// hosted app, even though normal extensions just use the host.
1007bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:351008 extensions::ProcessMap* process_map,
1009 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:171010 const GURL& url,
csharrison95f01e922017-04-24 18:52:351011 int opener_render_process_id) {
1012 // Note: includes web URLs that are part of an extension's web extent.
1013 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:171014 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:351015 return extension &&
1016 extension->permissions_data()->HasAPIPermission(
1017 APIPermission::kBackground) &&
1018 process_map->Contains(extension->id(), opener_render_process_id);
1019}
Kevin Marshall32f99d7e2017-07-11 23:17:461020
1021void InvokeCallbackOnThread(
1022 scoped_refptr<base::SequencedTaskRunner> task_runner,
1023 base::Callback<void(bool)> callback,
1024 bool result) {
tzikdf81f142018-10-26 00:23:341025 task_runner->PostTask(FROM_HERE, base::BindOnce(std::move(callback), result));
Kevin Marshall32f99d7e2017-07-11 23:17:461026}
csharrison95f01e922017-04-24 18:52:351027#endif
1028
John Abd-El-Malekd2377982018-01-08 22:23:121029chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
1030 const base::Callback<content::WebContents*()>& wc_getter) {
1031 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1032 auto* web_contents = wc_getter.Run();
1033 if (!web_contents)
1034 return nullptr;
1035
1036 return prerender::PrerenderContents::FromWebContents(web_contents);
1037}
1038
John Abd-El-Maleka67add82018-03-09 18:22:011039void LaunchURL(
1040 const GURL& url,
1041 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
1042 ui::PageTransition page_transition,
1043 bool has_user_gesture) {
1044 // If there is no longer a WebContents, the request may have raced with tab
1045 // closing. Don't fire the external request. (It may have been a prerender.)
1046 content::WebContents* web_contents = web_contents_getter.Run();
1047 if (!web_contents)
1048 return;
1049
1050 // Do not launch external requests attached to unswapped prerenders.
1051 prerender::PrerenderContents* prerender_contents =
1052 prerender::PrerenderContents::FromWebContents(web_contents);
1053 if (prerender_contents) {
1054 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
1055 prerender::ReportPrerenderExternalURL();
1056 return;
1057 }
1058
Robbie McElrath1294d242019-05-31 20:46:221059 // Do not launch external requests for schemes that have a handler registered.
1060 ProtocolHandlerRegistry* protocol_handler_registry =
1061 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1062 web_contents->GetBrowserContext());
1063 if (protocol_handler_registry &&
1064 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1065 return;
1066
John Abd-El-Maleka67add82018-03-09 18:22:011067 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:011068 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:191069 PolicyBlacklistFactory::GetForBrowserContext(
1070 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:011071 if (service) {
1072 const policy::URLBlacklist::URLBlacklistState url_state =
1073 service->GetURLBlacklistState(url);
1074 is_whitelisted =
1075 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1076 }
1077
1078 // If the URL is in whitelist, we launch it without asking the user and
1079 // without any additional security checks. Since the URL is whitelisted,
1080 // we assume it can be executed.
1081 if (is_whitelisted) {
1082 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1083 } else {
1084 ExternalProtocolHandler::LaunchUrl(
1085 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1086 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
1087 has_user_gesture);
1088 }
1089}
1090
Yutaka Hirano968d6252018-12-04 05:09:311091std::string GetProduct() {
1092 return version_info::GetProductNameAndVersionForUserAgent();
1093}
1094
Lukasz Anforowicz60d1253d2019-05-08 16:31:371095void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1096 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1097 // For renderer and utility (e.g. NetworkService) processes the switch is the
1098 // only available source, so below the combined (pref/policy + cmdline)
1099 // allowlist of secure origins is injected into |cmdline| for these other
1100 // processes.
1101 std::vector<std::string> allowlist =
1102 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1103 if (!allowlist.empty()) {
1104 cmdline->AppendSwitchASCII(
1105 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1106 base::JoinString(allowlist, ","));
1107 }
1108}
1109
[email protected]9dbfff12011-07-01 19:37:071110} // namespace
[email protected]c5dbef02011-05-13 05:06:091111
Yutaka Hirano968d6252018-12-04 05:09:311112std::string GetUserAgent() {
1113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1114 if (command_line->HasSwitch(switches::kUserAgent)) {
1115 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1116 if (net::HttpUtil::IsValidHeaderValue(ua))
1117 return ua;
1118 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1119 }
1120
John Delaneyac24e572019-04-30 19:47:021121 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1122 return content::GetFrozenUserAgent(
1123 command_line->HasSwitch(switches::kUseMobileUserAgent))
1124 .as_string();
1125 }
1126
Yutaka Hirano968d6252018-12-04 05:09:311127 std::string product = GetProduct();
1128#if defined(OS_ANDROID)
1129 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1130 product += " Mobile";
1131#endif
1132 return content::BuildUserAgentFromProduct(product);
1133}
1134
Mike West6e4cbb32019-02-13 09:40:171135blink::UserAgentMetadata GetUserAgentMetadata() {
1136 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171137 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301138 metadata.full_version = version_info::GetVersionNumber();
1139 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171140 metadata.platform = version_info::GetOSType();
1141
1142 // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces.
1143 metadata.architecture = "";
1144 metadata.model = "";
1145
1146 return metadata;
1147}
1148
Ran Jia96d43d42018-05-02 17:14:531149ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051150 StartupData* startup_data)
Wojciech Dzierżanowski45380802019-04-29 14:50:321151 : data_reduction_proxy_throttle_manager_(
1152 nullptr,
1153 base::OnTaskRunnerDeleter(nullptr)),
Jeremy Roman495db682019-07-12 16:03:241154 startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161155#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371156 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421157 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371158 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251159 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371160 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401161 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551162
1163 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401164#endif
[email protected]1deace22013-05-22 06:14:461165
Ahmed Fakhryd70bf37b2018-04-04 17:07:241166#if defined(OS_CHROMEOS)
1167 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1168#endif // defined(OS_CHROMEOS)
1169
brettw00899e62016-11-12 02:10:171170#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131171 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271172#endif
bena06f7d62017-04-04 20:48:521173
Sigurdur Asgeirsson70696672019-02-08 16:14:511174 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
Sigurdur Asgeirsson50945f92019-01-25 20:26:011175
bena06f7d62017-04-04 20:48:521176 gpu_binder_registry_.AddInterface(
Mike Wittman16fa5362018-09-04 17:27:301177 base::Bind(&metrics::CallStackProfileCollector::Create));
[email protected]e461da2f2012-02-16 19:06:401178}
1179
1180ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031181 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1182 delete extra_parts_[i];
1183 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401184}
1185
[email protected]bca18382012-06-25 19:15:231186// static
Chris Palmerac7d75642017-11-22 20:12:541187void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1188 PrefRegistrySimple* registry) {
1189 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1190 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Chris Hamilton8206aad2018-07-18 01:00:031191 registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true);
Julian Pastarmovfac28002018-02-01 11:17:451192 registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies,
1193 false);
Chris Palmerac7d75642017-11-22 20:12:541194}
1195
1196// static
[email protected]37ca3fe02013-07-05 15:32:441197void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341198 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251199 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1200 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1201 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281202 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1203 // user policy in addition to the same named ones in Local State (which are
1204 // used for mapping the command-line flags).
1205 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1206 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571207 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401208 registry->RegisterDictionaryPref(
1209 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041210 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101211#if !defined(OS_ANDROID)
1212 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561213 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101214#endif
[email protected]bca18382012-06-25 19:15:231215}
1216
[email protected]eabbfb12013-04-05 23:28:351217// static
1218void ChromeContentBrowserClient::SetApplicationLocale(
1219 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481220 // The common case is that this function is called early in Chrome startup
1221 // before any threads are created or registered. When there are no threads,
1222 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001223 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331224 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481225 return;
1226 }
1227
1228 // Otherwise we're being called to change the locale. In this case set it on
1229 // the IO thread.
thestig00844cea2015-09-08 21:44:521230 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351231
Eric Seckler8652dcd52018-09-20 10:42:281232 base::PostTaskWithTraits(
1233 FROM_HERE, {BrowserThread::IO},
Scott Violet875789e2018-02-02 07:46:481234 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351235}
1236
Patrick Monette61dfef92019-05-30 23:06:271237std::unique_ptr<content::BrowserMainParts>
1238ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311239 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271240 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301241 // Construct the Main browser parts based on the OS type.
1242#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051243 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271244 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1245#elif defined(OS_MACOSX)
1246 main_parts =
1247 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1248#elif defined(OS_CHROMEOS)
1249 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1250 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261251#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271252 main_parts =
1253 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141254#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271255 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1256 startup_data_);
[email protected]b48c9182011-10-26 18:03:301257#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271258 main_parts =
1259 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041260#else
[email protected]b48c9182011-10-26 18:03:301261 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271262 main_parts =
1263 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301264#endif
1265
Xi Han9fd44002019-04-30 17:39:361266 bool add_profiles_extra_parts = true;
1267#if defined(OS_ANDROID)
1268 if (startup_data_->HasBuiltProfilePrefService())
1269 add_profiles_extra_parts = false;
1270#endif
1271 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271272 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031273
Xi Han9fd44002019-04-30 17:39:361274 // Construct additional browser parts. Stages are called in the order in
1275 // which they are added.
[email protected]c7480942011-11-08 19:18:271276#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221277#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1278#if defined(USE_X11)
1279 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1280#else
estaded3aa0e82016-02-17 22:55:211281 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221282#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211283#else
riajiang7d6ec5c2017-01-25 16:40:331284 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351285#endif
1286#endif
1287
1288#if defined(OS_CHROMEOS)
1289 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331290 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221291#endif
[email protected]dc04be7c2012-03-15 23:57:491292
[email protected]e8b6ca02013-07-10 18:00:511293#if defined(USE_X11)
1294 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241295#endif
1296
Sigurdur Asgeirsson54b72702019-04-12 14:18:541297 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001298
Albert J. Wong59d85acb2017-08-10 00:50:571299 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571300
Patrick Monette61dfef92019-05-30 23:06:271301 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041302
Ben Goodger16331302018-01-23 00:43:211303 main_parts->AddParts(ChromeService::GetInstance()->CreateExtraParts());
1304
[email protected]50462bf02011-11-21 19:13:311305 return main_parts;
[email protected]f967b722011-09-07 00:58:041306}
1307
michaeln96f887e22015-04-13 23:58:311308void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091309 const base::Location& from_here,
michaeln96f887e22015-04-13 23:58:311310 const scoped_refptr<base::TaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211311 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121312 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
michaeln96f887e22015-04-13 23:58:311313}
1314
falkenb09d443f2016-04-07 12:36:121315bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1316 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1317}
1318
Gabriel Charettec8cca992017-08-10 18:21:491319void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1320 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1321}
1322
John Abd-El-Malek9d57f9c2019-02-20 18:50:041323bool ChromeContentBrowserClient::IsShuttingDown() {
1324 return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID;
1325}
1326
[email protected]e94bbcb2012-09-07 05:33:571327std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191328 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571329 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531330 std::string partition_id;
1331
1332 // The partition ID for webview guest processes is the string value of its
1333 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451334 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531335 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171336#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501337 // The partition ID for extensions with isolated storage is treated similarly
1338 // to the above.
1339 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1340 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1341 partition_id = site.spec();
1342#endif
[email protected]1bc28312012-11-08 08:31:531343
[email protected]056efdc2013-04-06 00:14:531344 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531345 return partition_id;
1346}
1347
1348bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1349 content::BrowserContext* browser_context,
1350 const std::string& partition_id) {
1351 // The default ID is empty and is always valid.
1352 if (partition_id.empty())
1353 return true;
1354
1355 return GURL(partition_id).is_valid();
1356}
1357
1358void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1359 content::BrowserContext* browser_context,
1360 const GURL& site,
[email protected]14acc642012-11-17 12:20:101361 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531362 std::string* partition_domain,
1363 std::string* partition_name,
1364 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101365 // Default to the browser-wide storage partition and override based on |site|
1366 // below.
1367 partition_domain->clear();
1368 partition_name->clear();
1369 *in_memory = false;
1370
brettw00899e62016-11-12 02:10:171371#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451372 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331373 site, partition_domain, partition_name, in_memory);
1374
1375 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101376 // If |can_be_default| is false, the caller is stating that the |site|
1377 // should be parsed as if it had isolated storage. In particular it is
1378 // important to NOT check ExtensionService for the is_storage_isolated()
1379 // attribute because this code path is run during Extension uninstall
1380 // to do cleanup after the Extension has already been unloaded from the
1381 // ExtensionService.
1382 bool is_isolated = !can_be_default;
1383 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341384 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1385 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101386 }
[email protected]1bc28312012-11-08 08:31:531387
[email protected]14acc642012-11-17 12:20:101388 if (is_isolated) {
1389 CHECK(site.has_host());
1390 // For extensions with isolated storage, the the host of the |site| is
1391 // the |partition_domain|. The |in_memory| and |partition_name| are only
1392 // used in guest schemes so they are cleared here.
1393 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531394 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101395 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531396 }
[email protected]1df3d972014-06-11 04:55:181397 success = true;
1398 }
1399#endif
1400
[email protected]14acc642012-11-17 12:20:101401 // Assert that if |can_be_default| is false, the code above must have found a
1402 // non-default partition. If this fails, the caller has a serious logic
1403 // error about which StoragePartition they expect to be in and it is not
1404 // safe to continue.
1405 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441406}
1407
[email protected]38b098f2012-03-14 21:11:571408content::WebContentsViewDelegate*
1409 ChromeContentBrowserClient::GetWebContentsViewDelegate(
1410 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101411 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321412}
1413
Bo Liu4ade6b1b22017-11-28 02:26:351414bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1415#if defined(OS_ANDROID)
1416 const base::android::ApplicationState app_state =
1417 base::android::ApplicationStatusListener::GetState();
1418 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1419 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1420 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1421#else
1422 return true;
1423#endif
1424}
1425
[email protected]6f2862742013-12-20 07:53:191426void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ben Goodger16331302018-01-23 00:43:211427 content::RenderProcessHost* host,
1428 service_manager::mojom::ServiceRequest* service_request) {
[email protected]f3b1a082011-11-18 00:34:301429 int id = host->GetID();
1430 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
horo062ef5352017-03-29 08:16:071431 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
thakis678822e2017-04-20 17:20:341432#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491433 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061434#endif
Brett Wilson65f951c2016-11-03 22:06:121435#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401436 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031437#endif
[email protected]ba780c12013-10-01 17:07:061438 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
thestig397accd2015-04-04 00:03:041439 host->AddFilter(new TtsMessageFilter(host->GetBrowserContext()));
[email protected]10e5c5e52013-10-03 18:44:061440 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
grunell34f2e5e2016-04-08 12:54:591441 new WebRtcLoggingHandlerHost(id, profile,
1442 g_browser_process->webrtc_log_uploader());
[email protected]10e5c5e52013-10-03 18:44:061443 host->AddFilter(webrtc_logging_handler_host);
avi284ec612017-05-03 01:52:231444 host->SetUserData(
1445 WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey,
Jeremy Romanec48d7a2018-03-01 17:35:091446 std::make_unique<base::UserDataAdapter<WebRtcLoggingHandlerHost>>(
avi284ec612017-05-03 01:52:231447 webrtc_logging_handler_host));
tereliusfa159cc2016-04-13 15:13:021448
grunell086a4112017-03-02 09:23:041449 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1450 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021451 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121452 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021453 host->SetUserData(
1454 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091455 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021456 audio_debug_recordings_handler));
1457
Nico Weberaf3b00b2017-09-11 17:58:171458#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031459 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1460 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351461#endif
jeremyim364ac1182015-03-03 18:49:431462
Xiaohan Wang9b34281b2017-09-08 23:48:331463#if defined(OS_ANDROID)
1464 // Data cannot be persisted if the profile is off the record.
1465 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061466 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071467
1468 // Register CrashMemoryMetricsCollector to report oom related metrics.
1469 host->SetUserData(
1470 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1471 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331472#endif
1473
Jun Caidb3f93cc2018-07-09 21:54:551474 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061475 RendererUpdaterFactory::GetForProfile(original_profile)
1476 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071477
[email protected]a48ab7112014-08-01 16:48:031478 for (size_t i = 0; i < extra_parts_.size(); ++i)
1479 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]edece212011-11-16 11:56:561480
Ken Rockot40a1df792019-05-08 22:15:521481 mojo::PendingRemote<service_manager::mojom::Service> service;
1482 *service_request = service.InitWithNewPipeAndPassReceiver();
Ben Goodger16331302018-01-23 00:43:211483 service_manager::Identity renderer_identity = host->GetChildIdentity();
Ken Rockot0adc1e42019-05-24 08:20:081484 mojo::Remote<service_manager::mojom::ProcessMetadata> metadata;
Ken Rockota86fa542018-11-13 21:47:131485 ChromeService::GetInstance()->connector()->RegisterServiceInstance(
Ben Goodger16331302018-01-23 00:43:211486 service_manager::Identity(chrome::mojom::kRendererServiceName,
Ken Rockotd2ed25a2018-11-06 22:25:371487 renderer_identity.instance_group(),
Ken Rockota86fa542018-11-13 21:47:131488 renderer_identity.instance_id(),
1489 base::Token::CreateRandom()),
Ken Rockot0adc1e42019-05-24 08:20:081490 std::move(service), metadata.BindNewPipeAndPassReceiver());
[email protected]05fcf982011-04-19 00:44:141491}
1492
[email protected]3d7474ff2011-07-27 17:47:371493GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571494 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301495 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371496 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521497 if (!profile)
1498 return url;
1499
Marc Treib7d467b792017-12-04 13:31:031500#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291501 // If the input |url| should be assigned to the Instant renderer, make its
1502 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311503 // This needs to happen even if |url| corresponds to an isolated origin; see
1504 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131505 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1506 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031507#endif
[email protected]b3cb3a32013-07-31 01:32:291508
brettw00899e62016-11-12 02:10:171509#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301510 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1511 url);
[email protected]d5a74be2014-08-08 01:01:271512#else
1513 return url;
1514#endif
[email protected]36fb2c7c2011-04-04 15:49:081515}
1516
Alexander Yashkin6aedc6e2018-08-15 08:58:451517bool ChromeContentBrowserClient::
1518 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1519 content::BrowserContext* browser_context,
1520 content::SiteInstance* candidate_site_instance,
1521 bool is_main_frame,
1522 const GURL& candidate_url,
1523 const GURL& destination_url) {
1524 DCHECK(browser_context);
1525 DCHECK(candidate_site_instance);
1526#if BUILDFLAG(ENABLE_EXTENSIONS)
1527 return ChromeContentBrowserClientExtensionsPart::
1528 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1529 browser_context, candidate_site_instance, is_main_frame,
1530 candidate_url, destination_url);
1531#else
1532 return true;
1533#endif
1534}
1535
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521536bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411537#if defined(OS_ANDROID)
1538 return true;
1539#elif defined(OS_CHROMEOS)
Huanzhong Huangafa98092019-06-24 12:01:241540 return TabletModeClient::Get() &&
1541 TabletModeClient::Get()->tablet_mode_enabled();
Ahmed Fakhrye6a2c642018-06-20 02:58:411542#else
1543 return false;
1544#endif // defined(OS_ANDROID)
1545}
1546
[email protected]056ad2a2011-07-12 02:13:551547bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371548 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521549 // Non-extension, non-Instant URLs should generally use
1550 // process-per-site-instance. Because we expect to use the effective URL,
1551 // URLs for hosted apps (apart from bookmark apps) should have an extension
1552 // scheme by now.
1553
1554 Profile* profile = Profile::FromBrowserContext(browser_context);
1555 if (!profile)
1556 return false;
1557
Marc Treib7d467b792017-12-04 13:31:031558#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131559 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521560 return true;
Marc Treib7d467b792017-12-04 13:31:031561#endif
[email protected]c5dec6292013-01-25 04:54:521562
brettw00899e62016-11-12 02:10:171563#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131564 return ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1565 profile, effective_url);
[email protected]d5a74be2014-08-08 01:01:271566#else
1567 return false;
1568#endif
[email protected]056ad2a2011-07-12 02:13:551569}
1570
Lukasz Anforowicz32d27122018-04-09 21:48:331571bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1572 content::BrowserContext* browser_context,
1573 const GURL& site_url) {
1574 Profile* profile = Profile::FromBrowserContext(browser_context);
1575 if (!profile)
1576 return false;
1577
1578#if !defined(OS_ANDROID)
1579 // Instant renderers should not use a spare process, because they require
1580 // passing switches::kInstantProcess to the renderer process when it
1581 // launches. A spare process is launched earlier, before it is known which
1582 // navigation will use it, so it lacks this flag.
1583 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1584 return false;
1585#endif
1586
1587#if BUILDFLAG(ENABLE_EXTENSIONS)
1588 return ChromeContentBrowserClientExtensionsPart::
1589 ShouldUseSpareRenderProcessHost(profile, site_url);
1590#else
1591 return true;
1592#endif
1593}
1594
nickcc0d9142015-10-14 16:27:101595bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Lukasz Anforowicz4aff3b82019-04-04 16:00:331596 content::BrowserOrResourceContext browser_or_resource_context,
nickcc0d9142015-10-14 16:27:101597 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171598#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101599 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Lukasz Anforowicz4aff3b82019-04-04 16:00:331600 browser_or_resource_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101601 return true;
1602 }
1603#endif
1604 return false;
1605}
1606
nick7d0984c2015-08-29 00:13:461607// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1608// origin-lock enforcement, where we don't have a way to efficiently know
1609// effective URLs on the IO thread, and wind up killing processes that e.g.
1610// request cookies for their actual URL. This whole function (and its
1611// ExtensionsPart) should be removed once we add that ability to the IO thread.
1612bool ChromeContentBrowserClient::ShouldLockToOrigin(
1613 content::BrowserContext* browser_context,
1614 const GURL& effective_site_url) {
1615 // Origin lock to the search scheme would kill processes upon legitimate
1616 // requests for cookies from the search engine's domain.
1617 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1618 return false;
1619
brettw00899e62016-11-12 02:10:171620#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461621 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1622 browser_context, effective_site_url)) {
1623 return false;
1624 }
1625#endif
1626 return true;
creise5d6d1732015-08-25 19:47:061627}
1628
Lukasz Anforowicz05f356e2018-03-13 20:26:111629const char*
Lukasz Anforowiczce869f0b2018-08-06 18:33:371630ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() {
Charles Reis358baf472017-12-06 05:30:431631#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz05f356e2018-03-13 20:26:111632 // Don't block responses for extension processes or for content scripts.
1633 // TODO(creis): When every extension fetch (including content scripts) has
1634 // been made to go through an extension-specific URLLoaderFactory, this
1635 // mechanism ought to work by enumerating the host permissions from the
1636 // extension manifest, and forwarding them on to the network service while
1637 // brokering the URLLoaderFactory.
1638 return extensions::kExtensionScheme;
1639#else
1640 return nullptr;
Charles Reis358baf472017-12-06 05:30:431641#endif
Charles Reis358baf472017-12-06 05:30:431642}
1643
Lukasz Anforowicz2f810162018-10-03 21:38:071644network::mojom::URLLoaderFactoryPtrInfo
1645ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests(
1646 content::RenderProcessHost* process,
1647 network::mojom::NetworkContext* network_context,
Clark DuValla5e25b752018-11-27 22:08:161648 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Lukasz Anforowicz2f810162018-10-03 21:38:071649 const url::Origin& request_initiator) {
1650#if BUILDFLAG(ENABLE_EXTENSIONS)
1651 return ChromeContentBrowserClientExtensionsPart::
Clark DuValla5e25b752018-11-27 22:08:161652 CreateURLLoaderFactoryForNetworkRequests(
1653 process, network_context, header_client, request_initiator);
Lukasz Anforowicz2f810162018-10-03 21:38:071654#else
1655 return network::mojom::URLLoaderFactoryPtrInfo();
1656#endif
1657}
1658
[email protected]73b718f2014-01-27 02:59:461659// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1660// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411661void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1662 std::vector<std::string>* additional_schemes) {
1663 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241664 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351665 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061666}
1667
alexmos94875b3b2017-03-16 22:19:011668void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1669 std::vector<std::string>* additional_schemes) {
1670 GetAdditionalWebUISchemes(additional_schemes);
1671
1672#if BUILDFLAG(ENABLE_EXTENSIONS)
1673 additional_schemes->push_back(extensions::kExtensionScheme);
1674#endif
1675}
1676
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521677bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011678 return webui::LogWebUIUrl(web_ui_url);
1679}
1680
John Abd-El-Malek04bfa8532018-07-12 05:28:221681bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1682 const url::Origin& origin) {
1683 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1684 origin);
1685}
1686
[email protected]46fb9442011-12-09 17:57:471687bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1688 return ProfileIOData::IsHandledURL(url);
1689}
1690
[email protected]c4365fa42013-05-14 01:08:241691bool ChromeContentBrowserClient::CanCommitURL(
1692 content::RenderProcessHost* process_host,
1693 const GURL& url) {
brettw00899e62016-11-12 02:10:171694#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131695 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1696 process_host, url);
[email protected]d5a74be2014-08-08 01:01:271697#else
1698 return true;
1699#endif
[email protected]c4365fa42013-05-14 01:08:241700}
1701
[email protected]9a60d1602013-09-11 04:09:121702bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1703 content::SiteInstance* site_instance, const GURL& url) {
brettw00899e62016-11-12 02:10:171704#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131705 bool result;
1706 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
alexmos1c3da4f2016-11-03 06:06:111707 site_instance, url, &result))
[email protected]f7daaa32014-08-02 07:58:131708 return result;
[email protected]d5a74be2014-08-08 01:01:271709#endif
[email protected]879816a92014-04-29 00:53:541710
1711 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1712 // the signin page may host untrusted web content.
alexmos1c3da4f2016-11-03 06:06:111713 GURL from_url = site_instance->GetSiteURL();
[email protected]879816a92014-04-29 00:53:541714 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
1715 url.SchemeIs(content::kChromeUIScheme) &&
brettwb65cd5c2016-01-23 00:46:381716 url.host_piece() != chrome::kChromeUIChromeSigninHost) {
[email protected]879816a92014-04-29 00:53:541717 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
1718 << chrome::kChromeUIChromeSigninURL;
1719 return false;
1720 }
1721
[email protected]9a60d1602013-09-11 04:09:121722 return true;
1723}
1724
avi7595a1bc2016-11-17 20:24:011725namespace {
1726
1727// Returns whether a SiteInstance holds a NTP. TODO(mastiz): This
1728// really really really needs to be moved to a shared place where all the code
1729// that needs to know this can access it. See http://crbug.com/624410.
1730bool IsNTPSiteInstance(SiteInstance* site_instance) {
1731 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1732 // use for making security decisions 99.44% of the time, for detecting the NTP
1733 // it is reliable and the correct way. Again, see http://crbug.com/624410.
1734 return site_instance &&
1735 site_instance->GetSiteURL().SchemeIs(chrome::kChromeSearchScheme) &&
1736 (site_instance->GetSiteURL().host_piece() ==
1737 chrome::kChromeSearchRemoteNtpHost ||
1738 site_instance->GetSiteURL().host_piece() ==
1739 chrome::kChromeSearchLocalNtpHost);
1740}
1741
1742} // namespace
1743
rdevlin.cronina32a0902016-11-09 15:50:201744void ChromeContentBrowserClient::OverrideNavigationParams(
1745 SiteInstance* site_instance,
1746 ui::PageTransition* transition,
1747 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581748 content::Referrer* referrer,
1749 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201750 DCHECK(transition);
1751 DCHECK(is_renderer_initiated);
1752 DCHECK(referrer);
mastiza77db6992016-06-30 09:48:421753 // TODO(crbug.com/624410): Factor the predicate to identify a URL as an NTP
1754 // to a shared library.
avi7595a1bc2016-11-17 20:24:011755 if (IsNTPSiteInstance(site_instance) &&
rdevlin.cronina32a0902016-11-09 15:50:201756 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581757 // Clicks on tiles of the new tab page should be treated as if a user
1758 // clicked on a bookmark. This is consistent with native implementations
1759 // like Android's. This also helps ensure that security features (like
1760 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1761 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201762 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1763 *is_renderer_initiated = false;
1764 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581765 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421766 }
rdevlin.cronina32a0902016-11-09 15:50:201767
brettw00899e62016-11-12 02:10:171768#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.cronina32a0902016-11-09 15:50:201769 ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams(
Lukasz Anforowicz63f3b9432019-05-30 05:42:581770 site_instance, transition, is_renderer_initiated, referrer,
1771 initiator_origin);
rdevlin.cronina32a0902016-11-09 15:50:201772#endif
mastiza77db6992016-06-30 09:48:421773}
1774
Charles Reis29e9dd12017-09-28 00:59:151775bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1776 const GURL& url,
1777 SiteInstance* parent_site_instance) {
1778 return url.SchemeIs(chrome::kChromeSearchScheme) &&
1779 IsNTPSiteInstance(parent_site_instance);
1780}
1781
[email protected]2a5221b2011-09-27 23:07:311782bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301783 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311784 const GURL& site_url) {
1785 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301786 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521787 // This may be NULL during tests. In that case, just assume any site can
1788 // share any host.
1789 if (!profile)
1790 return true;
1791
Marc Treib7895941d2017-11-28 12:37:021792#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141793 // Instant URLs should only be in the instant process and instant process
1794 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521795 InstantService* instant_service =
1796 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141797 if (instant_service) {
1798 bool is_instant_process = instant_service->IsInstantProcess(
1799 process_host->GetID());
1800 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131801 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141802 if (is_instant_process || should_be_in_instant_process)
1803 return is_instant_process && should_be_in_instant_process;
1804 }
Marc Treib7895941d2017-11-28 12:37:021805#endif
[email protected]c5dec6292013-01-25 04:54:521806
brettw00899e62016-11-12 02:10:171807#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131808 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1809 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271810#else
1811 return true;
1812#endif
[email protected]2a5221b2011-09-27 23:07:311813}
1814
[email protected]28c5d0b72014-05-13 08:19:591815bool ChromeContentBrowserClient::MayReuseHost(
1816 content::RenderProcessHost* process_host) {
1817 // If there is currently a prerender in progress for the host provided,
1818 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041819 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591820 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371821 prerender::PrerenderManagerFactory::GetForBrowserContext(
1822 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591823 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491824 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591825 return false;
1826 }
1827
1828 return true;
1829}
1830
[email protected]76411f412012-02-22 18:56:061831bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1832 content::BrowserContext* browser_context, const GURL& url) {
1833 // It has to be a valid URL for us to check for an extension.
1834 if (!url.is_valid())
1835 return false;
1836
brettw00899e62016-11-12 02:10:171837#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061838 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131839 return ChromeContentBrowserClientExtensionsPart::
1840 ShouldTryToUseExistingProcessHost(
1841 profile, url);
[email protected]d5a74be2014-08-08 01:01:271842#else
1843 return false;
1844#endif
[email protected]76411f412012-02-22 18:56:061845}
1846
Alex Moshchuk9c9e3882018-11-02 19:57:031847bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1848 content::RenderFrameHost* main_frame) {
1849#if BUILDFLAG(ENABLE_EXTENSIONS)
1850 return ChromeContentBrowserClientExtensionsPart::
1851 ShouldSubframesTryToReuseExistingProcess(main_frame);
1852#else
1853 return true;
1854#endif
1855}
1856
[email protected]6f371442011-11-09 06:45:461857void ChromeContentBrowserClient::SiteInstanceGotProcess(
1858 SiteInstance* site_instance) {
1859 CHECK(site_instance->HasProcess());
1860
1861 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021862 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521863 if (!profile)
1864 return;
1865
Marc Treib7895941d2017-11-28 12:37:021866#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521867 // Remember the ID of the Instant process to signal the renderer process
1868 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131869 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1870 profile)) {
[email protected]c5dec6292013-01-25 04:54:521871 InstantService* instant_service =
1872 InstantServiceFactory::GetForProfile(profile);
1873 if (instant_service)
1874 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1875 }
Marc Treib7895941d2017-11-28 12:37:021876#endif
[email protected]c5dec6292013-01-25 04:54:521877
[email protected]a48ab7112014-08-01 16:48:031878 for (size_t i = 0; i < extra_parts_.size(); ++i)
1879 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461880}
1881
1882void ChromeContentBrowserClient::SiteInstanceDeleting(
1883 SiteInstance* site_instance) {
1884 if (!site_instance->HasProcess())
1885 return;
1886
[email protected]a48ab7112014-08-01 16:48:031887 for (size_t i = 0; i < extra_parts_.size(); ++i)
1888 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461889}
1890
[email protected]453f5432013-11-26 19:43:001891bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141892 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081893 const GURL& current_url,
1894 const GURL& new_url) {
brettw00899e62016-11-12 02:10:171895#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131896 return ChromeContentBrowserClientExtensionsPart::
1897 ShouldSwapBrowsingInstancesForNavigation(
1898 site_instance, current_url, new_url);
[email protected]d5a74be2014-08-08 01:01:271899#else
1900 return false;
1901#endif
[email protected]e3daf3c2011-10-05 21:17:081902}
1903
Nasko Oskovd83b5712018-05-04 04:50:571904bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1905 // TODO(nasko): Consider supporting error page isolation in subframes if
1906 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381907 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571908}
1909
[email protected]3d831992013-07-04 01:13:291910bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1911 return !url.SchemeIs(chrome::kChromeNativeScheme);
1912}
1913
Alex Moshchukd252c192017-07-17 22:03:481914std::vector<url::Origin>
1915ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1916 std::vector<url::Origin> isolated_origin_list;
1917
Alex Moshchuk89352a72017-10-25 20:25:591918// Sign-in process isolation is not needed on Android, see
1919// https://crbug.com/739418.
1920#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381921 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121922 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591923#endif
Alex Moshchukd252c192017-07-17 22:03:481924
Alex Moshchuk81d2a29e2019-07-16 01:14:381925#if BUILDFLAG(ENABLE_EXTENSIONS)
1926 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1927 GetOriginsRequiringDedicatedProcess();
1928 std::move(std::begin(origins_from_extensions),
1929 std::end(origins_from_extensions),
1930 std::back_inserter(isolated_origin_list));
1931#endif
1932
Alex Moshchukd252c192017-07-17 22:03:481933 return isolated_origin_list;
1934}
1935
Lukasz Anforowicz5e201abd2018-03-24 00:41:061936bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341937 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1938}
1939
1940bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Lukasz Anforowicz0711a0f2019-03-28 18:15:311941 // Using 1077 rather than 1024 because 1) it helps ensure that devices with
1942 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one
1943 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2.
1944 // See also https://crbug.com/844118.
1945 constexpr int kDefaultMemoryThresholdMb = 1077;
Aaron Colwell25617f72018-11-27 20:56:341946
1947 // TODO(acolwell): Rename feature since it now affects more than just the
1948 // site-per-process case.
Lukasz Anforowicz46275d92018-04-12 14:57:381949 if (base::FeatureList::IsEnabled(
1950 features::kSitePerProcessOnlyForHighMemoryClients)) {
Lukasz Anforowicz46275d92018-04-12 14:57:381951 int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
1952 features::kSitePerProcessOnlyForHighMemoryClients,
1953 features::kSitePerProcessOnlyForHighMemoryClientsParamName,
1954 kDefaultMemoryThresholdMb);
Aaron Colwell25617f72018-11-27 20:56:341955 return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb;
Lukasz Anforowicz46275d92018-04-12 14:57:381956 }
1957
Aaron Colwell25617f72018-11-27 20:56:341958#if defined(OS_ANDROID)
1959 if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) {
1960 return true;
1961 }
1962#endif
1963
1964 return false;
Lukasz Anforowicz5e201abd2018-03-24 00:41:061965}
1966
Alex Moshchuk082b5f82019-03-14 01:34:161967std::vector<std::string>
1968ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1969 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1970 return {"Isolate Password Sites"};
1971 else
1972 return {};
1973}
1974
Alex Moshchuke256d562019-04-26 21:43:571975void ChromeContentBrowserClient::PersistIsolatedOrigin(
1976 content::BrowserContext* context,
1977 const url::Origin& origin) {
1978 DCHECK(!context->IsOffTheRecord());
1979 Profile* profile = Profile::FromBrowserContext(context);
1980 ListPrefUpdate update(profile->GetPrefs(),
1981 prefs::kUserTriggeredIsolatedOrigins);
1982 base::ListValue* list = update.Get();
1983 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361984 if (!base::Contains(list->GetList(), value))
Alex Moshchuke256d562019-04-26 21:43:571985 list->GetList().push_back(std::move(value));
1986}
1987
Ken Rockot314714c2017-11-05 23:36:241988bool ChromeContentBrowserClient::IsFileAccessAllowed(
1989 const base::FilePath& path,
1990 const base::FilePath& absolute_path,
1991 const base::FilePath& profile_path) {
1992 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1993 profile_path);
1994}
1995
[email protected]d2e1a0a2014-06-16 15:49:371996namespace {
1997
1998bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171999 const base::CommandLine& browser_command_line =
2000 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:352001 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372002 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:352003 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:372004 return false;
[email protected]9ef49b42014-08-07 16:44:242005 return true;
[email protected]d2e1a0a2014-06-16 15:49:372006}
2007
bmcquade5d2d9cf32015-06-19 17:42:282008void MaybeAppendBlinkSettingsSwitchForFieldTrial(
2009 const base::CommandLine& browser_command_line,
2010 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:522011 // List of field trials that modify the blink-settings command line flag. No
2012 // two field trials in the list should specify the same keys, otherwise one
2013 // field trial may overwrite another. See Source/core/frame/Settings.in in
2014 // Blink for the list of valid keys.
2015 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:162016 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
2017 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
2018 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
2019 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:522020 };
2021
2022 std::vector<std::string> blink_settings;
2023 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
2024 // Each blink-settings field trial should include a forcing_flag group,
2025 // to make sure that clients that specify the blink-settings flag on the
2026 // command line are excluded from the experiment groups. To make
2027 // sure we assign clients that specify this flag to the forcing_flag
2028 // group, we must call GetVariationParams for each field trial first
2029 // (for example, before checking HasSwitch() and returning), since
2030 // GetVariationParams has the side-effect of assigning the client to
2031 // a field trial group.
2032 std::map<std::string, std::string> params;
2033 if (variations::GetVariationParams(field_trial_name, &params)) {
2034 for (const auto& param : params) {
2035 blink_settings.push_back(base::StringPrintf(
2036 "%s=%s", param.first.c_str(), param.second.c_str()));
2037 }
2038 }
2039 }
pmeenan9ac669682015-08-17 14:57:032040
bmcquade9dd54cc2015-06-22 16:56:522041 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282042 return;
2043 }
2044
2045 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2046 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032047 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522048 // blink-settings flag into a group with no params, and we return
2049 // above if no params were specified, so it's an error if we reach
2050 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282051 LOG(WARNING) << "Received field trial params, "
2052 "but blink-settings switch already specified.";
2053 return;
2054 }
2055
bmcquade5d2d9cf32015-06-19 17:42:282056 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262057 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282058}
2059
zpengdb4a58e2017-01-10 17:40:322060#if defined(OS_ANDROID)
Ben Goodger6a695c012017-06-20 20:21:202061template <typename Interface>
2062void ForwardToJavaFrameRegistry(
Ben Goodger6a695c012017-06-20 20:21:202063 mojo::InterfaceRequest<Interface> request,
2064 content::RenderFrameHost* render_frame_host) {
2065 render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request));
mgiuca3d9a1962017-04-07 05:25:442066}
2067
Ben Goodger6a695c012017-06-20 20:21:202068template <typename Interface>
2069void ForwardToJavaWebContentsRegistry(
Ben Goodger6a695c012017-06-20 20:21:202070 mojo::InterfaceRequest<Interface> request,
2071 content::RenderFrameHost* render_frame_host) {
2072 content::WebContents* contents =
2073 content::WebContents::FromRenderFrameHost(render_frame_host);
2074 if (contents)
2075 contents->GetJavaInterfaces()->GetInterface(std::move(request));
sammc0285a442016-10-04 23:03:562076}
2077#endif
2078
[email protected]d2e1a0a2014-06-16 15:49:372079} // namespace
2080
[email protected]b80f68432011-05-02 17:22:302081void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172082 base::CommandLine* command_line,
2083 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062084#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352085 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062086 GoogleUpdateSettings::LoadMetricsClientInfo();
2087 if (client_info) {
2088 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2089 client_info->client_id);
2090 }
2091#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022092#if defined(OS_ANDROID)
2093 bool enable_crash_reporter = true;
2094#else
2095 bool enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2096#endif
2097 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512098 std::string switch_value;
dcheng4af48582016-04-19 00:29:352099 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532100 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512101 if (client_info)
2102 switch_value = client_info->client_id;
2103 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252104 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302105 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512106 switch_value);
[email protected]b80f68432011-05-02 17:22:302107 }
Mark Mentovaic67fa64f2015-03-24 14:00:062108#endif
[email protected]b80f68432011-05-02 17:22:302109
[email protected]f1933792011-06-14 00:49:342110 if (logging::DialogsAreSuppressed())
2111 command_line->AppendSwitch(switches::kNoErrorDialogs);
2112
[email protected]b80f68432011-05-02 17:22:302113 std::string process_type =
2114 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172115 const base::CommandLine& browser_command_line =
2116 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322117
[email protected]7c9b6f92013-09-10 18:11:352118 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:562119 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:352120 switches::kUserDataDir, // Make logs go to the right file.
2121 };
2122 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372123 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322124
fqj15ff3f72015-10-09 19:20:022125 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432126 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312127 };
fqj15ff3f72015-10-09 19:20:022128 command_line->CopySwitchesFrom(browser_command_line,
2129 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372130 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312131
fqj15ff3f72015-10-09 19:20:022132#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332133 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2134 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522135 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332136 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2137 homedir.value().c_str());
2138#endif
2139
[email protected]718eab62011-10-05 21:16:522140 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032141 content::RenderProcessHost* process =
2142 content::RenderProcessHost::FromID(child_process_id);
2143 Profile* profile =
2144 process ? Profile::FromBrowserContext(process->GetBrowserContext())
2145 : NULL;
2146 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2147 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(
2148 command_line, process, profile);
2149 }
2150
[email protected]b80f68432011-05-02 17:22:302151#if defined(OS_CHROMEOS)
2152 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:442153 browser_command_line.GetSwitchValueASCII(
2154 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302155 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:442156 command_line->AppendSwitchASCII(
2157 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:302158#endif
2159
[email protected]30335fdf02014-02-26 19:51:272160 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
2161 browser_command_line,
sdefresne9fb67692015-08-03 18:48:222162 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372163 if (process) {
[email protected]a8d851f82011-12-21 00:32:372164 PrefService* prefs = profile->GetPrefs();
2165 // Currently this pref is only registered if applied via a policy.
2166 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2167 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2168 // Turn this policy into a command line switch.
2169 command_line->AppendSwitch(switches::kDisable3DAPIs);
2170 }
[email protected]718eab62011-10-05 21:16:522171
[email protected]1733b782014-06-19 18:51:552172 const base::ListValue* switches =
2173 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2174 if (switches) {
2175 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112176 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552177 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142178 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552179 command_line->AppendSwitch(switch_to_enable);
2180 }
2181 }
2182
[email protected]a8d851f82011-12-21 00:32:372183 // Disable client-side phishing detection in the renderer if it is
2184 // disabled in the Profile preferences or the browser process.
2185 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2186 !g_browser_process->safe_browsing_detection_service()) {
2187 command_line->AppendSwitch(
2188 switches::kDisableClientSidePhishingDetection);
2189 }
[email protected]0045b0f42012-07-26 11:52:082190
vitalybukaa7ae5052014-09-26 04:11:132191 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2192 command_line->AppendSwitch(switches::kDisablePrintPreview);
2193
Marc Treib7895941d2017-11-28 12:37:022194#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522195 InstantService* instant_service =
2196 InstantServiceFactory::GetForProfile(profile);
2197 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542198 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522199 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542200 }
Marc Treib7895941d2017-11-28 12:37:022201#endif
fqjba8749c2015-10-29 15:33:072202
fqj38306f7b2015-11-02 16:59:062203 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542204 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432205 command_line->AppendSwitch(
2206 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542207 }
Daniel Vogelheim976f1c22017-11-22 16:26:032208
Lukasz Anforowicz60d1253d2019-05-08 16:31:372209 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2210
Amr Aboelkherb04cbf32019-04-29 15:17:102211 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2212 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292213 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102214 }
[email protected]47c7ec82012-01-18 03:29:212215 }
[email protected]4287a3d2011-06-13 23:56:512216
[email protected]d2e1a0a2014-06-16 15:49:372217 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352218 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042219
bmcquade5d2d9cf32015-06-19 17:42:282220 MaybeAppendBlinkSettingsSwitchForFieldTrial(
2221 browser_command_line, command_line);
2222
mdjonesa6b9e172016-09-23 16:24:302223#if defined(OS_ANDROID)
2224 // If the platform is Android, force the distillability service on.
2225 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2226#endif
2227
[email protected]47c7ec82012-01-18 03:29:212228 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512229 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192230 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412231 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302232#if defined(OS_CHROMEOS)
2233 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2234#endif
brettw00899e62016-11-12 02:10:172235#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512236 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272237 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172238 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512239 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272240 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172241 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172242 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282243#endif
estark4b003b332015-02-14 01:07:052244 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512245 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482246 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512247 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502248 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572249 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462250 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302251 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512252 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172253#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242254 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482255 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552256#endif
[email protected]ce304ce2013-02-22 21:54:452257 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172258#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592259 switches::kForcePNaClSubzero,
2260#endif
Marc Treibad33cf942017-08-24 11:19:002261 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512262 switches::kJavaScriptHarmony,
iclelland79237e92016-06-23 12:03:512263 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552264 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022265 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512266 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512267 switches::kPpapiFlashPath,
2268 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032269 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092270 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512271 };
2272
2273 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372274 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172275 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172276#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382277 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:512278 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:512279 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272280 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a612eb32014-03-31 22:09:172281 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382282 };
2283
2284 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372285 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282286#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372287 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132288 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512289 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512290 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502291 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172292#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242293 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582294 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592295 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412296 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552297#endif
[email protected]4287a3d2011-06-13 23:56:512298 switches::kPpapiFlashPath,
2299 switches::kPpapiFlashVersion,
2300 };
2301
2302 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372303 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112304 } else if (process_type == switches::kGpuProcess) {
2305 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2306 // because GPU is expected to be unreliable.
2307 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2308 !command_line->HasSwitch(switches::kDisableBreakpad))
2309 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302310 }
[email protected]6f08af82011-09-15 01:19:032311
Ian Barkley-Yeung550aae052019-07-11 00:11:112312#if defined(OS_CHROMEOS)
2313 if (breakpad::ShouldPassCrashLoopBefore(process_type)) {
2314 static const char* const kSwitchNames[] = {
2315 switches::kCrashLoopBefore,
2316 };
2317 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2318 base::size(kSwitchNames));
2319 }
2320#endif
2321
wittman832321f52016-10-10 18:18:382322 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
2323 process_type,
2324 command_line);
Andrew Comminos66057672019-05-01 00:03:342325
2326#if defined(OS_LINUX)
2327 // Processes may only query perf_event_open with the BPF sandbox disabled.
2328 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2329 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2330 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2331 }
2332#endif
[email protected]b80f68432011-05-02 17:22:302333}
2334
Scott Violet776edf82017-09-29 02:03:012335void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
2336 const service_manager::Identity& identity,
2337 base::CommandLine* command_line) {
Scott Violet776edf82017-09-29 02:03:012338#if defined(OS_CHROMEOS)
Mohsen Izadif1958f22019-01-18 20:29:312339 if (identity.name() == viz::mojom::kVizServiceName) {
Mohsen Izadif1958f22019-01-18 20:29:312340 if (ui::OzonePlatform::EnsureInstance()->GetMessageLoopTypeForGpu() ==
2341 base::MessageLoop::TYPE_UI) {
2342 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2343 }
Maggie Chen867b5822019-05-16 02:03:142344 content::GpuDataManager::GetInstance()->AppendGpuCommandLine(
2345 command_line, content::GPU_PROCESS_KIND_SANDBOXED);
Mohsen Izadif1958f22019-01-18 20:29:312346 }
Scott Violet776edf82017-09-29 02:03:012347#endif
Guido Urdaneta191635e2018-05-09 16:00:532348
2349#if defined(OS_MACOSX)
Guido Urdaneta1a2917432018-05-10 18:32:322350 // On Mac, the video-capture and audio services require a CFRunLoop, provided
2351 // by a UI message loop, to run AVFoundation and CoreAudio code.
2352 // See https://crbug.com/834581
2353 if (identity.name() == video_capture::mojom::kServiceName ||
2354 identity.name() == audio::mojom::kServiceName)
Guido Urdaneta191635e2018-05-09 16:00:532355 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2356#endif
Scott Violet776edf82017-09-29 02:03:012357}
2358
[email protected]b80f68432011-05-02 17:22:302359std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432360 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332361 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302362 return g_browser_process->GetApplicationLocale();
2363}
2364
[email protected]597a867b2011-11-18 18:31:202365std::string ChromeContentBrowserClient::GetAcceptLangs(
2366 content::BrowserContext* context) {
2367 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202368 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082369}
2370
Dana Fried34d580002019-04-24 20:05:482371gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492372 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482373 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082374}
2375
bengre8a146f2016-03-10 01:20:222376bool ChromeContentBrowserClient::IsDataSaverEnabled(
2377 content::BrowserContext* browser_context) {
Robert Ogdenc995d4fe2019-03-25 19:18:372378 Profile* profile = Profile::FromBrowserContext(browser_context);
2379 return profile && data_reduction_proxy::DataReductionProxySettings::
2380 IsDataSaverEnabledByUser(profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222381}
2382
Kenichi Ishibashi46329872018-07-17 09:43:402383void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2384 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192385 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402386 DCHECK(browser_context);
2387 DCHECK(out_prefs);
2388 renderer_preferences_util::UpdateFromSystemSettings(
2389 out_prefs, Profile::FromBrowserContext(browser_context));
2390}
2391
[email protected]a2176792011-05-08 19:30:492392bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:092393 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:192394 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:202395 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522396 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202397 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken71691402017-01-27 03:38:002398 return io_data->GetCookieSettings()->IsCookieAccessAllowed(manifest_url,
2399 first_party);
[email protected]a2176792011-05-08 19:30:492400}
2401
falken3dbc36e2014-10-10 16:48:072402bool ChromeContentBrowserClient::AllowServiceWorker(
2403 const GURL& scope,
2404 const GURL& first_party_url,
David Bertoni3b3597d82019-06-22 02:29:362405 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202406 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342407 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522408 DCHECK_CURRENTLY_ON(BrowserThread::IO);
rdevlin.croninf5863da2015-09-10 19:21:452409
brettw00899e62016-11-12 02:10:172410#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452411 // Check if this is an extension-related service worker, and, if so, if it's
2412 // allowed (this can return false if, e.g., the extension is disabled).
2413 // If it's not allowed, return immediately. We deliberately do *not* report
2414 // to the TabSpecificContentSettings, since the service worker is blocked
2415 // because of the extension, rather than because of the user's content
2416 // settings.
2417 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
David Bertoni3b3597d82019-06-22 02:29:362418 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452419 return false;
2420 }
2421#endif
2422
falken3dbc36e2014-10-10 16:48:072423 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202424
shimazuce8af88122016-10-06 23:49:212425 // Check if JavaScript is allowed.
2426 content_settings::SettingInfo info;
2427 std::unique_ptr<base::Value> value =
2428 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
2429 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2430 std::string(), &info);
2431 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2432 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2433
2434 // Check if cookies are allowed.
2435 bool allow_serviceworker =
falken71691402017-01-27 03:38:002436 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope,
2437 first_party_url);
falken4a22dce2015-04-30 08:25:202438 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242439 // Only post the task if this is for a specific tab.
2440 if (!wc_getter.is_null()) {
Eric Seckler8652dcd52018-09-20 10:42:282441 base::PostTaskWithTraits(
2442 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512443 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342444 std::move(wc_getter), scope, !allow_javascript,
tzik29ea5c72017-04-20 02:16:512445 !allow_serviceworker));
rdevlin.croninf5863da2015-09-10 19:21:452446 }
shimazuce8af88122016-10-06 23:49:212447 return allow_javascript && allow_serviceworker;
falken3dbc36e2014-10-10 16:48:072448}
2449
Jochen Eisinger0ff7645c2017-11-28 08:11:262450bool ChromeContentBrowserClient::AllowSharedWorker(
2451 const GURL& worker_url,
2452 const GURL& main_frame_url,
2453 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372454 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262455 content::BrowserContext* context,
2456 int render_process_id,
2457 int render_frame_id) {
2458 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2459
2460 // Check if cookies are allowed.
2461 bool allow =
2462 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
2463 ->IsCookieAccessAllowed(worker_url, main_frame_url);
2464
2465 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372466 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2467 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262468 return allow;
2469}
2470
Kunihiko Sakamotof586da62019-03-28 03:03:042471bool ChromeContentBrowserClient::AllowSignedExchange(
2472 content::ResourceContext* resource_context) {
2473 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2474 // Null-check safe_browsing_service_ as in unit tests |resource_context| is a
2475 // MockResourceContext and the cast doesn't work.
2476 if (!safe_browsing_service_)
2477 return false;
2478 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
2479 return io_data->signed_exchange_enabled()->GetValue();
2480}
2481
[email protected]ed24fad2011-05-10 22:44:012482bool ChromeContentBrowserClient::AllowGetCookie(
2483 const GURL& url,
2484 const GURL& first_party,
2485 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:202486 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:012487 int render_process_id,
[email protected]f3add922013-12-20 23:17:162488 int render_frame_id) {
thestig00844cea2015-09-08 21:44:522489 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202490 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken71691402017-01-27 03:38:002491 bool allow =
2492 io_data->GetCookieSettings()->IsCookieAccessAllowed(url, first_party);
Clark DuVallc57280be2018-06-19 03:46:232493 OnCookiesRead(render_process_id, render_frame_id, url, first_party,
2494 cookie_list, !allow);
[email protected]ed24fad2011-05-10 22:44:012495
[email protected]ed24fad2011-05-10 22:44:012496 return allow;
2497}
2498
2499bool ChromeContentBrowserClient::AllowSetCookie(
2500 const GURL& url,
2501 const GURL& first_party,
Victor Costan9ab2fe12017-11-16 20:53:372502 const net::CanonicalCookie& cookie,
[email protected]df02aca2012-02-09 21:03:202503 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:012504 int render_process_id,
Clark DuVallc57280be2018-06-19 03:46:232505 int render_frame_id) {
thestig00844cea2015-09-08 21:44:522506 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202507 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092508 content_settings::CookieSettings* cookie_settings =
2509 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002510 bool allow = cookie_settings->IsCookieAccessAllowed(url, first_party);
[email protected]30fde822011-10-28 09:49:052511
Clark DuVallc57280be2018-06-19 03:46:232512 OnCookieChange(render_process_id, render_frame_id, url, first_party, cookie,
2513 !allow);
2514 return allow;
2515}
2516
2517void ChromeContentBrowserClient::OnCookiesRead(
2518 int process_id,
2519 int routing_id,
2520 const GURL& url,
2521 const GURL& first_party_url,
2522 const net::CookieList& cookie_list,
2523 bool blocked_by_policy) {
2524 base::RepeatingCallback<content::WebContents*(void)> wc_getter =
Ken Rockot42dfa782018-06-28 21:08:412525 base::BindRepeating(&GetWebContentsFromProcessAndFrameId, process_id,
2526 routing_id);
Maks Orlovich2fd169e62019-06-21 17:10:382527 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
2528 // Internal calls from AllowGetCookie are on IO thread, so need to jump.
2529 base::PostTaskWithTraits(
2530 FROM_HERE, {BrowserThread::UI},
2531 base::BindOnce(&TabSpecificContentSettings::CookiesRead, wc_getter, url,
2532 first_party_url, cookie_list, blocked_by_policy));
2533 } else {
2534 TabSpecificContentSettings::CookiesRead(wc_getter, url, first_party_url,
2535 cookie_list, blocked_by_policy);
2536 }
Clark DuVallc57280be2018-06-19 03:46:232537}
2538
2539void ChromeContentBrowserClient::OnCookieChange(
2540 int process_id,
2541 int routing_id,
2542 const GURL& url,
2543 const GURL& first_party_url,
2544 const net::CanonicalCookie& cookie,
2545 bool blocked_by_policy) {
2546 base::RepeatingCallback<content::WebContents*(void)> wc_getter =
Ken Rockot42dfa782018-06-28 21:08:412547 base::BindRepeating(&GetWebContentsFromProcessAndFrameId, process_id,
2548 routing_id);
Maks Orlovich2fd169e62019-06-21 17:10:382549 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
2550 // Internal calls from AllowSetCookie are on IO thread, so need to jump.
2551 base::PostTaskWithTraits(
2552 FROM_HERE, {BrowserThread::UI},
2553 base::BindOnce(&TabSpecificContentSettings::CookieChanged, wc_getter,
2554 url, first_party_url, cookie, blocked_by_policy));
2555 } else {
2556 TabSpecificContentSettings::CookieChanged(wc_getter, url, first_party_url,
2557 cookie, blocked_by_policy);
2558 }
[email protected]ed24fad2011-05-10 22:44:012559}
2560
[email protected]f917df22014-07-10 07:45:492561void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352562 const GURL& url,
[email protected]df02aca2012-02-09 21:03:202563 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172564 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492565 base::Callback<void(bool)> callback) {
thestig00844cea2015-09-08 21:44:522566 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202567 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092568 content_settings::CookieSettings* cookie_settings =
2569 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002570 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352571
brettw00899e62016-11-12 02:10:172572#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492573 GuestPermissionRequestHelper(url, render_frames, callback, allow);
2574#else
2575 FileSystemAccessed(url, render_frames, callback, allow);
2576#endif
2577}
2578
brettw00899e62016-11-12 02:10:172579#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492580void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2581 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172582 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492583 base::Callback<void(bool)> callback,
2584 bool allow) {
thestig00844cea2015-09-08 21:44:522585 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]f917df22014-07-10 07:45:492586 std::map<int, int> process_map;
2587 std::map<int, int>::const_iterator it;
2588 bool has_web_view_guest = false;
2589 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172590 for (const auto& it : render_frames) {
2591 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492592 continue;
2593
Lukasz Anforowicz09060bdf72018-08-23 15:53:172594 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492595
Lukasz Anforowicz09060bdf72018-08-23 15:53:172596 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492597 has_web_view_guest = true;
2598 }
2599 if (!has_web_view_guest) {
2600 FileSystemAccessed(url, render_frames, callback, allow);
2601 return;
2602 }
[email protected]dffb9fc2014-07-16 04:14:022603 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492604 it = process_map.begin();
Eric Seckler8652dcd52018-09-20 10:42:282605 base::PostTaskWithTraits(
2606 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512607 base::BindOnce(
2608 &ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread,
2609 it->first, it->second, url, allow,
Kevin Marshall32f99d7e2017-07-11 23:17:462610 base::Bind(
2611 &ChromeContentBrowserClient::FileSystemAccessed,
2612 weak_factory_.GetWeakPtr(), url, render_frames,
2613 base::Bind(&InvokeCallbackOnThread,
2614 base::SequencedTaskRunnerHandle::Get(), callback))));
[email protected]f917df22014-07-10 07:45:492615}
2616
2617void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
2618 int render_process_id,
2619 int render_frame_id,
2620 const GURL& url,
2621 bool allowed_by_default,
2622 const base::Callback<void(bool)>& callback) {
thestig00844cea2015-09-08 21:44:522623 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]140d6cd92014-08-12 18:26:462624 extensions::WebViewPermissionHelper* web_view_permission_helper =
2625 extensions::WebViewPermissionHelper::FromFrameID(
2626 render_process_id, render_frame_id);
[email protected]f917df22014-07-10 07:45:492627 web_view_permission_helper->RequestFileSystemPermission(url,
2628 allowed_by_default,
2629 callback);
2630}
2631#endif
2632
2633void ChromeContentBrowserClient::FileSystemAccessed(
2634 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172635 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492636 base::Callback<void(bool)> callback,
2637 bool allow) {
[email protected]62151052012-02-01 18:40:482638 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172639 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282640 base::PostTaskWithTraits(
2641 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512642 base::BindOnce(&TabSpecificContentSettings::FileSystemAccessed,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172643 it.child_id, it.frame_routing_id, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:352644 }
[email protected]f917df22014-07-10 07:45:492645 callback.Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352646}
2647
[email protected]7c5ff9a2012-03-02 07:42:492648bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2649 const GURL& url,
[email protected]7c5ff9a2012-03-02 07:42:492650 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172651 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
thestig00844cea2015-09-08 21:44:522652 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c5ff9a2012-03-02 07:42:492653 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092654 content_settings::CookieSettings* cookie_settings =
2655 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002656 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492657
2658 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172659 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282660 base::PostTaskWithTraits(
2661 FROM_HERE, {BrowserThread::UI},
Lukasz Anforowicz09060bdf72018-08-23 15:53:172662 base::BindOnce(&TabSpecificContentSettings::IndexedDBAccessed,
Joshua Bell7cdaafca2018-10-31 06:27:112663 it.child_id, it.frame_routing_id, url, !allow));
[email protected]7c5ff9a2012-03-02 07:42:492664 }
2665
2666 return allow;
2667}
2668
Ben Kelly6b2e61c2019-03-14 16:06:292669bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2670 const GURL& url,
2671 content::ResourceContext* context,
2672 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2673 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2674 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
2675 content_settings::CookieSettings* cookie_settings =
2676 io_data->GetCookieSettings();
2677 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2678
2679 // Record access to CacheStorage for potential display in UI.
2680 for (const auto& it : render_frames) {
2681 base::PostTaskWithTraits(
2682 FROM_HERE, {BrowserThread::UI},
2683 base::BindOnce(&TabSpecificContentSettings::CacheStorageAccessed,
2684 it.child_id, it.frame_routing_id, url, !allow));
2685 }
2686
2687 return allow;
2688}
2689
jyasskinc993ce8d2016-03-31 00:38:342690ChromeContentBrowserClient::AllowWebBluetoothResult
2691ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452692 content::BrowserContext* browser_context,
2693 const url::Origin& requesting_origin,
2694 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342695 // TODO(crbug.com/598890): Don't disable if
2696 // base::CommandLine::ForCurrentProcess()->
2697 // HasSwitch(switches::kEnableWebBluetooth) is true.
2698 if (variations::GetVariationParamValue(
2699 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2700 "Bluetooth") ==
2701 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2702 // The kill switch is enabled for this permission. Block requests.
2703 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2704 }
2705
jyasskin98bdd3992016-02-26 20:25:452706 const HostContentSettingsMap* const content_settings =
2707 HostContentSettingsMapFactory::GetForProfile(
2708 Profile::FromBrowserContext(browser_context));
2709
csharrisonaec2c542016-10-12 19:40:362710 if (content_settings->GetContentSetting(
2711 requesting_origin.GetURL(), embedding_origin.GetURL(),
2712 CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD,
2713 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342714 return AllowWebBluetoothResult::BLOCK_POLICY;
2715 }
2716 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452717}
2718
beaufort.francois01135bf2016-11-23 14:37:362719std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2720 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2721 "blocklist_additions");
scheib74250322016-04-07 03:32:212722}
2723
John Abd-El-Malek21bca7c2018-10-26 22:13:332724#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522725void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek21bca7c2018-10-26 22:13:332726 const std::string& username_hash) {
2727 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(username_hash);
2728}
2729#endif
2730
Reilly Grant19aaccd2018-07-16 22:06:372731scoped_refptr<network::SharedURLLoaderFactory>
2732ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2734 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2735
2736 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372737 return nullptr;
2738
Min Qinda0d55b2018-10-12 18:30:052739 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372740 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042741}
2742
Sean Gilhulyda1ee4b2018-11-13 21:56:092743network::mojom::NetworkContext*
2744ChromeContentBrowserClient::GetSystemNetworkContext() {
2745 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2746 DCHECK(g_browser_process->system_network_context_manager());
2747 return g_browser_process->system_network_context_manager()->GetContext();
2748}
2749
Andrew Moylan17329fc2017-09-25 07:43:302750std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2751 return google_apis::GetAPIKey();
2752}
2753
Ke He21ee87f2018-05-30 02:35:322754#if defined(OS_ANDROID)
2755bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2756 // Indicate that Chrome uses the GMS core location provider.
2757 return true;
2758}
2759#endif
2760
Yeolf3dc22ca2019-04-18 17:25:322761scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412762ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2763 return new ChromeQuotaPermissionContext();
2764}
2765
michaeln10e5fc352017-02-07 02:07:582766void ChromeContentBrowserClient::GetQuotaSettings(
2767 content::BrowserContext* context,
2768 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452769 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582770 if (g_default_quota_settings) {
2771 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452772 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582773 return;
2774 }
taptede6d878e2017-06-24 01:53:452775 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062776 partition->GetPath(), context->IsOffTheRecord(),
2777 storage::GetDefaultDiskInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512778}
2779
Mythri Alle0b8de0d2018-10-22 11:06:222780content::GeneratedCodeCacheSettings
2781ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2782 content::BrowserContext* context) {
2783 base::FilePath cache_path;
2784 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2785 // If we pass 0 for size, disk_cache will pick a default size using the
2786 // heuristics based on available disk size. These are implemented in
2787 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162788 int64_t size_in_bytes = 0;
2789 PrefService* prefs = Profile::FromBrowserContext(context)->GetPrefs();
2790 DCHECK(prefs);
2791 size_in_bytes = prefs->GetInteger(prefs::kDiskCacheSize);
2792 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222793}
2794
[email protected]848dd042011-06-04 18:24:032795void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262796 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172797 int cert_error,
2798 const net::SSLInfo& ssl_info,
2799 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232800 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222801 bool strict_enforcement,
[email protected]83c13fe2014-08-15 04:49:102802 bool expired_previous_decision,
estark719dde52016-08-09 03:14:272803 const base::Callback<void(content::CertificateRequestResultType)>&
2804 callback) {
clamy0d32d6d2015-11-24 11:16:262805 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232806 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142807 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022808 // have a context for making the right decision, so block the
2809 // request hard, without an info bar to allow showing the insecure
2810 // content.
estark719dde52016-08-09 03:14:272811 if (!callback.is_null())
2812 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022813 return;
2814 }
2815
[email protected]f9034cf2011-07-21 12:43:412816 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572817 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262818 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572819 if (prerender_contents) {
2820 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272821 if (!callback.is_null()) {
2822 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
2823 }
[email protected]09667f02014-01-06 15:37:572824 return;
[email protected]f9034cf2011-07-21 12:43:412825 }
2826
Carlos IL5a9e7512019-06-13 22:35:282827 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2828 return;
[email protected]848dd042011-06-04 18:24:032829}
2830
Alexander Hendrichbcf2616e2018-05-18 08:21:102831namespace {
2832
Pavol Markob211ab22019-01-23 20:03:042833certificate_matching::CertificatePrincipalPattern
2834ParseCertificatePrincipalPattern(const base::Value* pattern) {
2835 return certificate_matching::CertificatePrincipalPattern::
2836 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2837}
2838
Alexander Hendrichbcf2616e2018-05-18 08:21:102839// Attempts to auto-select a client certificate according to the value of
2840// |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for
2841// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2842std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2843 Profile* profile,
2844 const GURL& requesting_url,
2845 net::ClientCertIdentityList& client_certs) {
2846 HostContentSettingsMap* host_content_settings_map =
2847 HostContentSettingsMapFactory::GetForProfile(profile);
2848 std::unique_ptr<base::Value> setting =
2849 host_content_settings_map->GetWebsiteSetting(
2850 requesting_url, requesting_url,
2851 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL);
2852
Pavol Markob211ab22019-01-23 20:03:042853 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102854 return nullptr;
2855
Alexander Hendrichbcf2616e2018-05-18 08:21:102856 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042857 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2858 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102859 // |setting_dict| has the wrong format (e.g. single filter instead of a
2860 // list of filters). This content setting is only provided by
2861 // the |PolicyProvider|, which should always set it to a valid format.
2862 // Therefore, delete the invalid value.
2863 host_content_settings_map->SetWebsiteSettingDefaultScope(
2864 requesting_url, requesting_url,
2865 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042866 return nullptr;
2867 }
2868
2869 for (const base::Value& filter : filters->GetList()) {
2870 DCHECK(filter.is_dict());
2871
2872 auto issuer_pattern = ParseCertificatePrincipalPattern(
2873 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2874 auto subject_pattern = ParseCertificatePrincipalPattern(
2875 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2876 // Use the first certificate that is matched by the filter.
2877 for (auto& client_cert : client_certs) {
2878 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2879 subject_pattern.Matches(client_cert->certificate()->subject())) {
2880 return std::move(client_cert);
2881 }
2882 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102883 }
2884
2885 return nullptr;
2886}
2887
Eric Romana00cf682018-11-01 20:09:112888void AddDataReductionProxyBinding(
2889 content::ResourceContext* resource_context,
2890 data_reduction_proxy::mojom::DataReductionProxyRequest request) {
2891 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2892 auto* io_data = ProfileIOData::FromResourceContext(resource_context);
2893 if (io_data && io_data->data_reduction_proxy_io_data()) {
2894 io_data->data_reduction_proxy_io_data()->Clone(std::move(request));
2895 }
2896}
2897
Alexander Hendrichbcf2616e2018-05-18 08:21:102898} // namespace
2899
Daniel McArdle85735f52019-06-25 03:27:062900base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192901 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402902 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082903 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352904 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022905 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192906 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022907 if (prerender_contents) {
2908 prerender_contents->Destroy(
2909 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062910 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452911 }
2912
[email protected]791879c2013-12-17 07:22:412913 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2914 DCHECK(requesting_url.is_valid())
2915 << "Invalid URL string: https://"
2916 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452917
Pavol Marko230ea2c92017-12-03 22:35:442918 bool may_show_cert_selection = true;
2919
davidben3b8455ae72015-03-11 19:42:192920 Profile* profile =
2921 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442922#if defined(OS_CHROMEOS)
2923 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2924 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2925 // and remove the command-line flag after prototype phase when the
2926 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2927 may_show_cert_selection =
2928 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2929
2930 content::StoragePartition* storage_partition =
2931 content::BrowserContext::GetStoragePartition(
2932 profile, web_contents->GetSiteInstance());
2933 chromeos::login::SigninPartitionManager* signin_partition_manager =
2934 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2935 profile);
2936
2937 // On the sign-in profile, only allow client certs in the context of the
2938 // sign-in frame.
2939 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2940 storage_partition)) {
2941 LOG(WARNING)
2942 << "Client cert requested in sign-in profile in wrong context.";
2943 // Continue without client certificate. We do this to mimic the case of no
2944 // client certificate being present in the profile's certificate store.
2945 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062946 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442947 }
2948 VLOG(1) << "Client cert requested in sign-in profile.";
2949 }
2950#endif // defined(OS_CHROMEOS)
2951
Alexander Hendrichbcf2616e2018-05-18 08:21:102952 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2953 AutoSelectCertificate(profile, requesting_url, client_certs);
2954 if (auto_selected_identity) {
2955 // The callback will own |auto_selected_identity| and |delegate|, keeping
2956 // them alive until after ContinueWithCertificate is called.
2957 scoped_refptr<net::X509Certificate> cert =
2958 auto_selected_identity->certificate();
2959 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2960 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582961 base::BindOnce(
2962 &content::ClientCertificateDelegate::ContinueWithCertificate,
2963 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322964 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062965 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452966 }
2967
Pavol Marko230ea2c92017-12-03 22:35:442968 if (!may_show_cert_selection) {
2969 LOG(WARNING) << "No client cert matched by policy and user selection is "
2970 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322971 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442972 // Continue without client certificate. We do this to mimic the case of no
2973 // client certificate being present in the profile's certificate store.
2974 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062975 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442976 }
2977
Daniel McArdle85735f52019-06-25 03:27:062978 return chrome::ShowSSLClientCertificateSelector(
2979 web_contents, cert_request_info, std::move(client_certs),
2980 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452981}
2982
[email protected]dc73a7b2012-03-25 15:27:182983content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562984 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182985}
2986
peterc26c6c62014-12-10 14:13:592987content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022988ChromeContentBrowserClient::GetPlatformNotificationService(
2989 content::BrowserContext* browser_context) {
2990 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2991 Profile* profile = Profile::FromBrowserContext(browser_context);
2992 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042993}
2994
[email protected]9f3fba52011-06-08 20:37:192995bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352996 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352997 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572998 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352999 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:033000 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:233001 const GURL& target_url,
3002 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:213003 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:233004 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:483005 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:233006 bool user_gesture,
3007 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:013008 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:353009 DCHECK_CURRENTLY_ON(BrowserThread::UI);
3010 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:013011
csharrison95f01e922017-04-24 18:52:353012 content::WebContents* web_contents =
3013 content::WebContents::FromRenderFrameHost(opener);
3014 Profile* profile =
3015 Profile::FromBrowserContext(web_contents->GetBrowserContext());
3016 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:013017 *no_javascript_access = false;
3018
[email protected]9f3fba52011-06-08 20:37:193019 // If the opener is trying to create a background window but doesn't have
3020 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:033021 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:173022#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:353023 auto* process_map = extensions::ProcessMap::Get(profile);
3024 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:173025 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
3026 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:013027 return false;
3028 }
3029
[email protected]7b54ca02012-03-02 18:06:533030 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
3031 // return a recently installed Extension even if this CanCreateWindow call
3032 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:013033 // because the permission check above would have caused an early return
3034 // already. We must use the full URL to find hosted apps, though, and not
3035 // just the origin.
[email protected]be9915fb2013-07-18 09:28:553036 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353037 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:293038 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:013039 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:023040#endif
[email protected]190e5e22013-07-27 05:59:233041
3042 return true;
[email protected]9f3fba52011-06-08 20:37:193043 }
[email protected]056efdc2013-04-06 00:14:533044
brettw00899e62016-11-12 02:10:173045#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:463046 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:353047 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:233048 return true;
lazyboy04b75d32016-02-25 03:12:183049 }
3050
nick0fbc3922016-12-16 20:52:073051 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:353052 // Intentionally duplicating |registry| code from above because we want to
3053 // reduce calls to retrieve them as this function is a SYNC IPC handler.
3054 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:183055 const Extension* extension =
csharrison95f01e922017-04-24 18:52:353056 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:143057 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:533058 UMA_HISTOGRAM_ENUMERATION(
3059 "Extensions.AppLoadedInTab",
3060 ClassifyAppLoadedInTabSource(opener_url, extension),
3061 APP_LOADED_IN_TAB_SOURCE_MAX);
3062
3063 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:163064 return false;
lazyboy5d5fede02016-03-10 04:10:143065 }
lazyboy04b75d32016-02-25 03:12:183066 }
[email protected]5940b0d2014-07-01 00:18:263067#endif
[email protected]190e5e22013-07-27 05:59:233068
Charles Harrisonaf2acd02017-08-18 22:46:023069#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:233070 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:353071 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:583072 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
3073 content_settings, opener_top_level_frame_url, target_url,
3074 user_gesture)) {
csharrison95f01e922017-04-24 18:52:353075 FlashDownloadInterception::InterceptFlashDownloadNavigation(
3076 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:583077 return false;
3078 }
3079#endif
3080
Charles Harrisonaf2acd02017-08-18 22:46:023081 // Don't let prerenders open popups.
3082 if (auto* prerender_contents =
3083 prerender::PrerenderContents::FromWebContents(web_contents)) {
3084 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
3085 return false;
3086 }
3087
Nasko Oskove9f19782019-01-04 18:32:353088 BlockedWindowParams blocked_params(target_url, source_origin, referrer,
3089 frame_name, disposition, features,
3090 user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:133091 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Charlie Harrison804659a2018-10-16 16:43:383092 if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params,
3093 nullptr /*=open_url_params*/,
3094 blocked_params.features())) {
Charles Harrisonaf2acd02017-08-18 22:46:023095 return false;
[email protected]916615b2013-09-11 18:19:443096 }
[email protected]190e5e22013-07-27 05:59:233097
zpengdb4a58e2017-01-10 17:40:323098#if defined(OS_ANDROID)
csharrison95f01e922017-04-24 18:52:353099 auto* single_tab_mode_helper =
3100 SingleTabModeTabHelper::FromWebContents(web_contents);
Bo Liu3d5b8d692017-12-14 22:42:033101 if (single_tab_mode_helper &&
3102 single_tab_mode_helper->block_all_new_windows()) {
Jinsuk Kim6f9253c2019-03-11 02:45:073103 TabModelList::HandlePopupNavigation(&nav_params);
[email protected]190e5e22013-07-27 05:59:233104 return false;
3105 }
[email protected]916615b2013-09-11 18:19:443106#endif
[email protected]190e5e22013-07-27 05:59:233107
[email protected]9f3fba52011-06-08 20:37:193108 return true;
3109}
3110
[email protected]99907362012-01-11 05:41:403111void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
thestig00844cea2015-09-08 21:44:523112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
yzshenefcb7c72017-06-16 23:12:303113
John Abd-El-Malekc098bc82019-05-31 19:33:553114 // TODO(jam): move this creation elsewhere so we can remove this method.
yzshenefcb7c72017-06-16 23:12:303115 safe_browsing_service_ = g_browser_process->safe_browsing_service();
[email protected]3cb054e62011-06-13 05:21:173116}
3117
[email protected]c52b2892012-03-07 11:01:023118content::SpeechRecognitionManagerDelegate*
zorkb548de082014-11-14 21:40:473119 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003120 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513121}
3122
Katie D840d9532018-11-27 06:20:483123content::TtsControllerDelegate*
3124ChromeContentBrowserClient::GetTtsControllerDelegate() {
3125 TtsControllerDelegateImpl* delegate =
3126 TtsControllerDelegateImpl::GetInstance();
3127#if !defined(OS_ANDROID)
3128 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3129 delegate->SetTtsEngineDelegate(tts_extension_engine);
3130#endif
3131 return delegate;
3132}
3133
Katie D4713ee42018-11-30 01:48:273134content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3135#ifdef OS_CHROMEOS
3136 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273137#else
3138 return nullptr;
3139#endif
3140}
3141
Evan Liu7cdbf8872019-06-19 16:47:213142base::Optional<ui::CaptionStyle> GetCaptionStyleFromPrefs(PrefService* prefs) {
3143 if (!prefs) {
3144 return base::nullopt;
3145 }
3146
3147 ui::CaptionStyle style;
3148
3149 style.text_size = prefs->GetString(prefs::kAccessibilityCaptionsTextSize);
3150 style.font_family = prefs->GetString(prefs::kAccessibilityCaptionsTextFont);
Evan Liuf248d402019-06-26 22:57:103151 if (!prefs->GetString(prefs::kAccessibilityCaptionsTextColor).empty()) {
3152 style.text_color = base::StringPrintf(
3153 "rgba(%s,%s)",
3154 prefs->GetString(prefs::kAccessibilityCaptionsTextColor).c_str(),
3155 base::NumberToString(
3156 prefs->GetInteger(prefs::kAccessibilityCaptionsTextOpacity) / 100.0)
3157 .c_str());
3158 }
3159
3160 if (!prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).empty()) {
3161 style.background_color = base::StringPrintf(
3162 "rgba(%s,%s)",
3163 prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).c_str(),
3164 base::NumberToString(
3165 prefs->GetInteger(prefs::kAccessibilityCaptionsBackgroundOpacity) /
3166 100.0)
3167 .c_str());
3168 }
3169
Evan Liu7cdbf8872019-06-19 16:47:213170 style.text_shadow = prefs->GetString(prefs::kAccessibilityCaptionsTextShadow);
3171
3172 return style;
3173}
3174
[email protected]64d69de42012-02-06 00:19:543175void ChromeContentBrowserClient::OverrideWebkitPrefs(
creis7b2d3d12015-02-12 23:29:503176 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:063177 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:583178 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063179 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063180
aelias0df335a2017-03-02 23:43:513181// Fill font preferences. These are not registered on Android
3182// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453183#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193184 FontFamilyCache::FillFontFamilyMap(profile,
3185 prefs::kWebKitStandardFontFamilyMap,
3186 &web_prefs->standard_font_family_map);
3187 FontFamilyCache::FillFontFamilyMap(profile,
3188 prefs::kWebKitFixedFontFamilyMap,
3189 &web_prefs->fixed_font_family_map);
3190 FontFamilyCache::FillFontFamilyMap(profile,
3191 prefs::kWebKitSerifFontFamilyMap,
3192 &web_prefs->serif_font_family_map);
3193 FontFamilyCache::FillFontFamilyMap(profile,
3194 prefs::kWebKitSansSerifFontFamilyMap,
3195 &web_prefs->sans_serif_font_family_map);
3196 FontFamilyCache::FillFontFamilyMap(profile,
3197 prefs::kWebKitCursiveFontFamilyMap,
3198 &web_prefs->cursive_font_family_map);
3199 FontFamilyCache::FillFontFamilyMap(profile,
3200 prefs::kWebKitFantasyFontFamilyMap,
3201 &web_prefs->fantasy_font_family_map);
3202 FontFamilyCache::FillFontFamilyMap(profile,
3203 prefs::kWebKitPictographFontFamilyMap,
3204 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063205
[email protected]64d69de42012-02-06 00:19:543206 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403207 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543208 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403209 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543210 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403211 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543212 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403213 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513214#endif
[email protected]f3986f82012-01-03 20:00:063215
[email protected]ddf72142012-05-22 04:52:403216 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063217
[email protected]64d69de42012-02-06 00:19:543218 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063219 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213220 web_prefs->javascript_can_access_clipboard =
3221 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543222 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063223
[email protected]ddf72142012-05-22 04:52:403224 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543225 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573226
Avi Drissman1aa6cb92019-01-23 15:58:383227 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543228 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573229
[email protected]ddf72142012-05-22 04:52:403230 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543231 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543232 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403233 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063234
Zhenyao Moa3fda9972017-09-16 01:34:403235 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3236 web_prefs->webgl1_enabled = false;
3237 web_prefs->webgl2_enabled = false;
3238 }
[email protected]f3986f82012-01-03 20:00:063239
[email protected]64d69de42012-02-06 00:19:543240 web_prefs->allow_running_insecure_content =
3241 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323242#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053243 web_prefs->font_scale_factor =
3244 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3245 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323246 web_prefs->force_enable_zoom =
3247 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Becky Zhoubbfbde32019-02-20 17:07:593248 web_prefs->force_dark_mode_enabled =
3249 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]d3b935f2012-10-19 23:14:323250#endif
[email protected]5c915252013-05-07 13:15:393251
[email protected]af4256d52013-06-04 20:39:073252#if defined(OS_ANDROID)
3253 web_prefs->password_echo_enabled =
3254 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3255#else
[email protected]9d06d88d2012-02-23 22:37:083256 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073257#endif
3258
[email protected]64d69de42012-02-06 00:19:543259 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063260 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543261 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063262 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3263
brettw00899e62016-11-12 02:10:173264#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053265 std::string image_animation_policy =
3266 prefs->GetString(prefs::kAnimationPolicy);
3267 if (image_animation_policy == kAnimationPolicyOnce)
3268 web_prefs->animation_policy =
3269 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3270 else if (image_animation_policy == kAnimationPolicyNone)
3271 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3272 else
3273 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3274#endif
3275
[email protected]f3986f82012-01-03 20:00:063276 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153277 web_prefs->default_encoding =
3278 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543279 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403280 prefs->ClearPref(prefs::kDefaultCharset);
3281 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063282 }
[email protected]64d69de42012-02-06 00:19:543283 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063284
mkwst05544102015-01-10 20:26:163285 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3286 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073287 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163288 web_prefs->strict_mixed_content_checking = true;
3289 web_prefs->strict_powerful_feature_restrictions = true;
3290 }
3291
Robert Ogdencf2872d2019-03-19 18:59:373292 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213293
Tarun Bansal333819e2018-05-15 16:38:423294 web_prefs->data_saver_holdback_web_api_enabled =
3295 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3296 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423297
Jinsuk Kima3d393ce2019-05-27 00:57:423298 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133299 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533300#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423301 auto* delegate = TabAndroid::FromWebContents(contents)
3302 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3303 contents->GetDelegate())
3304 : nullptr;
3305 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133306 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423307 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133308
Mounir Lamouri9c99a1602018-07-05 15:01:443309 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423310 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383311
3312 web_prefs->preferred_color_scheme =
Jinsuk Kima3d393ce2019-05-27 00:57:423313 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3314 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113315 }
Ian Vollick6243dfe02018-03-08 01:08:533316#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533317
Mounir Lamouri6926107f2019-01-31 18:17:433318 // web_app_scope value is platform specific.
3319#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423320 if (delegate)
3321 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433322#elif BUILDFLAG(ENABLE_EXTENSIONS)
3323 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253324 web_prefs->web_app_scope = GURL();
3325 // Set |web_app_scope| based on the app associated with the app window if
3326 // any. Note that the app associated with the window never changes, even
3327 // if the app navigates off scope. This is not a problem because we still
3328 // want to use the scope of the app associated with the window, not the
3329 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433330 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233331 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443332 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273333 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443334 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253335 // HostedApps that are PWAs are always created through WebAppProvider
3336 // or BookmarkAppHelper for profiles that support them, so we should
3337 // always be able to retrieve a WebAppProvider from the Profile.
3338 //
3339 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
3340 // so there is no need to test for HasScope().
3341 web_prefs->web_app_scope =
3342 web_app::WebAppProvider::Get(profile)
3343 ->registrar()
Eric Willigerse339c1e2019-05-13 19:22:443344 .GetScopeUrlForApp(*browser->app_controller()->GetAppId());
Mounir Lamouri6926107f2019-01-31 18:17:433345 }
Mounir Lamouri6926107f2019-01-31 18:17:433346 }
3347#endif
3348
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533349#if BUILDFLAG(ENABLE_EXTENSIONS)
3350 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443351 if (browser && browser->app_controller() &&
3352 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533353 web_prefs->strict_mixed_content_checking = true;
3354 }
3355#endif
3356
Ian Vollick6243dfe02018-03-08 01:08:533357 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113358 }
zqzhang93e959d12017-03-16 13:10:203359
Ian Vollick6243dfe02018-03-08 01:08:533360#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143361 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113362#endif // defined(OS_ANDROID)
3363
Tarun Bansal73d67f02018-01-17 05:56:253364 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3365 // Obtain the maximum effective connection type at which the feature is
3366 // enabled.
3367 std::string effective_connection_type_param =
3368 base::GetFieldTrialParamValueByFeature(
3369 features::kLowPriorityIframes,
3370 "max_effective_connection_type_threshold");
3371
3372 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3373 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3374 if (effective_connection_type) {
3375 web_prefs->low_priority_iframes_threshold =
3376 effective_connection_type.value();
3377 }
3378 }
3379
rajendrante87ed712018-11-30 01:55:003380 web_prefs->lazy_load_enabled =
3381 (base::FeatureList::IsEnabled(features::kLazyFrameLoading) ||
3382 base::FeatureList::IsEnabled(features::kLazyImageLoading)) &&
rajendrant413b993f2018-12-03 23:33:383383 (!contents || !contents->GetDelegate() ||
rajendrante87ed712018-11-30 01:55:003384 contents->GetDelegate()->ShouldAllowLazyLoad());
3385
Scott Little878f7d6702018-05-31 22:09:063386 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3387 const char* param_name =
3388 web_prefs->data_saver_enabled
3389 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3390 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3391 "saver_enabled";
3392
3393 base::StringPairs pairs;
3394 base::SplitStringIntoKeyValuePairs(
3395 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3396 param_name),
3397 ':', ',', &pairs);
3398
3399 for (const auto& pair : pairs) {
3400 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3401 net::GetEffectiveConnectionTypeForName(pair.first);
3402 int value = 0;
3403 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3404 web_prefs->lazy_frame_loading_distance_thresholds_px
3405 [effective_connection_type.value()] = value;
3406 }
3407 }
3408 }
3409
rajendrantd8026342018-08-29 08:08:393410 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3411 const char* param_name =
3412 web_prefs->data_saver_enabled
3413 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3414 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3415 "saver_enabled";
3416
3417 base::StringPairs pairs;
3418 base::SplitStringIntoKeyValuePairs(
3419 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3420 param_name),
3421 ':', ',', &pairs);
3422
3423 for (const auto& pair : pairs) {
3424 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3425 net::GetEffectiveConnectionTypeForName(pair.first);
3426 int value = 0;
3427 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3428 web_prefs->lazy_image_loading_distance_thresholds_px
3429 [effective_connection_type.value()] = value;
3430 }
3431 }
3432 }
3433
Tarun Bansald10f17a02018-09-13 00:23:173434 if (base::FeatureList::IsEnabled(
3435 features::kNetworkQualityEstimatorWebHoldback)) {
3436 std::string effective_connection_type_param =
3437 base::GetFieldTrialParamValueByFeature(
3438 features::kNetworkQualityEstimatorWebHoldback,
3439 "web_effective_connection_type_override");
3440
3441 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3442 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3443 DCHECK(effective_connection_type_param.empty() ||
3444 effective_connection_type);
3445 if (effective_connection_type) {
3446 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3447 effective_connection_type.value());
3448 web_prefs->network_quality_estimator_web_holdback =
3449 effective_connection_type.value();
3450 }
3451 }
3452
Dan Beamf0a7e112019-06-07 18:40:583453 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103454#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563455 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593456 // If autoplay is allowed by policy then force the no user gesture required
3457 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103458 web_prefs->autoplay_policy =
3459 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553460 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593461 web_prefs->autoplay_policy ==
3462 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553463 // If the autoplay disable settings feature is enabled and the autoplay
3464 // policy is set to using the unified policy then set the default autoplay
3465 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593466 web_prefs->autoplay_policy =
3467 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3468 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3469 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103470 }
Alison Maher67fd4d9f2019-07-12 18:34:213471#if !defined(OS_MACOSX)
3472 // Mac has a concept of high contrast that does not relate to forced colors.
Alison Maherbe15c072019-07-08 18:12:393473 web_prefs->forced_colors = native_theme->UsesHighContrastColors()
3474 ? blink::ForcedColors::kActive
3475 : blink::ForcedColors::kNone;
Alison Maher67fd4d9f2019-07-12 18:34:213476#endif // !defined(OS_MACOSX)
3477
3478 switch (native_theme->GetPreferredColorScheme()) {
3479 case ui::NativeTheme::PreferredColorScheme::kDark:
3480 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3481 break;
3482 case ui::NativeTheme::PreferredColorScheme::kLight:
3483 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3484 break;
3485 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3486 web_prefs->preferred_color_scheme =
3487 blink::PreferredColorScheme::kNoPreference;
3488 }
François Beaufort4f8107d2018-03-05 12:12:103489#endif // !defined(OS_ANDROID)
3490
Dave Tapuskac6627e12018-08-30 15:07:193491 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493492
Dan Beam836c02a2019-06-15 01:58:273493 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3494 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3495 // explicitly uses light (instead of not dark), which is why we don't reset
3496 // back to no-preference. https://crbug.com/965811
3497 if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3498 bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme);
3499#if BUILDFLAG(ENABLE_EXTENSIONS)
3500 if (!force_light) {
3501 force_light =
3502 contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
3503 contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
3504 }
3505#endif
3506 if (force_light)
3507 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
Dan Beamf0a7e112019-06-07 18:40:583508 }
3509
Elly Fong-Jonesf92897392019-01-24 16:05:493510 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213511 base::Optional<ui::CaptionStyle> style;
3512
3513 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3514 ::switches::kForceCaptionStyle)) {
3515 style = ui::CaptionStyle::FromSpec(
3516 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3517 switches::kForceCaptionStyle));
3518 }
3519
3520 // Apply system caption style.
3521 if (!style) {
3522 style = native_theme->GetSystemCaptionStyle();
3523 }
3524
3525 // Apply caption style from preferences if system caption style is undefined.
3526 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
3527 style = GetCaptionStyleFromPrefs(prefs);
3528 }
3529
3530 if (style) {
3531 web_prefs->text_track_background_color = style->background_color;
3532 web_prefs->text_track_text_color = style->text_color;
3533 web_prefs->text_track_text_size = style->text_size;
3534 web_prefs->text_track_text_shadow = style->text_shadow;
3535 web_prefs->text_track_font_family = style->font_family;
3536 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563537 web_prefs->text_track_window_color = style->window_color;
3538 web_prefs->text_track_window_padding = style->window_padding;
3539 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213540 }
Elly Fong-Jonesf92897392019-01-24 16:05:493541
[email protected]a48ab7112014-08-01 16:48:033542 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503543 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363544}
3545
[email protected]b8148ac2011-07-13 22:03:253546void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3547 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033548 for (size_t i = 0; i < extra_parts_.size(); ++i)
3549 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253550
[email protected]b3adbd02011-11-30 22:23:273551 // about: handler. Must come before chrome: handler, since it will
3552 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053553 // actually handle them. Also relies on a preliminary fixup phase.
3554 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253555 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3556 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033557
madfbd10852017-01-20 03:15:333558 // The group policy NTP URL handler must be registered before the other NTP
3559 // URL handlers below.
3560 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3561 BrowserURLHandler::null_handler());
3562
zpengdb4a58e2017-01-10 17:40:323563#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033564 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353565 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033566 BrowserURLHandler::null_handler());
3567#else
[email protected]231dba22013-07-25 23:53:033568 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133569 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3570 &search::HandleNewTabURLReverseRewrite);
[email protected]4bd78e92014-03-28 18:54:033571#endif
[email protected]231dba22013-07-25 23:53:033572
[email protected]b8148ac2011-07-13 22:03:253573 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313574 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3575 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063576
3577 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3578 // the user.
3579 handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite,
3580 &HandlePreviewsLitePageURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253581}
3582
[email protected]650b2d52013-02-10 03:41:453583base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493584 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323585}
3586
[email protected]c9b6eb62011-10-18 20:49:393587std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3588 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3589}
3590
Dominik Röttsches47347832019-03-12 17:45:013591base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3592 base::FilePath user_data_dir;
3593 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3594 DCHECK(!user_data_dir.empty());
3595 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3596}
3597
jmadill57b52d42015-08-21 18:16:133598base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3599 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523600 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133601 DCHECK(!user_data_dir.empty());
3602 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3603}
3604
Khushal7ca0b782018-07-20 05:53:273605base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3606 base::FilePath user_data_dir;
3607 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3608 DCHECK(!user_data_dir.empty());
3609 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3610}
3611
[email protected]b7631cc2012-09-15 05:08:383612void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3613 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163614#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553615 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543616#endif
[email protected]b7631cc2012-09-15 05:08:383617}
3618
[email protected]0c7193742012-11-07 19:05:033619content::BrowserPpapiHost*
3620 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
3621 int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173622#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553623 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033624 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:023625 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
3626 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:033627 if (host->process() &&
3628 host->process()->GetData().id == plugin_process_id) {
3629 // Found the plugin.
3630 return host->browser_ppapi_host();
3631 }
3632 ++iter;
3633 }
[email protected]a56f8322014-07-16 21:13:553634#endif
[email protected]0c7193742012-11-07 19:05:033635 return NULL;
3636}
3637
[email protected]38cd8f7f2012-06-15 22:06:073638bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583639 content::BrowserContext* browser_context,
3640 const GURL& url,
[email protected]dda54822013-06-15 01:26:393641 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123642 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163643#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553644 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3645 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403646#else
[email protected]a658d452012-03-02 12:45:293647 return false;
[email protected]93f72062013-05-29 20:29:403648#endif
[email protected]e461da2f2012-02-16 19:06:403649}
3650
adrian.belgund54465ba2016-05-18 10:03:583651bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3652 content::BrowserContext* browser_context,
3653 const GURL& url) {
brettw4b461082016-11-19 18:55:163654#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583655 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3656 browser_context, url);
3657#else
3658 return false;
3659#endif
3660}
3661
adrian.belgun5b341c72016-06-22 22:24:083662std::unique_ptr<content::VpnServiceProxy>
3663ChromeContentBrowserClient::GetVpnServiceProxy(
3664 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173665#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083666 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3667 browser_context);
3668#else
3669 return nullptr;
3670#endif
3671}
3672
Brett Wilson804e83c2017-08-18 22:57:333673std::unique_ptr<ui::SelectFilePolicy>
3674ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3675 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433676}
3677
[email protected]7d9424702013-04-14 13:14:163678void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3679 std::vector<std::string>* additional_allowed_schemes) {
3680 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3681 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483682 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293683 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033684 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3685 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3686 additional_allowed_schemes);
3687 }
[email protected]7d9424702013-04-14 13:14:163688}
3689
falkenad185092016-06-16 06:10:023690void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3691 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043692 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023693}
3694
[email protected]c79859b82014-03-20 22:43:553695void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313696 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033697 for (size_t i = 0; i < extra_parts_.size(); ++i)
3698 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553699}
3700
nzolghadrd87a308d2016-12-07 15:45:563701::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3702 return g_browser_process->rappor_service();
3703}
3704
[email protected]f19bbf62013-07-09 01:22:323705void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313706 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533707 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003708 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3709 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313710#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313711 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313712 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313713 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093714 auto backend = std::make_unique<chromeos::FileSystemBackend>(
3715 std::make_unique<drive::FileSystemBackendDelegate>(),
3716 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3717 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473718 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093719 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3720 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053721 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3722 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473723 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323724 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313725 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003726 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313727#endif
[email protected]445b7db2013-08-02 04:58:273728
[email protected]a48ab7112014-08-01 16:48:033729 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3730 extra_parts_[i]->GetAdditionalFileSystemBackends(
3731 browser_context, storage_partition_path, additional_backends);
3732 }
[email protected]02250952013-04-24 23:52:533733}
3734
jcivellie6f550742017-01-06 19:29:123735#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183736void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173737 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383738 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203739 PosixFileDescriptorInfo* mappings) {
Albert J. Wongb6942532017-07-13 22:49:303740
jcivellie6f550742017-01-06 19:29:123741#if defined(OS_ANDROID)
3742 base::MemoryMappedFile::Region region;
3743 int fd = ui::GetMainAndroidPackFd(&region);
3744 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003745
jcivellie6f550742017-01-06 19:29:123746 fd = ui::GetCommonResourcesPackFd(&region);
3747 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393748
jcivellie6f550742017-01-06 19:29:123749 fd = ui::GetLocalePackFd(&region);
3750 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383751
zpeng368afac82017-07-17 18:47:453752 // Optional secondary locale .pak file.
3753 fd = ui::GetSecondaryLocalePackFd(&region);
3754 if (fd != -1) {
3755 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3756 }
3757
[email protected]09560f7f2014-06-10 18:40:283758 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523759 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283760 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023761#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383762 int crash_signal_fd = GetCrashSignalFD(command_line);
3763 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133764 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383765 }
jcivellie6f550742017-01-06 19:29:123766}
3767#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303768
[email protected]4a65826d2011-08-25 16:04:013769#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033770base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:523771 int sandbox_type) {
wfh182da09c2015-06-24 19:23:033772 // TODO(wfh): Add support for more process types here. crbug.com/499523
3773 switch (sandbox_type) {
Tom Sepez15d4e5202017-09-27 23:59:053774 case service_manager::SANDBOX_TYPE_RENDERER:
Jerry Lina0de7ce2018-06-22 15:18:363775 return base::string16(install_static::GetSandboxSidPrefix()) +
3776 L"129201922";
Tom Sepez15d4e5202017-09-27 23:59:053777 case service_manager::SANDBOX_TYPE_UTILITY:
wfh182da09c2015-06-24 19:23:033778 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053779 case service_manager::SANDBOX_TYPE_GPU:
wfh182da09c2015-06-24 19:23:033780 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053781 case service_manager::SANDBOX_TYPE_PPAPI:
Jerry Lina0de7ce2018-06-22 15:18:363782 return base::string16(install_static::GetSandboxSidPrefix()) +
3783 L"129201925";
Nico Weberaf3b00b2017-09-11 17:58:173784#if BUILDFLAG(ENABLE_NACL)
wfh182da09c2015-06-24 19:23:033785 case PROCESS_TYPE_NACL_LOADER:
3786 return base::string16();
3787 case PROCESS_TYPE_NACL_BROKER:
3788 return base::string16();
3789#endif
3790 }
3791
3792 // Should never reach here.
3793 CHECK(0);
3794 return base::string16();
3795}
3796
rickyz50109312015-11-11 00:37:083797bool ChromeContentBrowserClient::PreSpawnRenderer(
3798 sandbox::TargetPolicy* policy) {
[email protected]34f48682013-03-20 00:30:183799 // This code is duplicated in nacl_exe_win_64.cc.
3800 // Allow the server side of a pipe restricted to the "chrome.nacl."
3801 // namespace so that it cannot impersonate other system or other chrome
3802 // service pipes.
3803 sandbox::ResultCode result = policy->AddRule(
3804 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
3805 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
3806 L"\\\\.\\pipe\\chrome.nacl.*");
rickyz50109312015-11-11 00:37:083807 if (result != sandbox::SBOX_ALL_OK)
3808 return false;
rickyz50109312015-11-11 00:37:083809 return result == sandbox::SBOX_ALL_OK;
[email protected]34f48682013-03-20 00:30:183810}
wfhc91e9672016-01-27 00:14:203811#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013812
bend1dd50f52016-06-26 22:10:483813void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
bena06f7d62017-04-04 20:48:523814 service_manager::BinderRegistry* registry,
Sam McNally52e50282017-11-29 00:54:023815 blink::AssociatedInterfaceRegistry* associated_registry,
leon.han0b618792016-06-16 01:53:513816 content::RenderProcessHost* render_process_host) {
nigeltaobeff0a102017-04-29 09:30:373817 // The CacheStatsRecorder is an associated binding, instead of a
3818 // non-associated one, because the sender (in the renderer process) posts the
3819 // message after a time delay, in order to rate limit. The association
3820 // protects against the render process host ID being recycled in that time
3821 // gap between the preparation and the execution of that IPC.
3822 associated_registry->AddInterface(
3823 base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID()));
3824
ben5be0b9132016-08-03 00:17:183825 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
Eric Seckler8652dcd52018-09-20 10:42:283826 base::CreateSingleThreadTaskRunnerWithTraits(
3827 {content::BrowserThread::UI});
bend1dd50f52016-06-26 22:10:483828 registry->AddInterface(
nigeltao2f673762016-10-14 03:27:283829 base::Bind(&rappor::RapporRecorderImpl::Create,
3830 g_browser_process->rappor_service()),
3831 ui_task_runner);
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183832 registry->AddInterface(
Mike Wittman16fa5362018-09-04 17:27:303833 base::BindRepeating(&metrics::CallStackProfileCollector::Create));
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183834
dvallet233f57ab2016-12-21 03:17:103835 if (NetBenchmarking::CheckBenchmarkingEnabled()) {
3836 Profile* profile =
3837 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Alexandr Ilin4909ec82018-06-06 10:22:483838 auto* loading_predictor =
3839 predictors::LoadingPredictorFactory::GetForProfile(profile);
Robbie McElrathb0f248c2018-07-24 19:44:163840 registry->AddInterface(
3841 base::BindRepeating(
3842 &NetBenchmarking::Create,
3843 loading_predictor ? loading_predictor->GetWeakPtr() : nullptr,
Robbie McElrathb0f248c2018-07-24 19:44:163844 render_process_host->GetID()),
3845 ui_task_runner);
dvallet233f57ab2016-12-21 03:17:103846 }
yzshen2d8fb422017-06-01 20:29:403847
Yuzhu Shencb3011f62018-02-08 02:51:503848#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
Adam Rice41b89592017-07-28 10:33:443849 if (safe_browsing_service_) {
Yuzhu Shencb3011f62018-02-08 02:51:503850 content::ResourceContext* resource_context =
3851 render_process_host->GetBrowserContext()->GetResourceContext();
yzshen2d8fb422017-06-01 20:29:403852 registry->AddInterface(
Yuzhu Shen44094e22017-07-18 22:52:353853 base::Bind(
3854 &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
Yuzhu Shencb3011f62018-02-08 02:51:503855 render_process_host->GetID(), resource_context,
Yuzhu Shen44094e22017-07-18 22:52:353856 base::Bind(
3857 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Yuzhu Shencb3011f62018-02-08 02:51:503858 base::Unretained(this), resource_context)),
Eric Seckler8652dcd52018-09-20 10:42:283859 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}));
yzshen2d8fb422017-06-01 20:29:403860 }
Yuzhu Shencb3011f62018-02-08 02:51:503861#endif // defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
yzshen2d8fb422017-06-01 20:29:403862
Eric Romana00cf682018-11-01 20:09:113863 if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
3864 registry->AddInterface(base::BindRepeating(
3865 &AddDataReductionProxyBinding,
3866 render_process_host->GetBrowserContext()->GetResourceContext()));
3867 }
3868
chrisha927d8fe2017-01-18 23:09:513869#if defined(OS_WIN)
Patrick Monette9a10ae22018-06-14 22:18:183870 // Add the ModuleEventSink interface. This is the interface used by renderer
3871 // processes to notify the browser of modules in their address space. The
3872 // process handle is not yet available at this point so pass in a callback
3873 // to allow to retrieve a duplicate at the time the interface is actually
3874 // created. It is safe to pass a raw pointer to |render_process_host|: the
Patrick Monetteaa2ec562019-03-20 23:37:453875 // callback will be invoked during the Mojo initialization, which occurs while
3876 // the |render_process_host| is alive.
Patrick Monette9a10ae22018-06-14 22:18:183877 auto get_process = base::BindRepeating(
3878 [](content::RenderProcessHost* host) -> base::Process {
3879 return host->GetProcess().Duplicate();
3880 },
3881 base::Unretained(render_process_host));
Patrick Monette9a10ae22018-06-14 22:18:183882 registry->AddInterface(
Patrick Monetteaa2ec562019-03-20 23:37:453883 base::BindRepeating(
3884 &ModuleEventSinkImpl::Create, std::move(get_process),
3885 content::PROCESS_TYPE_RENDERER,
3886 base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)),
Patrick Monette9a10ae22018-06-14 22:18:183887 ui_task_runner);
chrisha927d8fe2017-01-18 23:09:513888#endif
Dan Harrington964d48c2018-08-03 15:52:243889#if defined(OS_ANDROID)
Carlos Knippschild63b3f042018-11-20 22:55:043890 Profile* profile =
3891 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Dan Harrington964d48c2018-08-03 15:52:243892 registry->AddInterface(
3893 base::BindRepeating(&android::AvailableOfflineContentProvider::Create,
Carlos Knippschild63b3f042018-11-20 22:55:043894 profile),
Eric Seckler8652dcd52018-09-20 10:42:283895 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
Dan Harrington964d48c2018-08-03 15:52:243896#endif
chrisha927d8fe2017-01-18 23:09:513897
Nicholas Verneb5df4f72017-11-08 09:12:073898 for (auto* ep : extra_parts_) {
3899 ep->ExposeInterfacesToRenderer(registry, associated_registry,
3900 render_process_host);
3901 }
sammc335844522016-06-09 10:15:593902}
3903
bendd157e1a2016-07-22 03:15:573904void ChromeContentBrowserClient::ExposeInterfacesToMediaService(
ben8408b132017-05-01 23:48:503905 service_manager::BinderRegistry* registry,
xhwang9ab96482015-05-11 22:02:333906 content::RenderFrameHost* render_frame_host) {
Xiaohan Wang15303d0c2017-10-06 05:22:443907#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3908 registry->AddInterface(
3909 base::Bind(&OutputProtectionImpl::Create, render_frame_host));
ben155ecf82016-06-21 22:43:263910 registry->AddInterface(
John Rummell1b5da6102017-11-02 02:15:453911 base::Bind(&PlatformVerificationImpl::Create, render_frame_host));
Xiaohan Wang15303d0c2017-10-06 05:22:443912#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:493913
xhwangdb24d602017-05-20 06:32:243914#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
cm.sanchiad3f42a62017-11-07 11:33:353915 registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host));
xhwang116acb92017-04-03 18:27:203916#endif
xhwang9ab96482015-05-11 22:02:333917}
3918
Ben Goodger6a695c012017-06-20 20:21:203919void ChromeContentBrowserClient::BindInterfaceRequestFromFrame(
3920 content::RenderFrameHost* render_frame_host,
Ben Goodger6a695c012017-06-20 20:21:203921 const std::string& interface_name,
3922 mojo::ScopedMessagePipeHandle interface_pipe) {
Sam McNallyfaf9a402017-10-31 03:06:313923 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3924 !worker_interfaces_parameterized_) {
3925 InitWebContextInterfaces();
3926 }
Ben Goodger6a695c012017-06-20 20:21:203927
Ben Goodger272e0632017-07-19 23:27:003928 if (!frame_interfaces_parameterized_->TryBindInterface(
3929 interface_name, &interface_pipe, render_frame_host)) {
3930 frame_interfaces_->TryBindInterface(interface_name, &interface_pipe);
juncai1bf9f7c2016-03-22 20:46:563931 }
rockot0fa66a82015-06-11 17:25:453932}
3933
Mario Sanchez Prada39dee4a2019-07-09 07:15:403934void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113935 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403936 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3937 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113938 render_frame_host);
3939}
3940
Ken Rockot0aad7ec2018-07-31 15:58:443941bool ChromeContentBrowserClient::BindAssociatedInterfaceRequestFromFrame(
3942 content::RenderFrameHost* render_frame_host,
3943 const std::string& interface_name,
3944 mojo::ScopedInterfaceEndpointHandle* handle) {
3945 if (interface_name == autofill::mojom::AutofillDriver::Name_) {
3946 autofill::ContentAutofillDriverFactory::BindAutofillDriver(
Shimi Zhang6b72d292019-07-12 20:52:423947 mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>(
3948 std::move(*handle)),
Ken Rockot0aad7ec2018-07-31 15:58:443949 render_frame_host);
3950 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583951 }
3952 if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) {
Shimi Zhang6b72d292019-07-12 20:52:423953 password_manager::ContentPasswordManagerDriverFactory::
3954 BindPasswordManagerDriver(
3955 autofill::mojom::PasswordManagerDriverAssociatedRequest(
3956 std::move(*handle)),
3957 render_frame_host);
Dominic Battre97d5edf2019-03-26 13:41:383958 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583959 }
3960 if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) {
Tao Bai02ab4dd42019-03-06 00:30:373961 content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver(
Shimi Zhang8ee32332019-07-12 17:59:363962 mojo::PendingAssociatedReceiver<
3963 content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)),
Tao Bai02ab4dd42019-03-06 00:30:373964 render_frame_host);
3965 return true;
Ken Rockot0aad7ec2018-07-31 15:58:443966 }
3967
3968 return false;
3969}
3970
Sam McNallyfaf9a402017-10-31 03:06:313971void ChromeContentBrowserClient::BindInterfaceRequestFromWorker(
3972 content::RenderProcessHost* render_process_host,
3973 const url::Origin& origin,
3974 const std::string& interface_name,
3975 mojo::ScopedMessagePipeHandle interface_pipe) {
3976 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3977 !worker_interfaces_parameterized_) {
3978 InitWebContextInterfaces();
3979 }
3980
3981 worker_interfaces_parameterized_->BindInterface(
3982 interface_name, std::move(interface_pipe), render_process_host, origin);
3983}
3984
bena06f7d62017-04-04 20:48:523985void ChromeContentBrowserClient::BindInterfaceRequest(
ben2c36828d2017-05-02 04:09:013986 const service_manager::BindSourceInfo& source_info,
bena06f7d62017-04-04 20:48:523987 const std::string& interface_name,
3988 mojo::ScopedMessagePipeHandle* interface_pipe) {
Ben Goodger272e0632017-07-19 23:27:003989 if (source_info.identity.name() == content::mojom::kGpuServiceName)
3990 gpu_binder_registry_.TryBindInterface(interface_name, interface_pipe);
wittman757af872016-08-16 00:13:463991}
3992
Ken Rockotfa5d57112019-05-29 20:57:143993void ChromeContentBrowserClient::WillStartServiceManager() {
John Abd-El-Malek27b3ebd22019-02-12 18:59:183994#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:053995 if (startup_data_) {
3996 auto* chrome_feature_list_creator =
3997 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183998 // This has to run very early before ServiceManagerContext is created.
3999 const base::Value* force_network_in_process_value =
Xi Han85079c22019-04-18 21:43:054000 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:184001 ->GetPolicyService()
4002 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
4003 std::string()))
4004 .GetValue(policy::key::kForceNetworkInProcess);
4005 bool force_network_in_process = false;
4006 if (force_network_in_process_value)
4007 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
4008 if (force_network_in_process)
4009 content::ForceInProcessNetworkService(true);
4010 }
4011#endif
xhwang5e630462015-10-30 03:18:484012}
4013
Ken Rockot06fd2832019-05-24 17:24:444014void ChromeContentBrowserClient::RunServiceInstance(
4015 const service_manager::Identity& identity,
4016 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
4017 const std::string& service_name = identity.name();
Ken Rockot08750522018-11-29 07:41:344018 if (service_name == prefs::mojom::kLocalStateServiceName) {
4019 if (!g_browser_process || !g_browser_process->pref_service_factory())
4020 return;
4021
Ken Rockotd80eb102018-11-29 14:55:164022 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot08750522018-11-29 07:41:344023 g_browser_process->pref_service_factory()->CreatePrefService(
Ken Rockot06fd2832019-05-24 17:24:444024 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414025 return;
Ken Rockot08750522018-11-29 07:41:344026 }
4027
Alexander Woolfed183c512019-05-17 01:18:034028#if defined(OS_WIN)
4029 bool run_quarantine_service_in_process =
4030 !base::FeatureList::IsEnabled(quarantine::kOutOfProcessQuarantine);
4031#else
4032 bool run_quarantine_service_in_process = true;
4033#endif
4034
4035 if (run_quarantine_service_in_process &&
4036 service_name == quarantine::mojom::kServiceName) {
4037 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:444038 std::make_unique<quarantine::QuarantineService>(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414039 return;
Alexander Woolfed183c512019-05-17 01:18:034040 }
4041
Ken Rockot3d8be742018-11-22 08:59:384042#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
4043 if (service_name == media::mojom::kMediaServiceName) {
Ken Rockotd80eb102018-11-29 14:55:164044 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:444045 media::CreateMediaService(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414046 return;
Ken Rockot3d8be742018-11-22 08:59:384047 }
4048#endif
Ken Rockote116c202018-11-30 01:52:504049
Ken Rockotc15f34992018-12-01 21:27:574050#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
4051 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
4052 switches::kLaunchInProcessSimpleBrowserSwitch) &&
4053 service_name == simple_browser::mojom::kServiceName) {
4054 service_manager::Service::RunAsyncUntilTermination(
4055 std::make_unique<simple_browser::SimpleBrowserService>(
Ken Rockot06fd2832019-05-24 17:24:444056 std::move(*receiver), simple_browser::SimpleBrowserService::
4057 UIInitializationMode::kUseEnvironmentUI));
Lei Zhang194fcd32019-05-23 16:19:414058 return;
Ken Rockotc15f34992018-12-01 21:27:574059 }
4060#endif
4061
Ken Rockote116c202018-11-30 01:52:504062#if defined(OS_CHROMEOS)
Lei Zhang194fcd32019-05-23 16:19:414063 if (base::FeatureList::IsEnabled(
4064 chromeos::features::kUpdatedCellularActivationUi) &&
4065 service_name == chromeos::cellular_setup::mojom::kServiceName) {
Kyle Horimoto1d6a679f2019-04-16 23:24:214066 service_manager::Service::RunAsyncUntilTermination(
4067 std::make_unique<chromeos::cellular_setup::CellularSetupService>(
Ken Rockot06fd2832019-05-24 17:24:444068 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414069 return;
Kyle Horimoto1d6a679f2019-04-16 23:24:214070 }
4071
Regan Hsu07912b7d2018-12-13 21:27:014072 if (service_name == chromeos::secure_channel::mojom::kServiceName) {
Ken Rockotc15f34992018-12-01 21:27:574073 service_manager::Service::RunAsyncUntilTermination(
4074 std::make_unique<chromeos::secure_channel::SecureChannelService>(
Ken Rockot06fd2832019-05-24 17:24:444075 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414076 return;
Ken Rockotc15f34992018-12-01 21:27:574077 }
4078
Luum Habtemariamc295b4ea2019-04-24 20:18:514079 if (service_name == chromeos::printing::mojom::kCupsProxyServiceName) {
4080 service_manager::Service::RunAsyncUntilTermination(
4081 std::make_unique<chromeos::printing::CupsProxyService>(
Luum Habtemariamce0d1a92019-06-21 03:26:524082 std::move(*receiver),
4083 std::make_unique<chromeos::CupsProxyServiceDelegateImpl>()));
Lei Zhang194fcd32019-05-23 16:19:414084 return;
Luum Habtemariamc295b4ea2019-04-24 20:18:514085 }
4086
Steven Bennetts0c565d5b2019-04-24 23:52:454087 if (service_name == chromeos::network_config::mojom::kServiceName) {
4088 service_manager::Service::RunAsyncUntilTermination(
4089 std::make_unique<chromeos::network_config::NetworkConfigService>(
Ken Rockot06fd2832019-05-24 17:24:444090 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:414091 return;
Steven Bennetts0c565d5b2019-04-24 23:52:454092 }
4093
Ken Rockot06fd2832019-05-24 17:24:444094 auto service = ash_service_registry::HandleServiceRequest(
4095 service_name, std::move(*receiver));
Ken Rockotc15f34992018-12-01 21:27:574096 if (service)
4097 service_manager::Service::RunAsyncUntilTermination(std::move(service));
Lei Zhang194fcd32019-05-23 16:19:414098#endif // defined(OS_CHROMEOS)
Ken Rockot3d8be742018-11-22 08:59:384099}
4100
Ken Rockot06fd2832019-05-24 17:24:444101void ChromeContentBrowserClient::RunServiceInstanceOnIOThread(
4102 const service_manager::Identity& identity,
4103 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
4104 if (identity.name() == chrome::mojom::kServiceName) {
4105 ChromeService::GetInstance()->CreateChromeServiceRequestHandler().Run(
4106 std::move(*receiver));
4107 return;
4108 }
4109
4110#if defined(OS_ANDROID)
4111 if (identity.name() == proxy_resolver::mojom::kProxyResolverServiceName) {
4112 service_manager::Service::RunAsyncUntilTermination(
4113 std::make_unique<proxy_resolver::ProxyResolverService>(
4114 std::move(*receiver)));
4115 return;
4116 }
Ken Rockot06fd2832019-05-24 17:24:444117#endif
4118
4119 if (identity.name() == heap_profiling::mojom::kServiceName) {
4120 heap_profiling::HeapProfilingService::GetServiceFactory().Run(
4121 std::move(*receiver));
4122 return;
4123 }
4124}
4125
Ken Rockot8f39a272018-12-21 23:38:354126base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174127ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:584128 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:584129 return GetChromeContentBrowserOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584130 if (name == content::mojom::kGpuServiceName)
Ken Rockot341089f2019-01-11 23:11:584131 return GetChromeContentGpuOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584132 if (name == content::mojom::kRendererServiceName)
4133 return GetChromeContentRendererOverlayManifest();
4134 if (name == content::mojom::kUtilityServiceName)
4135 return GetChromeContentUtilityOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:584136 return base::nullopt;
benc70c0e32016-09-22 03:50:374137}
4138
Ken Rockot69aade02019-01-23 21:19:514139std::vector<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174140ChromeContentBrowserClient::GetExtraServiceManifests() {
Ken Rockot06fd2832019-05-24 17:24:444141 auto manifests = GetChromeBuiltinServiceManifests();
4142 manifests.push_back(GetChromeRendererManifest());
4143
Nico Weberaf3b00b2017-09-11 17:58:174144#if BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444145 manifests.push_back(GetNaClLoaderManifest());
Ken Rockot69aade02019-01-23 21:19:514146#if defined(OS_WIN) && defined(ARCH_CPU_X86)
Ken Rockot06fd2832019-05-24 17:24:444147 manifests.push_back(GetNaClBrokerManifest());
sammc2b0375b2016-12-22 01:26:174148#endif // defined(OS_WIN)
Nico Weberaf3b00b2017-09-11 17:58:174149#endif // BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444150
4151 return manifests;
sammc2b0375b2016-12-22 01:26:174152}
4153
peterbbcccc12015-02-11 22:23:334154void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:374155 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:334156 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:294157 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:084158 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:374159 DCHECK(ShouldAllowOpenURL(site_instance, params.url));
4160
4161 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:084162
zpengdb4a58e2017-01-10 17:40:324163#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:224164 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:294165 std::move(callback));
jam1c5a91492016-02-24 20:47:534166#else
cm.sanchi2522bc92017-12-04 08:04:134167 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
4168 params.url, params.transition);
4169 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:084170 nav_params.user_gesture = params.user_gesture;
4171
4172 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:294173 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:334174#endif
mlamourieb40d552015-02-05 00:57:084175}
4176
zhaobinf3704f82017-01-12 07:19:364177content::ControllerPresentationServiceDelegate*
4178ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
4179 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:464180 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:094181 return media_router::PresentationServiceDelegateImpl::
4182 GetOrCreateForWebContents(web_contents);
4183 }
haibinlu9e605a92015-06-06 03:45:094184 return nullptr;
4185}
4186
zhaobinf3704f82017-01-12 07:19:364187content::ReceiverPresentationServiceDelegate*
4188ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
4189 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:364190 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
4191 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
4192 // created for offscreen presentations. The WebContents must belong to
4193 // an incognito profile.
4194 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
4195 FromWebContents(web_contents)) {
4196 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
4197 return impl;
4198 }
4199 }
zhaobinf3704f82017-01-12 07:19:364200 return nullptr;
4201}
4202
horo48d4d3e2015-02-27 03:04:004203void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
4204 const GURL& url) {
mathp46284f32015-03-11 13:06:414205 if (url.is_valid()) {
4206 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
4207 metric, url);
4208 }
horo48d4d3e2015-02-27 03:04:004209}
4210
Matt Falkenhagen8479b202017-07-14 04:35:314211std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
4212 // Don't change these returned strings. They are written (in hashed form) into
4213 // UMA logs. If you add more strings, you must update histograms.xml and get
4214 // histograms review. Only Google domains should be here for privacy purposes.
4215 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
4216 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194217 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:314218 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194219 if (url.host() == "docs.google.com")
4220 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:314221 return std::string();
4222}
4223
avid6d88b912017-01-13 00:16:004224std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:474225ChromeContentBrowserClient::CreateThrottlesForNavigation(
4226 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:004227 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:274228
bmcquadeb4556552017-03-24 22:24:374229 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
4230 // that may delay or cancel navigations, so only NavigationThrottles that
4231 // don't delay or cancel navigations (e.g. throttles that are only observing
4232 // callbacks without affecting navigation behavior) should be added before
4233 // MetricsNavigationThrottle.
4234 if (handle->IsInMainFrame()) {
4235 throttles.push_back(
4236 page_load_metrics::MetricsNavigationThrottle::Create(handle));
4237 }
4238
brettw4b461082016-11-19 18:55:164239#if BUILDFLAG(ENABLE_PLUGINS)
tommycliae590f1602016-11-02 03:59:234240 std::unique_ptr<content::NavigationThrottle> flash_url_throttle =
4241 FlashDownloadInterception::MaybeCreateThrottleFor(handle);
4242 if (flash_url_throttle)
4243 throttles.push_back(std::move(flash_url_throttle));
trizzofo8ddaeb72016-09-01 23:18:274244#endif
4245
mmenkedb2637ff2017-03-30 23:59:424246#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4247 std::unique_ptr<content::NavigationThrottle> supervised_user_throttle =
4248 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle);
4249 if (supervised_user_throttle)
4250 throttles.push_back(std::move(supervised_user_throttle));
4251#endif
4252
clamy40c9e142015-09-29 11:18:474253#if defined(OS_ANDROID)
4254 // TODO(davidben): This is insufficient to integrate with prerender properly.
4255 // https://crbug.com/370595
4256 prerender::PrerenderContents* prerender_contents =
4257 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
4258 if (!prerender_contents && handle->IsInMainFrame()) {
4259 throttles.push_back(
4260 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304261 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474262 }
Min Qin0ab0e162017-11-14 21:57:194263 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574264#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474265 if (handle->IsInMainFrame()) {
4266 // Redirect some navigations to apps that have registered matching URL
4267 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574268 auto url_to_app_throttle =
4269 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:474270 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:094271 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:474272 }
4273#endif
clamy49678312015-10-22 21:59:004274
4275#if defined(OS_CHROMEOS)
4276 // Check if we need to add merge session throttle. This throttle will postpone
4277 // loading of main frames.
4278 if (handle->IsInMainFrame()) {
4279 // Add interstitial page while merge session process (cookie reconstruction
4280 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4281 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024282 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4283 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004284 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4285 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4286 }
Maggie Caia2f03f52019-04-02 02:13:284287 }
4288#endif
djacobo21e56e02016-07-02 01:14:314289
Maggie Caia2f03f52019-04-02 02:13:284290#if !defined(OS_ANDROID)
4291 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:154292 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:284293#if defined(OS_CHROMEOS)
4294 chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
4295#else
4296 apps::AppsNavigationThrottle::MaybeCreate(handle);
4297#endif
Dominick Ng7c289942018-03-27 05:57:154298 if (url_to_apps_throttle)
4299 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004300 }
4301#endif
4302
brettw00899e62016-11-12 02:10:174303#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004304 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094305 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514306
4307 std::unique_ptr<content::NavigationThrottle> user_script_throttle =
4308 extensions::ExtensionsBrowserClient::Get()
4309 ->GetUserScriptListener()
4310 ->CreateNavigationThrottle(handle);
4311 if (user_script_throttle)
4312 throttles.push_back(std::move(user_script_throttle));
naskob9164c42016-06-07 01:21:354313#endif
4314
bauerb8f9c37742017-03-30 15:04:124315#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4316 std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle =
4317 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle);
4318 if (supervised_user_nav_throttle)
4319 throttles.push_back(std::move(supervised_user_nav_throttle));
4320#endif
4321
csharrisone985ebc2017-04-04 17:05:034322 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:104323 if (auto* subresource_filter_client =
4324 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
4325 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
4326 &throttles);
csharrisone985ebc2017-04-04 17:05:034327 }
4328
zhenw6edd49c2017-07-12 05:49:454329#if !defined(OS_ANDROID)
4330 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4331 // enabled on non-Android platforms.
4332 std::unique_ptr<content::NavigationThrottle>
4333 background_tab_navigation_throttle = resource_coordinator::
4334 BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle);
4335 if (background_tab_navigation_throttle)
4336 throttles.push_back(std::move(background_tab_navigation_throttle));
4337#endif
4338
Michael Thiessen4c9e4a82019-03-08 04:39:444339#if defined(FULL_SAFE_BROWSING)
Jialiu Linbdbb81d2017-10-11 21:29:094340 std::unique_ptr<content::NavigationThrottle>
4341 password_protection_navigation_throttle =
4342 safe_browsing::MaybeCreateNavigationThrottle(handle);
4343 if (password_protection_navigation_throttle) {
4344 throttles.push_back(std::move(password_protection_navigation_throttle));
4345 }
4346#endif
4347
Joe DeBlasio6e8409a2019-02-20 23:08:274348 std::unique_ptr<content::NavigationThrottle>
Mustafa Emre Acere14f6262019-04-02 00:19:314349 lookalike_url_navigation_throttle = lookalikes::
Joe DeBlasio6e8409a2019-02-20 23:08:274350 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle);
4351 if (lookalike_url_navigation_throttle)
4352 throttles.push_back(std::move(lookalike_url_navigation_throttle));
Joe DeBlasio6e8409a2019-02-20 23:08:274353
Amber Wonf56d8f42017-08-31 22:29:404354 std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle =
4355 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle);
4356 if (pdf_iframe_throttle)
4357 throttles.push_back(std::move(pdf_iframe_throttle));
Amber Won6b5edc752017-08-17 19:23:544358
Charles Harrison6dd11d282017-10-03 06:14:514359 std::unique_ptr<content::NavigationThrottle> tab_under_throttle =
4360 TabUnderNavigationThrottle::MaybeCreate(handle);
4361 if (tab_under_throttle)
4362 throttles.push_back(std::move(tab_under_throttle));
4363
Jeremy Romanec48d7a2018-03-01 17:35:094364 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534365 handle, handle->GetWebContents()->GetBrowserContext()));
4366
Carlos IL5a9e7512019-06-13 22:35:284367 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4368 handle,
4369 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
4370 base::Bind(&SSLErrorHandler::HandleSSLError)));
Lucas Garron94b16052017-11-11 01:58:124371
Christopher Thompson4137cec2017-12-19 05:34:234372 std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle =
4373 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle);
4374 if (https_upgrade_timing_throttle)
4375 throttles.push_back(std::move(https_upgrade_timing_throttle));
4376
Dmitry Gozman57b92ce2017-12-28 22:24:544377#if !defined(OS_ANDROID)
4378 std::unique_ptr<content::NavigationThrottle> devtools_throttle =
4379 DevToolsWindow::MaybeCreateNavigationThrottle(handle);
4380 if (devtools_throttle)
4381 throttles.push_back(std::move(devtools_throttle));
Conley Owensaafcf122018-02-26 18:53:514382
4383 std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle =
4384 NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle);
4385 if (new_tab_page_throttle)
4386 throttles.push_back(std::move(new_tab_page_throttle));
jdoerrie4f9376f2018-12-12 18:26:204387
4388 std::unique_ptr<content::NavigationThrottle>
4389 google_password_manager_throttle =
4390 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(
4391 handle);
4392 if (google_password_manager_throttle)
4393 throttles.push_back(std::move(google_password_manager_throttle));
Dmitry Gozman57b92ce2017-12-28 22:24:544394#endif
4395
Robert Ogdenafd250b2018-07-25 22:21:034396 std::unique_ptr<content::NavigationThrottle> previews_lite_page_throttle =
4397 PreviewsLitePageDecider::MaybeCreateThrottleFor(handle);
4398 if (previews_lite_page_throttle)
4399 throttles.push_back(std::move(previews_lite_page_throttle));
Carlos IL4ee307e2018-12-22 03:19:004400 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
4401 throttles.push_back(
4402 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
4403 handle));
4404 }
Robert Ogdenafd250b2018-07-25 22:21:034405
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334406#if defined(OS_WIN) || defined(OS_MACOSX) || \
4407 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134408 std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle =
4409 browser_switcher::BrowserSwitcherNavigationThrottle ::
4410 MaybeCreateThrottleFor(handle);
4411 if (browser_switcher_throttle)
4412 throttles.push_back(std::move(browser_switcher_throttle));
4413#endif
4414
dchenge73d8520c2015-12-27 01:19:094415 return throttles;
clamy40c9e142015-09-29 11:18:474416}
4417
clamy1e5574e2016-09-29 16:48:444418std::unique_ptr<content::NavigationUIData>
4419ChromeContentBrowserClient::GetNavigationUIData(
4420 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094421 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444422}
4423
Xiaohan Wanga4e41842018-06-26 18:45:104424void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4425 const std::string& key_system,
4426 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4427 base::flat_set<media::VideoCodec>* video_codecs,
4428 base::flat_set<media::EncryptionMode>* encryption_schemes) {
4429#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264430 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104431 if (key_system == kWidevineKeySystem) {
4432 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4433 encryption_schemes);
4434 }
4435#endif
4436}
4437
[email protected]487974a2014-06-13 16:49:014438content::DevToolsManagerDelegate*
4439ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354440#if defined(OS_ANDROID)
4441 return new DevToolsManagerDelegateAndroid();
4442#else
[email protected]487974a2014-06-13 16:49:014443 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354444#endif
[email protected]487974a2014-06-13 16:49:014445}
4446
Rayan Kanso411e84e2019-02-13 15:27:404447void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4448 content::BrowserContext* browser_context,
4449 int service,
4450 base::Time expiration_time) {
4451 Profile* profile = Profile::FromBrowserContext(browser_context);
4452 DCHECK(profile);
4453
4454 auto* pref_service = profile->GetPrefs();
4455 DCHECK(pref_service);
4456
4457 DictionaryPrefUpdate pref_update(
4458 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4459 base::DictionaryValue* exp_dict = pref_update.Get();
4460
4461 // Convert |expiration_time| to minutes since that is the most granular
4462 // option that returns an int. base::Value does not accept int64.
4463 int expiration_time_minutes =
4464 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4465 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4466}
4467
4468base::flat_map<int, base::Time>
4469ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4470 content::BrowserContext* browser_context) {
4471 Profile* profile = Profile::FromBrowserContext(browser_context);
4472 DCHECK(profile);
4473
4474 auto* pref_service = profile->GetPrefs();
4475 DCHECK(pref_service);
4476
4477 auto* expiration_dict = pref_service->GetDictionary(
4478 prefs::kDevToolsBackgroundServicesExpirationDict);
4479 DCHECK(expiration_dict);
4480
4481 base::flat_map<int, base::Time> expiration_times;
4482 for (const auto& it : *expiration_dict) {
4483 // key.
4484 int service = 0;
4485 bool did_convert = base::StringToInt(it.first, &service);
4486 DCHECK(did_convert);
4487
4488 // value.
4489 DCHECK(it.second->is_int());
4490 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4491 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4492
4493 expiration_times[service] = expiration_time;
4494 }
4495
4496 return expiration_times;
4497}
4498
oysteinec563c582015-02-13 19:19:524499content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524500 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524501}
4502
[email protected]a6868c22013-10-09 02:50:294503bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4504 content::BrowserContext* browser_context,
4505 const GURL& url) {
brettw4b461082016-11-19 18:55:164506#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554507 return ChromeContentBrowserClientPluginsPart::
4508 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4509 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294510#else
4511 return false;
4512#endif
4513}
4514
[email protected]aec5ed52014-06-20 07:51:424515bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4516 content::BrowserContext* browser_context,
4517 const GURL& url) {
brettw4b461082016-11-19 18:55:164518#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554519 return ChromeContentBrowserClientPluginsPart::
4520 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4521 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064522#else
4523 return false;
4524#endif
4525}
4526
mlamourif8c23a2002015-01-27 13:10:104527void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014528 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434529 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524530 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104531
4532 WebContents* web_contents =
4533 WebContents::FromRenderFrameHost(render_frame_host);
4534 DCHECK(web_contents);
4535
mlamourif8c23a2002015-01-27 13:10:104536 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374537 prerender::PrerenderManagerFactory::GetForBrowserContext(
4538 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104539 if (prerender_manager &&
4540 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
danakj0018a29a2018-12-01 01:03:434541 *visibility_state = content::PageVisibilityState::kPrerender;
mlamourif8c23a2002015-01-27 13:10:104542 }
4543}
4544
Andrew Moylan8ed9d83c82019-01-29 20:23:524545// Forward image Annotator requests to the image_annotation service.
4546void BindImageAnnotator(image_annotation::mojom::AnnotatorRequest request,
4547 RenderFrameHost* const frame_host) {
4548 content::BrowserContext::GetConnectorFor(
4549 frame_host->GetProcess()->GetBrowserContext())
4550 ->BindInterface(image_annotation::mojom::kServiceName,
4551 std::move(request));
4552}
4553
Sam McNallyfaf9a402017-10-31 03:06:314554void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094555 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4556 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014557 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Sam McNallyfaf9a402017-10-31 03:06:314558 worker_interfaces_parameterized_ =
Jeremy Romanec48d7a2018-03-01 17:35:094559 std::make_unique<service_manager::BinderRegistryWithArgs<
Sam McNallyfaf9a402017-10-31 03:06:314560 content::RenderProcessHost*, const url::Origin&>>();
Ben Goodger6a695c012017-06-20 20:21:204561
Michael Martis4a542f52017-07-28 01:51:444562 // Register mojo ContentTranslateDriver interface only for main frame.
Anthony Vallee-Duboise2432137a2019-01-17 20:06:014563 frame_interfaces_parameterized_->AddInterface(
4564 base::BindRepeating(&language::BindContentTranslateDriver));
Ben Goodger6a695c012017-06-20 20:21:204565
4566 frame_interfaces_parameterized_->AddInterface(
Eric Lawrenced0acf2a7c2017-07-20 18:02:484567 base::Bind(&InsecureSensitiveInputDriverFactory::BindDriver));
Andrew Moylan8ed9d83c82019-01-29 20:23:524568 frame_interfaces_parameterized_->AddInterface(
4569 base::BindRepeating(&BindImageAnnotator));
Ben Goodger6a695c012017-06-20 20:21:204570
4571#if defined(OS_ANDROID)
4572 frame_interfaces_parameterized_->AddInterface(base::Bind(
Matt Giucaee4aefb2017-08-04 03:11:554573 &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>));
Ben Goodger6a695c012017-06-20 20:21:204574 frame_interfaces_parameterized_->AddInterface(
4575 base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>));
Kim Paulhamus3d33e442018-03-29 23:04:144576 frame_interfaces_parameterized_->AddInterface(
Amos Limdddb6992018-07-19 22:14:324577 base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>));
Michael Thiessen909ba032019-03-26 23:47:434578#if defined(BROWSER_MEDIA_CONTROLS_MENU)
4579 frame_interfaces_parameterized_->AddInterface(base::Bind(
4580 &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>));
4581#endif
Ben Goodger6a695c012017-06-20 20:21:204582#else
4583 if (base::FeatureList::IsEnabled(features::kWebPayments)) {
4584 frame_interfaces_parameterized_->AddInterface(
4585 base::Bind(&payments::CreatePaymentRequest));
4586 }
4587#endif
4588
Ben Goodger6a695c012017-06-20 20:21:204589#if defined(OS_ANDROID)
Matt Giuca00e993602017-06-23 05:17:544590 frame_interfaces_parameterized_->AddInterface(base::Bind(
4591 &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>));
Michael Thiessen07c444c2019-04-26 03:53:114592#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
4593 frame_interfaces_parameterized_->AddInterface(base::Bind(
4594 &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>));
4595#endif
Ben Goodger6a695c012017-06-20 20:21:204596#endif
Reilly Grant8e5c85c2017-07-07 16:35:064597
Jay Harris5a42aa21b2018-11-28 01:23:554598#if !defined(OS_ANDROID)
Eric Stevenson1d074a972018-12-07 14:16:454599 frame_interfaces_parameterized_->AddInterface(
Jay Harris1ddcffa2019-07-09 03:07:404600 base::BindRepeating(&badging::BadgeManager::BindRequest));
Eric Stevensonc3b18052018-10-01 22:22:004601#endif
4602
Reilly Grant8e5c85c2017-07-07 16:35:064603 frame_interfaces_parameterized_->AddInterface(
Lu Chen5bec7a302018-06-26 18:52:324604 base::BindRepeating(&NavigationPredictor::Create));
Dan Harringtonbc87c062018-10-31 15:21:244605
4606#if defined(OS_ANDROID)
4607 frame_interfaces_parameterized_->AddInterface(
4608 base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create),
4609 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
4610#endif
Ben Goodger6a695c012017-06-20 20:21:204611}
4612
[email protected]30335fdf02014-02-26 19:51:274613void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174614 base::CommandLine* to_command_line,
4615 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544616 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274617#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544618 const version_info::Channel kMaxDisableEncryptionChannel =
4619 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274620#else
sdefresne6e883e42015-07-30 08:05:544621 const version_info::Channel kMaxDisableEncryptionChannel =
4622 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274623#endif
4624 if (channel <= kMaxDisableEncryptionChannel) {
4625 static const char* const kWebRtcDevSwitchNames[] = {
4626 switches::kDisableWebRtcEncryption,
4627 };
Avi Drissmand251e912018-12-26 15:46:374628 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4629 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274630 }
4631}
bashi933629552016-10-13 23:32:404632
miu54dca6c2016-11-17 10:59:384633#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4634void ChromeContentBrowserClient::CreateMediaRemoter(
4635 content::RenderFrameHost* render_frame_host,
4636 media::mojom::RemotingSourcePtr source,
4637 media::mojom::RemoterRequest request) {
miu54dca6c2016-11-17 10:59:384638 CastRemotingConnector::CreateMediaRemoter(
4639 render_frame_host, std::move(source), std::move(request));
miu54dca6c2016-11-17 10:59:384640}
4641#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464642
Michael Giuffrida6802ffe2017-09-29 03:40:254643base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4644 const base::CommandLine& command_line) {
4645 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164646}
4647
John Abd-El-Malek8efa11f2019-01-06 00:51:534648namespace {
4649// TODO(jam): move this to a separate file.
Clark DuVall8512cee62019-06-26 01:14:214650template <class HandlerRegistry>
John Abd-El-Malek8efa11f2019-01-06 00:51:534651class ProtocolHandlerThrottle : public content::URLLoaderThrottle {
4652 public:
4653 explicit ProtocolHandlerThrottle(
Clark DuVall8512cee62019-06-26 01:14:214654 const HandlerRegistry& protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534655 : protocol_handler_registry_(protocol_handler_registry) {}
4656 ~ProtocolHandlerThrottle() override = default;
4657
4658 void WillStartRequest(network::ResourceRequest* request,
4659 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294660 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534661 }
4662
4663 void WillRedirectRequest(net::RedirectInfo* redirect_info,
4664 const network::ResourceResponseHead& response_head,
4665 bool* defer,
4666 std::vector<std::string>* to_be_removed_headers,
4667 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294668 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534669 }
4670
4671 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294672 void TranslateUrl(GURL* url) {
4673 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4674 return;
4675 GURL translated_url = protocol_handler_registry_->Translate(*url);
4676 if (!translated_url.is_empty())
4677 *url = translated_url;
4678 }
4679
Clark DuVall8512cee62019-06-26 01:14:214680 HandlerRegistry protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534681};
4682} // namespace
4683
yzshenefcb7c72017-06-16 23:12:304684std::vector<std::unique_ptr<content::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194685ChromeContentBrowserClient::CreateURLLoaderThrottlesOnIO(
Yuzhu Shencb3011f62018-02-08 02:51:504686 const network::ResourceRequest& request,
4687 content::ResourceContext* resource_context,
4688 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
Yuzhu Shen9508fc72018-02-08 23:18:594689 content::NavigationUIData* navigation_ui_data,
4690 int frame_tree_node_id) {
yzshenefcb7c72017-06-16 23:12:304691 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Clark DuVallfffa41e2019-06-25 20:27:194692 DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
yzshenefcb7c72017-06-16 23:12:304693
4694 std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
Yuzhu Shen44094e22017-07-18 22:52:354695
Vasilii Sukhanov0163c5142018-10-10 08:30:034696 ProfileIOData* io_data = nullptr;
Clark DuVall92335842018-10-10 16:49:094697 // Only set |io_data| if needed, as in unit tests |resource_context| is a
Clark DuVall6eee9cb2018-10-09 22:08:124698 // MockResourceContext and the cast doesn't work.
Clark DuVall92335842018-10-10 16:49:094699 if (safe_browsing_service_ ||
4700 data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Vasilii Sukhanov0163c5142018-10-10 08:30:034701 io_data = ProfileIOData::FromResourceContext(resource_context);
Clark DuVall92335842018-10-10 16:49:094702 }
4703
rajendrant43194072019-04-15 22:13:434704 ChromeNavigationUIData* chrome_navigation_ui_data =
4705 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4706 if (chrome_navigation_ui_data && io_data &&
4707 io_data->data_reduction_proxy_io_data() &&
Clark DuVall05faba12018-10-29 19:34:484708 data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Wojciech Dzierżanowski45380802019-04-29 14:50:324709 if (!data_reduction_proxy_throttle_manager_) {
4710 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4711 data_reduction_proxy::DataReductionProxyThrottleManager,
4712 base::OnTaskRunnerDeleter>(
4713 new data_reduction_proxy::DataReductionProxyThrottleManager(
4714 io_data->data_reduction_proxy_io_data(),
4715 io_data->data_reduction_proxy_io_data()->CreateThrottleConfig()),
4716 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4717 }
Clark DuVall92335842018-10-10 16:49:094718 net::HttpRequestHeaders headers;
4719 data_reduction_proxy::DataReductionProxyRequestOptions* request_options =
4720 io_data->data_reduction_proxy_io_data()->request_options();
rajendrant43194072019-04-15 22:13:434721 uint64_t page_id =
4722 base::FeatureList::IsEnabled(
4723 data_reduction_proxy::features::
4724 kDataReductionProxyPopulatePreviewsPageIDToPingback)
4725 ? chrome_navigation_ui_data->data_reduction_proxy_page_id()
4726 : request_options->GeneratePageId();
4727 request_options->AddPageIDRequestHeader(&headers, page_id);
Clark DuVall92335842018-10-10 16:49:094728 result.push_back(std::make_unique<
4729 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
Wojciech Dzierżanowski45380802019-04-29 14:50:324730 headers, data_reduction_proxy_throttle_manager_.get()));
Clark DuVall92335842018-10-10 16:49:094731 }
Vasilii Sukhanov0163c5142018-10-10 08:30:034732
4733#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
Clark DuVall92335842018-10-10 16:49:094734 if (io_data && safe_browsing_service_) {
John Abd-El-Malek9fb60492018-08-02 04:28:504735 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4736 request.url, io_data->safe_browsing_whitelist_domains());
John Abd-El-Malek7577f262019-06-10 21:23:234737 if (!matches_enterprise_whitelist) {
John Abd-El-Malek39d5daaa2018-04-02 21:31:414738 auto* delegate = GetSafeBrowsingUrlCheckerDelegate(resource_context);
4739 if (delegate && !delegate->ShouldSkipRequestCheck(
4740 resource_context, request.url, frame_tree_node_id,
4741 -1 /* render_process_id */, -1 /* render_frame_id */,
4742 request.originated_from_service_worker)) {
4743 auto safe_browsing_throttle =
4744 safe_browsing::BrowserURLLoaderThrottle::MaybeCreate(delegate,
4745 wc_getter);
4746 if (safe_browsing_throttle)
4747 result.push_back(std::move(safe_browsing_throttle));
4748 }
Yuzhu Shencb3011f62018-02-08 02:51:504749 }
4750 }
4751#endif // defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
Yuzhu Shen44094e22017-07-18 22:52:354752
Egor Pasko0f4403e2019-01-24 17:42:204753 if (chrome_navigation_ui_data &&
4754 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4755 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4756 chrome_navigation_ui_data->prerender_mode(),
4757 chrome_navigation_ui_data->prerender_histogram_prefix(),
4758 base::BindOnce(GetPrerenderCanceller, wc_getter),
4759 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})));
John Abd-El-Malek9fb60492018-08-02 04:28:504760 }
Jun Cai605ff0e72018-06-12 22:29:204761
John Abd-El-Malek9fb60492018-08-02 04:28:504762 if (io_data) {
Jun Cai605ff0e72018-06-12 22:29:204763 bool is_off_the_record = io_data->IsOffTheRecord();
4764 bool is_signed_in =
4765 !is_off_the_record &&
4766 !io_data->google_services_account_id()->GetValue().empty();
4767
Chris Mumford809d8fb2018-11-10 12:26:114768 chrome::mojom::DynamicParams dynamic_params = {
4769 io_data->force_google_safesearch()->GetValue(),
John Abd-El-Malek9fb60492018-08-02 04:28:504770 io_data->force_youtube_restrict()->GetValue(),
Chris Mumford809d8fb2018-11-10 12:26:114771 io_data->allowed_domains_for_apps()->GetValue(),
4772 variations::VariationsHttpHeaderProvider::GetInstance()
4773 ->GetClientDataHeader(is_signed_in)};
4774 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
4775 is_off_the_record, std::move(dynamic_params)));
John Abd-El-Malek8efa11f2019-01-06 00:51:534776
Clark DuVall8512cee62019-06-26 01:14:214777 result.push_back(
4778 std::make_unique<ProtocolHandlerThrottle<
4779 scoped_refptr<ProtocolHandlerRegistry::IOThreadDelegate>>>(
4780 io_data->protocol_handler_registry_io_thread_delegate()));
John Abd-El-Malekd2377982018-01-08 22:23:124781 }
4782
John Abd-El-Malekecc6f5f2018-03-02 18:47:394783#if BUILDFLAG(ENABLE_PLUGINS)
Matt Falkenhagene75bdd452019-04-03 07:41:524784 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
4785 resource_context, request.resource_type, frame_tree_node_id));
John Abd-El-Malekecc6f5f2018-03-02 18:47:394786#endif
Reilly Grant37877802018-08-18 00:58:354787
John Abd-El-Malek7577f262019-06-10 21:23:234788 auto delegate = std::make_unique<signin::HeaderModificationDelegateImpl>(
4789 resource_context);
4790 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4791 std::move(delegate), navigation_ui_data, wc_getter);
4792 if (signin_throttle)
4793 result.push_back(std::move(signin_throttle));
4794
yzshenefcb7c72017-06-16 23:12:304795 return result;
4796}
4797
Clark DuVallfffa41e2019-06-25 20:27:194798std::vector<std::unique_ptr<content::URLLoaderThrottle>>
4799ChromeContentBrowserClient::CreateURLLoaderThrottles(
4800 const network::ResourceRequest& request,
4801 content::BrowserContext* browser_context,
4802 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4803 content::NavigationUIData* navigation_ui_data,
4804 int frame_tree_node_id) {
4805 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4806
4807 std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
4808
4809 Profile* profile = Profile::FromBrowserContext(browser_context);
4810
4811 ChromeNavigationUIData* chrome_navigation_ui_data =
4812 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4813
Clark DuVall68eb997f2019-06-28 05:42:284814 auto* drp_settings =
4815 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4816 browser_context);
4817 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4818 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4819 drp_settings) {
4820 if (!data_reduction_proxy_throttle_manager_) {
4821 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4822 data_reduction_proxy::DataReductionProxyThrottleManager,
4823 base::OnTaskRunnerDeleter>(
4824 new data_reduction_proxy::DataReductionProxyThrottleManager(
4825 drp_settings->data_reduction_proxy_service(),
4826 data_reduction_proxy::DataReductionProxyThrottleManager::
4827 CreateConfig(drp_settings->proxies_for_http())),
4828 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4829 }
4830 net::HttpRequestHeaders headers;
4831 data_reduction_proxy::DataReductionProxyRequestOptions::
4832 AddPageIDRequestHeader(
4833 &headers,
4834 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4835 result.push_back(std::make_unique<
4836 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4837 headers, data_reduction_proxy_throttle_manager_.get()));
4838 }
4839
Clark DuVallfffa41e2019-06-25 20:27:194840 if (chrome_navigation_ui_data &&
4841 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4842 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4843 chrome_navigation_ui_data->prerender_mode(),
4844 chrome_navigation_ui_data->prerender_histogram_prefix(),
4845 base::BindOnce(GetPrerenderCanceller, wc_getter),
4846 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})));
4847 }
4848
4849 bool is_off_the_record = profile->IsOffTheRecord();
4850 bool is_signed_in = !is_off_the_record &&
4851 !profile->GetPrefs()
4852 ->GetString(prefs::kGoogleServicesUserAccountId)
4853 .empty();
4854
4855 chrome::mojom::DynamicParams dynamic_params = {
4856 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4857 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4858 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4859 variations::VariationsHttpHeaderProvider::GetInstance()
4860 ->GetClientDataHeader(is_signed_in)};
4861 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
4862 is_off_the_record, std::move(dynamic_params)));
4863
Clark DuVall8512cee62019-06-26 01:14:214864 result.push_back(
4865 std::make_unique<ProtocolHandlerThrottle<ProtocolHandlerRegistry*>>(
4866 ProtocolHandlerRegistryFactory::GetForBrowserContext(
4867 browser_context)));
4868
Clark DuVall39c2cfc2019-06-25 21:49:284869#if BUILDFLAG(ENABLE_PLUGINS)
4870 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
4871 browser_context, request.resource_type, frame_tree_node_id));
4872#endif
4873
Clark DuVallfffa41e2019-06-25 20:27:194874 return result;
4875}
4876
Ken Rockot6414c4d92017-11-08 19:58:324877void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464878 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324879 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414880#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464881 content::WebContents* web_contents =
4882 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414883#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324884 factories->emplace(
4885 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574886 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464887 web_contents->GetBrowserContext(),
4888 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414889#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4890#if defined(OS_CHROMEOS)
4891 Profile* profile =
4892 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304893 factories->emplace(content::kExternalFileScheme,
4894 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4895 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414896#endif // defined(OS_CHROMEOS)
4897#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324898}
4899
Ting Shao2dc60582019-07-15 04:43:364900void ChromeContentBrowserClient::
4901 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4902 content::BrowserContext* browser_context,
4903 NonNetworkURLLoaderFactoryMap* factories) {
4904#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4905 DCHECK(browser_context);
4906 DCHECK(factories);
4907#if BUILDFLAG(ENABLE_EXTENSIONS)
4908 factories->emplace(
4909 extensions::kExtensionScheme,
4910 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4911 browser_context));
4912#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4913#if defined(OS_CHROMEOS)
4914 Profile* profile = Profile::FromBrowserContext(browser_context);
4915 factories->emplace(content::kExternalFileScheme,
4916 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4917 profile, content::ChildProcessHost::kInvalidUniqueID));
4918#endif // defined(OS_CHROMEOS)
4919#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4920}
4921
Jay Civelli2578ebe2018-06-05 18:44:314922namespace {
4923
4924// The FileURLLoaderFactory provided to the extension background pages.
4925// Checks with the ChildProcessSecurityPolicy to validate the file access.
4926class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4927 public:
4928 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4929
4930 private:
4931 // network::mojom::URLLoaderFactory:
4932 void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
4933 int32_t routing_id,
4934 int32_t request_id,
4935 uint32_t options,
4936 const network::ResourceRequest& request,
4937 network::mojom::URLLoaderClientPtr client,
4938 const net::MutableNetworkTrafficAnnotationTag&
4939 traffic_annotation) override {
4940 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4941 child_id_, request.url)) {
4942 client->OnComplete(
4943 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
4944 return;
4945 }
4946 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454947 /*observer=*/nullptr,
4948 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314949 }
4950
4951 void Clone(network::mojom::URLLoaderFactoryRequest loader) override {
4952 bindings_.AddBinding(this, std::move(loader));
4953 }
4954
4955 int child_id_;
4956 mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
4957 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4958};
4959
4960} // namespace
4961
Ken Rockot6414c4d92017-11-08 19:58:324962void ChromeContentBrowserClient::
4963 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464964 int render_process_id,
4965 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324966 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414967#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4968 content::RenderFrameHost* frame_host =
4969 RenderFrameHost::FromID(render_process_id, render_frame_id);
4970 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4971#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4972
4973#if defined(OS_CHROMEOS)
4974 if (web_contents) {
4975 Profile* profile =
4976 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304977 factories->emplace(content::kExternalFileScheme,
4978 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4979 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414980 }
4981#endif // defined(OS_CHROMEOS)
4982
Ken Rockot6414c4d92017-11-08 19:58:324983#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464984 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4985 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324986 if (factory)
4987 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234988
4989 // This logic should match
4990 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314991 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234992 return;
Jay Civellic9bbf72d2018-03-24 01:58:314993
4994 Profile* profile =
4995 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4996 InstantService* instant_service =
4997 InstantServiceFactory::GetForProfile(profile);
4998 // The test below matches what's done by ShouldServiceRequestIOThread in
4999 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:465000 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:315001 factories->emplace(
5002 chrome::kChromeSearchScheme,
5003 content::CreateWebUIURLLoader(
5004 frame_host, chrome::kChromeSearchScheme,
5005 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:235006 }
Jay Civellic9bbf72d2018-03-24 01:58:315007
Chris Mumfordbae8a742018-03-01 23:02:235008 extensions::ChromeExtensionWebContentsObserver* web_observer =
5009 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
5010 web_contents);
5011
Karan Bhatia91928572018-03-06 01:18:075012 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
5013 // to the |web_contents|.
5014 if (!web_observer)
5015 return;
5016
Chris Mumfordbae8a742018-03-01 23:02:235017 const Extension* extension =
5018 web_observer->GetExtensionFromFrame(frame_host, false);
5019 if (!extension)
5020 return;
5021
Sam McNally7414eeb72018-09-03 04:05:305022 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:235023 // Support for chrome:// scheme if appropriate.
5024 if ((extension->is_extension() || extension->is_platform_app()) &&
5025 Manifest::IsComponentLocation(extension->location())) {
5026 // Components of chrome that are implemented as extensions or platform apps
5027 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:305028 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
5029 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
5030 }
5031 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
5032 (extension->is_platform_app() &&
5033 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:235034 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:025035 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
5036 // URLs. Hosted apps are not allowed because they are served via web servers
5037 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:305038 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
5039 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:025040 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:305041 }
5042 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:235043 factories->emplace(
5044 content::kChromeUIScheme,
5045 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
5046 std::move(allowed_webui_hosts)));
5047 }
Jay Civelli2578ebe2018-06-05 18:44:315048
5049 // Extension with a background page get file access that gets approval from
5050 // ChildProcessSecurityPolicy.
5051 extensions::ExtensionHost* host =
5052 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
5053 ->GetBackgroundHostForExtension(extension->id());
5054 if (host) {
5055 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
5056 render_process_id));
5057 }
Chris Mumfordbae8a742018-03-01 23:02:235058#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:325059}
5060
Ken Rockota0dfaca12018-02-15 07:26:255061bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:215062 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:255063 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:385064 int render_process_id,
Ken Rockota0dfaca12018-02-15 07:26:255065 bool is_navigation,
Ken Rockot1726e182019-02-28 09:48:565066 bool is_download,
Lukasz Anforowicz762733652018-09-28 14:48:265067 const url::Origin& request_initiator,
Clark DuVall8dc4e502018-09-07 01:51:125068 network::mojom::URLLoaderFactoryRequest* factory_request,
Clark DuValla5e25b752018-11-27 22:08:165069 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Clark DuVall8dc4e502018-09-07 01:51:125070 bool* bypass_redirect_checks) {
Reilly Grant24bf8332018-08-27 21:55:015071 bool use_proxy = false;
5072
Ken Rockota0dfaca12018-02-15 07:26:255073#if BUILDFLAG(ENABLE_EXTENSIONS)
5074 auto* web_request_api =
5075 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:215076 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:255077
5078 // NOTE: Some unit test environments do not initialize
5079 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:015080 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:125081 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:385082 web_request_api->MaybeProxyURLLoaderFactory(
5083 browser_context, frame, render_process_id, is_navigation,
Ken Rockot1726e182019-02-28 09:48:565084 is_download, factory_request, header_client);
Clark DuVall8dc4e502018-09-07 01:51:125085 if (bypass_redirect_checks)
5086 *bypass_redirect_checks = use_proxy_for_web_request;
5087 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:015088 }
Ken Rockota0dfaca12018-02-15 07:26:255089#endif
Reilly Grant24bf8332018-08-27 21:55:015090
Reilly Grantcc22e602018-09-07 15:25:205091 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Lukasz Anforowicz762733652018-09-28 14:48:265092 frame, is_navigation, request_initiator, factory_request);
Reilly Grant24bf8332018-08-27 21:55:015093
5094 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:255095}
5096
Jian Lide7b43792018-06-01 23:22:135097std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
5098ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
5099 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:145100 int frame_tree_node_id,
5101 const scoped_refptr<network::SharedURLLoaderFactory>&
5102 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:135103 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
5104 interceptors;
5105#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:235106 interceptors.push_back(
5107 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
5108 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:135109#endif
Ryan Sturmaf523742019-01-16 00:15:455110
Robert Ogden3d5d5b42019-04-22 05:13:115111 ChromeNavigationUIData* chrome_navigation_ui_data =
5112 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5113
Ryan Sturm27d93f412019-02-15 21:30:145114 // TODO(ryansturm): Once this is on the UI thread, stop passing
5115 // |network_loader_factory| and have interceptors create one themselves.
5116 // https://crbug.com/931786
John Abd-El-Malek7577f262019-06-10 21:23:235117 if (base::FeatureList::IsEnabled(
Ryan Sturmaf523742019-01-16 00:15:455118 previews::features::kHTTPSServerPreviewsUsingURLLoader)) {
5119 interceptors.push_back(
5120 std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:115121 network_loader_factory,
5122 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
5123 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:455124 }
5125
Jian Lide7b43792018-06-01 23:22:135126 return interceptors;
5127}
5128
Yutaka Hirano8e0b4d432019-07-04 07:12:385129bool ChromeContentBrowserClient::WillInterceptWebSocket(
5130 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:335131#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:385132 if (!frame) {
5133 return false;
5134 }
5135 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:335136 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
5137 frame->GetProcess()->GetBrowserContext());
5138
5139 // NOTE: Some unit test environments do not initialize
5140 // BrowserContextKeyedAPI factories for e.g. WebRequest.
5141 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:385142 return false;
Yutaka Hirano36c94952018-05-30 21:33:335143
Yutaka Hirano8e0b4d432019-07-04 07:12:385144 return web_request_api->MayHaveProxies();
5145#else
5146 return false;
5147#endif
5148}
5149
5150void ChromeContentBrowserClient::CreateWebSocket(
5151 content::RenderFrameHost* frame,
5152 WebSocketFactory factory,
5153 const GURL& url,
5154 const GURL& site_for_cookies,
5155 const base::Optional<std::string>& user_agent,
5156 network::mojom::WebSocketHandshakeClientPtr handshake_client) {
5157#if BUILDFLAG(ENABLE_EXTENSIONS)
5158 if (!frame) {
5159 return;
5160 }
5161 auto* web_request_api =
5162 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
5163 frame->GetProcess()->GetBrowserContext());
5164
5165 DCHECK(web_request_api);
5166 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
5167 site_for_cookies, user_agent,
5168 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:335169#endif
5170}
5171
Maks Orlovich710d5e32019-07-09 20:16:455172bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
5173 content::BrowserContext* browser_context,
5174 const url::Origin& origin,
5175 bool is_service_worker,
5176 int process_id,
5177 int routing_id,
5178 network::mojom::RestrictedCookieManagerRequest* request) {
5179 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5180#if BUILDFLAG(ENABLE_EXTENSIONS)
5181 if (origin.scheme() == extensions::kExtensionScheme) {
5182 extensions::ChromeExtensionCookies::Get(browser_context)
5183 ->CreateRestrictedCookieManager(origin, std::move(*request));
5184 return true;
5185 }
5186#endif
5187 return false;
5188}
5189
Matt Menkeae4fdb12018-06-02 06:32:545190void ChromeContentBrowserClient::OnNetworkServiceCreated(
5191 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:535192 PrefService* local_state;
5193 if (g_browser_process) {
5194 DCHECK(g_browser_process->local_state());
5195 local_state = g_browser_process->local_state();
5196 } else {
Xi Han85079c22019-04-18 21:43:055197 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
5198 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:535199 }
5200
5201 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
5202 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
5203
Henrique Nakashimaa3b1c5d2019-07-03 19:25:495204 // Create SystemNetworkContextManager if it has not been created yet. We need
5205 // to set up global NetworkService state before anything else uses it and this
5206 // is the first opportunity to initialize SystemNetworkContextManager with the
5207 // NetworkService.
5208 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:535209 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:075210
Min Qin8caab1d2018-10-03 17:28:135211 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:545212 network_service);
5213}
5214
Ken Rockota0dfaca12018-02-15 07:26:255215network::mojom::NetworkContextPtr
5216ChromeContentBrowserClient::CreateNetworkContext(
5217 content::BrowserContext* context,
5218 bool in_memory,
5219 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:505220 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:455221 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:255222}
5223
Robert Sesek34f68f312019-01-14 20:25:115224std::vector<base::FilePath>
5225ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
5226 base::FilePath user_data_dir;
5227 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
5228 DCHECK(!user_data_dir.empty());
5229
5230 base::FilePath cache_dir;
5231 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
5232 DCHECK(!cache_dir.empty());
5233
5234 // On some platforms, the cache is a child of the user_data_dir so only
5235 // return the one path.
5236 if (user_data_dir.IsParent(cache_dir))
5237 return {user_data_dir};
5238
5239 return {user_data_dir, cache_dir};
5240}
5241
Min Qin75ed6df2017-12-01 20:39:155242bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135243 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155244#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5245 // It is OK to load the saved offline copy, in MHTML format.
5246 ChromeNavigationUIData* chrome_navigation_ui_data =
5247 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5248 if (!chrome_navigation_ui_data)
5249 return false;
5250 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5251 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5252 return offline_page_data && offline_page_data->is_offline_page();
5253#else
5254 return false;
5255#endif
5256}
5257
Min Qin30a78a12017-12-06 01:29:135258bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5259 const GURL& url,
5260 const std::string& mime_type) {
5261#if BUILDFLAG(ENABLE_EXTENSIONS)
5262 // Special-case user scripts to get downloaded instead of viewed.
5263 return extensions::UserScript::IsURLUserScript(url, mime_type);
5264#else
5265 return false;
5266#endif
5267}
5268
Donna Wu838ac362018-08-10 10:36:335269void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345270 content::RenderFrameHost* render_frame_host,
Donna Wu838ac362018-08-10 10:36:335271 mojo::InterfaceRequest<blink::mojom::WebUsbService> request) {
Reilly Grantc31b8192017-12-15 19:54:345272 if (!base::FeatureList::IsEnabled(features::kWebUsb))
5273 return;
5274
Reilly Grantc31b8192017-12-15 19:54:345275 WebContents* web_contents =
5276 WebContents::FromRenderFrameHost(render_frame_host);
5277 if (!web_contents) {
5278 NOTREACHED();
5279 return;
5280 }
5281
5282 UsbTabHelper* tab_helper =
5283 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Donna Wu838ac362018-08-10 10:36:335284 tab_helper->CreateWebUsbService(render_frame_host, std::move(request));
Reilly Grantc31b8192017-12-15 19:54:345285}
5286
Reilly Grant0d282322019-01-29 02:42:585287#if !defined(OS_ANDROID)
5288content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5289 if (!serial_delegate_)
5290 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5291 return serial_delegate_.get();
5292}
Matt Reynolds93616f9b2019-06-07 01:28:525293
5294content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5295 if (!hid_delegate_)
5296 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5297 return hid_delegate_.get();
5298}
Reilly Grant0d282322019-01-29 02:42:585299#endif
5300
Balazs Engedya7ff70982018-06-04 18:14:475301std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5302ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:225303 content::RenderFrameHost* render_frame_host,
5304 const std::string& relying_party_id) {
5305 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
5306 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:475307}
5308
Martin Kreichgauerbcfda9cf2018-08-02 00:47:075309#if defined(OS_MACOSX)
5310bool ChromeContentBrowserClient::
5311 IsWebAuthenticationTouchIdAuthenticatorSupported() {
5312 return true;
5313}
5314#endif
5315
Jun Cai9409ded2018-01-30 00:19:465316std::unique_ptr<net::ClientCertStore>
5317ChromeContentBrowserClient::CreateClientCertStore(
5318 content::ResourceContext* resource_context) {
5319 if (!resource_context)
5320 return nullptr;
5321 return ProfileIOData::FromResourceContext(resource_context)
5322 ->CreateClientCertStore();
5323}
5324
David Benjamineced01fc2019-02-27 18:29:025325std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395326ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585327 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025328 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035329 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245330 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395331 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035332 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395333 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565334 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:035335 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:025336 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:205337 std::move(response_headers), LoginHandler::PRE_COMMIT,
5338 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:395339}
5340
John Abd-El-Maleka67add82018-03-09 18:22:015341bool ChromeContentBrowserClient::HandleExternalProtocol(
5342 const GURL& url,
5343 content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
5344 int child_id,
5345 content::NavigationUIData* navigation_data,
5346 bool is_main_frame,
5347 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455348 bool has_user_gesture,
Clark DuVallb6042ed32019-07-15 17:20:455349 network::mojom::URLLoaderFactoryPtr* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015350#if BUILDFLAG(ENABLE_EXTENSIONS)
5351 // External protocols are disabled for guests. An exception is made for the
5352 // "mailto" protocol, so that pages that utilize it work properly in a
5353 // WebView.
5354 ChromeNavigationUIData* chrome_data =
5355 static_cast<ChromeNavigationUIData*>(navigation_data);
5356 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5357 (chrome_data &&
5358 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5359 !url.SchemeIs(url::kMailToScheme)) {
5360 return false;
5361 }
5362#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5363
5364#if defined(OS_ANDROID)
5365 // Main frame external protocols are handled by
5366 // InterceptNavigationResourceThrottle.
5367 if (is_main_frame)
5368 return false;
5369#endif // defined(ANDROID)
5370
Eric Seckler8652dcd52018-09-20 10:42:285371 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
5372 base::BindOnce(&LaunchURL, url, web_contents_getter,
5373 page_transition, has_user_gesture));
John Abd-El-Maleka67add82018-03-09 18:22:015374 return true;
5375}
5376
Jennifer Apacible4f854a82018-04-06 22:22:115377std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285378ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5379 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115380#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
5381 defined(OS_CHROMEOS)
5382 // Note: content::OverlayWindow::Create() is defined by platform-specific
5383 // implementation in chrome/browser/ui/views. This layering hack, which goes
5384 // through //content and ContentBrowserClient, allows us to work around the
5385 // dependency constraints that disallow directly calling
5386 // chrome/browser/ui/views code either from here or from other code in
5387 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285388 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115389#else
5390 return nullptr;
5391#endif
5392}
5393
Clark DuVallfffa41e2019-06-25 20:27:195394bool ChromeContentBrowserClient::IsSafeRedirectTargetOnIO(
Clark DuVallbf7722f2018-08-03 18:03:335395 const GURL& url,
5396 content::ResourceContext* context) {
Clark DuVallfffa41e2019-06-25 20:27:195397 DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
Clark DuVallbf7722f2018-08-03 18:03:335398#if BUILDFLAG(ENABLE_EXTENSIONS)
5399 if (url.SchemeIs(extensions::kExtensionScheme)) {
5400 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
5401 const Extension* extension =
5402 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
5403 if (!extension)
5404 return false;
5405 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5406 extension, url.path());
5407 }
5408#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5409 return true;
5410}
5411
Clark DuVallfffa41e2019-06-25 20:27:195412bool ChromeContentBrowserClient::IsSafeRedirectTarget(
5413 const GURL& url,
5414 content::BrowserContext* context) {
5415#if BUILDFLAG(ENABLE_EXTENSIONS)
5416 if (url.SchemeIs(extensions::kExtensionScheme)) {
5417 const Extension* extension = extensions::ExtensionRegistry::Get(context)
5418 ->enabled_extensions()
5419 .GetByID(url.host());
5420 if (!extension)
5421 return false;
5422 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5423 extension, url.path());
5424 }
5425#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5426 return true;
5427}
5428
Kunihiko Sakamoto19aa7082019-02-25 03:14:435429void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565430 content::BrowserContext* browser_context,
Leon Hanf4003a162019-01-28 05:31:585431 blink::mojom::RendererPreferenceWatcherPtr watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565432 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435433 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5434 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565435}
5436
dbeam25472e0c2017-06-23 19:02:315437// Static; handles rewriting Web UI URLs.
5438bool ChromeContentBrowserClient::HandleWebUI(
5439 GURL* url,
5440 content::BrowserContext* browser_context) {
5441 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
5442 if (url->SchemeIs(content::kChromeUIScheme) &&
5443 (url->host() == chrome::kChromeUIHelpHost ||
5444 (url->host() == chrome::kChromeUIUberHost &&
5445 (url->path().empty() || url->path() == "/")))) {
5446 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5447 chrome::kChromeUIHelpHost);
5448 return true; // Return true to update the displayed URL.
5449 }
5450
5451 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5452 browser_context, *url)) {
5453 return false;
5454 }
5455
5456#if defined(OS_CHROMEOS)
5457 // Special case : in ChromeOS in Guest mode bookmarks and history are
5458 // disabled for security reasons. New tab page explains the reasons, so
5459 // we redirect user to new tab page.
5460 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5461 if (url->SchemeIs(content::kChromeUIScheme) &&
5462 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5463 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5464 // Rewrite with new tab URL
5465 *url = GURL(chrome::kChromeUINewTabURL);
5466 }
5467 }
5468#endif
5469
5470 return true;
5471}
5472
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065473bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5474 content::BrowserContext* browser_context,
5475 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325476 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065477#if defined(OS_ANDROID)
5478 return false;
5479#else
5480 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5481 ->GetForBrowserContext(browser_context)
5482 ->ShowPaymentHandlerWindow(url, std::move(callback));
5483 return true;
5484#endif
5485}
5486
dbeam25472e0c2017-06-23 19:02:315487// Static; reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
5488// "chrome://foo/".
5489bool ChromeContentBrowserClient::HandleWebUIReverse(
5490 GURL* url,
5491 content::BrowserContext* browser_context) {
5492 // No need to actually reverse-rewrite the URL, but return true to update the
5493 // displayed URL when rewriting chrome://help to chrome://settings/help.
5494 return url->SchemeIs(content::kChromeUIScheme) &&
5495 url->host() == chrome::kChromeUISettingsHost;
5496}
5497
Dan Beamf0a7e112019-06-07 18:40:585498const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
5499 return ui::NativeTheme::GetInstanceForWeb();
5500}
5501
scottmgde42fb92017-02-10 17:56:035502// static
michaeln10e5fc352017-02-07 02:07:585503void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
5504 const storage::QuotaSettings* settings) {
5505 g_default_quota_settings = settings;
5506}
Yuzhu Shen44094e22017-07-18 22:52:355507
5508safe_browsing::UrlCheckerDelegate*
Yuzhu Shencb3011f62018-02-08 02:51:505509ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
5510 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:355511 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5512
Yuzhu Shencb3011f62018-02-08 02:51:505513 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
5514 if (!io_data->safe_browsing_enabled()->GetValue())
5515 return nullptr;
5516
Yuzhu Shen44094e22017-07-18 22:52:355517 // |safe_browsing_service_| may be unavailable in tests.
5518 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5519 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435520 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355521 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435522 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355523 }
5524
5525 return safe_browsing_url_checker_delegate_.get();
5526}
Daniel Vogelheim6008f572018-09-24 14:35:145527
5528base::Optional<std::string>
5529ChromeContentBrowserClient::GetOriginPolicyErrorPage(
5530 content::OriginPolicyErrorReason error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185531 content::NavigationHandle* handle) {
5532 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5533 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145534}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525535
5536bool ChromeContentBrowserClient::CanIgnoreCertificateErrorIfNeeded() {
5537 // We require --user-data-dir flag too so that no dangerous changes are made
5538 // in the user's regular profile.
5539 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5540 switches::kUserDataDir);
5541}
rajendrantfeea8592018-10-19 18:26:065542
5543void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5544 int32_t network_traffic_annotation_id_hash,
5545 int64_t recv_bytes,
5546 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035547 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5548 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5549 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5550 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065551 }
5552}
Ryan Sturmaa05092f2018-10-21 03:56:545553
5554content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5555 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395556 content::NavigationHandle* navigation_handle,
5557 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135558 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5559 initial_state, navigation_handle, current_navigation_url);
5560
5561 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5562}
5563
5564content::PreviewsState
5565ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5566 content::PreviewsState initial_state,
5567 content::NavigationHandle* navigation_handle,
5568 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545569 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295570 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215571
Ryan Sturmaa05092f2018-10-21 03:56:545572 // If this is not a main frame, return the initial state. If there are no
5573 // previews in the state, return the state as is.
5574 if (!navigation_handle->IsInMainFrame() ||
5575 navigation_handle->IsSameDocument()) {
5576 return initial_state;
5577 }
5578
Robert Ogdena994eb42019-02-14 19:15:085579 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395580 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085581
5582 // Do not allow previews on POST navigations since the primary opt-out
5583 // mechanism is to reload the page. Because POST navigations are not
5584 // idempotent, we do not want to show a preview on a POST navigation where
5585 // opting out would cause another navigation, i.e.: a reload.
5586 if (navigation_handle->IsPost())
5587 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395588
5589 content::WebContents* web_contents = navigation_handle->GetWebContents();
5590 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5591
Ryan Sturmda2a0e02018-10-25 01:52:215592 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545593
5594 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5595 Profile::FromBrowserContext(browser_context));
5596 auto* data_reduction_proxy_settings =
5597 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5598 browser_context);
5599 // If the profile does not support previews or Data Saver, do not turn on
5600 // Previews.
5601 if (!previews_service || !previews_service->previews_ui_service() ||
5602 !data_reduction_proxy_settings) {
5603 return content::PREVIEWS_OFF;
5604 }
5605
5606 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215607 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545608 // If this tab does not have a PreviewsUITabHelper, no preview should be
5609 // served.
5610 if (!ui_tab_helper)
5611 return content::PREVIEWS_OFF;
5612
5613 DCHECK(!browser_context->IsOffTheRecord());
5614
5615 // Other previews objects should all exist and be initialized if we have made
5616 // it past earlier checks.
5617 previews::PreviewsDeciderImpl* previews_decider_impl =
5618 previews_service->previews_ui_service()->previews_decider_impl();
5619 DCHECK(previews_decider_impl);
5620
Ryan Sturm647d1d92018-11-07 15:41:395621 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545622 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5623
Ryan Sturm647d1d92018-11-07 15:41:395624 previews::PreviewsUserData* previews_data =
5625 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5626
5627 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315628 // previews) and cannot re-evaluate PreviewsState once previews triggering
5629 // logic has already been run, so they should not change. Assume that
5630 // previews triggering logic has run when PreviewsUserData already exists and
5631 // a Lite Page Redirect preview is not being attempted, since it may also
5632 // create a previews_data before this point.
5633 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395634 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315635 previews_triggering_logic_already_ran =
5636 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395637 } else {
5638 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5639 navigation_handle, previews_decider_impl->GeneratePageId());
5640 }
5641
5642 DCHECK(previews_data);
5643
Robert Ogden01770b362019-05-22 17:36:435644 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5645 previews::switches::kForceEnablePreviews)) {
5646 previews_decider_impl->LoadPageHints(current_navigation_url);
5647 return content::ALL_SUPPORTED_PREVIEWS;
5648 }
5649
Ryan Sturmaa05092f2018-10-21 03:56:545650 bool is_reload =
5651 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5652
Ryan Sturm647d1d92018-11-07 15:41:395653 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515654 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395655
5656 // For now, treat server previews types as a single decision, and do not
5657 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5658 // header, nor does the plumbing exist to modify the PreviewsState within the
5659 // URLLoader.
Seanac57e9b92019-04-29 19:19:315660 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395661 // Copy the server state that was used before the redirect for the initial
5662 // URL.
Robert Ogden869986f2019-06-20 19:12:055663 previews_state |=
5664 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395665 } else {
Doug Arnetta3dc71582018-11-08 00:25:105666 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Ryan Sturm647d1d92018-11-07 15:41:395667 previews_data, current_navigation_url, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305668 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395669 previews_state |= server_previews_enabled_state;
5670 }
Ryan Sturmaa05092f2018-10-21 03:56:545671 }
5672
Robert Ogden198d6572019-06-26 15:15:335673 // Evaluate Offline, NoScript, and ResourceBlocking previews.
Ryan Sturmaa05092f2018-10-21 03:56:545674 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315675 previews_data, previews_triggering_logic_already_ran,
Ryan Sturmaa05092f2018-10-21 03:56:545676 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
Ryan Sturm37b3069e2019-02-22 04:11:245677 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545678
5679 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395680 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545681 return content::PREVIEWS_OFF;
5682 }
5683
5684 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395685 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545686 return content::PREVIEWS_NO_TRANSFORM;
5687 }
5688
5689 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395690 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5691 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545692 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395693 }
5694
5695 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5696 if (delegate) {
5697 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5698 }
Ryan Sturmaa05092f2018-10-21 03:56:545699
5700 // If the allowed previews are limited by the embedder, ensure previews honors
5701 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395702 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5703 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545704 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5705 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5706 previews_state = content::PREVIEWS_OFF;
5707 }
Ryan Sturm647d1d92018-11-07 15:41:395708 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545709 return previews_state;
5710}
5711
5712// static
5713content::PreviewsState
5714ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5715 const GURL& url,
5716 data_reduction_proxy::DataReductionProxyData* drp_data,
5717 previews::PreviewsUserData* previews_user_data,
5718 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055719 content::PreviewsState initial_state,
5720 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545721 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5722 if (!previews::HasEnabledPreviews(initial_state))
5723 return content::PREVIEWS_OFF;
5724
5725 // Check if the server sent a preview directive.
5726 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555727 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545728
Ryan Sturmaa05092f2018-10-21 03:56:545729 // Check the various other client previews types.
5730 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055731 previews_user_data, url, previews_state, previews_decider,
5732 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545733}
5734
5735content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5736 content::PreviewsState initial_state,
5737 content::NavigationHandle* navigation_handle,
5738 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135739 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5740 initial_state, navigation_handle, response_headers);
5741
5742 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5743}
5744
5745content::PreviewsState
5746ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5747 content::PreviewsState initial_state,
5748 content::NavigationHandle* navigation_handle,
5749 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5751 // Only support HTTP and HTTPS.
5752 if (navigation_handle->IsErrorPage() ||
5753 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5754 return content::PREVIEWS_OFF;
5755 }
5756
5757 // If this is not a main frame, return the initial state. If there are no
5758 // previews in the state, return the state as is.
5759 if (!previews::HasEnabledPreviews(initial_state) ||
5760 !navigation_handle->IsInMainFrame() ||
5761 navigation_handle->IsSameDocument()) {
5762 return initial_state;
5763 }
5764
5765 // WebContents that don't have a PreviewsUITabHelper are not supported.
5766 PreviewsUITabHelper* ui_tab_helper =
5767 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5768 if (!ui_tab_helper)
5769 return content::PREVIEWS_OFF;
5770
5771 // If we did not previously create a PreviewsUserData, do not go any further.
5772 previews::PreviewsUserData* previews_user_data =
5773 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5774 if (!previews_user_data)
5775 return content::PREVIEWS_OFF;
5776
5777 PreviewsService* previews_service =
5778 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5779 navigation_handle->GetWebContents()->GetBrowserContext()));
5780
5781 if (!previews_service || !previews_service->previews_ui_service())
5782 return content::PREVIEWS_OFF;
5783
5784// Check if offline previews are being used and set it in the user data.
5785#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5786 offline_pages::OfflinePageTabHelper* tab_helper =
5787 offline_pages::OfflinePageTabHelper::FromWebContents(
5788 navigation_handle->GetWebContents());
5789
Ryan Sturmfc7d92f2019-02-12 02:24:235790 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5791 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5792
5793 // If this is an offline page, but not a preview, then we should not attempt
5794 // any previews or surface the previews UI.
5795 if (is_offline_page && !is_offline_preview)
5796 return content::PREVIEWS_OFF;
5797
5798 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545799#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5800
5801 // Annotate request if no-transform directive found in response headers.
5802 if (response_headers &&
5803 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265804 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545805 }
5806
5807 previews::PreviewsDeciderImpl* previews_decider_impl =
5808 previews_service->previews_ui_service()->previews_decider_impl();
5809 DCHECK(previews_decider_impl);
5810
Clark DuVall9c5a72cc2018-10-25 01:29:215811 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5812 auto* settings =
5813 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5814 navigation_handle->GetWebContents()->GetBrowserContext());
5815 if (settings) {
5816 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5817 // does not yet have all the response information.
5818 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5819 response_headers);
5820 }
Ryan Sturmaa05092f2018-10-21 03:56:545821
5822 // Determine effective PreviewsState for this committed main frame response.
5823 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215824 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055825 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545826
5827 // Double check that we never serve a preview when we have a
5828 // cache-control:no-transform directive.
5829 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5830 !previews::HasEnabledPreviews(committed_state));
5831
Robert Ogdended292c6f2019-05-03 22:44:515832 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545833 previews_user_data->set_committed_previews_state(committed_state);
5834
5835 previews::PreviewsType committed_type =
5836 previews::GetMainFramePreviewsType(committed_state);
5837
5838 // Capture committed previews type, if any, in PreviewsUserData.
5839 // Note: this is for the subset of previews types that are decided upon
5840 // navigation commit. Previews types that are determined prior to
5841 // navigation (such as for offline pages or for redirecting to another
5842 // url), are not set here.
5843 previews_user_data->SetCommittedPreviewsType(committed_type);
5844
5845 // Log the commit decision.
5846 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5847 previews_decider_impl->LogPreviewDecisionMade(
5848 (previews_user_data->cache_control_no_transform_directive()
5849 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5850 : previews::PreviewsEligibilityReason::COMMITTED),
5851 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055852 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055853 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545854
5855 return committed_state;
5856}
Charlie Harrison650e11422018-12-04 00:37:265857
5858void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5859 content::RenderFrameHost* render_frame_host,
5860 blink::mojom::WebFeature feature) {
5861 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5862 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5863 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5864 render_frame_host, new_features);
5865}
Yutaka Hirano968d6252018-12-04 05:09:315866
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525867std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315868 return ::GetProduct();
5869}
5870
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525871std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315872 return ::GetUserAgent();
5873}
Sam McNallyd54e23f92019-01-16 04:42:395874
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525875blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175876 return ::GetUserAgentMetadata();
5877}
5878
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525879base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275880 // This icon is available on Android, but adds 19KiB to the APK. Since it
5881 // isn't used on Android we exclude it to avoid bloat.
5882#if !defined(OS_ANDROID)
5883 return base::Optional<gfx::ImageSkia>(
5884 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5885 IDR_PRODUCT_LOGO_256));
5886#else
5887 return base::nullopt;
5888#endif
5889}
5890
Sam McNallyd54e23f92019-01-16 04:42:395891bool ChromeContentBrowserClient::IsBuiltinComponent(
5892 content::BrowserContext* browser_context,
5893 const url::Origin& origin) {
5894#if BUILDFLAG(ENABLE_EXTENSIONS)
5895 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5896 browser_context, origin);
5897#else
5898 return false;
5899#endif
5900}
Oleg Davydov2cc0167b2019-02-05 14:32:485901
5902bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5903 const GURL& url,
5904 content::BrowserContext* context) {
5905 PolicyBlacklistService* service =
5906 PolicyBlacklistFactory::GetForBrowserContext(context);
5907
5908 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5909 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5910 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5911}
Dominic Mazzoni21fb0282019-02-13 18:32:475912
5913ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5914 content::BrowserContext* browser_context) {
5915 Profile* profile = Profile::FromBrowserContext(browser_context);
5916 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5917}
Eric Karld6cd75b2019-03-14 22:01:365918
5919#if defined(OS_ANDROID)
5920content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525921ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365922 if (features::UseDisplayWideColorGamut()) {
5923 return WideColorGamutHeuristic::kUseDisplay;
5924 }
5925 return WideColorGamutHeuristic::kNone;
5926}
5927#endif
Ehsan Karamad91413d72019-03-22 16:37:485928
5929base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435930ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Ehsan Karamad91413d72019-03-22 16:37:485931 content::ResourceContext* resource_context) {
5932 base::flat_set<std::string> mime_types;
5933#if BUILDFLAG(ENABLE_PLUGINS)
5934 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(resource_context);
5935 for (const auto& pair : map)
5936 mime_types.insert(pair.first);
5937#endif
5938 return mime_types;
5939}
Yao Xiaod06607b2019-05-02 23:16:365940
5941void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5942 const content::WebContents* web_contents,
5943 const content::RenderFrameHost* frame_host,
5944 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525945 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365946 const ChromeSubresourceFilterClient* client =
5947 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5948 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
5949 if (!user_gesture) {
5950 if (base::FeatureList::IsEnabled(
5951 blink::features::
5952 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5953 download_policy->SetDisallowed(
5954 content::NavigationDownloadType::kAdFrameNoGesture);
5955 } else {
5956 download_policy->SetAllowed(
5957 content::NavigationDownloadType::kAdFrameNoGesture);
5958 }
5959 } else {
5960 download_policy->SetAllowed(
5961 content::NavigationDownloadType::kAdFrameGesture);
5962 }
5963 }
5964}
Jun Cai732a05e32019-05-29 19:34:195965
5966bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5967 content::BrowserContext* browser_context,
5968 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525969 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195970 const HostContentSettingsMap* const content_settings =
5971 HostContentSettingsMapFactory::GetForProfile(
5972 Profile::FromBrowserContext(browser_context));
5973
5974 if (content_settings->GetContentSetting(
5975 requesting_origin.GetURL(), embedding_origin.GetURL(),
5976 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING,
5977 std::string()) == CONTENT_SETTING_BLOCK) {
5978 return true;
5979 }
5980
5981 return false;
5982}
5983
5984void ChromeContentBrowserClient::BlockBluetoothScanning(
5985 content::BrowserContext* browser_context,
5986 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525987 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195988 HostContentSettingsMap* const content_settings =
5989 HostContentSettingsMapFactory::GetForProfile(
5990 Profile::FromBrowserContext(browser_context));
5991
5992 content_settings->SetContentSettingDefaultScope(
5993 requesting_origin.GetURL(), embedding_origin.GetURL(),
5994 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(),
5995 CONTENT_SETTING_BLOCK);
5996}