blob: df37ef820f0599e948942ba44fd6f8c9f775a548 [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"
Robbie McElrath127ad2b2019-07-22 22:38:11132#include "chrome/browser/signin/header_modification_delegate_on_io_thread_impl.h"
133#include "chrome/browser/signin/header_modification_delegate_on_ui_thread_impl.h"
Lukasz Anforowiczfd30af32019-03-28 17:33:28134#include "chrome/browser/site_isolation/site_isolation_policy.h"
[email protected]c52b2892012-03-07 11:01:02135#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
Katie D840d9532018-11-27 06:20:48136#include "chrome/browser/speech/tts_controller_delegate_impl.h"
[email protected]7a06d282013-05-03 04:39:33137#include "chrome/browser/speech/tts_message_filter.h"
Eric Lawrenced0acf2a7c2017-07-20 18:02:48138#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
[email protected]848dd042011-06-04 18:24:03139#include "chrome/browser/ssl/ssl_blocking_page.h"
estark3ba11132015-04-10 01:38:33140#include "chrome/browser/ssl/ssl_cert_reporter.h"
Joe DeBlasio9b996292019-01-31 05:09:32141#include "chrome/browser/ssl/ssl_client_auth_metrics.h"
[email protected]25af6ec2014-06-06 19:35:07142#include "chrome/browser/ssl/ssl_client_certificate_selector.h"
meacer4ef065e2015-01-09 03:21:35143#include "chrome/browser/ssl/ssl_error_handler.h"
Lucas Garron94b16052017-11-11 01:58:12144#include "chrome/browser/ssl/ssl_error_navigation_throttle.h"
Christopher Thompson4137cec2017-12-19 05:34:23145#include "chrome/browser/ssl/typed_navigation_timing_throttle.h"
csharrison77bf8342017-05-04 18:23:10146#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
meacer4ef065e2015-01-09 03:21:35147#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:45148#include "chrome/browser/tab_contents/tab_util.h"
oysteinec563c582015-02-13 19:19:52149#include "chrome/browser/tracing/chrome_tracing_delegate.h"
Dave Tapuskac6627e12018-08-30 15:07:19150#include "chrome/browser/translate/translate_service.h"
[email protected]916615b2013-09-11 18:19:44151#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
Charlie Harrison804659a2018-10-16 16:43:38152#include "chrome/browser/ui/blocked_content/popup_blocker.h"
Charles Harrison6dd11d282017-10-03 06:14:51153#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
thestige80821242015-09-30 23:46:08154#include "chrome/browser/ui/browser_navigator.h"
155#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]a28e3302013-02-03 03:50:43156#include "chrome/browser/ui/chrome_select_file_policy.h"
Jun Caibc561f412018-02-28 18:41:39157#include "chrome/browser/ui/login/login_handler.h"
Makoto Shimazuc7502932018-08-15 02:12:56158#include "chrome/browser/ui/prefs/pref_watcher.h"
[email protected]329ac972013-06-21 15:24:25159#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:44160#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
Dan Beamf0a7e112019-06-07 18:40:58161#include "chrome/browser/ui/ui_features.h"
[email protected]863f70a2012-01-27 02:05:50162#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
dbeambaee5bd2015-09-26 03:07:01163#include "chrome/browser/ui/webui/log_web_ui_url.h"
reillyg3ff45322015-10-23 21:16:25164#include "chrome/browser/usb/usb_tab_helper.h"
Ian Vollick6243dfe02018-03-08 01:08:53165#include "chrome/browser/vr/vr_tab_helper.h"
Giovanni Ortuño Urquididcd38852019-03-07 08:08:25166#include "chrome/browser/web_applications/components/app_registrar.h"
167#include "chrome/browser/web_applications/web_app_provider.h"
Scott Violet6200d332018-02-23 21:29:23168#include "chrome/common/buildflags.h"
sdefresne9fb67692015-08-03 18:48:22169#include "chrome/common/channel_info.h"
[email protected]4a65826d2011-08-25 16:04:01170#include "chrome/common/chrome_constants.h"
chrisha927d8fe2017-01-18 23:09:51171#include "chrome/common/chrome_features.h"
[email protected]a7944aa2012-10-15 10:12:14172#include "chrome/common/chrome_paths.h"
Mythri Alle0b8de0d2018-10-22 11:06:22173#include "chrome/common/chrome_paths_internal.h"
[email protected]b80f68432011-05-02 17:22:30174#include "chrome/common/chrome_switches.h"
Ben Goodgere25ef852017-08-11 00:17:50175#include "chrome/common/constants.mojom.h"
[email protected]779dd282013-10-19 15:57:02176#include "chrome/common/env_vars.h"
John Abd-El-Malek9fb60492018-08-02 04:28:50177#include "chrome/common/google_url_loader_throttle.h"
[email protected]f1933792011-06-14 00:49:34178#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37179#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12180#include "chrome/common/pref_names.h"
John Abd-El-Malekd2377982018-01-08 22:23:12181#include "chrome/common/prerender_url_loader_throttle.h"
Egor Paskod52474c32018-06-19 12:03:22182#include "chrome/common/prerender_util.h"
[email protected]3e69bc82011-05-26 23:22:38183#include "chrome/common/render_messages.h"
nigeltao7cd8d5582016-12-12 06:05:28184#include "chrome/common/renderer_configuration.mojom.h"
falkenad185092016-06-16 06:10:02185#include "chrome/common/secure_origin_whitelist.h"
wittman832321f52016-10-10 18:18:38186#include "chrome/common/stack_sampling_configuration.h"
[email protected]c5dbef02011-05-13 05:06:09187#include "chrome/common/url_constants.h"
benc70c0e32016-09-22 03:50:37188#include "chrome/grit/browser_resources.h"
[email protected]af39f002014-08-22 10:18:18189#include "chrome/grit/generated_resources.h"
[email protected]264c0acac2013-10-01 13:33:30190#include "chrome/installer/util/google_update_settings.h"
leon.han04b276e2016-06-01 01:34:16191#include "components/autofill/content/browser/content_autofill_driver_factory.h"
brettwf1958912015-10-07 19:43:12192#include "components/autofill/core/common/autofill_switches.h"
msramek1c8e19d2017-01-04 20:04:53193#include "components/browsing_data/core/browsing_data_utils.h"
[email protected]649b57272014-05-09 14:54:44194#include "components/cdm/browser/cdm_message_filter_android.h"
Pavol Markob211ab22019-01-23 20:03:04195#include "components/certificate_matching/certificate_principal_pattern.h"
[email protected]09cff78782014-04-20 22:04:48196#include "components/cloud_devices/common/cloud_devices_switches.h"
Tao Bai02ab4dd42019-03-06 00:30:37197#include "components/content_capture/browser/content_capture_receiver_manager.h"
mukai8eaec822014-10-25 17:53:16198#include "components/content_settings/core/browser/content_settings_utils.h"
drogerb1716972015-06-30 09:04:09199#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:16200#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:52201#include "components/content_settings/core/common/content_settings.h"
jyasskin98bdd3992016-02-26 20:25:45202#include "components/content_settings/core/common/content_settings_types.h"
tbansal08a0e3e2017-06-30 21:30:08203#include "components/content_settings/core/common/content_settings_utils.h"
Daniel Vogelheim976f1c22017-11-22 16:26:03204#include "components/content_settings/core/common/pref_names.h"
Clark DuVall92335842018-10-10 16:49:09205#include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h"
Ryan Sturmaa05092f2018-10-21 03:56:54206#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
Clark DuVall92335842018-10-10 16:49:09207#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
Clark DuVall68eb997f2019-06-28 05:42:28208#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
rajendrant43194072019-04-15 22:13:43209#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
Clark DuVall92335842018-10-10 16:49:09210#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
Wojciech Dzierżanowski45380802019-04-29 14:50:32211#include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h"
wychene55687342015-11-13 20:17:03212#include "components/dom_distiller/core/dom_distiller_switches.h"
[email protected]474a5a32014-07-28 18:23:24213#include "components/dom_distiller/core/url_constants.h"
blundella5e3240a2016-01-05 11:30:43214#include "components/error_page/common/error_page_switches.h"
khushalsagarc5447db22017-08-22 17:53:01215#include "components/feature_engagement/public/feature_constants.h"
216#include "components/feature_engagement/public/feature_list.h"
John Abd-El-Malek9cf3d7f02018-07-27 02:40:39217#include "components/google/core/common/google_util.h"
Alexandre Frechette572755b2019-02-13 22:30:20218#include "components/language/core/browser/pref_names.h"
wittmane16da2782016-09-21 16:43:04219#include "components/metrics/call_stack_profile_collector.h"
[email protected]8e885de2014-07-22 23:36:53220#include "components/metrics/client_info.h"
Xiangjun Zhang45474842018-08-17 21:07:59221#include "components/mirroring/mojom/constants.mojom.h"
222#include "components/mirroring/service/features.h"
Scott Violet9ae82892018-03-01 18:38:12223#include "components/nacl/common/buildflags.h"
sammc2b0375b2016-12-22 01:26:17224#include "components/nacl/common/nacl_constants.h"
drogerc690e8802015-09-21 14:29:16225#include "components/net_log/chrome_net_log.h"
leon.han97e8f752016-09-06 06:13:20226#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:06227#include "components/payments/content/payment_request_display_manager.h"
Doug Turner9dcaf5962017-12-21 04:38:53228#include "components/policy/content/policy_blacklist_navigation_throttle.h"
Michael Giuffrida01d7b5d2018-08-21 07:55:54229#include "components/policy/content/policy_blacklist_service.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18230#include "components/policy/core/common/policy_service.h"
231#include "components/policy/policy_constants.h"
[email protected]f0c8c4992014-05-15 17:37:26232#include "components/pref_registry/pref_registry_syncable.h"
Chris Palmerac7d75642017-11-22 20:12:54233#include "components/prefs/pref_registry_simple.h"
brettwb1fc1b82016-02-02 00:19:08234#include "components/prefs/pref_service.h"
235#include "components/prefs/scoped_user_pref_update.h"
Ryan Sturmaa05092f2018-10-21 03:56:54236#include "components/previews/content/previews_decider_impl.h"
237#include "components/previews/content/previews_ui_service.h"
238#include "components/previews/content/previews_user_data.h"
239#include "components/previews/core/previews_decider.h"
240#include "components/previews/core/previews_experiments.h"
Ryan Sturmaf523742019-01-16 00:15:45241#include "components/previews/core/previews_features.h"
Robert Ogden01770b362019-05-22 17:36:43242#include "components/previews/core/previews_switches.h"
nzolghadrd87a308d2016-12-07 15:45:56243#include "components/rappor/public/rappor_utils.h"
nigeltao2f673762016-10-14 03:27:28244#include "components/rappor/rappor_recorder_impl.h"
nzolghadrd87a308d2016-12-07 15:45:56245#include "components/rappor/rappor_service_impl.h"
Yuzhu Shen44094e22017-07-18 22:52:35246#include "components/safe_browsing/browser/browser_url_loader_throttle.h"
247#include "components/safe_browsing/browser/mojo_safe_browsing_impl.h"
248#include "components/safe_browsing/browser/url_checker_delegate.h"
Nico Weberbc5b06f2019-07-26 14:00:13249#include "components/safe_browsing/buildflags.h"
timvolodine89cf11712017-05-15 18:05:07250#include "components/safe_browsing/common/safe_browsing_prefs.h"
Tim Volodinee45938472017-09-21 10:08:22251#include "components/safe_browsing/db/database_manager.h"
Yuzhu Shencb3011f62018-02-08 02:51:50252#include "components/safe_browsing/features.h"
Jialiu Linbdbb81d2017-10-11 21:29:09253#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
Daniel Vogelheim6008f572018-09-24 14:35:14254#include "components/security_interstitials/content/origin_policy_ui.h"
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"
Miyoung Shinea48f772019-07-19 01:20:27258#include "components/services/patch/public/mojom/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 Blundell3517170e2019-07-11 08:16:34261#include "components/signin/public/base/signin_pref_names.h"
Scott Violetd7983c52018-03-03 00:24:41262#include "components/spellcheck/spellcheck_buildflags.h"
csharrisone985ebc2017-04-04 17:05:03263#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
[email protected]eba93c92014-01-07 17:34:17264#include "components/translate/core/common/translate_switches.h"
rsleevi24f64dc22015-08-07 21:39:21265#include "components/url_formatter/url_fixer.h"
bmcquade5d2d9cf32015-06-19 17:42:28266#include "components/variations/variations_associated_data.h"
Jun Cai0e568632018-08-09 02:05:33267#include "components/variations/variations_http_header_provider.h"
Kyle Milkab5c048e2017-07-07 02:38:46268#include "components/variations/variations_switches.h"
sdefresne9fb67692015-08-03 18:48:22269#include "components/version_info/version_info.h"
[email protected]e0ada9c2012-03-20 03:54:43270#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30271#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38272#include "content/public/browser/browser_ppapi_host.h"
Eric Seckler8652dcd52018-09-20 10:42:28273#include "content/public/browser/browser_task_traits.h"
[email protected]30a306f42013-06-10 03:09:03274#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31275#include "content/public/browser/browser_url_handler.h"
msrameke169ccb2017-04-26 05:21:41276#include "content/public/browser/browsing_data_remover.h"
Lucas Garronb9539b732017-10-31 00:22:09277#include "content/public/browser/certificate_request_result_type.h"
[email protected]0c7193742012-11-07 19:05:03278#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59279#include "content/public/browser/child_process_security_policy.h"
davidben3b8455ae72015-03-11 19:42:19280#include "content/public/browser/client_certificate_delegate.h"
Jay Civelli2578ebe2018-06-05 18:44:31281#include "content/public/browser/file_url_loader.h"
Mohsen Izadi6a6476b72018-12-07 04:34:35282#include "content/public/browser/gpu_data_manager.h"
clamy40c9e142015-09-29 11:18:47283#include "content/public/browser/navigation_handle.h"
284#include "content/public/browser/navigation_throttle.h"
Jennifer Apacible4f854a82018-04-06 22:22:11285#include "content/public/browser/overlay_window.h"
[email protected]094c8772013-12-21 17:54:50286#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30287#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33288#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05289#include "content/public/browser/resource_context.h"
jam608f2992016-03-31 16:35:34290#include "content/public/browser/storage_partition.h"
Katie D840d9532018-11-27 06:20:48291#include "content/public/browser/tts_controller.h"
Katie D4713ee42018-11-30 01:48:27292#include "content/public/browser/tts_platform.h"
Jian Lide7b43792018-06-01 23:22:13293#include "content/public/browser/url_loader_request_interceptor.h"
adrian.belgun5b341c72016-06-22 22:24:08294#include "content/public/browser/vpn_service_proxy.h"
[email protected]91ee3682012-01-19 15:02:19295#include "content/public/browser/web_contents.h"
Ryan Sturmda2a0e02018-10-25 01:52:21296#include "content/public/browser/web_contents_delegate.h"
Chris Mumfordbae8a742018-03-01 23:02:23297#include "content/public/browser/web_ui_url_loader_factory.h"
[email protected]e0ada9c2012-03-20 03:54:43298#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18299#include "content/public/common/content_descriptors.h"
juncai1bf9f7c2016-03-22 20:46:56300#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40301#include "content/public/common/content_switches.h"
John Abd-El-Malek27b3ebd22019-02-12 18:59:18302#include "content/public/common/network_service_util.h"
bend32292b2016-10-07 00:21:58303#include "content/public/common/service_manager_connection.h"
ben51bb6c62016-11-17 20:15:57304#include "content/public/common/service_names.mojom.h"
Chris Mumfordbae8a742018-03-01 23:02:23305#include "content/public/common/url_constants.h"
[email protected]22aa4f82013-09-24 17:01:44306#include "content/public/common/url_utils.h"
Yutaka Hirano968d6252018-12-04 05:09:31307#include "content/public/common/user_agent.h"
[email protected]b3a97b52014-07-09 06:25:05308#include "content/public/common/web_preferences.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56309#include "content/public/common/window_container_type.mojom-shared.h"
Bill Orreb429222018-08-08 21:14:43310#include "device/vr/buildflags/buildflags.h"
Scott Violetc8240b02018-03-08 22:03:59311#include "extensions/buildflags/buildflags.h"
Alex Moshchukd252c192017-07-17 22:03:48312#include "google_apis/gaia/gaia_urls.h"
Andrew Moylan17329fc2017-09-25 07:43:30313#include "google_apis/google_api_keys.h"
ericrk41a1579e2017-02-10 20:56:28314#include "gpu/config/gpu_switches.h"
grunell086a4112017-03-02 09:23:04315#include "media/audio/audio_manager.h"
François Beaufort8c08979fc2018-03-05 13:06:31316#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44317#include "media/media_buildflags.h"
318#include "media/mojo/buildflags.h"
Jay Civelli2578ebe2018-06-05 18:44:31319#include "mojo/public/cpp/bindings/binding_set.h"
Shimi Zhang6b72d292019-07-12 20:52:42320#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Ken Rockot40a1df792019-05-08 22:15:52321#include "mojo/public/cpp/bindings/pending_receiver.h"
322#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot0adc1e42019-05-24 08:20:08323#include "mojo/public/cpp/bindings/remote.h"
engedyafef0482017-07-06 15:40:53324#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Bence Béky6b44abf2018-04-11 10:32:51325#include "net/base/load_flags.h"
[email protected]3b455502012-12-11 18:22:58326#include "net/base/mime_util.h"
John Abd-El-Malek7577f262019-06-10 21:23:23327#include "net/http/http_util.h"
Jun Cai9409ded2018-01-30 00:19:46328#include "net/ssl/client_cert_store.h"
[email protected]536fd0b2013-03-14 17:41:57329#include "net/ssl/ssl_cert_request_info.h"
Scott Violet02e38b92018-03-27 23:42:14330#include "ppapi/buildflags/buildflags.h"
[email protected]b7631cc2012-09-15 05:08:38331#include "ppapi/host/ppapi_host.h"
Scott Violet318a55f2018-03-30 19:08:19332#include "printing/buildflags/buildflags.h"
Andrew Moylan8ed9d83c82019-01-29 20:23:52333#include "services/image_annotation/public/mojom/constants.mojom.h"
334#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:37335#include "services/network/public/cpp/is_potentially_trustworthy.h"
Lukasz Anforowicz9527fd42019-03-13 19:08:50336#include "services/network/public/cpp/network_switches.h"
Yuzhu Shencb3011f62018-02-08 02:51:50337#include "services/network/public/cpp/resource_request.h"
Sam McNallye36abbc2017-07-20 01:04:28338#include "services/preferences/public/cpp/in_process_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33339#include "services/preferences/public/mojom/preferences.mojom.h"
Jay Civelli668c097f2018-05-16 20:44:13340#include "services/service_manager/embedder/switches.h"
erikchena9db3a72018-04-12 16:24:00341#include "services/service_manager/public/cpp/connector.h"
Ken Rockot543f5e32018-02-04 02:13:50342#include "services/service_manager/public/mojom/connector.mojom.h"
Tom Sepez15d4e5202017-09-27 23:59:05343#include "services/service_manager/sandbox/sandbox_type.h"
Andrew Comminos66057672019-05-01 00:03:34344#include "services/service_manager/sandbox/switches.h"
Ken Rockotcebdf9c82019-05-28 20:33:03345#include "services/strings/grit/services_strings.h"
pilgrime92c5fcd2014-09-10 23:31:23346#include "storage/browser/fileapi/external_mount_points.h"
John Delaneyac24e572019-04-30 19:47:02347#include "third_party/blink/public/common/features.h"
Minggang Wangf6840ecf2019-07-29 05:15:02348#include "third_party/blink/public/common/loader/url_loader_throttle.h"
Julie Jeongeun Kimd3d00a12019-03-25 01:46:25349#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h"
Leon Hanc819dc62019-01-28 04:30:19350#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
Mike West6e4cbb32019-02-13 09:40:17351#include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h"
Eric Willigers3eeae17c2019-03-13 17:32:10352#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
Evan Liu7cdbf8872019-06-19 16:47:21353#include "third_party/skia/include/core/SkColor.h"
Xiaohan Wangf170c732018-09-27 05:45:26354#include "third_party/widevine/cdm/buildflags.h"
Scott Violetb72577d2019-01-09 22:18:18355#include "ui/base/buildflags.h"
[email protected]c9b6eb62011-10-18 20:49:39356#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08357#include "ui/base/resource/resource_bundle.h"
Scott Violet8ff9c302018-02-22 22:28:35358#include "ui/base/ui_base_features.h"
Evan Liu7cdbf8872019-06-19 16:47:21359#include "ui/base/ui_base_switches.h"
360#include "ui/gfx/color_utils.h"
Elly Fong-Jonesf92897392019-01-24 16:05:49361#include "ui/native_theme/caption_style.h"
362#include "ui/native_theme/native_theme.h"
[email protected]b47dc492014-08-17 07:05:57363#include "ui/resources/grit/ui_resources.h"
jyasskin98bdd3992016-02-26 20:25:45364#include "url/gurl.h"
365#include "url/origin.h"
[email protected]d977f9c2011-03-14 16:10:26366
Ken Rockot69aade02019-01-23 21:19:51367#if BUILDFLAG(ENABLE_NACL)
368#include "components/nacl/loader/nacl_loader_manifest.h"
369#if defined(OS_WIN) && defined(ARCH_CPU_X86)
370#include "components/nacl/broker/nacl_broker_manifest.h"
371#endif
372#endif
373
[email protected]b48c9182011-10-26 18:03:30374#if defined(OS_WIN)
wfhc91e9672016-01-27 00:14:20375#include "base/strings/string_tokenizer.h"
[email protected]199fc7a2011-09-28 22:45:38376#include "chrome/browser/chrome_browser_main_win.h"
Patrick Monettebb543942019-05-17 17:45:32377#include "chrome/browser/win/conflicts/module_database.h"
378#include "chrome/browser/win/conflicts/module_event_sink_impl.h"
Jerry Lina0de7ce2018-06-22 15:18:36379#include "chrome/install_static/install_util.h"
Ken Rockotfba9e742018-02-10 16:36:20380#include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h"
Ken Rockot7c168502019-05-30 07:58:46381#include "components/services/quarantine/public/cpp/quarantine_features_win.h"
[email protected]34f48682013-03-20 00:30:18382#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38383#elif defined(OS_MACOSX)
384#include "chrome/browser/chrome_browser_main_mac.h"
Guido Urdaneta1a2917432018-05-10 18:32:32385#include "services/audio/public/mojom/constants.mojom.h"
[email protected]b48c9182011-10-26 18:03:30386#elif defined(OS_CHROMEOS)
Scott Violet776edf82017-09-29 02:03:01387#include "ash/public/interfaces/constants.mojom.h"
Scott Violet47f00e52018-05-04 22:50:31388#include "chrome/browser/ash_service_registry.h"
hashimotoa53e7e82016-10-26 06:30:47389#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h"
nyaf5df1e32016-12-14 04:36:17390#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h"
[email protected]b48c9182011-10-26 18:03:30391#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
Ahmed Fakhryd70bf37b2018-04-04 17:07:24392#include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h"
Scott Violetef765b92017-06-09 21:26:36393#include "chrome/browser/chromeos/chrome_service_name.h"
Sam McNallyd8b7d822018-08-21 03:18:18394#include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h"
[email protected]07fe2752014-01-29 11:21:55395#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]5bc61cad2014-07-08 05:05:08396#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]43420a12014-04-21 03:20:48397#include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
Robbie McElrath6a45ea62018-12-05 06:53:41398#include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h"
[email protected]f19bbf62013-07-09 01:22:32399#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]bee0df312014-04-28 06:59:58400#include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h"
clamy49678312015-10-22 21:59:00401#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
402#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Pavol Marko230ea2c92017-12-03 22:35:44403#include "chrome/browser/chromeos/login/signin_partition_manager.h"
[email protected]5c915252013-05-07 13:15:39404#include "chrome/browser/chromeos/login/startup_utils.h"
edwardjung7db1c9e2015-03-25 15:44:31405#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
John Abd-El-Malek21bca7c2018-10-26 22:13:33406#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
Pavol Marko230ea2c92017-12-03 22:35:44407#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]c94ac692013-07-27 00:50:10408#include "chrome/browser/chromeos/system/input_device_settings.h"
Katie Db2d07092018-12-04 18:59:36409#include "chrome/browser/speech/tts_chromeos.h"
Steven Bennetts81d07be2018-01-08 20:45:27410#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
Huanzhong Huangafa98092019-06-24 12:01:24411#include "chrome/browser/ui/ash/tablet_mode_client.h"
djacobo21e56e02016-07-02 01:14:31412#include "chrome/browser/ui/browser_dialogs.h"
Steven Bennetts38e9bde22019-01-03 17:31:10413#include "chromeos/constants/chromeos_constants.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21414#include "chromeos/constants/chromeos_features.h"
Steven Bennetts38e9bde22019-01-03 17:31:10415#include "chromeos/constants/chromeos_switches.h"
Kyle Horimoto1d6a679f2019-04-16 23:24:21416#include "chromeos/services/cellular_setup/cellular_setup_service.h"
417#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
418#include "chromeos/services/cellular_setup/public/mojom/constants.mojom.h"
Leo Zhang84ce09e92018-08-25 01:55:36419#include "chromeos/services/ime/public/mojom/constants.mojom.h"
Steven Bennetts0c565d5b2019-04-24 23:52:45420#include "chromeos/services/network_config/network_config_service.h"
421#include "chromeos/services/network_config/public/mojom/constants.mojom.h"
Ryan Hansberry9a08623c2018-06-14 21:28:05422#include "chromeos/services/secure_channel/public/mojom/constants.mojom.h"
423#include "chromeos/services/secure_channel/secure_channel_service.h"
Ian Barkley-Yeung550aae052019-07-11 00:11:11424#include "components/crash/content/app/breakpad_linux.h"
[email protected]4d390782014-08-15 09:22:58425#include "components/user_manager/user_manager.h"
Ken Rockot543f5e32018-02-04 02:13:50426#include "services/service_manager/public/mojom/interface_provider_spec.mojom.h"
[email protected]81ce2c42012-03-24 01:43:26427#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30428#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09429#elif defined(OS_ANDROID)
Bo Liu4ade6b1b22017-11-28 02:26:35430#include "base/android/application_status_listener.h"
zqzhang93e959d12017-03-16 13:10:20431#include "chrome/browser/android/app_hooks.h"
Scott Violetef765b92017-06-09 21:26:36432#include "chrome/browser/android/chrome_context_util.h"
433#include "chrome/browser/android/devtools_manager_delegate_android.h"
Dan Harrington964d48c2018-08-03 15:52:24434#include "chrome/browser/android/download/available_offline_content_provider.h"
Min Qin0ab0e162017-11-14 21:57:19435#include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h"
Scott Violetef765b92017-06-09 21:26:36436#include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
437#include "chrome/browser/android/service_tab_launcher.h"
438#include "chrome/browser/android/tab_android.h"
Jinsuk Kima3d393ce2019-05-27 00:57:42439#include "chrome/browser/android/tab_web_contents_delegate_android.h"
Scott Violetef765b92017-06-09 21:26:36440#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09441#include "chrome/browser/chrome_browser_main_android.h"
Dan Harrington954c8822019-01-09 18:40:48442#include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h"
Jinsuk Kim6f9253c2019-03-11 02:45:07443#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
James Cook01e3e5ef2019-04-09 14:44:38444#include "chrome/common/chrome_descriptors.h"
Xing Liu302e0652018-04-27 18:23:08445#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Joshua Peraza934e5592018-07-18 23:43:11446#include "components/crash/content/browser/child_exit_observer_android.h"
Yuzu Saijo2d12ef92018-08-21 04:52:07447#include "components/crash/content/browser/crash_memory_metrics_collector_android.h"
clamy40c9e142015-09-29 11:18:47448#include "components/navigation_interception/intercept_navigation_delegate.h"
Scott Violetef765b92017-06-09 21:26:36449#include "content/public/browser/android/java_interfaces.h"
mfomitchev220b8562017-07-13 23:08:54450#include "services/service_manager/public/cpp/interface_provider.h"
Han Leonabbe7c902018-08-30 02:08:10451#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Julie Jeongeun Kimb6a0a1f2019-03-21 05:08:26452#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
agrieve05398f52015-06-24 18:59:00453#include "ui/base/resource/resource_bundle_android.h"
Scott Violetef765b92017-06-09 21:26:36454#include "ui/base/ui_base_paths.h"
[email protected]b48c9182011-10-26 18:03:30455#elif defined(OS_POSIX)
456#include "chrome/browser/chrome_browser_main_posix.h"
457#endif
458
tmartinofb341882017-02-10 19:36:53459#if !defined(OS_ANDROID)
Jay Harris1ddcffa2019-07-09 03:07:40460#include "chrome/browser/badging/badge_manager.h"
Scott Violetef765b92017-06-09 21:26:36461#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
Dmitry Gozman57b92ce2017-12-28 22:24:54462#include "chrome/browser/devtools/devtools_window.h"
Becca Hughes7d2bbb82018-08-07 22:56:59463#include "chrome/browser/media/unified_autoplay_config.h"
mathpf709499d2017-01-09 20:48:36464#include "chrome/browser/payments/payment_request_factory.h"
Marc Treib7895941d2017-11-28 12:37:02465#include "chrome/browser/search/instant_service.h"
466#include "chrome/browser/search/instant_service_factory.h"
Reilly Grant2814fb72019-03-19 17:04:46467#include "chrome/browser/serial/chrome_serial_delegate.h"
Collin Baker8a217552019-05-29 19:47:51468#include "chrome/browser/ui/browser.h"
469#include "chrome/browser/ui/browser_finder.h"
470#include "chrome/browser/ui/browser_list.h"
471#include "chrome/browser/ui/browser_window.h"
jdoerrie4f9376f2018-12-12 18:26:20472#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
Conley Owensaafcf122018-02-26 18:53:51473#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
Nina Satragno8c832df2019-07-29 15:59:39474#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
475#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
Jay Civelli4d53be9b2017-08-31 22:01:43476#include "chrome/common/importer/profile_import.mojom.h"
Austin Orione250d012019-05-29 02:56:27477#include "chrome/grit/chrome_unscaled_resources.h"
Maggie Caia2f03f52019-04-02 02:13:28478#endif // !defined(OS_ANDROID)
mathpf709499d2017-01-09 20:48:36479
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:33480#if defined(OS_WIN) || defined(OS_MACOSX) || \
481 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur4b840a92018-09-18 14:46:52482#include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h"
483#endif
484
[email protected]a220b5932013-09-21 03:47:44485#if defined(OS_POSIX) && !defined(OS_MACOSX)
Joshua Perazaf890e4b2019-01-03 19:19:02486#if !defined(OS_ANDROID)
[email protected]779dd282013-10-19 15:57:02487#include "base/debug/leak_annotations.h"
sdefresne8ba0b88c2015-09-18 10:33:13488#include "components/crash/content/app/breakpad_linux.h"
Joshua Perazaf890e4b2019-01-03 19:19:02489#endif // !defined(OS_ANDROID)
sdefresne8ba0b88c2015-09-18 10:33:13490#include "components/crash/content/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43491#endif
[email protected]b80f68432011-05-02 17:22:30492
Maggie Caia2f03f52019-04-02 02:13:28493// TODO(crbug.com/939205): Once the upcoming App Service is available, use a
494// single navigation throttle to display the intent picker on all platforms.
495#if !defined(OS_ANDROID)
496#if defined(OS_CHROMEOS)
497#include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h"
498#else
499#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
500#endif
501#endif
502
[email protected]e8b6ca02013-07-10 18:00:51503#if defined(TOOLKIT_VIEWS)
504#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
505#endif
506
estaded3aa0e82016-02-17 22:55:21507#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Maksim Sisov1f2f2e62019-05-08 07:56:22508#if defined(USE_X11)
509#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h"
510#else
estaded3aa0e82016-02-17 22:55:21511#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h"
Maksim Sisov1f2f2e62019-05-08 07:56:22512#endif // USE_X11
[email protected]e8b6ca02013-07-10 18:00:51513#endif
514
Mohsen Izadif1958f22019-01-18 20:29:31515#if defined(USE_OZONE)
516#include "ui/ozone/public/ozone_platform.h"
517#endif
518
[email protected]e8b6ca02013-07-10 18:00:51519#if defined(USE_X11)
520#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
521#endif
522
brettwab78fef2016-10-12 02:56:05523#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]7a2a6d802014-06-06 13:39:19524#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
525#endif
526
Nico Weberaf3b00b2017-09-11 17:58:17527#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:55528#include "components/nacl/browser/nacl_browser.h"
529#include "components/nacl/browser/nacl_host_message_filter.h"
530#include "components/nacl/browser/nacl_process_host.h"
531#include "components/nacl/common/nacl_process_type.h"
532#include "components/nacl/common/nacl_switches.h"
533#endif
534
brettw00899e62016-11-12 02:10:17535#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:05536#include "chrome/browser/accessibility/animation_policy_prefs.h"
Dominick Ng6ff51052018-07-06 05:30:20537#include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h"
[email protected]d5a74be2014-08-08 01:01:27538#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
Chris Mumfordbae8a742018-03-01 23:02:23539#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
Clark DuVall2cf99249e2018-09-19 19:11:51540#include "chrome/browser/extensions/user_script_listener.h"
541#include "chrome/browser/media/cast_transport_host_filter.h"
thestig2dbee717e2014-09-05 14:54:28542#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:53543#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Ken Rockot551f7482018-02-10 11:18:46544#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
Ken Rockot2ad4db32018-02-10 16:24:10545#include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h"
fsamuel8dfa19a2015-05-05 01:00:39546#include "components/guest_view/browser/guest_view_base.h"
547#include "components/guest_view/browser/guest_view_manager.h"
Ken Rockota0dfaca12018-02-15 07:26:25548#include "extensions/browser/api/web_request/web_request_api.h"
Jay Civelli2578ebe2018-06-05 18:44:31549#include "extensions/browser/extension_host.h"
naskob9164c42016-06-07 01:21:35550#include "extensions/browser/extension_navigation_throttle.h"
Ken Rockot6414c4d92017-11-08 19:58:32551#include "extensions/browser/extension_protocols.h"
reillyga3acbc12014-11-11 23:17:12552#include "extensions/browser/extension_registry.h"
Chris Mumford8f812662018-02-22 00:27:57553#include "extensions/browser/extension_system.h"
tfarina01710e32015-07-13 21:53:22554#include "extensions/browser/extension_util.h"
hanxi0d0a1e92014-08-26 18:39:48555#include "extensions/browser/guest_view/web_view/web_view_guest.h"
556#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
557#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Jay Civelli2578ebe2018-06-05 18:44:31558#include "extensions/browser/process_manager.h"
Dan Beam836c02a2019-06-15 01:58:27559#include "extensions/common/constants.h"
thestig2dbee717e2014-09-05 14:54:28560#include "extensions/common/extension.h"
561#include "extensions/common/extension_set.h"
[email protected]f7daaa32014-08-02 07:58:13562#include "extensions/common/manifest_handlers/background_info.h"
thestig2dbee717e2014-09-05 14:54:28563#include "extensions/common/manifest_handlers/shared_module_info.h"
Clark DuVallbf7722f2018-08-03 18:03:33564#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
thestig2dbee717e2014-09-05 14:54:28565#include "extensions/common/permissions/permissions_data.h"
566#include "extensions/common/permissions/socket_permission.h"
567#include "extensions/common/switches.h"
thakis678822e2017-04-20 17:20:34568#endif // BUILDFLAG(ENABLE_EXTENSIONS)
merkindb10455e2017-02-28 13:16:25569
brettw4b461082016-11-19 18:55:16570#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55571#include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
trizzofo8ddaeb72016-09-01 23:18:27572#include "chrome/browser/plugins/flash_download_interception.h"
John Abd-El-Malekecc6f5f2018-03-02 18:47:39573#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
jitendra.ks42e889a2014-12-05 09:05:55574#endif
575
bauerb8f9c37742017-03-30 15:04:12576#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
577#include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h"
578#endif
579
thakis678822e2017-04-20 17:20:34580#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
miu54dca6c2016-11-17 10:59:38581#include "chrome/browser/media/cast_remoting_connector.h"
haibinlu9e605a92015-06-06 03:45:09582#endif
583
weilifabbf7572017-05-22 19:05:16584#if BUILDFLAG(ENABLE_PRINTING)
Lei Zhanga2fa14c2018-05-15 00:05:21585#include "chrome/browser/printing/printing_message_filter.h"
Miyoung Shin0f25ee5402019-07-19 01:26:14586#include "components/services/pdf_compositor/public/mojom/pdf_compositor.mojom.h"
weilifabbf7572017-05-22 19:05:16587#endif
Lei Zhanga2fa14c2018-05-15 00:05:21588
589#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
590 (BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
Ken Rockoted7f41b2018-02-10 16:19:10591#include "chrome/services/printing/public/mojom/constants.mojom.h"
Jay Civelli9237eac2017-09-21 16:10:21592#endif
weilifabbf7572017-05-22 19:05:16593
Xiaohan Wanga4e41842018-06-26 18:45:10594#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:49595#include "chrome/browser/media/output_protection_impl.h"
Xiaohan Wanga4e41842018-06-26 18:45:10596#include "chrome/browser/media/platform_verification_impl.h"
Xiaohan Wangf170c732018-09-27 05:45:26597#if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:10598#include "chrome/browser/media/widevine_hardware_caps_win.h"
599#include "third_party/widevine/cdm/widevine_cdm_common.h"
600#endif
601#endif
602
xhwangdb24d602017-05-20 06:32:24603#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
xhwang116acb92017-04-03 18:27:20604#include "chrome/browser/media/android/cdm/media_drm_storage_factory.h"
605#endif
xhwangc86d76e42016-03-14 23:38:49606
xhwangdb24d602017-05-20 06:32:24607#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
Xiaohan Wang3fcfc152017-07-06 00:51:55608#include "media/mojo/interfaces/constants.mojom.h" // nogncheck
xhwangb1d65fd2016-10-19 20:55:52609#include "media/mojo/services/media_service_factory.h" // nogncheck
alokp6ecb2382016-01-27 00:40:00610#endif
611
mmenkedb2637ff2017-03-30 23:59:42612#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
613#include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h"
614#endif
615
Luum Habtemariam7f7c61752018-07-18 00:41:18616#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_CHROMEOS)
Luum Habtemariamc295b4ea2019-04-24 20:18:51617// TODO(crbug.com/948800): Doesn't match BUILD.gn of use_cups && is_chromeos.
Luum Habtemariam9d999932018-10-15 23:04:12618#include "chrome/services/cups_ipp_parser/public/mojom/constants.mojom.h"
Luum Habtemariam7f7c61752018-07-18 00:41:18619#endif
620
Nico Weberbc5b06f2019-07-26 14:00:13621#if BUILDFLAG(FULL_SAFE_BROWSING)
Daniel Ruberya1611e32019-04-24 21:38:35622#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
623#endif
624
Nico Weberbc5b06f2019-07-26 14:00:13625#if BUILDFLAG(FULL_SAFE_BROWSING) || defined(OS_CHROMEOS)
Ken Rockot3d366682018-02-10 11:13:26626#include "chrome/services/file_util/public/mojom/constants.mojom.h"
Jay Civellid5b614332017-11-10 03:37:05627#endif
628
Jian Lide7b43792018-06-01 23:22:13629#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
Ryan Sturmaa05092f2018-10-21 03:56:54630#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
Jian Lide7b43792018-06-01 23:22:13631#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
632#endif
633
Ken Rockot80b08e92018-08-15 04:22:02634#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
635#include "services/content/simple_browser/public/mojom/constants.mojom.h"
636#include "services/content/simple_browser/simple_browser_service.h"
637#endif
638
639#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
Ken Rockot99c5bc742018-07-12 15:36:56640#include "services/content/simple_browser/public/mojom/constants.mojom.h"
641#endif
642
Will Cassella40837ba2019-07-01 21:32:00643#if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID)
Bill Orreb429222018-08-08 21:14:43644#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
645#endif
646
Michael Thiessen909ba032019-03-26 23:47:43647#if defined(BROWSER_MEDIA_CONTROLS_MENU)
648#include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h"
649#endif
650
Michael Thiessen07c444c2019-04-26 03:53:11651#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
652#include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h"
653#endif
654
[email protected]c7abd422012-09-25 00:20:08655using base::FileDescriptor;
[email protected]631bb742011-11-02 11:29:39656using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31657using content::BrowserURLHandler;
msrameka3c7cfd2017-02-03 13:34:13658using content::BrowsingDataFilterBuilder;
[email protected]b9535422012-02-09 01:47:59659using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00660using content::QuotaPermissionContext;
[email protected]2626d142014-04-22 17:24:02661using content::RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11662using content::RenderViewHost;
[email protected]7491ad02014-07-05 19:10:07663using content::ResourceType;
[email protected]b6583592012-01-25 19:52:33664using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13665using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05666using content::WebPreferences;
[email protected]593d2a72013-07-26 08:48:38667using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39668
[email protected]0daaebfe2014-03-15 00:09:05669#if defined(OS_POSIX)
brettw3c98c7d32017-07-25 01:44:20670using content::PosixFileDescriptorInfo;
[email protected]0daaebfe2014-03-15 00:09:05671#endif
672
brettw00899e62016-11-12 02:10:17673#if BUILDFLAG(ENABLE_EXTENSIONS)
thestig2dbee717e2014-09-05 14:54:28674using extensions::APIPermission;
[email protected]d5a74be2014-08-08 01:01:27675using extensions::ChromeContentBrowserClientExtensionsPart;
thestig2dbee717e2014-09-05 14:54:28676using extensions::Extension;
thestig2dbee717e2014-09-05 14:54:28677using extensions::Manifest;
[email protected]d5a74be2014-08-08 01:01:27678#endif
679
brettw4b461082016-11-19 18:55:16680#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:55681using plugins::ChromeContentBrowserClientPluginsPart;
682#endif
683
[email protected]c5dbef02011-05-13 05:06:09684namespace {
685
michaeln10e5fc352017-02-07 02:07:58686const storage::QuotaSettings* g_default_quota_settings;
687
brettw4b461082016-11-19 18:55:16688#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]aec5ed52014-06-20 07:51:42689// TODO(teravest): Add renderer-side API-specific checking for these APIs so
690// that blanket permission isn't granted to all dev channel APIs for these.
691// http://crbug.com/386743
692const char* const kPredefinedAllowedDevChannelOrigins[] = {
693 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937
694 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937
695};
696
[email protected]9de4da52014-05-24 12:26:50697const char* const kPredefinedAllowedFileHandleOrigins[] = {
[email protected]10c39222013-11-13 20:09:25698 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
699 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
700};
701
[email protected]9de4da52014-05-24 12:26:50702const char* const kPredefinedAllowedSocketOrigins[] = {
Mike Frysingera9864c6a2017-12-18 22:12:31703 "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev)
704 "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable)
705 "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev)
706 "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable)
[email protected]99132682012-04-24 19:00:45707 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
708 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
709 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
710 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35711 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54712 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
713 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
714 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
715 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
716 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
717 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38718 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58719 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29720 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42721 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42722 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
723 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
724 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40725};
[email protected]93f72062013-05-29 20:29:40726#endif
[email protected]e461da2f2012-02-16 19:06:40727
lazyboy5d5fede02016-03-10 04:10:14728enum AppLoadedInTabSource {
nickb6ae0bd32017-04-18 20:53:53729 // A platform app page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14730 APP_LOADED_IN_TAB_SOURCE_APP = 0,
nickb6ae0bd32017-04-18 20:53:53731
732 // A platform app background page tried to load one of its own URLs in a tab.
lazyboy5d5fede02016-03-10 04:10:14733 APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE,
nickb6ae0bd32017-04-18 20:53:53734
735 // An extension or app tried to load a resource of a different platform app in
736 // a tab.
737 APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION,
738
739 // A non-app and non-extension page tried to load a platform app in a tab.
740 APP_LOADED_IN_TAB_SOURCE_OTHER,
741
lazyboy5d5fede02016-03-10 04:10:14742 APP_LOADED_IN_TAB_SOURCE_MAX
743};
744
Lei Zhang2cfceac2018-11-14 19:36:33745// Cached version of the locale so we can return the locale on the I/O
746// thread.
747std::string& GetIOThreadApplicationLocale() {
748 static base::NoDestructor<std::string> s;
749 return *s;
750}
751
[email protected]f8f93eb2012-09-25 03:06:24752// Returns a copy of the given url with its host set to given host and path set
753// to given path. Other parts of the url will be the same.
754GURL ReplaceURLHostAndPath(const GURL& url,
755 const std::string& host,
756 const std::string& path) {
[email protected]b45334502014-04-30 19:44:05757 url::Replacements<char> replacements;
758 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
759 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
[email protected]f8f93eb2012-09-25 03:06:24760 return url.ReplaceComponents(replacements);
761}
762
madfbd10852017-01-20 03:15:33763// Handles the rewriting of the new tab page URL based on group policy.
764bool HandleNewTabPageLocationOverride(
765 GURL* url,
766 content::BrowserContext* browser_context) {
767 if (!url->SchemeIs(content::kChromeUIScheme) ||
768 url->host() != chrome::kChromeUINewTabHost)
769 return false;
770
771 Profile* profile = Profile::FromBrowserContext(browser_context);
772 std::string ntp_location =
773 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
774 if (ntp_location.empty())
775 return false;
776
777 *url = GURL(ntp_location);
778 return true;
779}
780
Becca Hughesfe8c32c2018-03-21 13:36:56781#if !defined(OS_ANDROID)
782// Check if the current url is whitelisted based on a list of whitelisted urls.
783bool IsURLWhitelisted(const GURL& current_url,
784 const base::Value::ListStorage& whitelisted_urls) {
785 // Only check on HTTP and HTTPS pages.
786 if (!current_url.SchemeIsHTTPOrHTTPS())
787 return false;
788
789 for (auto const& value : whitelisted_urls) {
790 ContentSettingsPattern pattern =
791 ContentSettingsPattern::FromString(value.GetString());
792 if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid())
793 continue;
794 if (pattern.Matches(current_url))
795 return true;
796 }
797
798 return false;
799}
800
801// Check if autoplay is allowed by policy configuration.
802bool IsAutoplayAllowedByPolicy(content::WebContents* contents,
803 PrefService* prefs) {
804 DCHECK(prefs);
805
806 // Check if we have globally allowed autoplay by policy.
807 if (prefs->GetBoolean(prefs::kAutoplayAllowed) &&
808 prefs->IsManagedPreference(prefs::kAutoplayAllowed)) {
809 return true;
810 }
811
812 if (!contents)
813 return false;
814
815 // Check if the current URL matches a URL pattern on the whitelist.
816 const base::ListValue* autoplay_whitelist =
817 prefs->GetList(prefs::kAutoplayWhitelist);
818 return autoplay_whitelist &&
819 prefs->IsManagedPreference(prefs::kAutoplayWhitelist) &&
820 IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList());
821}
822#endif
823
Joshua Perazaf890e4b2019-01-03 19:19:02824#if defined(OS_ANDROID)
825int GetCrashSignalFD(const base::CommandLine& command_line) {
826 return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
827}
828#elif defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03829breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
830 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02831 base::FilePath dumps_path;
Avi Drissman9098f9002018-05-04 00:11:52832 base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
[email protected]779dd282013-10-19 15:57:02833 {
834 ANNOTATE_SCOPED_MEMORY_LEAK;
Lei Zhang74f3dd3f2019-04-10 00:16:31835 bool upload = !getenv(env_vars::kHeadless);
[email protected]0b818f72013-10-22 00:11:03836 breakpad::CrashHandlerHostLinux* crash_handler =
[email protected]9de4da52014-05-24 12:26:50837 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
[email protected]779dd282013-10-19 15:57:02838 crash_handler->StartUploaderThread();
839 return crash_handler;
840 }
841}
842
avi3ef9ec9e2014-12-22 22:50:17843int GetCrashSignalFD(const base::CommandLine& command_line) {
[email protected]9de4da52014-05-24 12:26:50844 // Extensions have the same process type as renderers.
[email protected]cd0f7af2014-01-16 23:50:39845 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
Lei Zhang74f3dd3f2019-04-10 00:16:31846 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02847 if (!crash_handler)
848 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18849 return crash_handler->GetDeathSignalSocket();
850 }
851
James Cook783fdeb2018-05-24 22:28:46852#if defined(OS_CHROMEOS)
853 // Mash services are utility processes, but crashes are reported using the
854 // service name as the process type to make the crash console easier to read.
855 if (command_line.HasSwitch(switches::kMashServiceName)) {
856 static base::NoDestructor<
857 std::map<std::string, breakpad::CrashHandlerHostLinux*>>
858 crash_handlers;
859 std::string service_name =
860 command_line.GetSwitchValueASCII(switches::kMashServiceName);
861 auto it = crash_handlers->find(service_name);
862 if (it == crash_handlers->end()) {
Lei Zhang74f3dd3f2019-04-10 00:16:31863 auto insert_result = crash_handlers->insert(
James Cook783fdeb2018-05-24 22:28:46864 std::make_pair(service_name, CreateCrashHandlerHost(service_name)));
Lei Zhang74f3dd3f2019-04-10 00:16:31865 it = insert_result.first;
James Cook783fdeb2018-05-24 22:28:46866 }
Lei Zhang74f3dd3f2019-04-10 00:16:31867 return it->second->GetDeathSignalSocket();
James Cook783fdeb2018-05-24 22:28:46868 }
869#endif // defined(OS_CHROMEOS)
870
[email protected]a1733df2012-06-22 11:24:18871 std::string process_type =
872 command_line.GetSwitchValueASCII(switches::kProcessType);
873
[email protected]779dd282013-10-19 15:57:02874 if (process_type == switches::kRendererProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31875 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02876 if (!crash_handler)
877 crash_handler = CreateCrashHandlerHost(process_type);
878 return crash_handler->GetDeathSignalSocket();
879 }
[email protected]a1733df2012-06-22 11:24:18880
[email protected]779dd282013-10-19 15:57:02881 if (process_type == switches::kPpapiPluginProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31882 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02883 if (!crash_handler)
884 crash_handler = CreateCrashHandlerHost(process_type);
885 return crash_handler->GetDeathSignalSocket();
886 }
[email protected]a1733df2012-06-22 11:24:18887
[email protected]779dd282013-10-19 15:57:02888 if (process_type == switches::kGpuProcess) {
Lei Zhang74f3dd3f2019-04-10 00:16:31889 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
[email protected]779dd282013-10-19 15:57:02890 if (!crash_handler)
891 crash_handler = CreateCrashHandlerHost(process_type);
892 return crash_handler->GetDeathSignalSocket();
893 }
[email protected]a1733df2012-06-22 11:24:18894
James Cook9207cc12017-10-19 17:08:39895 if (process_type == switches::kUtilityProcess) {
896 static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
897 if (!crash_handler)
898 crash_handler = CreateCrashHandlerHost(process_type);
899 return crash_handler->GetDeathSignalSocket();
900 }
901
[email protected]a1733df2012-06-22 11:24:18902 return -1;
903}
Joshua Perazaf890e4b2019-01-03 19:19:02904#endif // defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18905
[email protected]eabbfb12013-04-05 23:28:35906void SetApplicationLocaleOnIOThread(const std::string& locale) {
thestig00844cea2015-09-08 21:44:52907 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Lei Zhang2cfceac2018-11-14 19:36:33908 GetIOThreadApplicationLocale() = locale;
[email protected]eabbfb12013-04-05 23:28:35909}
910
estark3ba11132015-04-10 01:38:33911// An implementation of the SSLCertReporter interface used by
meacerf43117a2016-12-27 21:02:31912// SSLErrorHandler. Uses CertificateReportingService to send reports. The
913// service handles queueing and re-sending of failed reports. Each certificate
914// error creates a new instance of this class.
915class CertificateReportingServiceCertReporter : public SSLCertReporter {
estark3ba11132015-04-10 01:38:33916 public:
meacerf43117a2016-12-27 21:02:31917 explicit CertificateReportingServiceCertReporter(
Lucas Garron94b16052017-11-11 01:58:12918 content::WebContents* web_contents)
919 : service_(CertificateReportingServiceFactory::GetForBrowserContext(
920 web_contents->GetBrowserContext())) {}
meacerf43117a2016-12-27 21:02:31921 ~CertificateReportingServiceCertReporter() override {}
estark3ba11132015-04-10 01:38:33922
923 // SSLCertReporter implementation
estark4282f1172015-05-13 22:01:55924 void ReportInvalidCertificateChain(
925 const std::string& serialized_report) override {
meacerf43117a2016-12-27 21:02:31926 service_->Send(serialized_report);
estark3ba11132015-04-10 01:38:33927 }
928
929 private:
meacerf43117a2016-12-27 21:02:31930 CertificateReportingService* service_;
931
932 DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
estark3ba11132015-04-10 01:38:33933};
934
bshe4f53ce42015-11-30 16:56:31935#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:05936float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59937 static const float kMinFSM = 1.05f;
938 static const int kWidthForMinFSM = 320;
939 static const float kMaxFSM = 1.3f;
940 static const int kWidthForMaxFSM = 800;
941
boliu21c5afa2017-01-11 19:34:23942 int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
[email protected]b255a8e0e82013-10-22 04:03:59943
944 if (minWidth <= kWidthForMinFSM)
945 return kMinFSM;
946 if (minWidth >= kWidthForMaxFSM)
947 return kMaxFSM;
948
949 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
950 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
951 (kWidthForMaxFSM - kWidthForMinFSM);
952 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
953}
zpengdb4a58e2017-01-10 17:40:32954
[email protected]916615b2013-09-11 18:19:44955#endif // defined(OS_ANDROID)
956
brettw00899e62016-11-12 02:10:17957#if BUILDFLAG(ENABLE_EXTENSIONS)
nickb6ae0bd32017-04-18 20:53:53958
959AppLoadedInTabSource ClassifyAppLoadedInTabSource(
960 const GURL& opener_url,
961 const extensions::Extension* target_platform_app) {
962 if (opener_url.SchemeIs(extensions::kExtensionScheme)) {
963 if (opener_url.host_piece() == target_platform_app->id()) {
964 // This platform app was trying to window.open() one of its own URLs.
965 if (opener_url ==
966 extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) {
967 // Source was the background page.
968 return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE;
969 } else {
970 // Source was a different page inside the app.
971 return APP_LOADED_IN_TAB_SOURCE_APP;
972 }
973 }
974 // The forbidden app URL was being opened by a different app or extension.
975 return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION;
976 }
977 // The forbidden app URL was being opened by a non-extension page (e.g. http).
978 return APP_LOADED_IN_TAB_SOURCE_OTHER;
979}
[email protected]9c7656382014-08-08 21:02:30980
Charles Harrison34f67862017-08-22 01:04:17981// Returns true if there is is an extension matching |url| in
982// |opener_render_process_id| with APIPermission::kBackground.
983//
984// Note that GetExtensionOrAppByURL requires a full URL in order to match with a
985// hosted app, even though normal extensions just use the host.
986bool URLHasExtensionBackgroundPermission(
csharrison95f01e922017-04-24 18:52:35987 extensions::ProcessMap* process_map,
988 extensions::ExtensionRegistry* registry,
Charles Harrison34f67862017-08-22 01:04:17989 const GURL& url,
csharrison95f01e922017-04-24 18:52:35990 int opener_render_process_id) {
991 // Note: includes web URLs that are part of an extension's web extent.
992 const Extension* extension =
Charles Harrison34f67862017-08-22 01:04:17993 registry->enabled_extensions().GetExtensionOrAppByURL(url);
csharrison95f01e922017-04-24 18:52:35994 return extension &&
995 extension->permissions_data()->HasAPIPermission(
996 APIPermission::kBackground) &&
997 process_map->Contains(extension->id(), opener_render_process_id);
998}
Kevin Marshall32f99d7e2017-07-11 23:17:46999
1000void InvokeCallbackOnThread(
1001 scoped_refptr<base::SequencedTaskRunner> task_runner,
1002 base::Callback<void(bool)> callback,
1003 bool result) {
tzikdf81f142018-10-26 00:23:341004 task_runner->PostTask(FROM_HERE, base::BindOnce(std::move(callback), result));
Kevin Marshall32f99d7e2017-07-11 23:17:461005}
csharrison95f01e922017-04-24 18:52:351006#endif
1007
John Abd-El-Malekd2377982018-01-08 22:23:121008chrome::mojom::PrerenderCanceler* GetPrerenderCanceller(
1009 const base::Callback<content::WebContents*()>& wc_getter) {
1010 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1011 auto* web_contents = wc_getter.Run();
1012 if (!web_contents)
1013 return nullptr;
1014
1015 return prerender::PrerenderContents::FromWebContents(web_contents);
1016}
1017
John Abd-El-Maleka67add82018-03-09 18:22:011018void LaunchURL(
1019 const GURL& url,
1020 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
1021 ui::PageTransition page_transition,
1022 bool has_user_gesture) {
1023 // If there is no longer a WebContents, the request may have raced with tab
1024 // closing. Don't fire the external request. (It may have been a prerender.)
1025 content::WebContents* web_contents = web_contents_getter.Run();
1026 if (!web_contents)
1027 return;
1028
1029 // Do not launch external requests attached to unswapped prerenders.
1030 prerender::PrerenderContents* prerender_contents =
1031 prerender::PrerenderContents::FromWebContents(web_contents);
1032 if (prerender_contents) {
1033 prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
1034 prerender::ReportPrerenderExternalURL();
1035 return;
1036 }
1037
Robbie McElrath1294d242019-05-31 20:46:221038 // Do not launch external requests for schemes that have a handler registered.
1039 ProtocolHandlerRegistry* protocol_handler_registry =
1040 ProtocolHandlerRegistryFactory::GetForBrowserContext(
1041 web_contents->GetBrowserContext());
1042 if (protocol_handler_registry &&
1043 protocol_handler_registry->IsHandledProtocol(url.scheme()))
1044 return;
1045
John Abd-El-Maleka67add82018-03-09 18:22:011046 bool is_whitelisted = false;
John Abd-El-Maleka67add82018-03-09 18:22:011047 PolicyBlacklistService* service =
Oleg Davydov5cfe7ab2019-02-01 12:27:191048 PolicyBlacklistFactory::GetForBrowserContext(
1049 web_contents->GetBrowserContext());
John Abd-El-Maleka67add82018-03-09 18:22:011050 if (service) {
1051 const policy::URLBlacklist::URLBlacklistState url_state =
1052 service->GetURLBlacklistState(url);
1053 is_whitelisted =
1054 url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST;
1055 }
1056
1057 // If the URL is in whitelist, we launch it without asking the user and
1058 // without any additional security checks. Since the URL is whitelisted,
1059 // we assume it can be executed.
1060 if (is_whitelisted) {
1061 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents);
1062 } else {
1063 ExternalProtocolHandler::LaunchUrl(
1064 url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
1065 web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
1066 has_user_gesture);
1067 }
1068}
1069
Yutaka Hirano968d6252018-12-04 05:09:311070std::string GetProduct() {
1071 return version_info::GetProductNameAndVersionForUserAgent();
1072}
1073
Lukasz Anforowicz60d1253d2019-05-08 16:31:371074void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) {
1075 // |allowlist| combines pref/policy + cmdline switch in the browser process.
1076 // For renderer and utility (e.g. NetworkService) processes the switch is the
1077 // only available source, so below the combined (pref/policy + cmdline)
1078 // allowlist of secure origins is injected into |cmdline| for these other
1079 // processes.
1080 std::vector<std::string> allowlist =
1081 network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist();
1082 if (!allowlist.empty()) {
1083 cmdline->AppendSwitchASCII(
1084 network::switches::kUnsafelyTreatInsecureOriginAsSecure,
1085 base::JoinString(allowlist, ","));
1086 }
1087}
1088
[email protected]9dbfff12011-07-01 19:37:071089} // namespace
[email protected]c5dbef02011-05-13 05:06:091090
Yutaka Hirano968d6252018-12-04 05:09:311091std::string GetUserAgent() {
1092 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1093 if (command_line->HasSwitch(switches::kUserAgent)) {
1094 std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent);
1095 if (net::HttpUtil::IsValidHeaderValue(ua))
1096 return ua;
1097 LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent;
1098 }
1099
John Delaneyac24e572019-04-30 19:47:021100 if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) {
1101 return content::GetFrozenUserAgent(
1102 command_line->HasSwitch(switches::kUseMobileUserAgent))
1103 .as_string();
1104 }
1105
Yutaka Hirano968d6252018-12-04 05:09:311106 std::string product = GetProduct();
1107#if defined(OS_ANDROID)
1108 if (command_line->HasSwitch(switches::kUseMobileUserAgent))
1109 product += " Mobile";
1110#endif
1111 return content::BuildUserAgentFromProduct(product);
1112}
1113
Mike West6e4cbb32019-02-13 09:40:171114blink::UserAgentMetadata GetUserAgentMetadata() {
1115 blink::UserAgentMetadata metadata;
Mike West6e4cbb32019-02-13 09:40:171116 metadata.brand = version_info::GetProductName();
Mike Weste555be862019-02-20 16:17:301117 metadata.full_version = version_info::GetVersionNumber();
1118 metadata.major_version = version_info::GetMajorVersionNumber();
Mike West6e4cbb32019-02-13 09:40:171119 metadata.platform = version_info::GetOSType();
1120
1121 // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces.
1122 metadata.architecture = "";
1123 metadata.model = "";
1124
1125 return metadata;
1126}
1127
Ran Jia96d43d42018-05-02 17:14:531128ChromeContentBrowserClient::ChromeContentBrowserClient(
Xi Han85079c22019-04-18 21:43:051129 StartupData* startup_data)
Wojciech Dzierżanowski45380802019-04-29 14:50:321130 : data_reduction_proxy_throttle_manager_(
1131 nullptr,
1132 base::OnTaskRunnerDeleter(nullptr)),
Jeremy Roman495db682019-07-12 16:03:241133 startup_data_(startup_data) {
brettw4b461082016-11-19 18:55:161134#if BUILDFLAG(ENABLE_PLUGINS)
Avi Drissmand251e912018-12-26 15:46:371135 for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i)
[email protected]aec5ed52014-06-20 07:51:421136 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371137 for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i)
[email protected]10c39222013-11-13 20:09:251138 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
Avi Drissmand251e912018-12-26 15:46:371139 for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i)
[email protected]e461da2f2012-02-16 19:06:401140 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
jitendra.ks42e889a2014-12-05 09:05:551141
1142 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
[email protected]93f72062013-05-29 20:29:401143#endif
[email protected]1deace22013-05-22 06:14:461144
Ahmed Fakhryd70bf37b2018-04-04 17:07:241145#if defined(OS_CHROMEOS)
1146 extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart);
1147#endif // defined(OS_CHROMEOS)
1148
brettw00899e62016-11-12 02:10:171149#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131150 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
[email protected]d5a74be2014-08-08 01:01:271151#endif
bena06f7d62017-04-04 20:48:521152
Sigurdur Asgeirsson70696672019-02-08 16:14:511153 extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart);
Sigurdur Asgeirsson50945f92019-01-25 20:26:011154
bena06f7d62017-04-04 20:48:521155 gpu_binder_registry_.AddInterface(
Mike Wittman16fa5362018-09-04 17:27:301156 base::Bind(&metrics::CallStackProfileCollector::Create));
[email protected]e461da2f2012-02-16 19:06:401157}
1158
1159ChromeContentBrowserClient::~ChromeContentBrowserClient() {
[email protected]a48ab7112014-08-01 16:48:031160 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
1161 delete extra_parts_[i];
1162 extra_parts_.clear();
[email protected]e461da2f2012-02-16 19:06:401163}
1164
[email protected]bca18382012-06-25 19:15:231165// static
Chris Palmerac7d75642017-11-22 20:12:541166void ChromeContentBrowserClient::RegisterLocalStatePrefs(
1167 PrefRegistrySimple* registry) {
1168 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1169 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Chris Hamilton8206aad2018-07-18 01:00:031170 registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true);
Julian Pastarmovfac28002018-02-01 11:17:451171 registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies,
1172 false);
Chris Palmerac7d75642017-11-22 20:12:541173}
1174
1175// static
[email protected]37ca3fe02013-07-05 15:32:441176void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:341177 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:251178 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
1179 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
1180 registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures);
Pavol Marko6adbea7f2018-02-20 16:35:281181 // Register user prefs for mapping SitePerProcess and IsolateOrigins in
1182 // user policy in addition to the same named ones in Local State (which are
1183 // used for mapping the command-line flags).
1184 registry->RegisterStringPref(prefs::kIsolateOrigins, std::string());
1185 registry->RegisterBooleanPref(prefs::kSitePerProcess, false);
Alex Moshchuke256d562019-04-26 21:43:571186 registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins);
Rayan Kanso411e84e2019-02-13 15:27:401187 registry->RegisterDictionaryPref(
1188 prefs::kDevToolsBackgroundServicesExpirationDict);
Kunihiko Sakamotof586da62019-03-28 03:03:041189 registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true);
François Beaufort4f8107d2018-03-05 12:12:101190#if !defined(OS_ANDROID)
1191 registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false);
Becca Hughesfe8c32c2018-03-21 13:36:561192 registry->RegisterListPref(prefs::kAutoplayWhitelist);
François Beaufort4f8107d2018-03-05 12:12:101193#endif
[email protected]bca18382012-06-25 19:15:231194}
1195
[email protected]eabbfb12013-04-05 23:28:351196// static
1197void ChromeContentBrowserClient::SetApplicationLocale(
1198 const std::string& locale) {
Scott Violet875789e2018-02-02 07:46:481199 // The common case is that this function is called early in Chrome startup
1200 // before any threads are created or registered. When there are no threads,
1201 // we can just set the string without worrying about threadsafety.
Gabriel Charette192b8c92018-03-21 21:16:001202 if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
Lei Zhang2cfceac2018-11-14 19:36:331203 GetIOThreadApplicationLocale() = locale;
Scott Violet875789e2018-02-02 07:46:481204 return;
1205 }
1206
1207 // Otherwise we're being called to change the locale. In this case set it on
1208 // the IO thread.
thestig00844cea2015-09-08 21:44:521209 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]eabbfb12013-04-05 23:28:351210
Eric Seckler8652dcd52018-09-20 10:42:281211 base::PostTaskWithTraits(
1212 FROM_HERE, {BrowserThread::IO},
Scott Violet875789e2018-02-02 07:46:481213 base::BindOnce(&SetApplicationLocaleOnIOThread, locale));
[email protected]eabbfb12013-04-05 23:28:351214}
1215
Patrick Monette61dfef92019-05-30 23:06:271216std::unique_ptr<content::BrowserMainParts>
1217ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]50462bf02011-11-21 19:13:311218 const content::MainFunctionParams& parameters) {
Patrick Monette61dfef92019-05-30 23:06:271219 std::unique_ptr<ChromeBrowserMainParts> main_parts;
[email protected]b48c9182011-10-26 18:03:301220 // Construct the Main browser parts based on the OS type.
1221#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:051222 main_parts =
Patrick Monette61dfef92019-05-30 23:06:271223 std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_);
1224#elif defined(OS_MACOSX)
1225 main_parts =
1226 std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_);
1227#elif defined(OS_CHROMEOS)
1228 main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>(
1229 parameters, startup_data_);
[email protected]81ce2c42012-03-24 01:43:261230#elif defined(OS_LINUX)
Patrick Monette61dfef92019-05-30 23:06:271231 main_parts =
1232 std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_);
[email protected]6e677a342012-02-11 01:21:141233#elif defined(OS_ANDROID)
Patrick Monette61dfef92019-05-30 23:06:271234 main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters,
1235 startup_data_);
[email protected]b48c9182011-10-26 18:03:301236#elif defined(OS_POSIX)
Patrick Monette61dfef92019-05-30 23:06:271237 main_parts =
1238 std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_);
[email protected]f967b722011-09-07 00:58:041239#else
[email protected]b48c9182011-10-26 18:03:301240 NOTREACHED();
Patrick Monette61dfef92019-05-30 23:06:271241 main_parts =
1242 std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_);
[email protected]b48c9182011-10-26 18:03:301243#endif
1244
Xi Han9fd44002019-04-30 17:39:361245 bool add_profiles_extra_parts = true;
1246#if defined(OS_ANDROID)
1247 if (startup_data_->HasBuiltProfilePrefService())
1248 add_profiles_extra_parts = false;
1249#endif
1250 if (add_profiles_extra_parts)
Patrick Monette61dfef92019-05-30 23:06:271251 chrome::AddProfilesExtraParts(main_parts.get());
[email protected]7e75e4a2013-05-17 17:20:031252
Xi Han9fd44002019-04-30 17:39:361253 // Construct additional browser parts. Stages are called in the order in
1254 // which they are added.
[email protected]c7480942011-11-08 19:18:271255#if defined(TOOLKIT_VIEWS)
Maksim Sisov1f2f2e62019-05-08 07:56:221256#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1257#if defined(USE_X11)
1258 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11());
1259#else
estaded3aa0e82016-02-17 22:55:211260 main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux());
Maksim Sisov1f2f2e62019-05-08 07:56:221261#endif // USE_X11
estaded3aa0e82016-02-17 22:55:211262#else
riajiang7d6ec5c2017-01-25 16:40:331263 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
James Cookf9d34d22017-10-04 16:39:351264#endif
1265#endif
1266
1267#if defined(OS_CHROMEOS)
1268 // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos.
riajiang7d6ec5c2017-01-25 16:40:331269 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
skycea631e2016-12-16 21:52:221270#endif
[email protected]dc04be7c2012-03-15 23:57:491271
[email protected]e8b6ca02013-07-10 18:00:511272#if defined(USE_X11)
1273 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:241274#endif
1275
Sigurdur Asgeirsson54b72702019-04-12 14:18:541276 main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager);
Etienne Bergeron05d62532017-10-13 18:24:001277
Albert J. Wong59d85acb2017-08-10 00:50:571278 main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling);
Albert J. Wong59d85acb2017-08-10 00:50:571279
Patrick Monette61dfef92019-05-30 23:06:271280 chrome::AddMetricsExtraParts(main_parts.get());
[email protected]95132f52013-04-12 02:19:041281
Ben Goodger16331302018-01-23 00:43:211282 main_parts->AddParts(ChromeService::GetInstance()->CreateExtraParts());
1283
[email protected]50462bf02011-11-21 19:13:311284 return main_parts;
[email protected]f967b722011-09-07 00:58:041285}
1286
michaeln96f887e22015-04-13 23:58:311287void ChromeContentBrowserClient::PostAfterStartupTask(
Brett Wilsone1a70422017-09-12 05:10:091288 const base::Location& from_here,
michaeln96f887e22015-04-13 23:58:311289 const scoped_refptr<base::TaskRunner>& task_runner,
tzik6e427842017-04-05 10:13:211290 base::OnceClosure task) {
tzik070c8ffb2017-03-29 05:28:121291 AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task));
John Abd-El-Malek0e82fe7f2019-07-27 00:06:291292
1293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1294 safe_browsing_service_ = g_browser_process->safe_browsing_service();
michaeln96f887e22015-04-13 23:58:311295}
1296
falkenb09d443f2016-04-07 12:36:121297bool ChromeContentBrowserClient::IsBrowserStartupComplete() {
1298 return AfterStartupTaskUtils::IsBrowserStartupComplete();
1299}
1300
Gabriel Charettec8cca992017-08-10 18:21:491301void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() {
1302 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
1303}
1304
John Abd-El-Malek9d57f9c2019-02-20 18:50:041305bool ChromeContentBrowserClient::IsShuttingDown() {
1306 return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID;
1307}
1308
[email protected]e94bbcb2012-09-07 05:33:571309std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:191310 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:571311 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:531312 std::string partition_id;
1313
1314 // The partition ID for webview guest processes is the string value of its
1315 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
rogerta5f5bb822015-12-17 03:24:451316 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:531317 partition_id = site.spec();
brettw00899e62016-11-12 02:10:171318#if BUILDFLAG(ENABLE_EXTENSIONS)
blundellf650ea02016-02-08 11:50:501319 // The partition ID for extensions with isolated storage is treated similarly
1320 // to the above.
1321 else if (site.SchemeIs(extensions::kExtensionScheme) &&
1322 extensions::util::SiteHasIsolatedStorage(site, browser_context))
1323 partition_id = site.spec();
1324#endif
[email protected]1bc28312012-11-08 08:31:531325
[email protected]056efdc2013-04-06 00:14:531326 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:531327 return partition_id;
1328}
1329
1330bool ChromeContentBrowserClient::IsValidStoragePartitionId(
1331 content::BrowserContext* browser_context,
1332 const std::string& partition_id) {
1333 // The default ID is empty and is always valid.
1334 if (partition_id.empty())
1335 return true;
1336
1337 return GURL(partition_id).is_valid();
1338}
1339
1340void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
1341 content::BrowserContext* browser_context,
1342 const GURL& site,
[email protected]14acc642012-11-17 12:20:101343 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:531344 std::string* partition_domain,
1345 std::string* partition_name,
1346 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:101347 // Default to the browser-wide storage partition and override based on |site|
1348 // below.
1349 partition_domain->clear();
1350 partition_name->clear();
1351 *in_memory = false;
1352
brettw00899e62016-11-12 02:10:171353#if BUILDFLAG(ENABLE_EXTENSIONS)
rogerta5f5bb822015-12-17 03:24:451354 bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite(
[email protected]3f24f97c2013-11-17 21:53:331355 site, partition_domain, partition_name, in_memory);
1356
1357 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:101358 // If |can_be_default| is false, the caller is stating that the |site|
1359 // should be parsed as if it had isolated storage. In particular it is
1360 // important to NOT check ExtensionService for the is_storage_isolated()
1361 // attribute because this code path is run during Extension uninstall
1362 // to do cleanup after the Extension has already been unloaded from the
1363 // ExtensionService.
1364 bool is_isolated = !can_be_default;
1365 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:341366 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
1367 is_isolated = true;
[email protected]14acc642012-11-17 12:20:101368 }
[email protected]1bc28312012-11-08 08:31:531369
[email protected]14acc642012-11-17 12:20:101370 if (is_isolated) {
1371 CHECK(site.has_host());
1372 // For extensions with isolated storage, the the host of the |site| is
1373 // the |partition_domain|. The |in_memory| and |partition_name| are only
1374 // used in guest schemes so they are cleared here.
1375 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:531376 *in_memory = false;
[email protected]14acc642012-11-17 12:20:101377 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:531378 }
[email protected]1df3d972014-06-11 04:55:181379 success = true;
1380 }
1381#endif
1382
[email protected]14acc642012-11-17 12:20:101383 // Assert that if |can_be_default| is false, the code above must have found a
1384 // non-default partition. If this fails, the caller has a serious logic
1385 // error about which StoragePartition they expect to be in and it is not
1386 // safe to continue.
1387 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:441388}
1389
[email protected]38b098f2012-03-14 21:11:571390content::WebContentsViewDelegate*
1391 ChromeContentBrowserClient::GetWebContentsViewDelegate(
1392 content::WebContents* web_contents) {
cm.sanchi2db24a82017-11-16 07:22:101393 return CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:321394}
1395
Bo Liu4ade6b1b22017-11-28 02:26:351396bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() {
1397#if defined(OS_ANDROID)
1398 const base::android::ApplicationState app_state =
1399 base::android::ApplicationStatusListener::GetState();
1400 return base::android::APPLICATION_STATE_UNKNOWN == app_state ||
1401 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state ||
1402 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state;
1403#else
1404 return true;
1405#endif
1406}
1407
[email protected]6f2862742013-12-20 07:53:191408void ChromeContentBrowserClient::RenderProcessWillLaunch(
Ben Goodger16331302018-01-23 00:43:211409 content::RenderProcessHost* host,
1410 service_manager::mojom::ServiceRequest* service_request) {
[email protected]f3b1a082011-11-18 00:34:301411 int id = host->GetID();
1412 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
horo062ef5352017-03-29 08:16:071413 host->AddFilter(new ChromeRenderMessageFilter(id, profile));
thakis678822e2017-04-20 17:20:341414#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekb79dd6ba2018-12-07 01:20:491415 host->AddFilter(new cast::CastTransportHostFilter());
thestig73f4cdc2015-01-15 01:51:061416#endif
Brett Wilson65f951c2016-11-03 22:06:121417#if BUILDFLAG(ENABLE_PRINTING)
[email protected]168b77992014-08-20 11:48:401418 host->AddFilter(new printing::PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:031419#endif
[email protected]ba780c12013-10-01 17:07:061420 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
thestig397accd2015-04-04 00:03:041421 host->AddFilter(new TtsMessageFilter(host->GetBrowserContext()));
Darin Fisher8c84328c2019-07-23 02:50:001422
1423 WebRtcLoggingHandlerHost::AttachToRenderProcessHost(
1424 host, g_browser_process->webrtc_log_uploader());
tereliusfa159cc2016-04-13 15:13:021425
grunell086a4112017-03-02 09:23:041426 // The audio manager outlives the host, so it's safe to hand a raw pointer to
1427 // it to the AudioDebugRecordingsHandler, which is owned by the host.
tereliusfa159cc2016-04-13 15:13:021428 AudioDebugRecordingsHandler* audio_debug_recordings_handler =
Marina Ciocea741a4fb12018-01-27 09:55:121429 new AudioDebugRecordingsHandler(profile);
tereliusfa159cc2016-04-13 15:13:021430 host->SetUserData(
1431 AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey,
Jeremy Romanec48d7a2018-03-01 17:35:091432 std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>(
tereliusfa159cc2016-04-13 15:13:021433 audio_debug_recordings_handler));
1434
Nico Weberaf3b00b2017-09-11 17:58:171435#if BUILDFLAG(ENABLE_NACL)
Helen Li8897b022018-05-03 13:29:031436 host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(),
1437 profile->GetPath()));
[email protected]01e59752013-06-18 00:17:351438#endif
jeremyim364ac1182015-03-03 18:49:431439
Xiaohan Wang9b34281b2017-09-08 23:48:331440#if defined(OS_ANDROID)
1441 // Data cannot be persisted if the profile is off the record.
1442 host->AddFilter(
John Abd-El-Malek1f7fc912018-07-26 02:48:061443 new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false));
Yuzu Saijo2d12ef92018-08-21 04:52:071444
1445 // Register CrashMemoryMetricsCollector to report oom related metrics.
1446 host->SetUserData(
1447 CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey,
1448 std::make_unique<CrashMemoryMetricsCollector>(host));
Xiaohan Wang9b34281b2017-09-08 23:48:331449#endif
1450
Jun Caidb3f93cc2018-07-09 21:54:551451 Profile* original_profile = profile->GetOriginalProfile();
John Abd-El-Malek1f7fc912018-07-26 02:48:061452 RendererUpdaterFactory::GetForProfile(original_profile)
1453 ->InitializeRenderer(host);
[email protected]39a5b532011-10-22 01:47:071454
[email protected]a48ab7112014-08-01 16:48:031455 for (size_t i = 0; i < extra_parts_.size(); ++i)
1456 extra_parts_[i]->RenderProcessWillLaunch(host);
[email protected]edece212011-11-16 11:56:561457
Ken Rockot40a1df792019-05-08 22:15:521458 mojo::PendingRemote<service_manager::mojom::Service> service;
1459 *service_request = service.InitWithNewPipeAndPassReceiver();
Ben Goodger16331302018-01-23 00:43:211460 service_manager::Identity renderer_identity = host->GetChildIdentity();
Ken Rockot0adc1e42019-05-24 08:20:081461 mojo::Remote<service_manager::mojom::ProcessMetadata> metadata;
Ken Rockota86fa542018-11-13 21:47:131462 ChromeService::GetInstance()->connector()->RegisterServiceInstance(
Ben Goodger16331302018-01-23 00:43:211463 service_manager::Identity(chrome::mojom::kRendererServiceName,
Ken Rockotd2ed25a2018-11-06 22:25:371464 renderer_identity.instance_group(),
Ken Rockota86fa542018-11-13 21:47:131465 renderer_identity.instance_id(),
1466 base::Token::CreateRandom()),
Ken Rockot0adc1e42019-05-24 08:20:081467 std::move(service), metadata.BindNewPipeAndPassReceiver());
[email protected]05fcf982011-04-19 00:44:141468}
1469
[email protected]3d7474ff2011-07-27 17:47:371470GURL ChromeContentBrowserClient::GetEffectiveURL(
Alex Moshchukbb99a332017-11-22 04:49:571471 content::BrowserContext* browser_context,
Alex Moshchuka31c7882018-01-17 00:57:301472 const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:371473 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:521474 if (!profile)
1475 return url;
1476
Marc Treib7d467b792017-12-04 13:31:031477#if !defined(OS_ANDROID)
[email protected]b3cb3a32013-07-31 01:32:291478 // If the input |url| should be assigned to the Instant renderer, make its
1479 // effective URL distinct from other URLs on the search provider's domain.
Alex Moshchukca171372017-11-28 16:11:311480 // This needs to happen even if |url| corresponds to an isolated origin; see
1481 // https://crbug.com/755595.
sdefresne51bbec7b2015-08-03 14:18:131482 if (search::ShouldAssignURLToInstantRenderer(url, profile))
1483 return search::GetEffectiveURLForInstant(url, profile);
Marc Treib7d467b792017-12-04 13:31:031484#endif
[email protected]b3cb3a32013-07-31 01:32:291485
brettw00899e62016-11-12 02:10:171486#if BUILDFLAG(ENABLE_EXTENSIONS)
Alex Moshchuka31c7882018-01-17 00:57:301487 return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile,
1488 url);
[email protected]d5a74be2014-08-08 01:01:271489#else
1490 return url;
1491#endif
[email protected]36fb2c7c2011-04-04 15:49:081492}
1493
Alexander Yashkin6aedc6e2018-08-15 08:58:451494bool ChromeContentBrowserClient::
1495 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1496 content::BrowserContext* browser_context,
1497 content::SiteInstance* candidate_site_instance,
1498 bool is_main_frame,
1499 const GURL& candidate_url,
1500 const GURL& destination_url) {
1501 DCHECK(browser_context);
1502 DCHECK(candidate_site_instance);
1503#if BUILDFLAG(ENABLE_EXTENSIONS)
1504 return ChromeContentBrowserClientExtensionsPart::
1505 ShouldCompareEffectiveURLsForSiteInstanceSelection(
1506 browser_context, candidate_site_instance, is_main_frame,
1507 candidate_url, destination_url);
1508#else
1509 return true;
1510#endif
1511}
1512
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521513bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() {
Ahmed Fakhrye6a2c642018-06-20 02:58:411514#if defined(OS_ANDROID)
1515 return true;
1516#elif defined(OS_CHROMEOS)
Huanzhong Huangafa98092019-06-24 12:01:241517 return TabletModeClient::Get() &&
1518 TabletModeClient::Get()->tablet_mode_enabled();
Ahmed Fakhrye6a2c642018-06-20 02:58:411519#else
1520 return false;
1521#endif // defined(OS_ANDROID)
1522}
1523
[email protected]056ad2a2011-07-12 02:13:551524bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371525 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521526 Profile* profile = Profile::FromBrowserContext(browser_context);
1527 if (!profile)
1528 return false;
1529
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301530 // NTP should use process-per-site. This is a performance optimization to
1531 // reduce process count associated with NTP tabs.
1532 if (effective_url == GURL(chrome::kChromeUINewTabURL))
1533 return true;
Marc Treib7d467b792017-12-04 13:31:031534#if !defined(OS_ANDROID)
sdefresne51bbec7b2015-08-03 14:18:131535 if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521536 return true;
Marc Treib7d467b792017-12-04 13:31:031537#endif
[email protected]c5dec6292013-01-25 04:54:521538
brettw00899e62016-11-12 02:10:171539#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301540 if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
1541 profile, effective_url))
1542 return true;
[email protected]d5a74be2014-08-08 01:01:271543#endif
Lukasz Anforowiczfec6b9a2019-07-16 21:02:301544
1545 // Non-extension, non-NTP URLs should generally use process-per-site-instance
1546 // (rather than process-per-site).
1547 return false;
[email protected]056ad2a2011-07-12 02:13:551548}
1549
Lukasz Anforowicz32d27122018-04-09 21:48:331550bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost(
1551 content::BrowserContext* browser_context,
1552 const GURL& site_url) {
1553 Profile* profile = Profile::FromBrowserContext(browser_context);
1554 if (!profile)
1555 return false;
1556
1557#if !defined(OS_ANDROID)
1558 // Instant renderers should not use a spare process, because they require
1559 // passing switches::kInstantProcess to the renderer process when it
1560 // launches. A spare process is launched earlier, before it is known which
1561 // navigation will use it, so it lacks this flag.
1562 if (search::ShouldAssignURLToInstantRenderer(site_url, profile))
1563 return false;
1564#endif
1565
1566#if BUILDFLAG(ENABLE_EXTENSIONS)
1567 return ChromeContentBrowserClientExtensionsPart::
1568 ShouldUseSpareRenderProcessHost(profile, site_url);
1569#else
1570 return true;
1571#endif
1572}
1573
nickcc0d9142015-10-14 16:27:101574bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess(
Lukasz Anforowicz4aff3b82019-04-04 16:00:331575 content::BrowserOrResourceContext browser_or_resource_context,
nickcc0d9142015-10-14 16:27:101576 const GURL& effective_site_url) {
brettw00899e62016-11-12 02:10:171577#if BUILDFLAG(ENABLE_EXTENSIONS)
nickcc0d9142015-10-14 16:27:101578 if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess(
Lukasz Anforowicz4aff3b82019-04-04 16:00:331579 browser_or_resource_context, effective_site_url)) {
nickcc0d9142015-10-14 16:27:101580 return true;
1581 }
1582#endif
1583 return false;
1584}
1585
nick7d0984c2015-08-29 00:13:461586// TODO(creis, nick): https://crbug.com/160576 describes a weakness in our
1587// origin-lock enforcement, where we don't have a way to efficiently know
1588// effective URLs on the IO thread, and wind up killing processes that e.g.
1589// request cookies for their actual URL. This whole function (and its
1590// ExtensionsPart) should be removed once we add that ability to the IO thread.
1591bool ChromeContentBrowserClient::ShouldLockToOrigin(
1592 content::BrowserContext* browser_context,
1593 const GURL& effective_site_url) {
1594 // Origin lock to the search scheme would kill processes upon legitimate
1595 // requests for cookies from the search engine's domain.
1596 if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme))
1597 return false;
1598
brettw00899e62016-11-12 02:10:171599#if BUILDFLAG(ENABLE_EXTENSIONS)
nick7d0984c2015-08-29 00:13:461600 if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin(
1601 browser_context, effective_site_url)) {
1602 return false;
1603 }
1604#endif
1605 return true;
creise5d6d1732015-08-25 19:47:061606}
1607
Lukasz Anforowicz05f356e2018-03-13 20:26:111608const char*
Lukasz Anforowiczce869f0b2018-08-06 18:33:371609ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() {
Charles Reis358baf472017-12-06 05:30:431610#if BUILDFLAG(ENABLE_EXTENSIONS)
Lukasz Anforowicz05f356e2018-03-13 20:26:111611 // Don't block responses for extension processes or for content scripts.
1612 // TODO(creis): When every extension fetch (including content scripts) has
1613 // been made to go through an extension-specific URLLoaderFactory, this
1614 // mechanism ought to work by enumerating the host permissions from the
1615 // extension manifest, and forwarding them on to the network service while
1616 // brokering the URLLoaderFactory.
1617 return extensions::kExtensionScheme;
1618#else
1619 return nullptr;
Charles Reis358baf472017-12-06 05:30:431620#endif
Charles Reis358baf472017-12-06 05:30:431621}
1622
Maks Orlovich0e23e312019-07-16 13:13:561623bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
1624 base::StringPiece scheme) {
1625#if BUILDFLAG(ENABLE_EXTENSIONS)
1626 return scheme == extensions::kExtensionScheme;
1627#else
1628 return false;
1629#endif
1630}
1631
Lukasz Anforowicz2f810162018-10-03 21:38:071632network::mojom::URLLoaderFactoryPtrInfo
1633ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests(
1634 content::RenderProcessHost* process,
1635 network::mojom::NetworkContext* network_context,
Clark DuValla5e25b752018-11-27 22:08:161636 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Lukasz Anforowicz2f810162018-10-03 21:38:071637 const url::Origin& request_initiator) {
1638#if BUILDFLAG(ENABLE_EXTENSIONS)
1639 return ChromeContentBrowserClientExtensionsPart::
Clark DuValla5e25b752018-11-27 22:08:161640 CreateURLLoaderFactoryForNetworkRequests(
1641 process, network_context, header_client, request_initiator);
Lukasz Anforowicz2f810162018-10-03 21:38:071642#else
1643 return network::mojom::URLLoaderFactoryPtrInfo();
1644#endif
1645}
1646
[email protected]73b718f2014-01-27 02:59:461647// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1648// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411649void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1650 std::vector<std::string>* additional_schemes) {
1651 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]474a5a32014-07-28 18:23:241652 additional_schemes->push_back(dom_distiller::kDomDistillerScheme);
Andrey Kosyakov031e9e32017-08-18 21:00:351653 additional_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]672c8c12013-03-07 12:30:061654}
1655
alexmos94875b3b2017-03-16 22:19:011656void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes(
1657 std::vector<std::string>* additional_schemes) {
1658 GetAdditionalWebUISchemes(additional_schemes);
1659
1660#if BUILDFLAG(ENABLE_EXTENSIONS)
1661 additional_schemes->push_back(extensions::kExtensionScheme);
1662#endif
1663}
1664
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:521665bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) {
dbeambaee5bd2015-09-26 03:07:011666 return webui::LogWebUIUrl(web_ui_url);
1667}
1668
John Abd-El-Malek04bfa8532018-07-12 05:28:221669bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
1670 const url::Origin& origin) {
1671 return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
1672 origin);
1673}
1674
[email protected]46fb9442011-12-09 17:57:471675bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1676 return ProfileIOData::IsHandledURL(url);
1677}
1678
[email protected]c4365fa42013-05-14 01:08:241679bool ChromeContentBrowserClient::CanCommitURL(
1680 content::RenderProcessHost* process_host,
1681 const GURL& url) {
brettw00899e62016-11-12 02:10:171682#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131683 return ChromeContentBrowserClientExtensionsPart::CanCommitURL(
1684 process_host, url);
[email protected]d5a74be2014-08-08 01:01:271685#else
1686 return true;
1687#endif
[email protected]c4365fa42013-05-14 01:08:241688}
1689
[email protected]9a60d1602013-09-11 04:09:121690bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1691 content::SiteInstance* site_instance, const GURL& url) {
brettw00899e62016-11-12 02:10:171692#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131693 bool result;
1694 if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL(
alexmos1c3da4f2016-11-03 06:06:111695 site_instance, url, &result))
[email protected]f7daaa32014-08-02 07:58:131696 return result;
[email protected]d5a74be2014-08-08 01:01:271697#endif
[email protected]879816a92014-04-29 00:53:541698
1699 // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since
1700 // the signin page may host untrusted web content.
alexmos1c3da4f2016-11-03 06:06:111701 GURL from_url = site_instance->GetSiteURL();
[email protected]879816a92014-04-29 00:53:541702 if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL &&
1703 url.SchemeIs(content::kChromeUIScheme) &&
brettwb65cd5c2016-01-23 00:46:381704 url.host_piece() != chrome::kChromeUIChromeSigninHost) {
[email protected]879816a92014-04-29 00:53:541705 VLOG(1) << "Blocked navigation to " << url.spec() << " from "
1706 << chrome::kChromeUIChromeSigninURL;
1707 return false;
1708 }
1709
[email protected]9a60d1602013-09-11 04:09:121710 return true;
1711}
1712
rdevlin.cronina32a0902016-11-09 15:50:201713void ChromeContentBrowserClient::OverrideNavigationParams(
1714 SiteInstance* site_instance,
1715 ui::PageTransition* transition,
1716 bool* is_renderer_initiated,
Lukasz Anforowicz63f3b9432019-05-30 05:42:581717 content::Referrer* referrer,
1718 base::Optional<url::Origin>* initiator_origin) {
rdevlin.cronina32a0902016-11-09 15:50:201719 DCHECK(transition);
1720 DCHECK(is_renderer_initiated);
1721 DCHECK(referrer);
Moe Ahmadi26e2f502019-07-16 02:34:471722 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1723 // use for making security decisions 99.44% of the time, for detecting the NTP
1724 // it is reliable and the correct way. See http://crbug.com/624410.
1725 if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) &&
rdevlin.cronina32a0902016-11-09 15:50:201726 ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:581727 // Clicks on tiles of the new tab page should be treated as if a user
1728 // clicked on a bookmark. This is consistent with native implementations
1729 // like Android's. This also helps ensure that security features (like
1730 // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as
1731 // browser-initiated.
rdevlin.cronina32a0902016-11-09 15:50:201732 *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
1733 *is_renderer_initiated = false;
1734 *referrer = content::Referrer();
Lukasz Anforowicz63f3b9432019-05-30 05:42:581735 *initiator_origin = base::nullopt;
mastiza77db6992016-06-30 09:48:421736 }
rdevlin.cronina32a0902016-11-09 15:50:201737
brettw00899e62016-11-12 02:10:171738#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.cronina32a0902016-11-09 15:50:201739 ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams(
Lukasz Anforowicz63f3b9432019-05-30 05:42:581740 site_instance, transition, is_renderer_initiated, referrer,
1741 initiator_origin);
rdevlin.cronina32a0902016-11-09 15:50:201742#endif
mastiza77db6992016-06-30 09:48:421743}
1744
Charles Reis29e9dd12017-09-28 00:59:151745bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP(
1746 const GURL& url,
1747 SiteInstance* parent_site_instance) {
Moe Ahmadi26e2f502019-07-16 02:34:471748 // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to
1749 // use for making security decisions 99.44% of the time, for detecting the NTP
1750 // it is reliable and the correct way. See http://crbug.com/624410.
1751 return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance &&
1752 search::IsNTPURL(parent_site_instance->GetSiteURL());
Charles Reis29e9dd12017-09-28 00:59:151753}
1754
[email protected]2a5221b2011-09-27 23:07:311755bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301756 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311757 const GURL& site_url) {
1758 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301759 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521760 // This may be NULL during tests. In that case, just assume any site can
1761 // share any host.
1762 if (!profile)
1763 return true;
1764
Marc Treib7895941d2017-11-28 12:37:021765#if !defined(OS_ANDROID)
[email protected]d43f99fe2013-04-03 00:20:141766 // Instant URLs should only be in the instant process and instant process
1767 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521768 InstantService* instant_service =
1769 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141770 if (instant_service) {
1771 bool is_instant_process = instant_service->IsInstantProcess(
1772 process_host->GetID());
1773 bool should_be_in_instant_process =
sdefresne51bbec7b2015-08-03 14:18:131774 search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]d43f99fe2013-04-03 00:20:141775 if (is_instant_process || should_be_in_instant_process)
1776 return is_instant_process && should_be_in_instant_process;
1777 }
Marc Treib7895941d2017-11-28 12:37:021778#endif
[email protected]c5dec6292013-01-25 04:54:521779
brettw00899e62016-11-12 02:10:171780#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131781 return ChromeContentBrowserClientExtensionsPart::IsSuitableHost(
1782 profile, process_host, site_url);
[email protected]d5a74be2014-08-08 01:01:271783#else
1784 return true;
1785#endif
[email protected]2a5221b2011-09-27 23:07:311786}
1787
[email protected]28c5d0b72014-05-13 08:19:591788bool ChromeContentBrowserClient::MayReuseHost(
1789 content::RenderProcessHost* process_host) {
1790 // If there is currently a prerender in progress for the host provided,
1791 // it may not be shared. We require prerenders to be by themselves in a
davidben879199c2015-03-06 00:55:041792 // separate process so that we can monitor their resource usage.
[email protected]28c5d0b72014-05-13 08:19:591793 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:371794 prerender::PrerenderManagerFactory::GetForBrowserContext(
1795 process_host->GetBrowserContext());
[email protected]28c5d0b72014-05-13 08:19:591796 if (prerender_manager &&
[email protected]2290af22014-05-26 15:44:491797 !prerender_manager->MayReuseProcessHost(process_host)) {
[email protected]28c5d0b72014-05-13 08:19:591798 return false;
1799 }
1800
1801 return true;
1802}
1803
[email protected]76411f412012-02-22 18:56:061804bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1805 content::BrowserContext* browser_context, const GURL& url) {
1806 // It has to be a valid URL for us to check for an extension.
1807 if (!url.is_valid())
1808 return false;
1809
brettw00899e62016-11-12 02:10:171810#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]76411f412012-02-22 18:56:061811 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]f7daaa32014-08-02 07:58:131812 return ChromeContentBrowserClientExtensionsPart::
1813 ShouldTryToUseExistingProcessHost(
1814 profile, url);
[email protected]d5a74be2014-08-08 01:01:271815#else
1816 return false;
1817#endif
[email protected]76411f412012-02-22 18:56:061818}
1819
Alex Moshchuk9c9e3882018-11-02 19:57:031820bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess(
1821 content::RenderFrameHost* main_frame) {
1822#if BUILDFLAG(ENABLE_EXTENSIONS)
1823 return ChromeContentBrowserClientExtensionsPart::
1824 ShouldSubframesTryToReuseExistingProcess(main_frame);
1825#else
1826 return true;
1827#endif
1828}
1829
[email protected]6f371442011-11-09 06:45:461830void ChromeContentBrowserClient::SiteInstanceGotProcess(
1831 SiteInstance* site_instance) {
1832 CHECK(site_instance->HasProcess());
1833
1834 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021835 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521836 if (!profile)
1837 return;
1838
Marc Treib7895941d2017-11-28 12:37:021839#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:521840 // Remember the ID of the Instant process to signal the renderer process
1841 // on startup in |AppendExtraCommandLineSwitches| below.
sdefresne51bbec7b2015-08-03 14:18:131842 if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(),
1843 profile)) {
[email protected]c5dec6292013-01-25 04:54:521844 InstantService* instant_service =
1845 InstantServiceFactory::GetForProfile(profile);
1846 if (instant_service)
1847 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1848 }
Marc Treib7895941d2017-11-28 12:37:021849#endif
[email protected]c5dec6292013-01-25 04:54:521850
[email protected]a48ab7112014-08-01 16:48:031851 for (size_t i = 0; i < extra_parts_.size(); ++i)
1852 extra_parts_[i]->SiteInstanceGotProcess(site_instance);
[email protected]6f371442011-11-09 06:45:461853}
1854
1855void ChromeContentBrowserClient::SiteInstanceDeleting(
1856 SiteInstance* site_instance) {
1857 if (!site_instance->HasProcess())
1858 return;
1859
[email protected]a48ab7112014-08-01 16:48:031860 for (size_t i = 0; i < extra_parts_.size(); ++i)
1861 extra_parts_[i]->SiteInstanceDeleting(site_instance);
[email protected]6f371442011-11-09 06:45:461862}
1863
[email protected]453f5432013-11-26 19:43:001864bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141865 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081866 const GURL& current_url,
1867 const GURL& new_url) {
brettw00899e62016-11-12 02:10:171868#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f7daaa32014-08-02 07:58:131869 return ChromeContentBrowserClientExtensionsPart::
1870 ShouldSwapBrowsingInstancesForNavigation(
1871 site_instance, current_url, new_url);
[email protected]d5a74be2014-08-08 01:01:271872#else
1873 return false;
1874#endif
[email protected]e3daf3c2011-10-05 21:17:081875}
1876
Nasko Oskovd83b5712018-05-04 04:50:571877bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
1878 // TODO(nasko): Consider supporting error page isolation in subframes if
1879 // Site Isolation is enabled.
Nasko Oskov55d21e152018-06-27 23:59:381880 return in_main_frame;
Nasko Oskovd83b5712018-05-04 04:50:571881}
1882
[email protected]3d831992013-07-04 01:13:291883bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1884 return !url.SchemeIs(chrome::kChromeNativeScheme);
1885}
1886
Alex Moshchukd252c192017-07-17 22:03:481887std::vector<url::Origin>
1888ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() {
1889 std::vector<url::Origin> isolated_origin_list;
1890
Alex Moshchuk89352a72017-10-25 20:25:591891// Sign-in process isolation is not needed on Android, see
1892// https://crbug.com/739418.
1893#if !defined(OS_ANDROID)
Alex Moshchuk81d2a29e2019-07-16 01:14:381894 isolated_origin_list.push_back(
Alex Moshchuk36417aa2018-06-13 18:01:121895 url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()));
Alex Moshchuk89352a72017-10-25 20:25:591896#endif
Alex Moshchukd252c192017-07-17 22:03:481897
Alex Moshchuk81d2a29e2019-07-16 01:14:381898#if BUILDFLAG(ENABLE_EXTENSIONS)
1899 auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart::
1900 GetOriginsRequiringDedicatedProcess();
1901 std::move(std::begin(origins_from_extensions),
1902 std::end(origins_from_extensions),
1903 std::back_inserter(isolated_origin_list));
1904#endif
1905
Alex Moshchukd252c192017-07-17 22:03:481906 return isolated_origin_list;
1907}
1908
Lukasz Anforowicz5e201abd2018-03-24 00:41:061909bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() {
Aaron Colwell25617f72018-11-27 20:56:341910 return base::FeatureList::IsEnabled(features::kSitePerProcess);
1911}
1912
1913bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() {
Lukasz Anforowicz0711a0f2019-03-28 18:15:311914 // Using 1077 rather than 1024 because 1) it helps ensure that devices with
1915 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one
1916 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2.
1917 // See also https://crbug.com/844118.
1918 constexpr int kDefaultMemoryThresholdMb = 1077;
Aaron Colwell25617f72018-11-27 20:56:341919
1920 // TODO(acolwell): Rename feature since it now affects more than just the
1921 // site-per-process case.
Lukasz Anforowicz46275d92018-04-12 14:57:381922 if (base::FeatureList::IsEnabled(
1923 features::kSitePerProcessOnlyForHighMemoryClients)) {
Lukasz Anforowicz46275d92018-04-12 14:57:381924 int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
1925 features::kSitePerProcessOnlyForHighMemoryClients,
1926 features::kSitePerProcessOnlyForHighMemoryClientsParamName,
1927 kDefaultMemoryThresholdMb);
Aaron Colwell25617f72018-11-27 20:56:341928 return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb;
Lukasz Anforowicz46275d92018-04-12 14:57:381929 }
1930
Aaron Colwell25617f72018-11-27 20:56:341931#if defined(OS_ANDROID)
1932 if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) {
1933 return true;
1934 }
1935#endif
1936
1937 return false;
Lukasz Anforowicz5e201abd2018-03-24 00:41:061938}
1939
Alex Moshchuk082b5f82019-03-14 01:34:161940std::vector<std::string>
1941ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() {
1942 if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled())
1943 return {"Isolate Password Sites"};
1944 else
1945 return {};
1946}
1947
Alex Moshchuke256d562019-04-26 21:43:571948void ChromeContentBrowserClient::PersistIsolatedOrigin(
1949 content::BrowserContext* context,
1950 const url::Origin& origin) {
1951 DCHECK(!context->IsOffTheRecord());
1952 Profile* profile = Profile::FromBrowserContext(context);
1953 ListPrefUpdate update(profile->GetPrefs(),
1954 prefs::kUserTriggeredIsolatedOrigins);
1955 base::ListValue* list = update.Get();
1956 base::Value value(origin.Serialize());
Jan Wilken Dörriea8cb56302019-06-06 18:59:361957 if (!base::Contains(list->GetList(), value))
Alex Moshchuke256d562019-04-26 21:43:571958 list->GetList().push_back(std::move(value));
1959}
1960
Ken Rockot314714c2017-11-05 23:36:241961bool ChromeContentBrowserClient::IsFileAccessAllowed(
1962 const base::FilePath& path,
1963 const base::FilePath& absolute_path,
1964 const base::FilePath& profile_path) {
1965 return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path,
1966 profile_path);
1967}
1968
[email protected]d2e1a0a2014-06-16 15:49:371969namespace {
1970
1971bool IsAutoReloadEnabled() {
avi3ef9ec9e2014-12-22 22:50:171972 const base::CommandLine& browser_command_line =
1973 *base::CommandLine::ForCurrentProcess();
Elly Fong-Jones5f13ee12019-05-10 19:20:351974 if (browser_command_line.HasSwitch(switches::kEnableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371975 return true;
Elly Fong-Jones5f13ee12019-05-10 19:20:351976 if (browser_command_line.HasSwitch(switches::kDisableAutoReload))
[email protected]d2e1a0a2014-06-16 15:49:371977 return false;
[email protected]9ef49b42014-08-07 16:44:241978 return true;
[email protected]d2e1a0a2014-06-16 15:49:371979}
1980
bmcquade5d2d9cf32015-06-19 17:42:281981void MaybeAppendBlinkSettingsSwitchForFieldTrial(
1982 const base::CommandLine& browser_command_line,
1983 base::CommandLine* command_line) {
bmcquade9dd54cc2015-06-22 16:56:521984 // List of field trials that modify the blink-settings command line flag. No
1985 // two field trials in the list should specify the same keys, otherwise one
1986 // field trial may overwrite another. See Source/core/frame/Settings.in in
1987 // Blink for the list of valid keys.
1988 static const char* const kBlinkSettingsFieldTrials[] = {
jkarlin3bddb7d2016-09-21 18:44:161989 // Keys: disallowFetchForDocWrittenScriptsInMainFrame
1990 // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections
1991 // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G
1992 "DisallowFetchForDocWrittenScriptsInMainFrame",
bmcquade9dd54cc2015-06-22 16:56:521993 };
1994
1995 std::vector<std::string> blink_settings;
1996 for (const char* field_trial_name : kBlinkSettingsFieldTrials) {
1997 // Each blink-settings field trial should include a forcing_flag group,
1998 // to make sure that clients that specify the blink-settings flag on the
1999 // command line are excluded from the experiment groups. To make
2000 // sure we assign clients that specify this flag to the forcing_flag
2001 // group, we must call GetVariationParams for each field trial first
2002 // (for example, before checking HasSwitch() and returning), since
2003 // GetVariationParams has the side-effect of assigning the client to
2004 // a field trial group.
2005 std::map<std::string, std::string> params;
2006 if (variations::GetVariationParams(field_trial_name, &params)) {
2007 for (const auto& param : params) {
2008 blink_settings.push_back(base::StringPrintf(
2009 "%s=%s", param.first.c_str(), param.second.c_str()));
2010 }
2011 }
2012 }
pmeenan9ac669682015-08-17 14:57:032013
bmcquade9dd54cc2015-06-22 16:56:522014 if (blink_settings.empty()) {
bmcquade5d2d9cf32015-06-19 17:42:282015 return;
2016 }
2017
2018 if (browser_command_line.HasSwitch(switches::kBlinkSettings) ||
2019 command_line->HasSwitch(switches::kBlinkSettings)) {
pmeenan9ac669682015-08-17 14:57:032020 // The field trials should be configured to force users that specify the
bmcquade9dd54cc2015-06-22 16:56:522021 // blink-settings flag into a group with no params, and we return
2022 // above if no params were specified, so it's an error if we reach
2023 // this point.
bmcquade5d2d9cf32015-06-19 17:42:282024 LOG(WARNING) << "Received field trial params, "
2025 "but blink-settings switch already specified.";
2026 return;
2027 }
2028
bmcquade5d2d9cf32015-06-19 17:42:282029 command_line->AppendSwitchASCII(switches::kBlinkSettings,
brettwd94a22142015-07-15 05:19:262030 base::JoinString(blink_settings, ","));
bmcquade5d2d9cf32015-06-19 17:42:282031}
2032
zpengdb4a58e2017-01-10 17:40:322033#if defined(OS_ANDROID)
Ben Goodger6a695c012017-06-20 20:21:202034template <typename Interface>
2035void ForwardToJavaFrameRegistry(
Ben Goodger6a695c012017-06-20 20:21:202036 mojo::InterfaceRequest<Interface> request,
2037 content::RenderFrameHost* render_frame_host) {
2038 render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request));
mgiuca3d9a1962017-04-07 05:25:442039}
2040
Ben Goodger6a695c012017-06-20 20:21:202041template <typename Interface>
2042void ForwardToJavaWebContentsRegistry(
Ben Goodger6a695c012017-06-20 20:21:202043 mojo::InterfaceRequest<Interface> request,
2044 content::RenderFrameHost* render_frame_host) {
2045 content::WebContents* contents =
2046 content::WebContents::FromRenderFrameHost(render_frame_host);
2047 if (contents)
2048 contents->GetJavaInterfaces()->GetInterface(std::move(request));
sammc0285a442016-10-04 23:03:562049}
2050#endif
2051
[email protected]d2e1a0a2014-06-16 15:49:372052} // namespace
2053
[email protected]b80f68432011-05-02 17:22:302054void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
avi3ef9ec9e2014-12-22 22:50:172055 base::CommandLine* command_line,
2056 int child_process_id) {
Mark Mentovaic67fa64f2015-03-24 14:00:062057#if defined(OS_MACOSX)
dcheng4af48582016-04-19 00:29:352058 std::unique_ptr<metrics::ClientInfo> client_info =
Mark Mentovaic67fa64f2015-03-24 14:00:062059 GoogleUpdateSettings::LoadMetricsClientInfo();
2060 if (client_info) {
2061 command_line->AppendSwitchASCII(switches::kMetricsClientID,
2062 client_info->client_id);
2063 }
2064#elif defined(OS_POSIX)
Joshua Perazaf890e4b2019-01-03 19:19:022065#if defined(OS_ANDROID)
2066 bool enable_crash_reporter = true;
2067#else
2068 bool enable_crash_reporter = breakpad::IsCrashReporterEnabled();
2069#endif
2070 if (enable_crash_reporter) {
thestigcb7a59a2016-01-26 02:43:512071 std::string switch_value;
dcheng4af48582016-04-19 00:29:352072 std::unique_ptr<metrics::ClientInfo> client_info =
[email protected]8e885de2014-07-22 23:36:532073 GoogleUpdateSettings::LoadMetricsClientInfo();
thestigcb7a59a2016-01-26 02:43:512074 if (client_info)
2075 switch_value = client_info->client_id;
2076 switch_value.push_back(',');
Boris Vidolov86578012018-03-21 16:55:252077 switch_value.append(chrome::GetChannelName());
[email protected]b80f68432011-05-02 17:22:302078 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
thestigcb7a59a2016-01-26 02:43:512079 switch_value);
[email protected]b80f68432011-05-02 17:22:302080 }
Mark Mentovaic67fa64f2015-03-24 14:00:062081#endif
[email protected]b80f68432011-05-02 17:22:302082
[email protected]f1933792011-06-14 00:49:342083 if (logging::DialogsAreSuppressed())
2084 command_line->AppendSwitch(switches::kNoErrorDialogs);
2085
[email protected]b80f68432011-05-02 17:22:302086 std::string process_type =
2087 command_line->GetSwitchValueASCII(switches::kProcessType);
avi3ef9ec9e2014-12-22 22:50:172088 const base::CommandLine& browser_command_line =
2089 *base::CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:322090
[email protected]7c9b6f92013-09-10 18:11:352091 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:562092 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:352093 switches::kUserDataDir, // Make logs go to the right file.
2094 };
2095 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372096 base::size(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:322097
fqj15ff3f72015-10-09 19:20:022098 static const char* const kDinosaurEasterEggSwitches[] = {
blundella5e3240a2016-01-05 11:30:432099 error_page::switches::kDisableDinosaurEasterEgg,
edwardjung7db1c9e2015-03-25 15:44:312100 };
fqj15ff3f72015-10-09 19:20:022101 command_line->CopySwitchesFrom(browser_command_line,
2102 kDinosaurEasterEggSwitches,
Avi Drissmand251e912018-12-26 15:46:372103 base::size(kDinosaurEasterEggSwitches));
edwardjung7db1c9e2015-03-25 15:44:312104
fqj15ff3f72015-10-09 19:20:022105#if defined(OS_CHROMEOS)
[email protected]6bdc52272014-05-27 00:12:332106 // On Chrome OS need to pass primary user homedir (in multi-profiles session).
2107 base::FilePath homedir;
Avi Drissman9098f9002018-05-04 00:11:522108 base::PathService::Get(base::DIR_HOME, &homedir);
[email protected]6bdc52272014-05-27 00:12:332109 command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
2110 homedir.value().c_str());
2111#endif
2112
[email protected]718eab62011-10-05 21:16:522113 if (process_type == switches::kRendererProcess) {
[email protected]a48ab7112014-08-01 16:48:032114 content::RenderProcessHost* process =
2115 content::RenderProcessHost::FromID(child_process_id);
2116 Profile* profile =
2117 process ? Profile::FromBrowserContext(process->GetBrowserContext())
2118 : NULL;
2119 for (size_t i = 0; i < extra_parts_.size(); ++i) {
2120 extra_parts_[i]->AppendExtraRendererCommandLineSwitches(
2121 command_line, process, profile);
2122 }
2123
[email protected]b80f68432011-05-02 17:22:302124#if defined(OS_CHROMEOS)
2125 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:442126 browser_command_line.GetSwitchValueASCII(
2127 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:302128 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:442129 command_line->AppendSwitchASCII(
2130 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:302131#endif
2132
[email protected]30335fdf02014-02-26 19:51:272133 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
2134 browser_command_line,
sdefresne9fb67692015-08-03 18:48:222135 chrome::GetChannel());
[email protected]a8d851f82011-12-21 00:32:372136 if (process) {
[email protected]a8d851f82011-12-21 00:32:372137 PrefService* prefs = profile->GetPrefs();
2138 // Currently this pref is only registered if applied via a policy.
2139 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
2140 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
2141 // Turn this policy into a command line switch.
2142 command_line->AppendSwitch(switches::kDisable3DAPIs);
2143 }
[email protected]718eab62011-10-05 21:16:522144
[email protected]1733b782014-06-19 18:51:552145 const base::ListValue* switches =
2146 prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures);
2147 if (switches) {
2148 // Enable any deprecated features that have been re-enabled by policy.
jdoerrie601c7152018-10-02 23:43:112149 for (auto it = switches->begin(); it != switches->end(); ++it) {
[email protected]1733b782014-06-19 18:51:552150 std::string switch_to_enable;
jdoerriea5676c62017-04-11 18:09:142151 if (it->GetAsString(&switch_to_enable))
[email protected]1733b782014-06-19 18:51:552152 command_line->AppendSwitch(switch_to_enable);
2153 }
2154 }
2155
[email protected]a8d851f82011-12-21 00:32:372156 // Disable client-side phishing detection in the renderer if it is
2157 // disabled in the Profile preferences or the browser process.
2158 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
2159 !g_browser_process->safe_browsing_detection_service()) {
2160 command_line->AppendSwitch(
2161 switches::kDisableClientSidePhishingDetection);
2162 }
[email protected]0045b0f42012-07-26 11:52:082163
vitalybukaa7ae5052014-09-26 04:11:132164 if (prefs->GetBoolean(prefs::kPrintPreviewDisabled))
2165 command_line->AppendSwitch(switches::kDisablePrintPreview);
2166
Marc Treib7895941d2017-11-28 12:37:022167#if !defined(OS_ANDROID)
[email protected]c5dec6292013-01-25 04:54:522168 InstantService* instant_service =
2169 InstantServiceFactory::GetForProfile(profile);
2170 if (instant_service &&
Chris Palmerac7d75642017-11-22 20:12:542171 instant_service->IsInstantProcess(process->GetID())) {
[email protected]c5dec6292013-01-25 04:54:522172 command_line->AppendSwitch(switches::kInstantProcess);
Chris Palmerac7d75642017-11-22 20:12:542173 }
Marc Treib7895941d2017-11-28 12:37:022174#endif
fqjba8749c2015-10-29 15:33:072175
fqj38306f7b2015-11-02 16:59:062176 if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) &&
Chris Palmerac7d75642017-11-22 20:12:542177 !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) {
blundella5e3240a2016-01-05 11:30:432178 command_line->AppendSwitch(
2179 error_page::switches::kDisableDinosaurEasterEgg);
Chris Palmerac7d75642017-11-22 20:12:542180 }
Daniel Vogelheim976f1c22017-11-22 16:26:032181
Lukasz Anforowicz60d1253d2019-05-08 16:31:372182 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
2183
Amr Aboelkherb04cbf32019-04-29 15:17:102184 if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) &&
2185 prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) {
Avi Drissmanfb961262019-03-05 22:50:292186 command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload);
Amr Aboelkherb04cbf32019-04-29 15:17:102187 }
[email protected]47c7ec82012-01-18 03:29:212188 }
[email protected]4287a3d2011-06-13 23:56:512189
[email protected]d2e1a0a2014-06-16 15:49:372190 if (IsAutoReloadEnabled())
Elly Fong-Jones5f13ee12019-05-10 19:20:352191 command_line->AppendSwitch(switches::kEnableAutoReload);
[email protected]28ee4e72014-03-28 19:29:042192
bmcquade5d2d9cf32015-06-19 17:42:282193 MaybeAppendBlinkSettingsSwitchForFieldTrial(
2194 browser_command_line, command_line);
2195
mdjonesa6b9e172016-09-23 16:24:302196#if defined(OS_ANDROID)
2197 // If the platform is Android, force the distillability service on.
2198 command_line->AppendSwitch(switches::kEnableDistillabilityService);
2199#endif
2200
[email protected]47c7ec82012-01-18 03:29:212201 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:512202 static const char* const kSwitchNames[] = {
estade0ee91262014-10-23 19:29:192203 autofill::switches::kIgnoreAutocompleteOffForAutofill,
kolosad369932017-02-23 13:29:412204 autofill::switches::kShowAutofillSignatures,
Chris Mumford6b1696b2019-01-25 02:54:302205#if defined(OS_CHROMEOS)
2206 switches::kShortMergeSessionTimeoutForTest, // For tests only.
2207#endif
brettw00899e62016-11-12 02:10:172208#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]558878cc82013-11-09 01:25:512209 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:272210 extensions::switches::kAllowLegacyExtensionManifests,
Chris Mumford3f0eda92018-07-23 14:51:172211 extensions::switches::kDisableExtensionsHttpThrottling,
[email protected]c8d02992013-07-31 22:16:512212 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272213 extensions::switches::kExtensionsOnChromeURLs,
Chris Mumford3f0eda92018-07-23 14:51:172214 extensions::switches::kSetExtensionThrottleTestParams, // For tests only.
[email protected]a612eb32014-03-31 22:09:172215 extensions::switches::kWhitelistedExtensionID,
thestig2dbee717e2014-09-05 14:54:282216#endif
estark4b003b332015-02-14 01:07:052217 switches::kAllowInsecureLocalhost,
[email protected]4287a3d2011-06-13 23:56:512218 switches::kAppsGalleryURL,
[email protected]09cff78782014-04-20 22:04:482219 switches::kCloudPrintURL,
[email protected]6f5c141a2014-04-15 21:44:512220 switches::kCloudPrintXmppEndpoint,
[email protected]382fb0d2012-02-25 00:19:502221 switches::kDisableBundledPpapiFlash,
dslomova893e972014-12-05 09:39:572222 switches::kDisableJavaScriptHarmonyShipping,
Kyle Milkab5c048e2017-07-07 02:38:462223 variations::switches::kEnableBenchmarking,
mdjonesa6b9e172016-09-23 16:24:302224 switches::kEnableDistillabilityService,
[email protected]4287a3d2011-06-13 23:56:512225 switches::kEnableNaCl,
Nico Weberaf3b00b2017-09-11 17:58:172226#if BUILDFLAG(ENABLE_NACL)
[email protected]1b4ec382014-03-07 02:32:242227 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:482228 switches::kEnableNaClNonSfiMode,
[email protected]a56f8322014-07-16 21:13:552229#endif
[email protected]ce304ce2013-02-22 21:54:452230 switches::kEnableNetBenchmarking,
Nico Weberaf3b00b2017-09-11 17:58:172231#if BUILDFLAG(ENABLE_NACL)
stichnot7040ac832016-02-24 23:40:592232 switches::kForcePNaClSubzero,
2233#endif
Marc Treibad33cf942017-08-24 11:19:002234 switches::kForceUIDirection,
erikcorryb251cb92014-09-25 23:48:512235 switches::kJavaScriptHarmony,
iclelland79237e92016-06-23 12:03:512236 switches::kOriginTrialDisabledFeatures,
chasejdfec22ae2017-03-16 20:58:552237 switches::kOriginTrialDisabledTokens,
iclellandee4f4a72016-04-26 18:59:022238 switches::kOriginTrialPublicKey,
[email protected]4287a3d2011-06-13 23:56:512239 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:512240 switches::kPpapiFlashPath,
2241 switches::kPpapiFlashVersion,
wychene55687342015-11-13 20:17:032242 switches::kReaderModeHeuristics,
[email protected]499e7c52013-10-04 16:03:092243 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:512244 };
2245
2246 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372247 base::size(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:172248 } else if (process_type == switches::kUtilityProcess) {
brettw00899e62016-11-12 02:10:172249#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]a446534d2012-02-09 00:07:382250 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:512251 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:512252 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:272253 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a612eb32014-03-31 22:09:172254 extensions::switches::kWhitelistedExtensionID,
[email protected]a446534d2012-02-09 00:07:382255 };
2256
2257 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372258 base::size(kSwitchNames));
thestig2dbee717e2014-09-05 14:54:282259#endif
Lukasz Anforowicz60d1253d2019-05-08 16:31:372260 MaybeAppendSecureOriginsAllowlistSwitch(command_line);
Jay Civelli668c097f2018-05-16 20:44:132261 } else if (process_type == service_manager::switches::kZygoteProcess) {
[email protected]4287a3d2011-06-13 23:56:512262 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:512263 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:502264 switches::kDisableBundledPpapiFlash,
Nico Weberaf3b00b2017-09-11 17:58:172265#if BUILDFLAG(ENABLE_NACL)
rickyz3638a212014-10-29 23:50:242266 switches::kEnableNaClDebug,
[email protected]a9a8e2f2014-05-13 23:32:582267 switches::kEnableNaClNonSfiMode,
stichnot7040ac832016-02-24 23:40:592268 switches::kForcePNaClSubzero,
[email protected]0b470342014-04-15 12:59:412269 switches::kNaClDangerousNoSandboxNonSfi,
[email protected]a56f8322014-07-16 21:13:552270#endif
[email protected]4287a3d2011-06-13 23:56:512271 switches::kPpapiFlashPath,
2272 switches::kPpapiFlashVersion,
2273 };
2274
2275 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
Avi Drissmand251e912018-12-26 15:46:372276 base::size(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:112277 } else if (process_type == switches::kGpuProcess) {
2278 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
2279 // because GPU is expected to be unreliable.
2280 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
2281 !command_line->HasSwitch(switches::kDisableBreakpad))
2282 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:302283 }
[email protected]6f08af82011-09-15 01:19:032284
Ian Barkley-Yeung550aae052019-07-11 00:11:112285#if defined(OS_CHROMEOS)
2286 if (breakpad::ShouldPassCrashLoopBefore(process_type)) {
2287 static const char* const kSwitchNames[] = {
2288 switches::kCrashLoopBefore,
2289 };
2290 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
2291 base::size(kSwitchNames));
2292 }
2293#endif
2294
wittman832321f52016-10-10 18:18:382295 StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess(
2296 process_type,
2297 command_line);
Andrew Comminos66057672019-05-01 00:03:342298
2299#if defined(OS_LINUX)
2300 // Processes may only query perf_event_open with the BPF sandbox disabled.
2301 if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) &&
2302 command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2303 command_line->AppendSwitch(switches::kEnableThreadInstructionCount);
2304 }
2305#endif
[email protected]b80f68432011-05-02 17:22:302306}
2307
Scott Violet776edf82017-09-29 02:03:012308void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
2309 const service_manager::Identity& identity,
2310 base::CommandLine* command_line) {
Guido Urdaneta191635e2018-05-09 16:00:532311#if defined(OS_MACOSX)
Ken Rockot2f8c1dd22019-07-23 21:56:022312 // On Mac, the audio service requires a CFRunLoop, provided by a UI message
2313 // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581.
2314 if (identity.name() == audio::mojom::kServiceName)
Guido Urdaneta191635e2018-05-09 16:00:532315 command_line->AppendSwitch(switches::kMessageLoopTypeUi);
2316#endif
Scott Violet776edf82017-09-29 02:03:012317}
2318
[email protected]b80f68432011-05-02 17:22:302319std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:432320 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
Lei Zhang2cfceac2018-11-14 19:36:332321 return GetIOThreadApplicationLocale();
[email protected]b80f68432011-05-02 17:22:302322 return g_browser_process->GetApplicationLocale();
2323}
2324
[email protected]597a867b2011-11-18 18:31:202325std::string ChromeContentBrowserClient::GetAcceptLangs(
2326 content::BrowserContext* context) {
2327 Profile* profile = Profile::FromBrowserContext(context);
Alexandre Frechette572755b2019-02-13 22:30:202328 return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:082329}
2330
Dana Fried34d580002019-04-24 20:05:482331gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() {
Lei Zhang7640d542017-10-03 16:26:492332 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
Dana Fried34d580002019-04-24 20:05:482333 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
[email protected]ac55e292011-06-24 05:16:082334}
2335
bengre8a146f2016-03-10 01:20:222336bool ChromeContentBrowserClient::IsDataSaverEnabled(
2337 content::BrowserContext* browser_context) {
Robert Ogdenc995d4fe2019-03-25 19:18:372338 Profile* profile = Profile::FromBrowserContext(browser_context);
2339 return profile && data_reduction_proxy::DataReductionProxySettings::
2340 IsDataSaverEnabledByUser(profile->GetPrefs());
bengre8a146f2016-03-10 01:20:222341}
2342
Kenichi Ishibashi46329872018-07-17 09:43:402343void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker(
2344 content::BrowserContext* browser_context,
Leon Hanc819dc62019-01-28 04:30:192345 blink::mojom::RendererPreferences* out_prefs) {
Kenichi Ishibashi46329872018-07-17 09:43:402346 DCHECK(browser_context);
2347 DCHECK(out_prefs);
2348 renderer_preferences_util::UpdateFromSystemSettings(
2349 out_prefs, Profile::FromBrowserContext(browser_context));
2350}
2351
Clark DuVall5690e742019-07-17 18:26:172352bool ChromeContentBrowserClient::AllowAppCacheOnIO(
[email protected]5b52ad42011-05-26 14:26:092353 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:192354 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:202355 content::ResourceContext* context) {
thestig00844cea2015-09-08 21:44:522356 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Clark DuVall5690e742019-07-17 18:26:172357 DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
[email protected]df02aca2012-02-09 21:03:202358 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken71691402017-01-27 03:38:002359 return io_data->GetCookieSettings()->IsCookieAccessAllowed(manifest_url,
2360 first_party);
[email protected]a2176792011-05-08 19:30:492361}
2362
Clark DuVall5690e742019-07-17 18:26:172363bool ChromeContentBrowserClient::AllowAppCache(
2364 const GURL& manifest_url,
2365 const GURL& first_party,
2366 content::BrowserContext* context) {
2367 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2368 return CookieSettingsFactory::GetForProfile(
2369 Profile::FromBrowserContext(context))
2370 ->IsCookieAccessAllowed(manifest_url, first_party);
2371}
2372
falken3dbc36e2014-10-10 16:48:072373bool ChromeContentBrowserClient::AllowServiceWorker(
2374 const GURL& scope,
2375 const GURL& first_party_url,
David Bertoni3b3597d82019-06-22 02:29:362376 const GURL& script_url,
falken4a22dce2015-04-30 08:25:202377 content::ResourceContext* context,
tzikdf81f142018-10-26 00:23:342378 base::RepeatingCallback<content::WebContents*()> wc_getter) {
thestig00844cea2015-09-08 21:44:522379 DCHECK_CURRENTLY_ON(BrowserThread::IO);
rdevlin.croninf5863da2015-09-10 19:21:452380
brettw00899e62016-11-12 02:10:172381#if BUILDFLAG(ENABLE_EXTENSIONS)
rdevlin.croninf5863da2015-09-10 19:21:452382 // Check if this is an extension-related service worker, and, if so, if it's
2383 // allowed (this can return false if, e.g., the extension is disabled).
2384 // If it's not allowed, return immediately. We deliberately do *not* report
2385 // to the TabSpecificContentSettings, since the service worker is blocked
2386 // because of the extension, rather than because of the user's content
2387 // settings.
2388 if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker(
David Bertoni3b3597d82019-06-22 02:29:362389 scope, first_party_url, script_url, context)) {
rdevlin.croninf5863da2015-09-10 19:21:452390 return false;
2391 }
2392#endif
2393
falken3dbc36e2014-10-10 16:48:072394 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
falken4a22dce2015-04-30 08:25:202395
shimazuce8af88122016-10-06 23:49:212396 // Check if JavaScript is allowed.
2397 content_settings::SettingInfo info;
2398 std::unique_ptr<base::Value> value =
2399 io_data->GetHostContentSettingsMap()->GetWebsiteSetting(
2400 first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
2401 std::string(), &info);
2402 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
2403 bool allow_javascript = (setting == CONTENT_SETTING_ALLOW);
2404
2405 // Check if cookies are allowed.
2406 bool allow_serviceworker =
falken71691402017-01-27 03:38:002407 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope,
2408 first_party_url);
falken4a22dce2015-04-30 08:25:202409 // Record access to database for potential display in UI.
yzshenbc36c972016-12-21 21:39:242410 // Only post the task if this is for a specific tab.
2411 if (!wc_getter.is_null()) {
Eric Seckler8652dcd52018-09-20 10:42:282412 base::PostTaskWithTraits(
2413 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512414 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed,
tzikdf81f142018-10-26 00:23:342415 std::move(wc_getter), scope, !allow_javascript,
tzik29ea5c72017-04-20 02:16:512416 !allow_serviceworker));
rdevlin.croninf5863da2015-09-10 19:21:452417 }
shimazuce8af88122016-10-06 23:49:212418 return allow_javascript && allow_serviceworker;
falken3dbc36e2014-10-10 16:48:072419}
2420
Jochen Eisinger0ff7645c2017-11-28 08:11:262421bool ChromeContentBrowserClient::AllowSharedWorker(
2422 const GURL& worker_url,
2423 const GURL& main_frame_url,
2424 const std::string& name,
Hiroki Nakagawa018bb6d2017-11-30 03:31:372425 const url::Origin& constructor_origin,
Jochen Eisinger0ff7645c2017-11-28 08:11:262426 content::BrowserContext* context,
2427 int render_process_id,
2428 int render_frame_id) {
2429 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2430
2431 // Check if cookies are allowed.
2432 bool allow =
2433 CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context))
2434 ->IsCookieAccessAllowed(worker_url, main_frame_url);
2435
2436 TabSpecificContentSettings::SharedWorkerAccessed(
Hiroki Nakagawa018bb6d2017-11-30 03:31:372437 render_process_id, render_frame_id, worker_url, name, constructor_origin,
2438 !allow);
Jochen Eisinger0ff7645c2017-11-28 08:11:262439 return allow;
2440}
2441
Clark DuVallab63d142019-07-23 04:24:362442bool ChromeContentBrowserClient::AllowSignedExchangeOnIO(
Kunihiko Sakamotof586da62019-03-28 03:03:042443 content::ResourceContext* resource_context) {
2444 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Clark DuVallab63d142019-07-23 04:24:362445 DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
Kunihiko Sakamotof586da62019-03-28 03:03:042446 // Null-check safe_browsing_service_ as in unit tests |resource_context| is a
2447 // MockResourceContext and the cast doesn't work.
2448 if (!safe_browsing_service_)
2449 return false;
2450 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
2451 return io_data->signed_exchange_enabled()->GetValue();
2452}
2453
Clark DuVallab63d142019-07-23 04:24:362454bool ChromeContentBrowserClient::AllowSignedExchange(
2455 content::BrowserContext* browser_context) {
2456 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2457 Profile* profile = Profile::FromBrowserContext(browser_context);
2458 return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled);
2459}
2460
[email protected]f917df22014-07-10 07:45:492461void ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:352462 const GURL& url,
[email protected]df02aca2012-02-09 21:03:202463 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172464 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492465 base::Callback<void(bool)> callback) {
thestig00844cea2015-09-08 21:44:522466 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]df02aca2012-02-09 21:03:202467 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092468 content_settings::CookieSettings* cookie_settings =
2469 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002470 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]5c5a88e2011-11-12 00:45:352471
brettw00899e62016-11-12 02:10:172472#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492473 GuestPermissionRequestHelper(url, render_frames, callback, allow);
2474#else
2475 FileSystemAccessed(url, render_frames, callback, allow);
2476#endif
2477}
2478
brettw00899e62016-11-12 02:10:172479#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]f917df22014-07-10 07:45:492480void ChromeContentBrowserClient::GuestPermissionRequestHelper(
2481 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172482 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492483 base::Callback<void(bool)> callback,
2484 bool allow) {
thestig00844cea2015-09-08 21:44:522485 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]f917df22014-07-10 07:45:492486 std::map<int, int> process_map;
2487 std::map<int, int>::const_iterator it;
2488 bool has_web_view_guest = false;
2489 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172490 for (const auto& it : render_frames) {
2491 if (process_map.find(it.child_id) != process_map.end())
[email protected]f917df22014-07-10 07:45:492492 continue;
2493
Lukasz Anforowicz09060bdf72018-08-23 15:53:172494 process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id));
[email protected]f917df22014-07-10 07:45:492495
Lukasz Anforowicz09060bdf72018-08-23 15:53:172496 if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id))
[email protected]f917df22014-07-10 07:45:492497 has_web_view_guest = true;
2498 }
2499 if (!has_web_view_guest) {
2500 FileSystemAccessed(url, render_frames, callback, allow);
2501 return;
2502 }
[email protected]dffb9fc2014-07-16 04:14:022503 DCHECK_EQ(1U, process_map.size());
[email protected]f917df22014-07-10 07:45:492504 it = process_map.begin();
Eric Seckler8652dcd52018-09-20 10:42:282505 base::PostTaskWithTraits(
2506 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512507 base::BindOnce(
2508 &ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread,
2509 it->first, it->second, url, allow,
Kevin Marshall32f99d7e2017-07-11 23:17:462510 base::Bind(
2511 &ChromeContentBrowserClient::FileSystemAccessed,
2512 weak_factory_.GetWeakPtr(), url, render_frames,
2513 base::Bind(&InvokeCallbackOnThread,
2514 base::SequencedTaskRunnerHandle::Get(), callback))));
[email protected]f917df22014-07-10 07:45:492515}
2516
2517void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread(
2518 int render_process_id,
2519 int render_frame_id,
2520 const GURL& url,
2521 bool allowed_by_default,
2522 const base::Callback<void(bool)>& callback) {
thestig00844cea2015-09-08 21:44:522523 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]140d6cd92014-08-12 18:26:462524 extensions::WebViewPermissionHelper* web_view_permission_helper =
2525 extensions::WebViewPermissionHelper::FromFrameID(
2526 render_process_id, render_frame_id);
[email protected]f917df22014-07-10 07:45:492527 web_view_permission_helper->RequestFileSystemPermission(url,
2528 allowed_by_default,
2529 callback);
2530}
2531#endif
2532
2533void ChromeContentBrowserClient::FileSystemAccessed(
2534 const GURL& url,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172535 const std::vector<content::GlobalFrameRoutingId>& render_frames,
[email protected]f917df22014-07-10 07:45:492536 base::Callback<void(bool)> callback,
2537 bool allow) {
[email protected]62151052012-02-01 18:40:482538 // Record access to file system for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172539 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282540 base::PostTaskWithTraits(
2541 FROM_HERE, {BrowserThread::UI},
tzik29ea5c72017-04-20 02:16:512542 base::BindOnce(&TabSpecificContentSettings::FileSystemAccessed,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172543 it.child_id, it.frame_routing_id, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:352544 }
[email protected]f917df22014-07-10 07:45:492545 callback.Run(allow);
[email protected]5c5a88e2011-11-12 00:45:352546}
2547
[email protected]7c5ff9a2012-03-02 07:42:492548bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
2549 const GURL& url,
[email protected]7c5ff9a2012-03-02 07:42:492550 content::ResourceContext* context,
Lukasz Anforowicz09060bdf72018-08-23 15:53:172551 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
thestig00844cea2015-09-08 21:44:522552 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]7c5ff9a2012-03-02 07:42:492553 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
drogerb1716972015-06-30 09:04:092554 content_settings::CookieSettings* cookie_settings =
2555 io_data->GetCookieSettings();
falken71691402017-01-27 03:38:002556 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
[email protected]7c5ff9a2012-03-02 07:42:492557
2558 // Record access to IndexedDB for potential display in UI.
Lukasz Anforowicz09060bdf72018-08-23 15:53:172559 for (const auto& it : render_frames) {
Eric Seckler8652dcd52018-09-20 10:42:282560 base::PostTaskWithTraits(
2561 FROM_HERE, {BrowserThread::UI},
Lukasz Anforowicz09060bdf72018-08-23 15:53:172562 base::BindOnce(&TabSpecificContentSettings::IndexedDBAccessed,
Joshua Bell7cdaafca2018-10-31 06:27:112563 it.child_id, it.frame_routing_id, url, !allow));
[email protected]7c5ff9a2012-03-02 07:42:492564 }
2565
2566 return allow;
2567}
2568
Ben Kelly6b2e61c2019-03-14 16:06:292569bool ChromeContentBrowserClient::AllowWorkerCacheStorage(
2570 const GURL& url,
2571 content::ResourceContext* context,
2572 const std::vector<content::GlobalFrameRoutingId>& render_frames) {
2573 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2574 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
2575 content_settings::CookieSettings* cookie_settings =
2576 io_data->GetCookieSettings();
2577 bool allow = cookie_settings->IsCookieAccessAllowed(url, url);
2578
2579 // Record access to CacheStorage for potential display in UI.
2580 for (const auto& it : render_frames) {
2581 base::PostTaskWithTraits(
2582 FROM_HERE, {BrowserThread::UI},
2583 base::BindOnce(&TabSpecificContentSettings::CacheStorageAccessed,
2584 it.child_id, it.frame_routing_id, url, !allow));
2585 }
2586
2587 return allow;
2588}
2589
jyasskinc993ce8d2016-03-31 00:38:342590ChromeContentBrowserClient::AllowWebBluetoothResult
2591ChromeContentBrowserClient::AllowWebBluetooth(
jyasskin98bdd3992016-02-26 20:25:452592 content::BrowserContext* browser_context,
2593 const url::Origin& requesting_origin,
2594 const url::Origin& embedding_origin) {
jyasskinc993ce8d2016-03-31 00:38:342595 // TODO(crbug.com/598890): Don't disable if
2596 // base::CommandLine::ForCurrentProcess()->
2597 // HasSwitch(switches::kEnableWebBluetooth) is true.
2598 if (variations::GetVariationParamValue(
2599 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
2600 "Bluetooth") ==
2601 PermissionContextBase::kPermissionsKillSwitchBlockedValue) {
2602 // The kill switch is enabled for this permission. Block requests.
2603 return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED;
2604 }
2605
jyasskin98bdd3992016-02-26 20:25:452606 const HostContentSettingsMap* const content_settings =
2607 HostContentSettingsMapFactory::GetForProfile(
2608 Profile::FromBrowserContext(browser_context));
2609
csharrisonaec2c542016-10-12 19:40:362610 if (content_settings->GetContentSetting(
2611 requesting_origin.GetURL(), embedding_origin.GetURL(),
2612 CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD,
2613 std::string()) == CONTENT_SETTING_BLOCK) {
jyasskinc993ce8d2016-03-31 00:38:342614 return AllowWebBluetoothResult::BLOCK_POLICY;
2615 }
2616 return AllowWebBluetoothResult::ALLOW;
jyasskin98bdd3992016-02-26 20:25:452617}
2618
beaufort.francois01135bf2016-11-23 14:37:362619std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() {
2620 return variations::GetVariationParamValue("WebBluetoothBlocklist",
2621 "blocklist_additions");
scheib74250322016-04-07 03:32:212622}
2623
John Abd-El-Malek21bca7c2018-10-26 22:13:332624#if defined(OS_CHROMEOS)
John Abd-El-Maleka5b1a5d602018-11-05 19:20:522625void ChromeContentBrowserClient::OnTrustAnchorUsed(
John Abd-El-Malek21bca7c2018-10-26 22:13:332626 const std::string& username_hash) {
2627 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(username_hash);
2628}
2629#endif
2630
Reilly Grant19aaccd2018-07-16 22:06:372631scoped_refptr<network::SharedURLLoaderFactory>
2632ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() {
Min Qinda0d55b2018-10-12 18:30:052633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2634 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
2635
2636 if (!SystemNetworkContextManager::GetInstance())
Reilly Grant19aaccd2018-07-16 22:06:372637 return nullptr;
2638
Min Qinda0d55b2018-10-12 18:30:052639 return SystemNetworkContextManager::GetInstance()
Reilly Grant19aaccd2018-07-16 22:06:372640 ->GetSharedURLLoaderFactory();
Andrew Moylan8673dba2017-10-10 04:29:042641}
2642
Sean Gilhulyda1ee4b2018-11-13 21:56:092643network::mojom::NetworkContext*
2644ChromeContentBrowserClient::GetSystemNetworkContext() {
2645 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2646 DCHECK(g_browser_process->system_network_context_manager());
2647 return g_browser_process->system_network_context_manager()->GetContext();
2648}
2649
Andrew Moylan17329fc2017-09-25 07:43:302650std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
2651 return google_apis::GetAPIKey();
2652}
2653
Ke He21ee87f2018-05-30 02:35:322654#if defined(OS_ANDROID)
2655bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() {
2656 // Indicate that Chrome uses the GMS core location provider.
2657 return true;
2658}
2659#endif
2660
Yeolf3dc22ca2019-04-18 17:25:322661scoped_refptr<content::QuotaPermissionContext>
[email protected]317f96c92011-05-31 06:53:412662ChromeContentBrowserClient::CreateQuotaPermissionContext() {
2663 return new ChromeQuotaPermissionContext();
2664}
2665
michaeln10e5fc352017-02-07 02:07:582666void ChromeContentBrowserClient::GetQuotaSettings(
2667 content::BrowserContext* context,
2668 content::StoragePartition* partition,
taptede6d878e2017-06-24 01:53:452669 storage::OptionalQuotaSettingsCallback callback) {
michaeln10e5fc352017-02-07 02:07:582670 if (g_default_quota_settings) {
2671 // For debugging tests harness can inject settings.
taptede6d878e2017-06-24 01:53:452672 std::move(callback).Run(*g_default_quota_settings);
michaeln10e5fc352017-02-07 02:07:582673 return;
2674 }
taptede6d878e2017-06-24 01:53:452675 storage::GetNominalDynamicSettings(
Jarryd451ab7b2019-02-12 06:39:062676 partition->GetPath(), context->IsOffTheRecord(),
2677 storage::GetDefaultDiskInfoHelper(), std::move(callback));
calamityc96116b2015-11-03 04:30:512678}
2679
Mythri Alle0b8de0d2018-10-22 11:06:222680content::GeneratedCodeCacheSettings
2681ChromeContentBrowserClient::GetGeneratedCodeCacheSettings(
2682 content::BrowserContext* context) {
2683 base::FilePath cache_path;
2684 chrome::GetUserCacheDirectory(context->GetPath(), &cache_path);
2685 // If we pass 0 for size, disk_cache will pick a default size using the
2686 // heuristics based on available disk size. These are implemented in
2687 // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
Mythri Ab2486572019-06-13 14:48:162688 int64_t size_in_bytes = 0;
2689 PrefService* prefs = Profile::FromBrowserContext(context)->GetPrefs();
2690 DCHECK(prefs);
2691 size_in_bytes = prefs->GetInteger(prefs::kDiskCacheSize);
Mythri A6c1e4d12019-07-18 15:05:202692 base::FilePath disk_cache_dir = prefs->GetFilePath(prefs::kDiskCacheDir);
2693 if (!disk_cache_dir.empty())
2694 cache_path = disk_cache_dir.Append(cache_path.BaseName());
Mythri Ab2486572019-06-13 14:48:162695 return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path);
Mythri Alle0b8de0d2018-10-22 11:06:222696}
2697
[email protected]848dd042011-06-04 18:24:032698void ChromeContentBrowserClient::AllowCertificateError(
clamy0d32d6d2015-11-24 11:16:262699 content::WebContents* web_contents,
[email protected]4cf611e32012-02-13 16:06:172700 int cert_error,
2701 const net::SSLInfo& ssl_info,
2702 const GURL& request_url,
John Abd-El-Malekc5b8df912019-05-07 17:02:232703 bool is_main_frame_request,
[email protected]d9be47702012-05-16 03:41:222704 bool strict_enforcement,
[email protected]83c13fe2014-08-15 04:49:102705 bool expired_previous_decision,
estark719dde52016-08-09 03:14:272706 const base::Callback<void(content::CertificateRequestResultType)>&
2707 callback) {
clamy0d32d6d2015-11-24 11:16:262708 DCHECK(web_contents);
John Abd-El-Malekc5b8df912019-05-07 17:02:232709 if (!is_main_frame_request) {
irisu8452ddd62017-03-22 07:46:142710 // A sub-resource has a certificate error. The user doesn't really
[email protected]a2f76882013-02-25 21:36:022711 // have a context for making the right decision, so block the
2712 // request hard, without an info bar to allow showing the insecure
2713 // content.
estark719dde52016-08-09 03:14:272714 if (!callback.is_null())
2715 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
[email protected]a2f76882013-02-25 21:36:022716 return;
2717 }
2718
[email protected]f9034cf2011-07-21 12:43:412719 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]09667f02014-01-06 15:37:572720 prerender::PrerenderContents* prerender_contents =
clamy0d32d6d2015-11-24 11:16:262721 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]09667f02014-01-06 15:37:572722 if (prerender_contents) {
2723 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
estark719dde52016-08-09 03:14:272724 if (!callback.is_null()) {
2725 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
2726 }
[email protected]09667f02014-01-06 15:37:572727 return;
[email protected]f9034cf2011-07-21 12:43:412728 }
2729
Carlos IL5a9e7512019-06-13 22:35:282730 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2731 return;
[email protected]848dd042011-06-04 18:24:032732}
2733
Alexander Hendrichbcf2616e2018-05-18 08:21:102734namespace {
2735
Pavol Markob211ab22019-01-23 20:03:042736certificate_matching::CertificatePrincipalPattern
2737ParseCertificatePrincipalPattern(const base::Value* pattern) {
2738 return certificate_matching::CertificatePrincipalPattern::
2739 ParseFromOptionalDict(pattern, "CN", "L", "O", "OU");
2740}
2741
Alexander Hendrichbcf2616e2018-05-18 08:21:102742// Attempts to auto-select a client certificate according to the value of
2743// |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for
2744// |requesting_url|. If no certificate was auto-selected, returns nullptr.
2745std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate(
2746 Profile* profile,
2747 const GURL& requesting_url,
2748 net::ClientCertIdentityList& client_certs) {
2749 HostContentSettingsMap* host_content_settings_map =
2750 HostContentSettingsMapFactory::GetForProfile(profile);
2751 std::unique_ptr<base::Value> setting =
2752 host_content_settings_map->GetWebsiteSetting(
2753 requesting_url, requesting_url,
2754 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL);
2755
Pavol Markob211ab22019-01-23 20:03:042756 if (!setting || !setting->is_dict())
Alexander Hendrichbcf2616e2018-05-18 08:21:102757 return nullptr;
2758
Alexander Hendrichbcf2616e2018-05-18 08:21:102759 const base::Value* filters =
Pavol Markob211ab22019-01-23 20:03:042760 setting->FindKeyOfType("filters", base::Value::Type::LIST);
2761 if (!filters) {
Alexander Hendrichbcf2616e2018-05-18 08:21:102762 // |setting_dict| has the wrong format (e.g. single filter instead of a
2763 // list of filters). This content setting is only provided by
2764 // the |PolicyProvider|, which should always set it to a valid format.
2765 // Therefore, delete the invalid value.
2766 host_content_settings_map->SetWebsiteSettingDefaultScope(
2767 requesting_url, requesting_url,
2768 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr);
Pavol Markob211ab22019-01-23 20:03:042769 return nullptr;
2770 }
2771
2772 for (const base::Value& filter : filters->GetList()) {
2773 DCHECK(filter.is_dict());
2774
2775 auto issuer_pattern = ParseCertificatePrincipalPattern(
2776 filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY));
2777 auto subject_pattern = ParseCertificatePrincipalPattern(
2778 filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY));
2779 // Use the first certificate that is matched by the filter.
2780 for (auto& client_cert : client_certs) {
2781 if (issuer_pattern.Matches(client_cert->certificate()->issuer()) &&
2782 subject_pattern.Matches(client_cert->certificate()->subject())) {
2783 return std::move(client_cert);
2784 }
2785 }
Alexander Hendrichbcf2616e2018-05-18 08:21:102786 }
2787
2788 return nullptr;
2789}
2790
Eric Romana00cf682018-11-01 20:09:112791void AddDataReductionProxyBinding(
2792 content::ResourceContext* resource_context,
2793 data_reduction_proxy::mojom::DataReductionProxyRequest request) {
2794 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2795 auto* io_data = ProfileIOData::FromResourceContext(resource_context);
2796 if (io_data && io_data->data_reduction_proxy_io_data()) {
2797 io_data->data_reduction_proxy_io_data()->Clone(std::move(request));
2798 }
2799}
2800
Alexander Hendrichbcf2616e2018-05-18 08:21:102801} // namespace
2802
Daniel McArdle85735f52019-06-25 03:27:062803base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
davidben3b8455ae72015-03-11 19:42:192804 content::WebContents* web_contents,
[email protected]7a593db2012-02-13 21:19:402805 net::SSLCertRequestInfo* cert_request_info,
mattm436ccfe2017-06-19 20:24:082806 net::ClientCertIdentityList client_certs,
dcheng4af48582016-04-19 00:29:352807 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
[email protected]294084d2014-01-06 22:22:022808 prerender::PrerenderContents* prerender_contents =
davidben3b8455ae72015-03-11 19:42:192809 prerender::PrerenderContents::FromWebContents(web_contents);
[email protected]294084d2014-01-06 22:22:022810 if (prerender_contents) {
2811 prerender_contents->Destroy(
2812 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
Daniel McArdle85735f52019-06-25 03:27:062813 return base::OnceClosure();
[email protected]8ec26472011-06-06 16:52:452814 }
2815
[email protected]791879c2013-12-17 07:22:412816 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2817 DCHECK(requesting_url.is_valid())
2818 << "Invalid URL string: https://"
2819 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:452820
Pavol Marko230ea2c92017-12-03 22:35:442821 bool may_show_cert_selection = true;
2822
davidben3b8455ae72015-03-11 19:42:192823 Profile* profile =
2824 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Pavol Marko230ea2c92017-12-03 22:35:442825#if defined(OS_CHROMEOS)
2826 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
2827 // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false
2828 // and remove the command-line flag after prototype phase when the
2829 // DeviceLoginScreenAutoSelectCertificateForUrls policy is live.
2830 may_show_cert_selection =
2831 chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled();
2832
2833 content::StoragePartition* storage_partition =
2834 content::BrowserContext::GetStoragePartition(
2835 profile, web_contents->GetSiteInstance());
2836 chromeos::login::SigninPartitionManager* signin_partition_manager =
2837 chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext(
2838 profile);
2839
2840 // On the sign-in profile, only allow client certs in the context of the
2841 // sign-in frame.
2842 if (!signin_partition_manager->IsCurrentSigninStoragePartition(
2843 storage_partition)) {
2844 LOG(WARNING)
2845 << "Client cert requested in sign-in profile in wrong context.";
2846 // Continue without client certificate. We do this to mimic the case of no
2847 // client certificate being present in the profile's certificate store.
2848 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062849 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442850 }
2851 VLOG(1) << "Client cert requested in sign-in profile.";
2852 }
2853#endif // defined(OS_CHROMEOS)
2854
Alexander Hendrichbcf2616e2018-05-18 08:21:102855 std::unique_ptr<net::ClientCertIdentity> auto_selected_identity =
2856 AutoSelectCertificate(profile, requesting_url, client_certs);
2857 if (auto_selected_identity) {
2858 // The callback will own |auto_selected_identity| and |delegate|, keeping
2859 // them alive until after ContinueWithCertificate is called.
2860 scoped_refptr<net::X509Certificate> cert =
2861 auto_selected_identity->certificate();
2862 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2863 std::move(auto_selected_identity),
David Benjamin0cda2042019-04-08 23:00:582864 base::BindOnce(
2865 &content::ClientCertificateDelegate::ContinueWithCertificate,
2866 std::move(delegate), std::move(cert)));
Joe DeBlasio9b996292019-01-31 05:09:322867 LogClientAuthResult(ClientCertSelectionResult::kAutoSelect);
Daniel McArdle85735f52019-06-25 03:27:062868 return base::OnceClosure();
[email protected]6786bf402011-12-03 15:19:452869 }
2870
Pavol Marko230ea2c92017-12-03 22:35:442871 if (!may_show_cert_selection) {
2872 LOG(WARNING) << "No client cert matched by policy and user selection is "
2873 "not allowed.";
Joe DeBlasio9b996292019-01-31 05:09:322874 LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed);
Pavol Marko230ea2c92017-12-03 22:35:442875 // Continue without client certificate. We do this to mimic the case of no
2876 // client certificate being present in the profile's certificate store.
2877 delegate->ContinueWithCertificate(nullptr, nullptr);
Daniel McArdle85735f52019-06-25 03:27:062878 return base::OnceClosure();
Pavol Marko230ea2c92017-12-03 22:35:442879 }
2880
Daniel McArdle85735f52019-06-25 03:27:062881 return chrome::ShowSSLClientCertificateSelector(
2882 web_contents, cert_request_info, std::move(client_certs),
2883 std::move(delegate));
[email protected]8ec26472011-06-06 16:52:452884}
2885
[email protected]dc73a7b2012-03-25 15:27:182886content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:562887 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:182888}
2889
peterc26c6c62014-12-10 14:13:592890content::PlatformNotificationService*
Richard Knolld0eae962019-04-04 12:34:022891ChromeContentBrowserClient::GetPlatformNotificationService(
2892 content::BrowserContext* browser_context) {
2893 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2894 Profile* profile = Profile::FromBrowserContext(browser_context);
2895 return PlatformNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042896}
2897
[email protected]9f3fba52011-06-08 20:37:192898bool ChromeContentBrowserClient::CanCreateWindow(
csharrison95f01e922017-04-24 18:52:352899 RenderFrameHost* opener,
[email protected]2b751a12012-03-06 03:00:352900 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572901 const GURL& opener_top_level_frame_url,
Nasko Oskove9f19782019-01-04 18:32:352902 const url::Origin& source_origin,
scottmgde42fb92017-02-10 17:56:032903 content::mojom::WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232904 const GURL& target_url,
2905 const content::Referrer& referrer,
jochen67b271b2016-08-03 13:50:212906 const std::string& frame_name,
[email protected]190e5e22013-07-27 05:59:232907 WindowOpenDisposition disposition,
scottmg8e6c6082017-02-13 23:15:482908 const blink::mojom::WindowFeatures& features,
[email protected]190e5e22013-07-27 05:59:232909 bool user_gesture,
2910 bool opener_suppressed,
[email protected]03b6d552012-03-29 04:03:012911 bool* no_javascript_access) {
csharrison95f01e922017-04-24 18:52:352912 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2913 DCHECK(opener);
[email protected]03b6d552012-03-29 04:03:012914
csharrison95f01e922017-04-24 18:52:352915 content::WebContents* web_contents =
2916 content::WebContents::FromRenderFrameHost(opener);
2917 Profile* profile =
2918 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2919 DCHECK(profile);
[email protected]03b6d552012-03-29 04:03:012920 *no_javascript_access = false;
2921
[email protected]9f3fba52011-06-08 20:37:192922 // If the opener is trying to create a background window but doesn't have
2923 // the appropriate permission, fail the attempt.
scottmgde42fb92017-02-10 17:56:032924 if (container_type == content::mojom::WindowContainerType::BACKGROUND) {
brettw00899e62016-11-12 02:10:172925#if BUILDFLAG(ENABLE_EXTENSIONS)
csharrison95f01e922017-04-24 18:52:352926 auto* process_map = extensions::ProcessMap::Get(profile);
2927 auto* registry = extensions::ExtensionRegistry::Get(profile);
Charles Harrison34f67862017-08-22 01:04:172928 if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url,
2929 opener->GetProcess()->GetID())) {
[email protected]03b6d552012-03-29 04:03:012930 return false;
2931 }
2932
[email protected]7b54ca02012-03-02 18:06:532933 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2934 // return a recently installed Extension even if this CanCreateWindow call
2935 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012936 // because the permission check above would have caused an early return
2937 // already. We must use the full URL to find hosted apps, though, and not
2938 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552939 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352940 registry->enabled_extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292941 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012942 *no_javascript_access = true;
[email protected]dffb9fc2014-07-16 04:14:022943#endif
[email protected]190e5e22013-07-27 05:59:232944
2945 return true;
[email protected]9f3fba52011-06-08 20:37:192946 }
[email protected]056efdc2013-04-06 00:14:532947
brettw00899e62016-11-12 02:10:172948#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]140d6cd92014-08-12 18:26:462949 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
csharrison95f01e922017-04-24 18:52:352950 opener->GetProcess()->GetID())) {
[email protected]190e5e22013-07-27 05:59:232951 return true;
lazyboy04b75d32016-02-25 03:12:182952 }
2953
nick0fbc3922016-12-16 20:52:072954 if (target_url.SchemeIs(extensions::kExtensionScheme)) {
csharrison95f01e922017-04-24 18:52:352955 // Intentionally duplicating |registry| code from above because we want to
2956 // reduce calls to retrieve them as this function is a SYNC IPC handler.
2957 auto* registry = extensions::ExtensionRegistry::Get(profile);
lazyboy04b75d32016-02-25 03:12:182958 const Extension* extension =
csharrison95f01e922017-04-24 18:52:352959 registry->enabled_extensions().GetExtensionOrAppByURL(target_url);
lazyboy5d5fede02016-03-10 04:10:142960 if (extension && extension->is_platform_app()) {
nickb6ae0bd32017-04-18 20:53:532961 UMA_HISTOGRAM_ENUMERATION(
2962 "Extensions.AppLoadedInTab",
2963 ClassifyAppLoadedInTabSource(opener_url, extension),
2964 APP_LOADED_IN_TAB_SOURCE_MAX);
2965
2966 // window.open() may not be used to load v2 apps in a regular tab.
lazyboy39585ed2016-12-06 19:30:162967 return false;
lazyboy5d5fede02016-03-10 04:10:142968 }
lazyboy04b75d32016-02-25 03:12:182969 }
[email protected]5940b0d2014-07-01 00:18:262970#endif
[email protected]190e5e22013-07-27 05:59:232971
Charles Harrisonaf2acd02017-08-18 22:46:022972#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]190e5e22013-07-27 05:59:232973 HostContentSettingsMap* content_settings =
csharrison95f01e922017-04-24 18:52:352974 HostContentSettingsMapFactory::GetForProfile(profile);
tommycli61f6f0c2016-09-21 00:26:582975 if (FlashDownloadInterception::ShouldStopFlashDownloadAction(
2976 content_settings, opener_top_level_frame_url, target_url,
2977 user_gesture)) {
csharrison95f01e922017-04-24 18:52:352978 FlashDownloadInterception::InterceptFlashDownloadNavigation(
2979 web_contents, opener_top_level_frame_url);
tommycli61f6f0c2016-09-21 00:26:582980 return false;
2981 }
2982#endif
2983
Charles Harrisonaf2acd02017-08-18 22:46:022984 // Don't let prerenders open popups.
2985 if (auto* prerender_contents =
2986 prerender::PrerenderContents::FromWebContents(web_contents)) {
2987 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
2988 return false;
2989 }
2990
Nasko Oskove9f19782019-01-04 18:32:352991 BlockedWindowParams blocked_params(target_url, source_origin, referrer,
2992 frame_name, disposition, features,
2993 user_gesture, opener_suppressed);
cm.sanchi2522bc92017-12-04 08:04:132994 NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents);
Charlie Harrison804659a2018-10-16 16:43:382995 if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params,
2996 nullptr /*=open_url_params*/,
2997 blocked_params.features())) {
Charles Harrisonaf2acd02017-08-18 22:46:022998 return false;
[email protected]916615b2013-09-11 18:19:442999 }
[email protected]190e5e22013-07-27 05:59:233000
zpengdb4a58e2017-01-10 17:40:323001#if defined(OS_ANDROID)
csharrison95f01e922017-04-24 18:52:353002 auto* single_tab_mode_helper =
3003 SingleTabModeTabHelper::FromWebContents(web_contents);
Bo Liu3d5b8d692017-12-14 22:42:033004 if (single_tab_mode_helper &&
3005 single_tab_mode_helper->block_all_new_windows()) {
Jinsuk Kim6f9253c2019-03-11 02:45:073006 TabModelList::HandlePopupNavigation(&nav_params);
[email protected]190e5e22013-07-27 05:59:233007 return false;
3008 }
[email protected]916615b2013-09-11 18:19:443009#endif
[email protected]190e5e22013-07-27 05:59:233010
[email protected]9f3fba52011-06-08 20:37:193011 return true;
3012}
3013
[email protected]c52b2892012-03-07 11:01:023014content::SpeechRecognitionManagerDelegate*
zorkb548de082014-11-14 21:40:473015 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:003016 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:513017}
3018
Katie D840d9532018-11-27 06:20:483019content::TtsControllerDelegate*
3020ChromeContentBrowserClient::GetTtsControllerDelegate() {
3021 TtsControllerDelegateImpl* delegate =
3022 TtsControllerDelegateImpl::GetInstance();
3023#if !defined(OS_ANDROID)
3024 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
3025 delegate->SetTtsEngineDelegate(tts_extension_engine);
3026#endif
3027 return delegate;
3028}
3029
Katie D4713ee42018-11-30 01:48:273030content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() {
3031#ifdef OS_CHROMEOS
3032 return TtsPlatformImplChromeOs::GetInstance();
Katie D4713ee42018-11-30 01:48:273033#else
3034 return nullptr;
3035#endif
3036}
3037
Evan Liu7cdbf8872019-06-19 16:47:213038base::Optional<ui::CaptionStyle> GetCaptionStyleFromPrefs(PrefService* prefs) {
3039 if (!prefs) {
3040 return base::nullopt;
3041 }
3042
3043 ui::CaptionStyle style;
3044
3045 style.text_size = prefs->GetString(prefs::kAccessibilityCaptionsTextSize);
3046 style.font_family = prefs->GetString(prefs::kAccessibilityCaptionsTextFont);
Evan Liuf248d402019-06-26 22:57:103047 if (!prefs->GetString(prefs::kAccessibilityCaptionsTextColor).empty()) {
3048 style.text_color = base::StringPrintf(
3049 "rgba(%s,%s)",
3050 prefs->GetString(prefs::kAccessibilityCaptionsTextColor).c_str(),
3051 base::NumberToString(
3052 prefs->GetInteger(prefs::kAccessibilityCaptionsTextOpacity) / 100.0)
3053 .c_str());
3054 }
3055
3056 if (!prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).empty()) {
3057 style.background_color = base::StringPrintf(
3058 "rgba(%s,%s)",
3059 prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).c_str(),
3060 base::NumberToString(
3061 prefs->GetInteger(prefs::kAccessibilityCaptionsBackgroundOpacity) /
3062 100.0)
3063 .c_str());
3064 }
3065
Evan Liu7cdbf8872019-06-19 16:47:213066 style.text_shadow = prefs->GetString(prefs::kAccessibilityCaptionsTextShadow);
3067
3068 return style;
3069}
3070
[email protected]64d69de42012-02-06 00:19:543071void ChromeContentBrowserClient::OverrideWebkitPrefs(
creis7b2d3d12015-02-12 23:29:503072 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:063073 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:583074 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:063075 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:063076
aelias0df335a2017-03-02 23:43:513077// Fill font preferences. These are not registered on Android
3078// - http://crbug.com/308033, http://crbug.com/696364.
[email protected]33b79542013-10-18 11:18:453079#if !defined(OS_ANDROID)
[email protected]354de9e2014-08-07 03:27:193080 FontFamilyCache::FillFontFamilyMap(profile,
3081 prefs::kWebKitStandardFontFamilyMap,
3082 &web_prefs->standard_font_family_map);
3083 FontFamilyCache::FillFontFamilyMap(profile,
3084 prefs::kWebKitFixedFontFamilyMap,
3085 &web_prefs->fixed_font_family_map);
3086 FontFamilyCache::FillFontFamilyMap(profile,
3087 prefs::kWebKitSerifFontFamilyMap,
3088 &web_prefs->serif_font_family_map);
3089 FontFamilyCache::FillFontFamilyMap(profile,
3090 prefs::kWebKitSansSerifFontFamilyMap,
3091 &web_prefs->sans_serif_font_family_map);
3092 FontFamilyCache::FillFontFamilyMap(profile,
3093 prefs::kWebKitCursiveFontFamilyMap,
3094 &web_prefs->cursive_font_family_map);
3095 FontFamilyCache::FillFontFamilyMap(profile,
3096 prefs::kWebKitFantasyFontFamilyMap,
3097 &web_prefs->fantasy_font_family_map);
3098 FontFamilyCache::FillFontFamilyMap(profile,
3099 prefs::kWebKitPictographFontFamilyMap,
3100 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:063101
[email protected]64d69de42012-02-06 00:19:543102 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:403103 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:543104 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:403105 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:543106 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:403107 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:543108 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:403109 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
aelias0df335a2017-03-02 23:43:513110#endif
[email protected]f3986f82012-01-03 20:00:063111
[email protected]ddf72142012-05-22 04:52:403112 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063113
[email protected]64d69de42012-02-06 00:19:543114 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:063115 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
Joel Hockey08a6c84c2018-04-11 10:09:213116 web_prefs->javascript_can_access_clipboard =
3117 prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard);
[email protected]64d69de42012-02-06 00:19:543118 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:063119
[email protected]ddf72142012-05-22 04:52:403120 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:543121 web_prefs->javascript_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573122
Avi Drissman1aa6cb92019-01-23 15:58:383123 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
[email protected]64d69de42012-02-06 00:19:543124 web_prefs->web_security_enabled = false;
mkwsta1f7749b2015-12-28 09:28:573125
[email protected]ddf72142012-05-22 04:52:403126 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:543127 web_prefs->plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:543128 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:403129 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:063130
Zhenyao Moa3fda9972017-09-16 01:34:403131 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
3132 web_prefs->webgl1_enabled = false;
3133 web_prefs->webgl2_enabled = false;
3134 }
[email protected]f3986f82012-01-03 20:00:063135
[email protected]64d69de42012-02-06 00:19:543136 web_prefs->allow_running_insecure_content =
3137 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:323138#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:053139 web_prefs->font_scale_factor =
3140 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
3141 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:323142 web_prefs->force_enable_zoom =
3143 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
Becky Zhoubbfbde32019-02-20 17:07:593144 web_prefs->force_dark_mode_enabled =
3145 prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled);
[email protected]d3b935f2012-10-19 23:14:323146#endif
[email protected]5c915252013-05-07 13:15:393147
[email protected]af4256d52013-06-04 20:39:073148#if defined(OS_ANDROID)
3149 web_prefs->password_echo_enabled =
3150 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
3151#else
[email protected]9d06d88d2012-02-23 22:37:083152 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:073153#endif
3154
[email protected]64d69de42012-02-06 00:19:543155 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:063156 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:543157 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:063158 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
3159
brettw00899e62016-11-12 02:10:173160#if BUILDFLAG(ENABLE_EXTENSIONS)
je_julie.kim7fbb5a1a2015-02-09 17:26:053161 std::string image_animation_policy =
3162 prefs->GetString(prefs::kAnimationPolicy);
3163 if (image_animation_policy == kAnimationPolicyOnce)
3164 web_prefs->animation_policy =
3165 content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE;
3166 else if (image_animation_policy == kAnimationPolicyNone)
3167 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION;
3168 else
3169 web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED;
3170#endif
3171
[email protected]f3986f82012-01-03 20:00:063172 // Make sure we will set the default_encoding with canonical encoding name.
jinsukkim79df88a2017-01-04 06:26:153173 web_prefs->default_encoding =
3174 base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding);
[email protected]64d69de42012-02-06 00:19:543175 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:403176 prefs->ClearPref(prefs::kDefaultCharset);
3177 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:063178 }
[email protected]64d69de42012-02-06 00:19:543179 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:063180
mkwst05544102015-01-10 20:26:163181 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3182 switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
mkwst772ce8142015-01-16 13:28:073183 web_prefs->disable_reading_from_canvas = true;
mkwst05544102015-01-10 20:26:163184 web_prefs->strict_mixed_content_checking = true;
3185 web_prefs->strict_powerful_feature_restrictions = true;
3186 }
3187
Robert Ogdencf2872d2019-03-19 18:59:373188 web_prefs->data_saver_enabled = IsDataSaverEnabled(profile);
Ben Greenstein49878f52015-12-18 19:13:213189
Tarun Bansal333819e2018-05-15 16:38:423190 web_prefs->data_saver_holdback_web_api_enabled =
3191 base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback,
3192 "holdback_web", false);
Tarun Bansal333819e2018-05-15 16:38:423193
Jinsuk Kima3d393ce2019-05-27 00:57:423194 auto* contents = content::WebContents::FromRenderViewHost(rvh);
shaktisahuf97f7532017-02-24 22:46:133195 if (contents) {
Ian Vollick6243dfe02018-03-08 01:08:533196#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423197 auto* delegate = TabAndroid::FromWebContents(contents)
3198 ? static_cast<android::TabWebContentsDelegateAndroid*>(
3199 contents->GetDelegate())
3200 : nullptr;
3201 if (delegate) {
shaktisahuf97f7532017-02-24 22:46:133202 web_prefs->embedded_media_experience_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423203 delegate->ShouldEnableEmbeddedMediaExperience();
shaktisahuf97f7532017-02-24 22:46:133204
Mounir Lamouri9c99a1602018-07-05 15:01:443205 web_prefs->picture_in_picture_enabled =
Jinsuk Kima3d393ce2019-05-27 00:57:423206 delegate->IsPictureInPictureEnabled();
Rune Lillesveen17e48322019-04-15 23:12:383207
3208 web_prefs->preferred_color_scheme =
Jinsuk Kima3d393ce2019-05-27 00:57:423209 delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark
3210 : blink::PreferredColorScheme::kLight;
zqzhang183dc822017-02-15 17:04:113211 }
Ian Vollick6243dfe02018-03-08 01:08:533212#endif // defined(OS_ANDROID)
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533213
Mounir Lamouri6926107f2019-01-31 18:17:433214 // web_app_scope value is platform specific.
3215#if defined(OS_ANDROID)
Jinsuk Kima3d393ce2019-05-27 00:57:423216 if (delegate)
3217 web_prefs->web_app_scope = delegate->GetManifestScope();
Mounir Lamouri6926107f2019-01-31 18:17:433218#elif BUILDFLAG(ENABLE_EXTENSIONS)
3219 {
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253220 web_prefs->web_app_scope = GURL();
3221 // Set |web_app_scope| based on the app associated with the app window if
3222 // any. Note that the app associated with the window never changes, even
3223 // if the app navigates off scope. This is not a problem because we still
3224 // want to use the scope of the app associated with the window, not the
3225 // WebContents.
Mounir Lamouri6926107f2019-01-31 18:17:433226 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Alan Cutterd0bd51902019-05-22 04:15:233227 if (browser && browser->app_controller() &&
Eric Willigerse339c1e2019-05-13 19:22:443228 browser->app_controller()->CreatedForInstalledPwa()) {
Yining Wang234ad3272019-04-08 18:47:273229 // PWAs should be hosted apps.
Eric Willigerse339c1e2019-05-13 19:22:443230 DCHECK(browser->app_controller()->IsHostedApp());
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253231 // HostedApps that are PWAs are always created through WebAppProvider
Alexey Baskakovaca7a0c2019-07-29 07:34:053232 // for profiles that support them, so we should always be able to
3233 // retrieve a WebAppProvider from the Profile.
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253234 //
3235 // Similarly, if a Hosted Apps is a PWA, it will always have a scope
Alan Cutterf25cfe42019-07-16 02:40:123236 // so there is no need to test for has_value().
Giovanni Ortuño Urquididcd38852019-03-07 08:08:253237 web_prefs->web_app_scope =
3238 web_app::WebAppProvider::Get(profile)
3239 ->registrar()
Alan Cutterf25cfe42019-07-16 02:40:123240 .GetAppScope(*browser->app_controller()->GetAppId())
3241 .value();
Mounir Lamouri6926107f2019-01-31 18:17:433242 }
Mounir Lamouri6926107f2019-01-31 18:17:433243 }
3244#endif
3245
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533246#if BUILDFLAG(ENABLE_EXTENSIONS)
3247 Browser* browser = chrome::FindBrowserWithWebContents(contents);
Eric Willigerse339c1e2019-05-13 19:22:443248 if (browser && browser->app_controller() &&
3249 browser->app_controller()->CreatedForInstalledPwa()) {
Giovanni Ortuño Urquidid231ca32018-05-14 04:20:533250 web_prefs->strict_mixed_content_checking = true;
3251 }
3252#endif
3253
Ian Vollick6243dfe02018-03-08 01:08:533254 web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents);
zqzhang183dc822017-02-15 17:04:113255 }
zqzhang93e959d12017-03-16 13:10:203256
Ian Vollick6243dfe02018-03-08 01:08:533257#if defined(OS_ANDROID)
Ted Choc81c89fc52018-06-22 23:51:143258 web_prefs->video_fullscreen_detection_enabled = true;
zqzhang183dc822017-02-15 17:04:113259#endif // defined(OS_ANDROID)
3260
Tarun Bansal73d67f02018-01-17 05:56:253261 if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) {
3262 // Obtain the maximum effective connection type at which the feature is
3263 // enabled.
3264 std::string effective_connection_type_param =
3265 base::GetFieldTrialParamValueByFeature(
3266 features::kLowPriorityIframes,
3267 "max_effective_connection_type_threshold");
3268
3269 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3270 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3271 if (effective_connection_type) {
3272 web_prefs->low_priority_iframes_threshold =
3273 effective_connection_type.value();
3274 }
3275 }
3276
rajendrant0521cee2019-07-29 06:09:263277 web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() ||
3278 contents->GetDelegate()->ShouldAllowLazyLoad();
rajendrante87ed712018-11-30 01:55:003279
Scott Little878f7d6702018-05-31 22:09:063280 if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
3281 const char* param_name =
3282 web_prefs->data_saver_enabled
3283 ? "lazy_frame_loading_distance_thresholds_px_by_ect"
3284 : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_"
3285 "saver_enabled";
3286
3287 base::StringPairs pairs;
3288 base::SplitStringIntoKeyValuePairs(
3289 base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading,
3290 param_name),
3291 ':', ',', &pairs);
3292
3293 for (const auto& pair : pairs) {
3294 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3295 net::GetEffectiveConnectionTypeForName(pair.first);
3296 int value = 0;
3297 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3298 web_prefs->lazy_frame_loading_distance_thresholds_px
3299 [effective_connection_type.value()] = value;
3300 }
3301 }
3302 }
3303
rajendrantd8026342018-08-29 08:08:393304 if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) {
3305 const char* param_name =
3306 web_prefs->data_saver_enabled
3307 ? "lazy_image_loading_distance_thresholds_px_by_ect"
3308 : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_"
3309 "saver_enabled";
3310
3311 base::StringPairs pairs;
3312 base::SplitStringIntoKeyValuePairs(
3313 base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading,
3314 param_name),
3315 ':', ',', &pairs);
3316
3317 for (const auto& pair : pairs) {
3318 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3319 net::GetEffectiveConnectionTypeForName(pair.first);
3320 int value = 0;
3321 if (effective_connection_type && base::StringToInt(pair.second, &value)) {
3322 web_prefs->lazy_image_loading_distance_thresholds_px
3323 [effective_connection_type.value()] = value;
3324 }
3325 }
3326 }
3327
Tarun Bansald10f17a02018-09-13 00:23:173328 if (base::FeatureList::IsEnabled(
3329 features::kNetworkQualityEstimatorWebHoldback)) {
3330 std::string effective_connection_type_param =
3331 base::GetFieldTrialParamValueByFeature(
3332 features::kNetworkQualityEstimatorWebHoldback,
3333 "web_effective_connection_type_override");
3334
3335 base::Optional<net::EffectiveConnectionType> effective_connection_type =
3336 net::GetEffectiveConnectionTypeForName(effective_connection_type_param);
3337 DCHECK(effective_connection_type_param.empty() ||
3338 effective_connection_type);
3339 if (effective_connection_type) {
3340 DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
3341 effective_connection_type.value());
3342 web_prefs->network_quality_estimator_web_holdback =
3343 effective_connection_type.value();
3344 }
3345 }
3346
Dan Beamf0a7e112019-06-07 18:40:583347 auto* native_theme = GetWebTheme();
François Beaufort4f8107d2018-03-05 12:12:103348#if !defined(OS_ANDROID)
Becca Hughesfe8c32c2018-03-21 13:36:563349 if (IsAutoplayAllowedByPolicy(contents, prefs)) {
Becca Hughes7d2bbb82018-08-07 22:56:593350 // If autoplay is allowed by policy then force the no user gesture required
3351 // autoplay policy.
François Beaufort4f8107d2018-03-05 12:12:103352 web_prefs->autoplay_policy =
3353 content::AutoplayPolicy::kNoUserGestureRequired;
Mounir Lamouric21868082018-10-11 21:09:553354 } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) &&
Becca Hughes7d2bbb82018-08-07 22:56:593355 web_prefs->autoplay_policy ==
3356 content::AutoplayPolicy::kDocumentUserActivationRequired) {
Mounir Lamouric21868082018-10-11 21:09:553357 // If the autoplay disable settings feature is enabled and the autoplay
3358 // policy is set to using the unified policy then set the default autoplay
3359 // policy based on user preference.
Becca Hughes7d2bbb82018-08-07 22:56:593360 web_prefs->autoplay_policy =
3361 UnifiedAutoplayConfig::ShouldBlockAutoplay(profile)
3362 ? content::AutoplayPolicy::kDocumentUserActivationRequired
3363 : content::AutoplayPolicy::kNoUserGestureRequired;
François Beaufort4f8107d2018-03-05 12:12:103364 }
Alison Maher67fd4d9f2019-07-12 18:34:213365#if !defined(OS_MACOSX)
3366 // Mac has a concept of high contrast that does not relate to forced colors.
Alison Maherbe15c072019-07-08 18:12:393367 web_prefs->forced_colors = native_theme->UsesHighContrastColors()
3368 ? blink::ForcedColors::kActive
3369 : blink::ForcedColors::kNone;
Alison Maher67fd4d9f2019-07-12 18:34:213370#endif // !defined(OS_MACOSX)
3371
3372 switch (native_theme->GetPreferredColorScheme()) {
3373 case ui::NativeTheme::PreferredColorScheme::kDark:
3374 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark;
3375 break;
3376 case ui::NativeTheme::PreferredColorScheme::kLight:
3377 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
3378 break;
3379 case ui::NativeTheme::PreferredColorScheme::kNoPreference:
3380 web_prefs->preferred_color_scheme =
3381 blink::PreferredColorScheme::kNoPreference;
3382 }
François Beaufort4f8107d2018-03-05 12:12:103383#endif // !defined(OS_ANDROID)
3384
Dave Tapuskac6627e12018-08-30 15:07:193385 web_prefs->translate_service_available = TranslateService::IsAvailable(prefs);
Elly Fong-Jonesf92897392019-01-24 16:05:493386
Dan Beam836c02a2019-06-15 01:58:273387 // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
3388 // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
3389 // explicitly uses light (instead of not dark), which is why we don't reset
3390 // back to no-preference. https://crbug.com/965811
3391 if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
3392 bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme);
3393#if BUILDFLAG(ENABLE_EXTENSIONS)
3394 if (!force_light) {
3395 force_light =
3396 contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
3397 contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
3398 }
3399#endif
3400 if (force_light)
3401 web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight;
Dan Beamf0a7e112019-06-07 18:40:583402 }
3403
Elly Fong-Jonesf92897392019-01-24 16:05:493404 // Apply native CaptionStyle parameters.
Evan Liu7cdbf8872019-06-19 16:47:213405 base::Optional<ui::CaptionStyle> style;
3406
3407 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3408 ::switches::kForceCaptionStyle)) {
3409 style = ui::CaptionStyle::FromSpec(
3410 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3411 switches::kForceCaptionStyle));
3412 }
3413
3414 // Apply system caption style.
3415 if (!style) {
3416 style = native_theme->GetSystemCaptionStyle();
3417 }
3418
3419 // Apply caption style from preferences if system caption style is undefined.
3420 if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) {
3421 style = GetCaptionStyleFromPrefs(prefs);
3422 }
3423
3424 if (style) {
3425 web_prefs->text_track_background_color = style->background_color;
3426 web_prefs->text_track_text_color = style->text_color;
3427 web_prefs->text_track_text_size = style->text_size;
3428 web_prefs->text_track_text_shadow = style->text_shadow;
3429 web_prefs->text_track_font_family = style->font_family;
3430 web_prefs->text_track_font_variant = style->font_variant;
Abigail Klein74de85bd2019-07-11 19:11:563431 web_prefs->text_track_window_color = style->window_color;
3432 web_prefs->text_track_window_padding = style->window_padding;
3433 web_prefs->text_track_window_radius = style->window_radius;
Evan Liu7cdbf8872019-06-19 16:47:213434 }
Elly Fong-Jonesf92897392019-01-24 16:05:493435
[email protected]a48ab7112014-08-01 16:48:033436 for (size_t i = 0; i < extra_parts_.size(); ++i)
creis7b2d3d12015-02-12 23:29:503437 extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs);
[email protected]181a95ee2011-07-12 19:26:363438}
3439
[email protected]b8148ac2011-07-13 22:03:253440void ChromeContentBrowserClient::BrowserURLHandlerCreated(
3441 BrowserURLHandler* handler) {
[email protected]a48ab7112014-08-01 16:48:033442 for (size_t i = 0; i < extra_parts_.size(); ++i)
3443 extra_parts_[i]->BrowserURLHandlerCreated(handler);
[email protected]b8148ac2011-07-13 22:03:253444
[email protected]b3adbd02011-11-30 22:23:273445 // about: handler. Must come before chrome: handler, since it will
3446 // rewrite about: urls to chrome: URLs and then expect chrome: to
creis94a977f62015-02-18 23:51:053447 // actually handle them. Also relies on a preliminary fixup phase.
3448 handler->SetFixupHandler(&FixupBrowserAboutURL);
[email protected]b8148ac2011-07-13 22:03:253449 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
3450 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:033451
madfbd10852017-01-20 03:15:333452 // The group policy NTP URL handler must be registered before the other NTP
3453 // URL handlers below.
3454 handler->AddHandlerPair(&HandleNewTabPageLocationOverride,
3455 BrowserURLHandler::null_handler());
3456
zpengdb4a58e2017-01-10 17:40:323457#if defined(OS_ANDROID)
[email protected]4bd78e92014-03-28 18:54:033458 // Handler to rewrite chrome://newtab on Android.
ianwen465e17b2015-01-20 18:32:353459 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
[email protected]4bd78e92014-03-28 18:54:033460 BrowserURLHandler::null_handler());
3461#else
[email protected]231dba22013-07-25 23:53:033462 // Handler to rewrite chrome://newtab for InstantExtended.
sdefresne51bbec7b2015-08-03 14:18:133463 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
3464 &search::HandleNewTabURLReverseRewrite);
[email protected]4bd78e92014-03-28 18:54:033465#endif
[email protected]231dba22013-07-25 23:53:033466
[email protected]b8148ac2011-07-13 22:03:253467 // chrome: & friends.
dbeam25472e0c2017-06-23 19:02:313468 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
3469 &ChromeContentBrowserClient::HandleWebUIReverse);
Robert Ogdene7fdca92018-10-12 17:53:063470
3471 // Handler to rewrite Preview's Server Lite Page, to show the original URL to
3472 // the user.
3473 handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite,
3474 &HandlePreviewsLitePageURLRewriteReverse);
[email protected]b8148ac2011-07-13 22:03:253475}
3476
[email protected]650b2d52013-02-10 03:41:453477base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:493478 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:323479}
3480
[email protected]c9b6eb62011-10-18 20:49:393481std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
3482 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
3483}
3484
Dominik Röttsches47347832019-03-12 17:45:013485base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() {
3486 base::FilePath user_data_dir;
3487 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3488 DCHECK(!user_data_dir.empty());
3489 return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
3490}
3491
jmadill57b52d42015-08-21 18:16:133492base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
3493 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:523494 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
jmadill57b52d42015-08-21 18:16:133495 DCHECK(!user_data_dir.empty());
3496 return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache"));
3497}
3498
Khushal7ca0b782018-07-20 05:53:273499base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
3500 base::FilePath user_data_dir;
3501 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
3502 DCHECK(!user_data_dir.empty());
3503 return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
3504}
3505
[email protected]b7631cc2012-09-15 05:08:383506void ChromeContentBrowserClient::DidCreatePpapiPlugin(
3507 content::BrowserPpapiHost* browser_host) {
brettw4b461082016-11-19 18:55:163508#if BUILDFLAG(ENABLE_PLUGINS)
jitendra.ks42e889a2014-12-05 09:05:553509 ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host);
[email protected]6d17f6392012-12-05 05:24:543510#endif
[email protected]b7631cc2012-09-15 05:08:383511}
3512
[email protected]0c7193742012-11-07 19:05:033513content::BrowserPpapiHost*
3514 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
3515 int plugin_process_id) {
Nico Weberaf3b00b2017-09-11 17:58:173516#if BUILDFLAG(ENABLE_NACL)
[email protected]a56f8322014-07-16 21:13:553517 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:033518 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:023519 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
3520 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:033521 if (host->process() &&
3522 host->process()->GetData().id == plugin_process_id) {
3523 // Found the plugin.
3524 return host->browser_ppapi_host();
3525 }
3526 ++iter;
3527 }
[email protected]a56f8322014-07-16 21:13:553528#endif
[email protected]0c7193742012-11-07 19:05:033529 return NULL;
3530}
3531
[email protected]38cd8f7f2012-06-15 22:06:073532bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:583533 content::BrowserContext* browser_context,
3534 const GURL& url,
[email protected]dda54822013-06-15 01:26:393535 bool private_api,
[email protected]8b92ed182013-09-21 04:47:123536 const content::SocketPermissionRequest* params) {
brettw4b461082016-11-19 18:55:163537#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:553538 return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
3539 browser_context, url, private_api, params, allowed_socket_origins_);
[email protected]93f72062013-05-29 20:29:403540#else
[email protected]a658d452012-03-02 12:45:293541 return false;
[email protected]93f72062013-05-29 20:29:403542#endif
[email protected]e461da2f2012-02-16 19:06:403543}
3544
adrian.belgund54465ba2016-05-18 10:03:583545bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed(
3546 content::BrowserContext* browser_context,
3547 const GURL& url) {
brettw4b461082016-11-19 18:55:163548#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgund54465ba2016-05-18 10:03:583549 return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed(
3550 browser_context, url);
3551#else
3552 return false;
3553#endif
3554}
3555
adrian.belgun5b341c72016-06-22 22:24:083556std::unique_ptr<content::VpnServiceProxy>
3557ChromeContentBrowserClient::GetVpnServiceProxy(
3558 content::BrowserContext* browser_context) {
brettw00899e62016-11-12 02:10:173559#if BUILDFLAG(ENABLE_EXTENSIONS)
adrian.belgun5b341c72016-06-22 22:24:083560 return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy(
3561 browser_context);
3562#else
3563 return nullptr;
3564#endif
3565}
3566
Brett Wilson804e83c2017-08-18 22:57:333567std::unique_ptr<ui::SelectFilePolicy>
3568ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) {
3569 return std::make_unique<ChromeSelectFilePolicy>(web_contents);
[email protected]a28e3302013-02-03 03:50:433570}
3571
[email protected]7d9424702013-04-14 13:14:163572void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3573 std::vector<std::string>* additional_allowed_schemes) {
3574 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
3575 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:483576 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:293577 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]a48ab7112014-08-01 16:48:033578 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3579 extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem(
3580 additional_allowed_schemes);
3581 }
[email protected]7d9424702013-04-14 13:14:163582}
3583
falkenad185092016-06-16 06:10:023584void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist(
3585 std::set<std::string>* schemes) {
Daniel Vogelheim11e59b72017-11-22 15:44:043586 *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck();
falkenad185092016-06-16 06:10:023587}
3588
[email protected]c79859b82014-03-20 22:43:553589void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
[email protected]cd501a72014-08-22 19:58:313590 std::vector<storage::URLRequestAutoMountHandler>* handlers) {
[email protected]a48ab7112014-08-01 16:48:033591 for (size_t i = 0; i < extra_parts_.size(); ++i)
3592 extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers);
[email protected]c79859b82014-03-20 22:43:553593}
3594
nzolghadrd87a308d2016-12-07 15:45:563595::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() {
3596 return g_browser_process->rappor_service();
3597}
3598
[email protected]f19bbf62013-07-09 01:22:323599void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:313600 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:533601 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:003602 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
3603 additional_backends) {
[email protected]b40015c2013-06-26 08:13:313604#if defined(OS_CHROMEOS)
[email protected]cd501a72014-08-22 19:58:313605 storage::ExternalMountPoints* external_mount_points =
[email protected]0ff5eb52013-07-10 20:35:313606 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:313607 DCHECK(external_mount_points);
Jeremy Romanec48d7a2018-03-01 17:35:093608 auto backend = std::make_unique<chromeos::FileSystemBackend>(
3609 std::make_unique<drive::FileSystemBackendDelegate>(),
3610 std::make_unique<chromeos::file_system_provider::BackendDelegate>(),
3611 std::make_unique<chromeos::MTPFileSystemBackendDelegate>(
hashimotoa53e7e82016-10-26 06:30:473612 storage_partition_path),
Jeremy Romanec48d7a2018-03-01 17:35:093613 std::make_unique<arc::ArcContentFileSystemBackendDelegate>(),
3614 std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
Sam McNally47f2eac2018-08-28 06:45:053615 std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
3616 Profile::FromBrowserContext(browser_context)),
hashimotoa53e7e82016-10-26 06:30:473617 external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:323618 backend->AddSystemMountPoints();
[email protected]cd501a72014-08-22 19:58:313619 DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
avid6d88b912017-01-13 00:16:003620 additional_backends->push_back(std::move(backend));
[email protected]b40015c2013-06-26 08:13:313621#endif
[email protected]445b7db2013-08-02 04:58:273622
[email protected]a48ab7112014-08-01 16:48:033623 for (size_t i = 0; i < extra_parts_.size(); ++i) {
3624 extra_parts_[i]->GetAdditionalFileSystemBackends(
3625 browser_context, storage_partition_path, additional_backends);
3626 }
[email protected]02250952013-04-24 23:52:533627}
3628
jcivellie6f550742017-01-06 19:29:123629#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:183630void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
avi3ef9ec9e2014-12-22 22:50:173631 const base::CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:383632 int child_process_id,
brettw3c98c7d32017-07-25 01:44:203633 PosixFileDescriptorInfo* mappings) {
Albert J. Wongb6942532017-07-13 22:49:303634
jcivellie6f550742017-01-06 19:29:123635#if defined(OS_ANDROID)
3636 base::MemoryMappedFile::Region region;
3637 int fd = ui::GetMainAndroidPackFd(&region);
3638 mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region);
agrieve05398f52015-06-24 18:59:003639
jcivellie6f550742017-01-06 19:29:123640 fd = ui::GetCommonResourcesPackFd(&region);
3641 mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region);
[email protected]29699c22012-10-03 23:57:393642
jcivellie6f550742017-01-06 19:29:123643 fd = ui::GetLocalePackFd(&region);
3644 mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region);
[email protected]40da3e0c2012-10-24 22:03:383645
zpeng368afac82017-07-17 18:47:453646 // Optional secondary locale .pak file.
3647 fd = ui::GetSecondaryLocalePackFd(&region);
3648 if (fd != -1) {
3649 mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region);
3650 }
3651
[email protected]09560f7f2014-06-10 18:40:283652 base::FilePath app_data_path;
Avi Drissman9098f9002018-05-04 00:11:523653 base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
[email protected]09560f7f2014-06-10 18:40:283654 DCHECK(!app_data_path.empty());
Joshua Perazaf890e4b2019-01-03 19:19:023655#endif // defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:383656 int crash_signal_fd = GetCrashSignalFD(command_line);
3657 if (crash_signal_fd >= 0) {
Jay Civelli668c097f2018-05-16 20:44:133658 mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
[email protected]40da3e0c2012-10-24 22:03:383659 }
jcivellie6f550742017-01-06 19:29:123660}
3661#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:303662
[email protected]4a65826d2011-08-25 16:04:013663#if defined(OS_WIN)
wfh182da09c2015-06-24 19:23:033664base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:523665 int sandbox_type) {
wfh182da09c2015-06-24 19:23:033666 // TODO(wfh): Add support for more process types here. crbug.com/499523
3667 switch (sandbox_type) {
Tom Sepez15d4e5202017-09-27 23:59:053668 case service_manager::SANDBOX_TYPE_RENDERER:
Jerry Lina0de7ce2018-06-22 15:18:363669 return base::string16(install_static::GetSandboxSidPrefix()) +
3670 L"129201922";
Tom Sepez15d4e5202017-09-27 23:59:053671 case service_manager::SANDBOX_TYPE_UTILITY:
wfh182da09c2015-06-24 19:23:033672 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053673 case service_manager::SANDBOX_TYPE_GPU:
wfh182da09c2015-06-24 19:23:033674 return base::string16();
Tom Sepez15d4e5202017-09-27 23:59:053675 case service_manager::SANDBOX_TYPE_PPAPI:
Jerry Lina0de7ce2018-06-22 15:18:363676 return base::string16(install_static::GetSandboxSidPrefix()) +
3677 L"129201925";
Nico Weberaf3b00b2017-09-11 17:58:173678#if BUILDFLAG(ENABLE_NACL)
wfh182da09c2015-06-24 19:23:033679 case PROCESS_TYPE_NACL_LOADER:
3680 return base::string16();
3681 case PROCESS_TYPE_NACL_BROKER:
3682 return base::string16();
3683#endif
3684 }
3685
3686 // Should never reach here.
3687 CHECK(0);
3688 return base::string16();
3689}
3690
rickyz50109312015-11-11 00:37:083691bool ChromeContentBrowserClient::PreSpawnRenderer(
3692 sandbox::TargetPolicy* policy) {
[email protected]34f48682013-03-20 00:30:183693 // This code is duplicated in nacl_exe_win_64.cc.
3694 // Allow the server side of a pipe restricted to the "chrome.nacl."
3695 // namespace so that it cannot impersonate other system or other chrome
3696 // service pipes.
3697 sandbox::ResultCode result = policy->AddRule(
3698 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
3699 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
3700 L"\\\\.\\pipe\\chrome.nacl.*");
rickyz50109312015-11-11 00:37:083701 if (result != sandbox::SBOX_ALL_OK)
3702 return false;
rickyz50109312015-11-11 00:37:083703 return result == sandbox::SBOX_ALL_OK;
[email protected]34f48682013-03-20 00:30:183704}
wfhc91e9672016-01-27 00:14:203705#endif // defined(OS_WIN)
[email protected]4a65826d2011-08-25 16:04:013706
bend1dd50f52016-06-26 22:10:483707void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
bena06f7d62017-04-04 20:48:523708 service_manager::BinderRegistry* registry,
Sam McNally52e50282017-11-29 00:54:023709 blink::AssociatedInterfaceRegistry* associated_registry,
leon.han0b618792016-06-16 01:53:513710 content::RenderProcessHost* render_process_host) {
nigeltaobeff0a102017-04-29 09:30:373711 // The CacheStatsRecorder is an associated binding, instead of a
3712 // non-associated one, because the sender (in the renderer process) posts the
3713 // message after a time delay, in order to rate limit. The association
3714 // protects against the render process host ID being recycled in that time
3715 // gap between the preparation and the execution of that IPC.
3716 associated_registry->AddInterface(
3717 base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID()));
3718
ben5be0b9132016-08-03 00:17:183719 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
Eric Seckler8652dcd52018-09-20 10:42:283720 base::CreateSingleThreadTaskRunnerWithTraits(
3721 {content::BrowserThread::UI});
bend1dd50f52016-06-26 22:10:483722 registry->AddInterface(
nigeltao2f673762016-10-14 03:27:283723 base::Bind(&rappor::RapporRecorderImpl::Create,
3724 g_browser_process->rappor_service()),
3725 ui_task_runner);
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183726 registry->AddInterface(
Mike Wittman16fa5362018-09-04 17:27:303727 base::BindRepeating(&metrics::CallStackProfileCollector::Create));
Sadrul Habib Chowdhury16b3a162018-02-03 01:43:183728
dvallet233f57ab2016-12-21 03:17:103729 if (NetBenchmarking::CheckBenchmarkingEnabled()) {
3730 Profile* profile =
3731 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Alexandr Ilin4909ec82018-06-06 10:22:483732 auto* loading_predictor =
3733 predictors::LoadingPredictorFactory::GetForProfile(profile);
Robbie McElrathb0f248c2018-07-24 19:44:163734 registry->AddInterface(
3735 base::BindRepeating(
3736 &NetBenchmarking::Create,
3737 loading_predictor ? loading_predictor->GetWeakPtr() : nullptr,
Robbie McElrathb0f248c2018-07-24 19:44:163738 render_process_host->GetID()),
3739 ui_task_runner);
dvallet233f57ab2016-12-21 03:17:103740 }
yzshen2d8fb422017-06-01 20:29:403741
Nico Weberbc5b06f2019-07-26 14:00:133742#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Adam Rice41b89592017-07-28 10:33:443743 if (safe_browsing_service_) {
Yuzhu Shencb3011f62018-02-08 02:51:503744 content::ResourceContext* resource_context =
3745 render_process_host->GetBrowserContext()->GetResourceContext();
yzshen2d8fb422017-06-01 20:29:403746 registry->AddInterface(
Yuzhu Shen44094e22017-07-18 22:52:353747 base::Bind(
3748 &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
Yuzhu Shencb3011f62018-02-08 02:51:503749 render_process_host->GetID(), resource_context,
Yuzhu Shen44094e22017-07-18 22:52:353750 base::Bind(
3751 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
Yuzhu Shencb3011f62018-02-08 02:51:503752 base::Unretained(this), resource_context)),
Eric Seckler8652dcd52018-09-20 10:42:283753 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}));
yzshen2d8fb422017-06-01 20:29:403754 }
Nico Weberbc5b06f2019-07-26 14:00:133755#endif
yzshen2d8fb422017-06-01 20:29:403756
Eric Romana00cf682018-11-01 20:09:113757 if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
3758 registry->AddInterface(base::BindRepeating(
3759 &AddDataReductionProxyBinding,
3760 render_process_host->GetBrowserContext()->GetResourceContext()));
3761 }
3762
chrisha927d8fe2017-01-18 23:09:513763#if defined(OS_WIN)
Patrick Monette9a10ae22018-06-14 22:18:183764 // Add the ModuleEventSink interface. This is the interface used by renderer
3765 // processes to notify the browser of modules in their address space. The
3766 // process handle is not yet available at this point so pass in a callback
3767 // to allow to retrieve a duplicate at the time the interface is actually
3768 // created. It is safe to pass a raw pointer to |render_process_host|: the
Patrick Monetteaa2ec562019-03-20 23:37:453769 // callback will be invoked during the Mojo initialization, which occurs while
3770 // the |render_process_host| is alive.
Patrick Monette9a10ae22018-06-14 22:18:183771 auto get_process = base::BindRepeating(
3772 [](content::RenderProcessHost* host) -> base::Process {
3773 return host->GetProcess().Duplicate();
3774 },
3775 base::Unretained(render_process_host));
Patrick Monette9a10ae22018-06-14 22:18:183776 registry->AddInterface(
Patrick Monetteaa2ec562019-03-20 23:37:453777 base::BindRepeating(
3778 &ModuleEventSinkImpl::Create, std::move(get_process),
3779 content::PROCESS_TYPE_RENDERER,
3780 base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)),
Patrick Monette9a10ae22018-06-14 22:18:183781 ui_task_runner);
chrisha927d8fe2017-01-18 23:09:513782#endif
Dan Harrington964d48c2018-08-03 15:52:243783#if defined(OS_ANDROID)
Carlos Knippschild63b3f042018-11-20 22:55:043784 Profile* profile =
3785 Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Dan Harrington964d48c2018-08-03 15:52:243786 registry->AddInterface(
3787 base::BindRepeating(&android::AvailableOfflineContentProvider::Create,
Carlos Knippschild63b3f042018-11-20 22:55:043788 profile),
Eric Seckler8652dcd52018-09-20 10:42:283789 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
Dan Harrington964d48c2018-08-03 15:52:243790#endif
chrisha927d8fe2017-01-18 23:09:513791
Nicholas Verneb5df4f72017-11-08 09:12:073792 for (auto* ep : extra_parts_) {
3793 ep->ExposeInterfacesToRenderer(registry, associated_registry,
3794 render_process_host);
3795 }
sammc335844522016-06-09 10:15:593796}
3797
bendd157e1a2016-07-22 03:15:573798void ChromeContentBrowserClient::ExposeInterfacesToMediaService(
ben8408b132017-05-01 23:48:503799 service_manager::BinderRegistry* registry,
xhwang9ab96482015-05-11 22:02:333800 content::RenderFrameHost* render_frame_host) {
Xiaohan Wang15303d0c2017-10-06 05:22:443801#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3802 registry->AddInterface(
3803 base::Bind(&OutputProtectionImpl::Create, render_frame_host));
ben155ecf82016-06-21 22:43:263804 registry->AddInterface(
John Rummell1b5da6102017-11-02 02:15:453805 base::Bind(&PlatformVerificationImpl::Create, render_frame_host));
Xiaohan Wang15303d0c2017-10-06 05:22:443806#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc86d76e42016-03-14 23:38:493807
xhwangdb24d602017-05-20 06:32:243808#if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID)
cm.sanchiad3f42a62017-11-07 11:33:353809 registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host));
xhwang116acb92017-04-03 18:27:203810#endif
xhwang9ab96482015-05-11 22:02:333811}
3812
Ben Goodger6a695c012017-06-20 20:21:203813void ChromeContentBrowserClient::BindInterfaceRequestFromFrame(
3814 content::RenderFrameHost* render_frame_host,
Ben Goodger6a695c012017-06-20 20:21:203815 const std::string& interface_name,
3816 mojo::ScopedMessagePipeHandle interface_pipe) {
Sam McNallyfaf9a402017-10-31 03:06:313817 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3818 !worker_interfaces_parameterized_) {
3819 InitWebContextInterfaces();
3820 }
Ben Goodger6a695c012017-06-20 20:21:203821
Ben Goodger272e0632017-07-19 23:27:003822 if (!frame_interfaces_parameterized_->TryBindInterface(
3823 interface_name, &interface_pipe, render_frame_host)) {
3824 frame_interfaces_->TryBindInterface(interface_name, &interface_pipe);
juncai1bf9f7c2016-03-22 20:46:563825 }
rockot0fa66a82015-06-11 17:25:453826}
3827
Mario Sanchez Prada39dee4a2019-07-09 07:15:403828void ChromeContentBrowserClient::BindCredentialManagerReceiver(
Oksana Zhuravlova23ecbb402019-03-29 19:44:113829 content::RenderFrameHost* render_frame_host,
Mario Sanchez Prada39dee4a2019-07-09 07:15:403830 mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) {
3831 ChromePasswordManagerClient::BindCredentialManager(std::move(receiver),
Oksana Zhuravlova23ecbb402019-03-29 19:44:113832 render_frame_host);
3833}
3834
Ken Rockot0aad7ec2018-07-31 15:58:443835bool ChromeContentBrowserClient::BindAssociatedInterfaceRequestFromFrame(
3836 content::RenderFrameHost* render_frame_host,
3837 const std::string& interface_name,
3838 mojo::ScopedInterfaceEndpointHandle* handle) {
3839 if (interface_name == autofill::mojom::AutofillDriver::Name_) {
3840 autofill::ContentAutofillDriverFactory::BindAutofillDriver(
Shimi Zhang6b72d292019-07-12 20:52:423841 mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>(
3842 std::move(*handle)),
Ken Rockot0aad7ec2018-07-31 15:58:443843 render_frame_host);
3844 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583845 }
3846 if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) {
Shimi Zhang6b72d292019-07-12 20:52:423847 password_manager::ContentPasswordManagerDriverFactory::
3848 BindPasswordManagerDriver(
3849 autofill::mojom::PasswordManagerDriverAssociatedRequest(
3850 std::move(*handle)),
3851 render_frame_host);
Dominic Battre97d5edf2019-03-26 13:41:383852 return true;
Lei Zhang5b3f81f2019-04-10 00:54:583853 }
3854 if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) {
Tao Bai02ab4dd42019-03-06 00:30:373855 content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver(
Shimi Zhang8ee32332019-07-12 17:59:363856 mojo::PendingAssociatedReceiver<
3857 content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)),
Tao Bai02ab4dd42019-03-06 00:30:373858 render_frame_host);
3859 return true;
Ken Rockot0aad7ec2018-07-31 15:58:443860 }
3861
3862 return false;
3863}
3864
Sam McNallyfaf9a402017-10-31 03:06:313865void ChromeContentBrowserClient::BindInterfaceRequestFromWorker(
3866 content::RenderProcessHost* render_process_host,
3867 const url::Origin& origin,
3868 const std::string& interface_name,
3869 mojo::ScopedMessagePipeHandle interface_pipe) {
3870 if (!frame_interfaces_ && !frame_interfaces_parameterized_ &&
3871 !worker_interfaces_parameterized_) {
3872 InitWebContextInterfaces();
3873 }
3874
3875 worker_interfaces_parameterized_->BindInterface(
3876 interface_name, std::move(interface_pipe), render_process_host, origin);
3877}
3878
bena06f7d62017-04-04 20:48:523879void ChromeContentBrowserClient::BindInterfaceRequest(
ben2c36828d2017-05-02 04:09:013880 const service_manager::BindSourceInfo& source_info,
bena06f7d62017-04-04 20:48:523881 const std::string& interface_name,
3882 mojo::ScopedMessagePipeHandle* interface_pipe) {
Ben Goodger272e0632017-07-19 23:27:003883 if (source_info.identity.name() == content::mojom::kGpuServiceName)
3884 gpu_binder_registry_.TryBindInterface(interface_name, interface_pipe);
wittman757af872016-08-16 00:13:463885}
3886
Ken Rockotfa5d57112019-05-29 20:57:143887void ChromeContentBrowserClient::WillStartServiceManager() {
John Abd-El-Malek27b3ebd22019-02-12 18:59:183888#if defined(OS_WIN)
Xi Han85079c22019-04-18 21:43:053889 if (startup_data_) {
3890 auto* chrome_feature_list_creator =
3891 startup_data_->chrome_feature_list_creator();
John Abd-El-Malek27b3ebd22019-02-12 18:59:183892 // This has to run very early before ServiceManagerContext is created.
3893 const base::Value* force_network_in_process_value =
Xi Han85079c22019-04-18 21:43:053894 chrome_feature_list_creator->browser_policy_connector()
John Abd-El-Malek27b3ebd22019-02-12 18:59:183895 ->GetPolicyService()
3896 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
3897 std::string()))
3898 .GetValue(policy::key::kForceNetworkInProcess);
3899 bool force_network_in_process = false;
3900 if (force_network_in_process_value)
3901 force_network_in_process_value->GetAsBoolean(&force_network_in_process);
3902 if (force_network_in_process)
3903 content::ForceInProcessNetworkService(true);
3904 }
3905#endif
xhwang5e630462015-10-30 03:18:483906}
3907
Ken Rockot06fd2832019-05-24 17:24:443908void ChromeContentBrowserClient::RunServiceInstance(
3909 const service_manager::Identity& identity,
3910 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
3911 const std::string& service_name = identity.name();
Ken Rockot08750522018-11-29 07:41:343912 if (service_name == prefs::mojom::kLocalStateServiceName) {
3913 if (!g_browser_process || !g_browser_process->pref_service_factory())
3914 return;
3915
Ken Rockotd80eb102018-11-29 14:55:163916 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot08750522018-11-29 07:41:343917 g_browser_process->pref_service_factory()->CreatePrefService(
Ken Rockot06fd2832019-05-24 17:24:443918 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413919 return;
Ken Rockot08750522018-11-29 07:41:343920 }
3921
Alexander Woolfed183c512019-05-17 01:18:033922#if defined(OS_WIN)
3923 bool run_quarantine_service_in_process =
3924 !base::FeatureList::IsEnabled(quarantine::kOutOfProcessQuarantine);
3925#else
3926 bool run_quarantine_service_in_process = true;
3927#endif
3928
3929 if (run_quarantine_service_in_process &&
3930 service_name == quarantine::mojom::kServiceName) {
3931 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443932 std::make_unique<quarantine::QuarantineService>(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413933 return;
Alexander Woolfed183c512019-05-17 01:18:033934 }
3935
Ken Rockot3d8be742018-11-22 08:59:383936#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
3937 if (service_name == media::mojom::kMediaServiceName) {
Ken Rockotd80eb102018-11-29 14:55:163938 service_manager::Service::RunAsyncUntilTermination(
Ken Rockot06fd2832019-05-24 17:24:443939 media::CreateMediaService(std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413940 return;
Ken Rockot3d8be742018-11-22 08:59:383941 }
3942#endif
Ken Rockote116c202018-11-30 01:52:503943
Ken Rockotc15f34992018-12-01 21:27:573944#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
3945 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3946 switches::kLaunchInProcessSimpleBrowserSwitch) &&
3947 service_name == simple_browser::mojom::kServiceName) {
3948 service_manager::Service::RunAsyncUntilTermination(
3949 std::make_unique<simple_browser::SimpleBrowserService>(
Ken Rockot06fd2832019-05-24 17:24:443950 std::move(*receiver), simple_browser::SimpleBrowserService::
3951 UIInitializationMode::kUseEnvironmentUI));
Lei Zhang194fcd32019-05-23 16:19:413952 return;
Ken Rockotc15f34992018-12-01 21:27:573953 }
3954#endif
3955
Ken Rockote116c202018-11-30 01:52:503956#if defined(OS_CHROMEOS)
Lei Zhang194fcd32019-05-23 16:19:413957 if (base::FeatureList::IsEnabled(
3958 chromeos::features::kUpdatedCellularActivationUi) &&
3959 service_name == chromeos::cellular_setup::mojom::kServiceName) {
Kyle Horimoto1d6a679f2019-04-16 23:24:213960 service_manager::Service::RunAsyncUntilTermination(
3961 std::make_unique<chromeos::cellular_setup::CellularSetupService>(
Ken Rockot06fd2832019-05-24 17:24:443962 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413963 return;
Kyle Horimoto1d6a679f2019-04-16 23:24:213964 }
3965
Regan Hsu07912b7d2018-12-13 21:27:013966 if (service_name == chromeos::secure_channel::mojom::kServiceName) {
Ken Rockotc15f34992018-12-01 21:27:573967 service_manager::Service::RunAsyncUntilTermination(
3968 std::make_unique<chromeos::secure_channel::SecureChannelService>(
Ken Rockot06fd2832019-05-24 17:24:443969 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413970 return;
Ken Rockotc15f34992018-12-01 21:27:573971 }
3972
Steven Bennetts0c565d5b2019-04-24 23:52:453973 if (service_name == chromeos::network_config::mojom::kServiceName) {
3974 service_manager::Service::RunAsyncUntilTermination(
3975 std::make_unique<chromeos::network_config::NetworkConfigService>(
Ken Rockot06fd2832019-05-24 17:24:443976 std::move(*receiver)));
Lei Zhang194fcd32019-05-23 16:19:413977 return;
Steven Bennetts0c565d5b2019-04-24 23:52:453978 }
3979
Ken Rockot06fd2832019-05-24 17:24:443980 auto service = ash_service_registry::HandleServiceRequest(
3981 service_name, std::move(*receiver));
Ken Rockotc15f34992018-12-01 21:27:573982 if (service)
3983 service_manager::Service::RunAsyncUntilTermination(std::move(service));
Lei Zhang194fcd32019-05-23 16:19:413984#endif // defined(OS_CHROMEOS)
Ken Rockot3d8be742018-11-22 08:59:383985}
3986
Ken Rockot06fd2832019-05-24 17:24:443987void ChromeContentBrowserClient::RunServiceInstanceOnIOThread(
3988 const service_manager::Identity& identity,
3989 mojo::PendingReceiver<service_manager::mojom::Service>* receiver) {
3990 if (identity.name() == chrome::mojom::kServiceName) {
3991 ChromeService::GetInstance()->CreateChromeServiceRequestHandler().Run(
3992 std::move(*receiver));
3993 return;
3994 }
3995
Ken Rockot06fd2832019-05-24 17:24:443996 if (identity.name() == heap_profiling::mojom::kServiceName) {
3997 heap_profiling::HeapProfilingService::GetServiceFactory().Run(
3998 std::move(*receiver));
3999 return;
4000 }
4001}
4002
Ken Rockot8f39a272018-12-21 23:38:354003base::Optional<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174004ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
Lei Zhang5b3f81f2019-04-10 00:54:584005 if (name == content::mojom::kBrowserServiceName)
Ken Rockot341089f2019-01-11 23:11:584006 return GetChromeContentBrowserOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584007 if (name == content::mojom::kGpuServiceName)
Ken Rockot341089f2019-01-11 23:11:584008 return GetChromeContentGpuOverlayManifest();
Lei Zhang5b3f81f2019-04-10 00:54:584009 if (name == content::mojom::kRendererServiceName)
4010 return GetChromeContentRendererOverlayManifest();
4011 if (name == content::mojom::kUtilityServiceName)
4012 return GetChromeContentUtilityOverlayManifest();
Ken Rockot341089f2019-01-11 23:11:584013 return base::nullopt;
benc70c0e32016-09-22 03:50:374014}
4015
Ken Rockot69aade02019-01-23 21:19:514016std::vector<service_manager::Manifest>
sammc2b0375b2016-12-22 01:26:174017ChromeContentBrowserClient::GetExtraServiceManifests() {
Ken Rockot06fd2832019-05-24 17:24:444018 auto manifests = GetChromeBuiltinServiceManifests();
4019 manifests.push_back(GetChromeRendererManifest());
4020
Nico Weberaf3b00b2017-09-11 17:58:174021#if BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444022 manifests.push_back(GetNaClLoaderManifest());
Ken Rockot69aade02019-01-23 21:19:514023#if defined(OS_WIN) && defined(ARCH_CPU_X86)
Ken Rockot06fd2832019-05-24 17:24:444024 manifests.push_back(GetNaClBrokerManifest());
sammc2b0375b2016-12-22 01:26:174025#endif // defined(OS_WIN)
Nico Weberaf3b00b2017-09-11 17:58:174026#endif // BUILDFLAG(ENABLE_NACL)
Ken Rockot06fd2832019-05-24 17:24:444027
4028 return manifests;
sammc2b0375b2016-12-22 01:26:174029}
4030
peterbbcccc12015-02-11 22:23:334031void ChromeContentBrowserClient::OpenURL(
Matt Falkenhagen18c5c5d2018-11-26 02:55:374032 content::SiteInstance* site_instance,
peterbbcccc12015-02-11 22:23:334033 const content::OpenURLParams& params,
danakja9fe91c2019-05-01 19:02:294034 base::OnceCallback<void(content::WebContents*)> callback) {
mlamourieb40d552015-02-05 00:57:084035 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagen18c5c5d2018-11-26 02:55:374036 DCHECK(ShouldAllowOpenURL(site_instance, params.url));
4037
4038 content::BrowserContext* browser_context = site_instance->GetBrowserContext();
mlamourieb40d552015-02-05 00:57:084039
zpengdb4a58e2017-01-10 17:40:324040#if defined(OS_ANDROID)
pkotwiczaa289f02016-07-05 22:26:224041 ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params,
danakja9fe91c2019-05-01 19:02:294042 std::move(callback));
jam1c5a91492016-02-24 20:47:534043#else
cm.sanchi2522bc92017-12-04 08:04:134044 NavigateParams nav_params(Profile::FromBrowserContext(browser_context),
4045 params.url, params.transition);
4046 nav_params.FillNavigateParamsFromOpenURLParams(params);
mlamourieb40d552015-02-05 00:57:084047 nav_params.user_gesture = params.user_gesture;
4048
4049 Navigate(&nav_params);
danakja9fe91c2019-05-01 19:02:294050 std::move(callback).Run(nav_params.navigated_or_inserted_contents);
peterbbcccc12015-02-11 22:23:334051#endif
mlamourieb40d552015-02-05 00:57:084052}
4053
zhaobinf3704f82017-01-12 07:19:364054content::ControllerPresentationServiceDelegate*
4055ChromeContentBrowserClient::GetControllerPresentationServiceDelegate(
4056 content::WebContents* web_contents) {
mfoltz99bd44c2016-03-18 20:36:464057 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
haibinlu9e605a92015-06-06 03:45:094058 return media_router::PresentationServiceDelegateImpl::
4059 GetOrCreateForWebContents(web_contents);
4060 }
haibinlu9e605a92015-06-06 03:45:094061 return nullptr;
4062}
4063
zhaobinf3704f82017-01-12 07:19:364064content::ReceiverPresentationServiceDelegate*
4065ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate(
4066 content::WebContents* web_contents) {
zhaobinf3704f82017-01-12 07:19:364067 if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) {
4068 // ReceiverPresentationServiceDelegateImpl exists only for WebContents
4069 // created for offscreen presentations. The WebContents must belong to
4070 // an incognito profile.
4071 if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl::
4072 FromWebContents(web_contents)) {
4073 DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord());
4074 return impl;
4075 }
4076 }
zhaobinf3704f82017-01-12 07:19:364077 return nullptr;
4078}
4079
horo48d4d3e2015-02-27 03:04:004080void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric,
4081 const GURL& url) {
mathp46284f32015-03-11 13:06:414082 if (url.is_valid()) {
4083 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
4084 metric, url);
4085 }
horo48d4d3e2015-02-27 03:04:004086}
4087
Matt Falkenhagen8479b202017-07-14 04:35:314088std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) {
4089 // Don't change these returned strings. They are written (in hashed form) into
4090 // UMA logs. If you add more strings, you must update histograms.xml and get
4091 // histograms review. Only Google domains should be here for privacy purposes.
4092 // TODO(falken): Ideally Chrome would log the relevant UMA directly and this
4093 // function could be removed.
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194094 if (page_load_metrics::IsGoogleSearchResultUrl(url))
Matt Falkenhagen8479b202017-07-14 04:35:314095 return "search";
Matt Falkenhagen2c98ee29a2017-07-20 16:43:194096 if (url.host() == "docs.google.com")
4097 return "docs";
Matt Falkenhagen8479b202017-07-14 04:35:314098 return std::string();
4099}
4100
avid6d88b912017-01-13 00:16:004101std::vector<std::unique_ptr<content::NavigationThrottle>>
clamy40c9e142015-09-29 11:18:474102ChromeContentBrowserClient::CreateThrottlesForNavigation(
4103 content::NavigationHandle* handle) {
avid6d88b912017-01-13 00:16:004104 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
trizzofo8ddaeb72016-09-01 23:18:274105
bmcquadeb4556552017-03-24 22:24:374106 // MetricsNavigationThrottle requires that it runs before NavigationThrottles
4107 // that may delay or cancel navigations, so only NavigationThrottles that
4108 // don't delay or cancel navigations (e.g. throttles that are only observing
4109 // callbacks without affecting navigation behavior) should be added before
4110 // MetricsNavigationThrottle.
4111 if (handle->IsInMainFrame()) {
4112 throttles.push_back(
4113 page_load_metrics::MetricsNavigationThrottle::Create(handle));
4114 }
4115
brettw4b461082016-11-19 18:55:164116#if BUILDFLAG(ENABLE_PLUGINS)
tommycliae590f1602016-11-02 03:59:234117 std::unique_ptr<content::NavigationThrottle> flash_url_throttle =
4118 FlashDownloadInterception::MaybeCreateThrottleFor(handle);
4119 if (flash_url_throttle)
4120 throttles.push_back(std::move(flash_url_throttle));
trizzofo8ddaeb72016-09-01 23:18:274121#endif
4122
mmenkedb2637ff2017-03-30 23:59:424123#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4124 std::unique_ptr<content::NavigationThrottle> supervised_user_throttle =
4125 SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle);
4126 if (supervised_user_throttle)
4127 throttles.push_back(std::move(supervised_user_throttle));
4128#endif
4129
clamy40c9e142015-09-29 11:18:474130#if defined(OS_ANDROID)
4131 // TODO(davidben): This is insufficient to integrate with prerender properly.
4132 // https://crbug.com/370595
4133 prerender::PrerenderContents* prerender_contents =
4134 prerender::PrerenderContents::FromWebContents(handle->GetWebContents());
4135 if (!prerender_contents && handle->IsInMainFrame()) {
4136 throttles.push_back(
4137 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:304138 handle, navigation_interception::SynchronyMode::kAsync));
clamy40c9e142015-09-29 11:18:474139 }
Min Qin0ab0e162017-11-14 21:57:194140 throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle));
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574141#elif BUILDFLAG(ENABLE_EXTENSIONS)
clamy40c9e142015-09-29 11:18:474142 if (handle->IsInMainFrame()) {
4143 // Redirect some navigations to apps that have registered matching URL
4144 // handlers ('url_handlers' in the manifest).
Giovanni Ortuño Urquidi7ae7fb02017-10-09 01:49:574145 auto url_to_app_throttle =
4146 PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle);
clamy40c9e142015-09-29 11:18:474147 if (url_to_app_throttle)
dchenge73d8520c2015-12-27 01:19:094148 throttles.push_back(std::move(url_to_app_throttle));
clamy40c9e142015-09-29 11:18:474149 }
4150#endif
clamy49678312015-10-22 21:59:004151
4152#if defined(OS_CHROMEOS)
4153 // Check if we need to add merge session throttle. This throttle will postpone
4154 // loading of main frames.
4155 if (handle->IsInMainFrame()) {
4156 // Add interstitial page while merge session process (cookie reconstruction
4157 // from OAuth2 refresh token in ChromeOS login) is still in progress while
4158 // we are attempting to load a google property.
csharrisondd06bab2016-07-22 14:15:024159 if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
4160 !merge_session_throttling_utils::AreAllSessionMergedAlready() &&
clamy49678312015-10-22 21:59:004161 handle->GetURL().SchemeIsHTTPOrHTTPS()) {
4162 throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
4163 }
Maggie Caia2f03f52019-04-02 02:13:284164 }
4165#endif
djacobo21e56e02016-07-02 01:14:314166
Maggie Caia2f03f52019-04-02 02:13:284167#if !defined(OS_ANDROID)
4168 if (base::FeatureList::IsEnabled(features::kIntentPicker)) {
Dominick Ng7c289942018-03-27 05:57:154169 auto url_to_apps_throttle =
Maggie Caia2f03f52019-04-02 02:13:284170#if defined(OS_CHROMEOS)
4171 chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle);
4172#else
4173 apps::AppsNavigationThrottle::MaybeCreate(handle);
4174#endif
Dominick Ng7c289942018-03-27 05:57:154175 if (url_to_apps_throttle)
4176 throttles.push_back(std::move(url_to_apps_throttle));
clamy49678312015-10-22 21:59:004177 }
4178#endif
4179
brettw00899e62016-11-12 02:10:174180#if BUILDFLAG(ENABLE_EXTENSIONS)
avid6d88b912017-01-13 00:16:004181 throttles.push_back(
Jeremy Romanec48d7a2018-03-01 17:35:094182 std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
Clark DuVall2cf99249e2018-09-19 19:11:514183
4184 std::unique_ptr<content::NavigationThrottle> user_script_throttle =
4185 extensions::ExtensionsBrowserClient::Get()
4186 ->GetUserScriptListener()
4187 ->CreateNavigationThrottle(handle);
4188 if (user_script_throttle)
4189 throttles.push_back(std::move(user_script_throttle));
naskob9164c42016-06-07 01:21:354190#endif
4191
bauerb8f9c37742017-03-30 15:04:124192#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
4193 std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle =
4194 SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle);
4195 if (supervised_user_nav_throttle)
4196 throttles.push_back(std::move(supervised_user_nav_throttle));
4197#endif
4198
csharrisone985ebc2017-04-04 17:05:034199 content::WebContents* web_contents = handle->GetWebContents();
csharrison77bf8342017-05-04 18:23:104200 if (auto* subresource_filter_client =
4201 ChromeSubresourceFilterClient::FromWebContents(web_contents)) {
4202 subresource_filter_client->MaybeAppendNavigationThrottles(handle,
4203 &throttles);
csharrisone985ebc2017-04-04 17:05:034204 }
4205
zhenw6edd49c2017-07-12 05:49:454206#if !defined(OS_ANDROID)
4207 // BackgroundTabNavigationThrottle is used by TabManager, which is only
4208 // enabled on non-Android platforms.
4209 std::unique_ptr<content::NavigationThrottle>
4210 background_tab_navigation_throttle = resource_coordinator::
4211 BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle);
4212 if (background_tab_navigation_throttle)
4213 throttles.push_back(std::move(background_tab_navigation_throttle));
4214#endif
4215
Nico Weberbc5b06f2019-07-26 14:00:134216#if BUILDFLAG(FULL_SAFE_BROWSING)
Jialiu Linbdbb81d2017-10-11 21:29:094217 std::unique_ptr<content::NavigationThrottle>
4218 password_protection_navigation_throttle =
4219 safe_browsing::MaybeCreateNavigationThrottle(handle);
4220 if (password_protection_navigation_throttle) {
4221 throttles.push_back(std::move(password_protection_navigation_throttle));
4222 }
4223#endif
4224
Joe DeBlasio6e8409a2019-02-20 23:08:274225 std::unique_ptr<content::NavigationThrottle>
Mustafa Emre Acere14f6262019-04-02 00:19:314226 lookalike_url_navigation_throttle = lookalikes::
Joe DeBlasio6e8409a2019-02-20 23:08:274227 LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle);
4228 if (lookalike_url_navigation_throttle)
4229 throttles.push_back(std::move(lookalike_url_navigation_throttle));
Joe DeBlasio6e8409a2019-02-20 23:08:274230
Amber Wonf56d8f42017-08-31 22:29:404231 std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle =
4232 PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle);
4233 if (pdf_iframe_throttle)
4234 throttles.push_back(std::move(pdf_iframe_throttle));
Amber Won6b5edc752017-08-17 19:23:544235
Charles Harrison6dd11d282017-10-03 06:14:514236 std::unique_ptr<content::NavigationThrottle> tab_under_throttle =
4237 TabUnderNavigationThrottle::MaybeCreate(handle);
4238 if (tab_under_throttle)
4239 throttles.push_back(std::move(tab_under_throttle));
4240
Jeremy Romanec48d7a2018-03-01 17:35:094241 throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
Doug Turner9dcaf5962017-12-21 04:38:534242 handle, handle->GetWebContents()->GetBrowserContext()));
4243
Carlos IL5a9e7512019-06-13 22:35:284244 throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>(
4245 handle,
4246 std::make_unique<CertificateReportingServiceCertReporter>(web_contents),
4247 base::Bind(&SSLErrorHandler::HandleSSLError)));
Lucas Garron94b16052017-11-11 01:58:124248
Christopher Thompson4137cec2017-12-19 05:34:234249 std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle =
4250 TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle);
4251 if (https_upgrade_timing_throttle)
4252 throttles.push_back(std::move(https_upgrade_timing_throttle));
4253
Dmitry Gozman57b92ce2017-12-28 22:24:544254#if !defined(OS_ANDROID)
4255 std::unique_ptr<content::NavigationThrottle> devtools_throttle =
4256 DevToolsWindow::MaybeCreateNavigationThrottle(handle);
4257 if (devtools_throttle)
4258 throttles.push_back(std::move(devtools_throttle));
Conley Owensaafcf122018-02-26 18:53:514259
4260 std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle =
4261 NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle);
4262 if (new_tab_page_throttle)
4263 throttles.push_back(std::move(new_tab_page_throttle));
jdoerrie4f9376f2018-12-12 18:26:204264
4265 std::unique_ptr<content::NavigationThrottle>
4266 google_password_manager_throttle =
4267 GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(
4268 handle);
4269 if (google_password_manager_throttle)
4270 throttles.push_back(std::move(google_password_manager_throttle));
Dmitry Gozman57b92ce2017-12-28 22:24:544271#endif
4272
Robert Ogdenafd250b2018-07-25 22:21:034273 std::unique_ptr<content::NavigationThrottle> previews_lite_page_throttle =
4274 PreviewsLitePageDecider::MaybeCreateThrottleFor(handle);
4275 if (previews_lite_page_throttle)
4276 throttles.push_back(std::move(previews_lite_page_throttle));
Carlos IL4ee307e2018-12-22 03:19:004277 if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) {
4278 throttles.push_back(
4279 std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(
4280 handle));
4281 }
Robert Ogdenafd250b2018-07-25 22:21:034282
Nicolas Ouellet-Payeurbdcab0092018-10-22 14:50:334283#if defined(OS_WIN) || defined(OS_MACOSX) || \
4284 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
Nicolas Ouellet-Payeur995e7772018-09-13 16:02:134285 std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle =
4286 browser_switcher::BrowserSwitcherNavigationThrottle ::
4287 MaybeCreateThrottleFor(handle);
4288 if (browser_switcher_throttle)
4289 throttles.push_back(std::move(browser_switcher_throttle));
4290#endif
4291
dchenge73d8520c2015-12-27 01:19:094292 return throttles;
clamy40c9e142015-09-29 11:18:474293}
4294
clamy1e5574e2016-09-29 16:48:444295std::unique_ptr<content::NavigationUIData>
4296ChromeContentBrowserClient::GetNavigationUIData(
4297 content::NavigationHandle* navigation_handle) {
Jeremy Romanec48d7a2018-03-01 17:35:094298 return std::make_unique<ChromeNavigationUIData>(navigation_handle);
clamy1e5574e2016-09-29 16:48:444299}
4300
Xiaohan Wanga4e41842018-06-26 18:45:104301void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(
4302 const std::string& key_system,
4303 const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols,
4304 base::flat_set<media::VideoCodec>* video_codecs,
4305 base::flat_set<media::EncryptionMode>* encryption_schemes) {
4306#if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \
Xiaohan Wangf170c732018-09-27 05:45:264307 BUILDFLAG(ENABLE_WIDEVINE)
Xiaohan Wanga4e41842018-06-26 18:45:104308 if (key_system == kWidevineKeySystem) {
4309 GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs,
4310 encryption_schemes);
4311 }
4312#endif
4313}
4314
[email protected]487974a2014-06-13 16:49:014315content::DevToolsManagerDelegate*
4316ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
Pavel Feldman43f56b7c2016-08-30 00:04:354317#if defined(OS_ANDROID)
4318 return new DevToolsManagerDelegateAndroid();
4319#else
[email protected]487974a2014-06-13 16:49:014320 return new ChromeDevToolsManagerDelegate();
Pavel Feldman43f56b7c2016-08-30 00:04:354321#endif
[email protected]487974a2014-06-13 16:49:014322}
4323
Rayan Kanso411e84e2019-02-13 15:27:404324void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration(
4325 content::BrowserContext* browser_context,
4326 int service,
4327 base::Time expiration_time) {
4328 Profile* profile = Profile::FromBrowserContext(browser_context);
4329 DCHECK(profile);
4330
4331 auto* pref_service = profile->GetPrefs();
4332 DCHECK(pref_service);
4333
4334 DictionaryPrefUpdate pref_update(
4335 pref_service, prefs::kDevToolsBackgroundServicesExpirationDict);
4336 base::DictionaryValue* exp_dict = pref_update.Get();
4337
4338 // Convert |expiration_time| to minutes since that is the most granular
4339 // option that returns an int. base::Value does not accept int64.
4340 int expiration_time_minutes =
4341 expiration_time.ToDeltaSinceWindowsEpoch().InMinutes();
4342 exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes);
4343}
4344
4345base::flat_map<int, base::Time>
4346ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations(
4347 content::BrowserContext* browser_context) {
4348 Profile* profile = Profile::FromBrowserContext(browser_context);
4349 DCHECK(profile);
4350
4351 auto* pref_service = profile->GetPrefs();
4352 DCHECK(pref_service);
4353
4354 auto* expiration_dict = pref_service->GetDictionary(
4355 prefs::kDevToolsBackgroundServicesExpirationDict);
4356 DCHECK(expiration_dict);
4357
4358 base::flat_map<int, base::Time> expiration_times;
4359 for (const auto& it : *expiration_dict) {
4360 // key.
4361 int service = 0;
4362 bool did_convert = base::StringToInt(it.first, &service);
4363 DCHECK(did_convert);
4364
4365 // value.
4366 DCHECK(it.second->is_int());
4367 base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt());
4368 base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta);
4369
4370 expiration_times[service] = expiration_time;
4371 }
4372
4373 return expiration_times;
4374}
4375
oysteinec563c582015-02-13 19:19:524376content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() {
oysteinec563c582015-02-13 19:19:524377 return new ChromeTracingDelegate();
oysteinec563c582015-02-13 19:19:524378}
4379
[email protected]a6868c22013-10-09 02:50:294380bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
4381 content::BrowserContext* browser_context,
4382 const GURL& url) {
brettw4b461082016-11-19 18:55:164383#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554384 return ChromeContentBrowserClientPluginsPart::
4385 IsPluginAllowedToCallRequestOSFileHandle(browser_context, url,
4386 allowed_file_handle_origins_);
[email protected]a6868c22013-10-09 02:50:294387#else
4388 return false;
4389#endif
4390}
4391
[email protected]aec5ed52014-06-20 07:51:424392bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs(
4393 content::BrowserContext* browser_context,
4394 const GURL& url) {
brettw4b461082016-11-19 18:55:164395#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS)
jitendra.ks42e889a2014-12-05 09:05:554396 return ChromeContentBrowserClientPluginsPart::
4397 IsPluginAllowedToUseDevChannelAPIs(browser_context, url,
4398 allowed_dev_channel_origins_);
[email protected]8ddc6b7c2013-12-12 20:42:064399#else
4400 return false;
4401#endif
4402}
4403
mlamourif8c23a2002015-01-27 13:10:104404void ChromeContentBrowserClient::OverridePageVisibilityState(
xzhan96cf0a3c542017-11-17 04:33:014405 RenderFrameHost* render_frame_host,
danakj0018a29a2018-12-01 01:03:434406 content::PageVisibilityState* visibility_state) {
thestig00844cea2015-09-08 21:44:524407 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mlamourif8c23a2002015-01-27 13:10:104408
4409 WebContents* web_contents =
4410 WebContents::FromRenderFrameHost(render_frame_host);
4411 DCHECK(web_contents);
4412
mlamourif8c23a2002015-01-27 13:10:104413 prerender::PrerenderManager* prerender_manager =
drogerc1543152016-09-20 13:03:374414 prerender::PrerenderManagerFactory::GetForBrowserContext(
4415 web_contents->GetBrowserContext());
mlamourif8c23a2002015-01-27 13:10:104416 if (prerender_manager &&
4417 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
danakj0018a29a2018-12-01 01:03:434418 *visibility_state = content::PageVisibilityState::kPrerender;
mlamourif8c23a2002015-01-27 13:10:104419 }
4420}
4421
Andrew Moylan8ed9d83c82019-01-29 20:23:524422// Forward image Annotator requests to the image_annotation service.
4423void BindImageAnnotator(image_annotation::mojom::AnnotatorRequest request,
4424 RenderFrameHost* const frame_host) {
4425 content::BrowserContext::GetConnectorFor(
4426 frame_host->GetProcess()->GetBrowserContext())
4427 ->BindInterface(image_annotation::mojom::kServiceName,
4428 std::move(request));
4429}
4430
Sam McNallyfaf9a402017-10-31 03:06:314431void ChromeContentBrowserClient::InitWebContextInterfaces() {
Jeremy Romanec48d7a2018-03-01 17:35:094432 frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>();
4433 frame_interfaces_parameterized_ = std::make_unique<
Ben Goodger21ada1e2017-07-19 14:53:014434 service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>();
Sam McNallyfaf9a402017-10-31 03:06:314435 worker_interfaces_parameterized_ =
Jeremy Romanec48d7a2018-03-01 17:35:094436 std::make_unique<service_manager::BinderRegistryWithArgs<
Sam McNallyfaf9a402017-10-31 03:06:314437 content::RenderProcessHost*, const url::Origin&>>();
Ben Goodger6a695c012017-06-20 20:21:204438
Michael Martis4a542f52017-07-28 01:51:444439 // Register mojo ContentTranslateDriver interface only for main frame.
Anthony Vallee-Duboise2432137a2019-01-17 20:06:014440 frame_interfaces_parameterized_->AddInterface(
4441 base::BindRepeating(&language::BindContentTranslateDriver));
Ben Goodger6a695c012017-06-20 20:21:204442
4443 frame_interfaces_parameterized_->AddInterface(
Eric Lawrenced0acf2a7c2017-07-20 18:02:484444 base::Bind(&InsecureSensitiveInputDriverFactory::BindDriver));
Andrew Moylan8ed9d83c82019-01-29 20:23:524445 frame_interfaces_parameterized_->AddInterface(
4446 base::BindRepeating(&BindImageAnnotator));
Ben Goodger6a695c012017-06-20 20:21:204447
4448#if defined(OS_ANDROID)
4449 frame_interfaces_parameterized_->AddInterface(base::Bind(
Matt Giucaee4aefb2017-08-04 03:11:554450 &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>));
Ben Goodger6a695c012017-06-20 20:21:204451 frame_interfaces_parameterized_->AddInterface(
4452 base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>));
Kim Paulhamus3d33e442018-03-29 23:04:144453 frame_interfaces_parameterized_->AddInterface(
Amos Limdddb6992018-07-19 22:14:324454 base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>));
Michael Thiessen909ba032019-03-26 23:47:434455#if defined(BROWSER_MEDIA_CONTROLS_MENU)
4456 frame_interfaces_parameterized_->AddInterface(base::Bind(
4457 &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>));
4458#endif
Ben Goodger6a695c012017-06-20 20:21:204459#else
4460 if (base::FeatureList::IsEnabled(features::kWebPayments)) {
4461 frame_interfaces_parameterized_->AddInterface(
4462 base::Bind(&payments::CreatePaymentRequest));
4463 }
4464#endif
4465
Ben Goodger6a695c012017-06-20 20:21:204466#if defined(OS_ANDROID)
Matt Giuca00e993602017-06-23 05:17:544467 frame_interfaces_parameterized_->AddInterface(base::Bind(
4468 &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>));
Michael Thiessen07c444c2019-04-26 03:53:114469#if defined(ENABLE_SPATIAL_NAVIGATION_HOST)
4470 frame_interfaces_parameterized_->AddInterface(base::Bind(
4471 &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>));
4472#endif
Ben Goodger6a695c012017-06-20 20:21:204473#endif
Reilly Grant8e5c85c2017-07-07 16:35:064474
Jay Harris5a42aa21b2018-11-28 01:23:554475#if !defined(OS_ANDROID)
Eric Stevenson1d074a972018-12-07 14:16:454476 frame_interfaces_parameterized_->AddInterface(
Jay Harris1ddcffa2019-07-09 03:07:404477 base::BindRepeating(&badging::BadgeManager::BindRequest));
Eric Stevensonc3b18052018-10-01 22:22:004478#endif
4479
Reilly Grant8e5c85c2017-07-07 16:35:064480 frame_interfaces_parameterized_->AddInterface(
Lu Chen5bec7a302018-06-26 18:52:324481 base::BindRepeating(&NavigationPredictor::Create));
Dan Harringtonbc87c062018-10-31 15:21:244482
4483#if defined(OS_ANDROID)
4484 frame_interfaces_parameterized_->AddInterface(
4485 base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create),
4486 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}));
4487#endif
Ben Goodger6a695c012017-06-20 20:21:204488}
4489
[email protected]30335fdf02014-02-26 19:51:274490void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
avi3ef9ec9e2014-12-22 22:50:174491 base::CommandLine* to_command_line,
4492 const base::CommandLine& from_command_line,
sdefresne6e883e42015-07-30 08:05:544493 version_info::Channel channel) {
[email protected]30335fdf02014-02-26 19:51:274494#if defined(OS_ANDROID)
sdefresne6e883e42015-07-30 08:05:544495 const version_info::Channel kMaxDisableEncryptionChannel =
4496 version_info::Channel::BETA;
[email protected]30335fdf02014-02-26 19:51:274497#else
sdefresne6e883e42015-07-30 08:05:544498 const version_info::Channel kMaxDisableEncryptionChannel =
4499 version_info::Channel::DEV;
[email protected]30335fdf02014-02-26 19:51:274500#endif
4501 if (channel <= kMaxDisableEncryptionChannel) {
4502 static const char* const kWebRtcDevSwitchNames[] = {
4503 switches::kDisableWebRtcEncryption,
4504 };
Avi Drissmand251e912018-12-26 15:46:374505 to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames,
4506 base::size(kWebRtcDevSwitchNames));
[email protected]30335fdf02014-02-26 19:51:274507 }
4508}
bashi933629552016-10-13 23:32:404509
miu54dca6c2016-11-17 10:59:384510#if BUILDFLAG(ENABLE_MEDIA_REMOTING)
4511void ChromeContentBrowserClient::CreateMediaRemoter(
4512 content::RenderFrameHost* render_frame_host,
4513 media::mojom::RemotingSourcePtr source,
4514 media::mojom::RemoterRequest request) {
miu54dca6c2016-11-17 10:59:384515 CastRemotingConnector::CreateMediaRemoter(
4516 render_frame_host, std::move(source), std::move(request));
miu54dca6c2016-11-17 10:59:384517}
4518#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
robliaobf5a32e2016-12-09 03:35:464519
Michael Giuffrida6802ffe2017-09-29 03:40:254520base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
4521 const base::CommandLine& command_line) {
4522 return logging::GetLogFileName(command_line);
kerrnela67fad52017-06-14 20:18:164523}
4524
John Abd-El-Malek8efa11f2019-01-06 00:51:534525namespace {
4526// TODO(jam): move this to a separate file.
Clark DuVall8512cee62019-06-26 01:14:214527template <class HandlerRegistry>
Minggang Wangf6840ecf2019-07-29 05:15:024528class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
John Abd-El-Malek8efa11f2019-01-06 00:51:534529 public:
4530 explicit ProtocolHandlerThrottle(
Clark DuVall8512cee62019-06-26 01:14:214531 const HandlerRegistry& protocol_handler_registry)
John Abd-El-Malek8efa11f2019-01-06 00:51:534532 : protocol_handler_registry_(protocol_handler_registry) {}
4533 ~ProtocolHandlerThrottle() override = default;
4534
4535 void WillStartRequest(network::ResourceRequest* request,
4536 bool* defer) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294537 TranslateUrl(&request->url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534538 }
4539
4540 void WillRedirectRequest(net::RedirectInfo* redirect_info,
4541 const network::ResourceResponseHead& response_head,
4542 bool* defer,
4543 std::vector<std::string>* to_be_removed_headers,
4544 net::HttpRequestHeaders* modified_headers) override {
Robbie McElrath16aaed6c2019-06-04 00:50:294545 TranslateUrl(&redirect_info->new_url);
John Abd-El-Malek8efa11f2019-01-06 00:51:534546 }
4547
4548 private:
Robbie McElrath16aaed6c2019-06-04 00:50:294549 void TranslateUrl(GURL* url) {
4550 if (!protocol_handler_registry_->IsHandledProtocol(url->scheme()))
4551 return;
4552 GURL translated_url = protocol_handler_registry_->Translate(*url);
4553 if (!translated_url.is_empty())
4554 *url = translated_url;
4555 }
4556
Clark DuVall8512cee62019-06-26 01:14:214557 HandlerRegistry protocol_handler_registry_;
John Abd-El-Malek8efa11f2019-01-06 00:51:534558};
4559} // namespace
4560
Minggang Wangf6840ecf2019-07-29 05:15:024561std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194562ChromeContentBrowserClient::CreateURLLoaderThrottlesOnIO(
Yuzhu Shencb3011f62018-02-08 02:51:504563 const network::ResourceRequest& request,
4564 content::ResourceContext* resource_context,
4565 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
Yuzhu Shen9508fc72018-02-08 23:18:594566 content::NavigationUIData* navigation_ui_data,
4567 int frame_tree_node_id) {
yzshenefcb7c72017-06-16 23:12:304568 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Matt Falkenhagen7c943742019-07-18 08:03:084569 // TODO(falken): Uncomment out the DCHECK when PlzWorker is moved to the UI
4570 // thread.
4571 // DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
yzshenefcb7c72017-06-16 23:12:304572
Minggang Wangf6840ecf2019-07-29 05:15:024573 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Yuzhu Shen44094e22017-07-18 22:52:354574
Vasilii Sukhanov0163c5142018-10-10 08:30:034575 ProfileIOData* io_data = nullptr;
Clark DuVall92335842018-10-10 16:49:094576 // Only set |io_data| if needed, as in unit tests |resource_context| is a
Clark DuVall6eee9cb2018-10-09 22:08:124577 // MockResourceContext and the cast doesn't work.
Clark DuVall92335842018-10-10 16:49:094578 if (safe_browsing_service_ ||
4579 data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Vasilii Sukhanov0163c5142018-10-10 08:30:034580 io_data = ProfileIOData::FromResourceContext(resource_context);
Clark DuVall92335842018-10-10 16:49:094581 }
4582
rajendrant43194072019-04-15 22:13:434583 ChromeNavigationUIData* chrome_navigation_ui_data =
4584 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4585 if (chrome_navigation_ui_data && io_data &&
4586 io_data->data_reduction_proxy_io_data() &&
Clark DuVall05faba12018-10-29 19:34:484587 data_reduction_proxy::params::IsEnabledWithNetworkService()) {
Wojciech Dzierżanowski45380802019-04-29 14:50:324588 if (!data_reduction_proxy_throttle_manager_) {
4589 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4590 data_reduction_proxy::DataReductionProxyThrottleManager,
4591 base::OnTaskRunnerDeleter>(
4592 new data_reduction_proxy::DataReductionProxyThrottleManager(
4593 io_data->data_reduction_proxy_io_data(),
4594 io_data->data_reduction_proxy_io_data()->CreateThrottleConfig()),
4595 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4596 }
Clark DuVall92335842018-10-10 16:49:094597 net::HttpRequestHeaders headers;
4598 data_reduction_proxy::DataReductionProxyRequestOptions* request_options =
4599 io_data->data_reduction_proxy_io_data()->request_options();
rajendrant43194072019-04-15 22:13:434600 uint64_t page_id =
4601 base::FeatureList::IsEnabled(
4602 data_reduction_proxy::features::
4603 kDataReductionProxyPopulatePreviewsPageIDToPingback)
4604 ? chrome_navigation_ui_data->data_reduction_proxy_page_id()
4605 : request_options->GeneratePageId();
4606 request_options->AddPageIDRequestHeader(&headers, page_id);
Clark DuVall92335842018-10-10 16:49:094607 result.push_back(std::make_unique<
4608 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
Wojciech Dzierżanowski45380802019-04-29 14:50:324609 headers, data_reduction_proxy_throttle_manager_.get()));
Clark DuVall92335842018-10-10 16:49:094610 }
Vasilii Sukhanov0163c5142018-10-10 08:30:034611
Nico Weberbc5b06f2019-07-26 14:00:134612#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall92335842018-10-10 16:49:094613 if (io_data && safe_browsing_service_) {
John Abd-El-Malek9fb60492018-08-02 04:28:504614 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4615 request.url, io_data->safe_browsing_whitelist_domains());
John Abd-El-Malek7577f262019-06-10 21:23:234616 if (!matches_enterprise_whitelist) {
Clark DuVall5497288d2019-07-17 00:17:564617 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4618 base::BindOnce(
4619 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4620 base::Unretained(this)),
4621 wc_getter, frame_tree_node_id, resource_context));
Yuzhu Shencb3011f62018-02-08 02:51:504622 }
4623 }
Nico Weberbc5b06f2019-07-26 14:00:134624#endif
Yuzhu Shen44094e22017-07-18 22:52:354625
Egor Pasko0f4403e2019-01-24 17:42:204626 if (chrome_navigation_ui_data &&
4627 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4628 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4629 chrome_navigation_ui_data->prerender_mode(),
4630 chrome_navigation_ui_data->prerender_histogram_prefix(),
4631 base::BindOnce(GetPrerenderCanceller, wc_getter),
4632 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})));
John Abd-El-Malek9fb60492018-08-02 04:28:504633 }
Jun Cai605ff0e72018-06-12 22:29:204634
John Abd-El-Malek9fb60492018-08-02 04:28:504635 if (io_data) {
Jun Cai605ff0e72018-06-12 22:29:204636 bool is_off_the_record = io_data->IsOffTheRecord();
4637 bool is_signed_in =
4638 !is_off_the_record &&
4639 !io_data->google_services_account_id()->GetValue().empty();
4640
Chris Mumford809d8fb2018-11-10 12:26:114641 chrome::mojom::DynamicParams dynamic_params = {
4642 io_data->force_google_safesearch()->GetValue(),
John Abd-El-Malek9fb60492018-08-02 04:28:504643 io_data->force_youtube_restrict()->GetValue(),
Chris Mumford809d8fb2018-11-10 12:26:114644 io_data->allowed_domains_for_apps()->GetValue(),
4645 variations::VariationsHttpHeaderProvider::GetInstance()
4646 ->GetClientDataHeader(is_signed_in)};
4647 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
4648 is_off_the_record, std::move(dynamic_params)));
John Abd-El-Malek8efa11f2019-01-06 00:51:534649
Clark DuVall8512cee62019-06-26 01:14:214650 result.push_back(
4651 std::make_unique<ProtocolHandlerThrottle<
4652 scoped_refptr<ProtocolHandlerRegistry::IOThreadDelegate>>>(
4653 io_data->protocol_handler_registry_io_thread_delegate()));
John Abd-El-Malekd2377982018-01-08 22:23:124654 }
4655
John Abd-El-Malekecc6f5f2018-03-02 18:47:394656#if BUILDFLAG(ENABLE_PLUGINS)
Matt Falkenhagene75bdd452019-04-03 07:41:524657 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
4658 resource_context, request.resource_type, frame_tree_node_id));
John Abd-El-Malekecc6f5f2018-03-02 18:47:394659#endif
Reilly Grant37877802018-08-18 00:58:354660
Robbie McElrath127ad2b2019-07-22 22:38:114661 auto delegate =
4662 std::make_unique<signin::HeaderModificationDelegateOnIOThreadImpl>(
4663 resource_context);
John Abd-El-Malek7577f262019-06-10 21:23:234664 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4665 std::move(delegate), navigation_ui_data, wc_getter);
4666 if (signin_throttle)
4667 result.push_back(std::move(signin_throttle));
4668
yzshenefcb7c72017-06-16 23:12:304669 return result;
4670}
4671
Minggang Wangf6840ecf2019-07-29 05:15:024672std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
Clark DuVallfffa41e2019-06-25 20:27:194673ChromeContentBrowserClient::CreateURLLoaderThrottles(
4674 const network::ResourceRequest& request,
4675 content::BrowserContext* browser_context,
4676 const base::RepeatingCallback<content::WebContents*()>& wc_getter,
4677 content::NavigationUIData* navigation_ui_data,
4678 int frame_tree_node_id) {
4679 DCHECK_CURRENTLY_ON(BrowserThread::UI);
4680
Minggang Wangf6840ecf2019-07-29 05:15:024681 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
Clark DuVallfffa41e2019-06-25 20:27:194682
4683 Profile* profile = Profile::FromBrowserContext(browser_context);
4684
4685 ChromeNavigationUIData* chrome_navigation_ui_data =
4686 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
4687
Clark DuVall68eb997f2019-06-28 05:42:284688 auto* drp_settings =
4689 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
4690 browser_context);
4691 if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() &&
4692 data_reduction_proxy::params::IsEnabledWithNetworkService() &&
4693 drp_settings) {
4694 if (!data_reduction_proxy_throttle_manager_) {
4695 data_reduction_proxy_throttle_manager_ = std::unique_ptr<
4696 data_reduction_proxy::DataReductionProxyThrottleManager,
4697 base::OnTaskRunnerDeleter>(
4698 new data_reduction_proxy::DataReductionProxyThrottleManager(
4699 drp_settings->data_reduction_proxy_service(),
4700 data_reduction_proxy::DataReductionProxyThrottleManager::
4701 CreateConfig(drp_settings->proxies_for_http())),
4702 base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get()));
4703 }
4704 net::HttpRequestHeaders headers;
4705 data_reduction_proxy::DataReductionProxyRequestOptions::
4706 AddPageIDRequestHeader(
4707 &headers,
4708 chrome_navigation_ui_data->data_reduction_proxy_page_id());
4709 result.push_back(std::make_unique<
4710 data_reduction_proxy::DataReductionProxyURLLoaderThrottle>(
4711 headers, data_reduction_proxy_throttle_manager_.get()));
4712 }
4713
Nico Weberbc5b06f2019-07-26 14:00:134714#if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)
Clark DuVall5497288d2019-07-17 00:17:564715 bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy(
4716 request.url, *profile->GetPrefs());
4717 if (!matches_enterprise_whitelist) {
4718 result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
4719 base::BindOnce(
4720 &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
4721 base::Unretained(this)),
4722 wc_getter, frame_tree_node_id, profile->GetResourceContext()));
4723 }
Nico Weberbc5b06f2019-07-26 14:00:134724#endif
Clark DuVall5497288d2019-07-17 00:17:564725
Clark DuVallfffa41e2019-06-25 20:27:194726 if (chrome_navigation_ui_data &&
4727 chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) {
4728 result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
4729 chrome_navigation_ui_data->prerender_mode(),
4730 chrome_navigation_ui_data->prerender_histogram_prefix(),
4731 base::BindOnce(GetPrerenderCanceller, wc_getter),
4732 base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})));
4733 }
4734
4735 bool is_off_the_record = profile->IsOffTheRecord();
4736 bool is_signed_in = !is_off_the_record &&
4737 !profile->GetPrefs()
4738 ->GetString(prefs::kGoogleServicesUserAccountId)
4739 .empty();
4740
4741 chrome::mojom::DynamicParams dynamic_params = {
4742 profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
4743 profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
4744 profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
4745 variations::VariationsHttpHeaderProvider::GetInstance()
4746 ->GetClientDataHeader(is_signed_in)};
4747 result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
4748 is_off_the_record, std::move(dynamic_params)));
4749
Clark DuVall8512cee62019-06-26 01:14:214750 result.push_back(
4751 std::make_unique<ProtocolHandlerThrottle<ProtocolHandlerRegistry*>>(
4752 ProtocolHandlerRegistryFactory::GetForBrowserContext(
4753 browser_context)));
4754
Clark DuVall39c2cfc2019-06-25 21:49:284755#if BUILDFLAG(ENABLE_PLUGINS)
4756 result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
4757 browser_context, request.resource_type, frame_tree_node_id));
4758#endif
4759
Robbie McElrath127ad2b2019-07-22 22:38:114760 auto delegate =
4761 std::make_unique<signin::HeaderModificationDelegateOnUIThreadImpl>(
4762 profile);
4763 auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate(
4764 std::move(delegate), navigation_ui_data, wc_getter);
4765 if (signin_throttle)
4766 result.push_back(std::move(signin_throttle));
4767
Clark DuVallfffa41e2019-06-25 20:27:194768 return result;
4769}
4770
Ken Rockot6414c4d92017-11-08 19:58:324771void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464772 int frame_tree_node_id,
Ken Rockot6414c4d92017-11-08 19:58:324773 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414774#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
John Abd-El-Malekea006302018-05-10 05:50:464775 content::WebContents* web_contents =
4776 content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
Robbie McElrath6a45ea62018-12-05 06:53:414777#if BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324778 factories->emplace(
4779 extensions::kExtensionScheme,
Chris Mumford8f812662018-02-22 00:27:574780 extensions::CreateExtensionNavigationURLLoaderFactory(
John Abd-El-Malekea006302018-05-10 05:50:464781 web_contents->GetBrowserContext(),
4782 !!extensions::WebViewGuest::FromWebContents(web_contents)));
Robbie McElrath6a45ea62018-12-05 06:53:414783#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4784#if defined(OS_CHROMEOS)
4785 Profile* profile =
4786 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304787 factories->emplace(content::kExternalFileScheme,
4788 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4789 profile, content::ChildProcessHost::kInvalidUniqueID));
Robbie McElrath6a45ea62018-12-05 06:53:414790#endif // defined(OS_CHROMEOS)
4791#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
Ken Rockot6414c4d92017-11-08 19:58:324792}
4793
Ting Shao2dc60582019-07-15 04:43:364794void ChromeContentBrowserClient::
4795 RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
4796 content::BrowserContext* browser_context,
4797 NonNetworkURLLoaderFactoryMap* factories) {
4798#if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4799 DCHECK(browser_context);
4800 DCHECK(factories);
4801#if BUILDFLAG(ENABLE_EXTENSIONS)
4802 factories->emplace(
4803 extensions::kExtensionScheme,
4804 extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
4805 browser_context));
4806#endif // BUILDFLAG(ENABLE_EXTENSIONS)
4807#if defined(OS_CHROMEOS)
4808 Profile* profile = Profile::FromBrowserContext(browser_context);
4809 factories->emplace(content::kExternalFileScheme,
4810 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4811 profile, content::ChildProcessHost::kInvalidUniqueID));
4812#endif // defined(OS_CHROMEOS)
4813#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS)
4814}
4815
Jay Civelli2578ebe2018-06-05 18:44:314816namespace {
4817
4818// The FileURLLoaderFactory provided to the extension background pages.
4819// Checks with the ChildProcessSecurityPolicy to validate the file access.
4820class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
4821 public:
4822 explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
4823
4824 private:
4825 // network::mojom::URLLoaderFactory:
4826 void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
4827 int32_t routing_id,
4828 int32_t request_id,
4829 uint32_t options,
4830 const network::ResourceRequest& request,
4831 network::mojom::URLLoaderClientPtr client,
4832 const net::MutableNetworkTrafficAnnotationTag&
4833 traffic_annotation) override {
4834 if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
4835 child_id_, request.url)) {
4836 client->OnComplete(
4837 network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
4838 return;
4839 }
4840 content::CreateFileURLLoader(request, std::move(loader), std::move(client),
John Abd-El-Malek916f2b82019-02-19 23:49:454841 /*observer=*/nullptr,
4842 /* allow_directory_listing */ true);
Jay Civelli2578ebe2018-06-05 18:44:314843 }
4844
4845 void Clone(network::mojom::URLLoaderFactoryRequest loader) override {
4846 bindings_.AddBinding(this, std::move(loader));
4847 }
4848
4849 int child_id_;
4850 mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
4851 DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
4852};
4853
4854} // namespace
4855
Ken Rockot6414c4d92017-11-08 19:58:324856void ChromeContentBrowserClient::
4857 RegisterNonNetworkSubresourceURLLoaderFactories(
John Abd-El-Malekea006302018-05-10 05:50:464858 int render_process_id,
4859 int render_frame_id,
Ken Rockot6414c4d92017-11-08 19:58:324860 NonNetworkURLLoaderFactoryMap* factories) {
Robbie McElrath6a45ea62018-12-05 06:53:414861#if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4862 content::RenderFrameHost* frame_host =
4863 RenderFrameHost::FromID(render_process_id, render_frame_id);
4864 WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
4865#endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS)
4866
4867#if defined(OS_CHROMEOS)
4868 if (web_contents) {
4869 Profile* profile =
4870 Profile::FromBrowserContext(web_contents->GetBrowserContext());
Robbie McElrath89cc9332019-03-05 02:12:304871 factories->emplace(content::kExternalFileScheme,
4872 std::make_unique<chromeos::ExternalFileURLLoaderFactory>(
4873 profile, render_process_id));
Robbie McElrath6a45ea62018-12-05 06:53:414874 }
4875#endif // defined(OS_CHROMEOS)
4876
Ken Rockot6414c4d92017-11-08 19:58:324877#if BUILDFLAG(ENABLE_EXTENSIONS)
John Abd-El-Malekea006302018-05-10 05:50:464878 auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
4879 render_frame_id);
Ken Rockot6414c4d92017-11-08 19:58:324880 if (factory)
4881 factories->emplace(extensions::kExtensionScheme, std::move(factory));
Chris Mumfordbae8a742018-03-01 23:02:234882
4883 // This logic should match
4884 // ChromeExtensionWebContentsObserver::RenderFrameCreated.
Jay Civellic9bbf72d2018-03-24 01:58:314885 if (!web_contents)
Chris Mumfordbae8a742018-03-01 23:02:234886 return;
Jay Civellic9bbf72d2018-03-24 01:58:314887
4888 Profile* profile =
4889 Profile::FromBrowserContext(web_contents->GetBrowserContext());
4890 InstantService* instant_service =
4891 InstantServiceFactory::GetForProfile(profile);
4892 // The test below matches what's done by ShouldServiceRequestIOThread in
4893 // local_ntp_source.cc.
John Abd-El-Malekea006302018-05-10 05:50:464894 if (instant_service->IsInstantProcess(render_process_id)) {
Jay Civellic9bbf72d2018-03-24 01:58:314895 factories->emplace(
4896 chrome::kChromeSearchScheme,
4897 content::CreateWebUIURLLoader(
4898 frame_host, chrome::kChromeSearchScheme,
4899 /*allowed_webui_hosts=*/base::flat_set<std::string>()));
Chris Mumfordbae8a742018-03-01 23:02:234900 }
Jay Civellic9bbf72d2018-03-24 01:58:314901
Chris Mumfordbae8a742018-03-01 23:02:234902 extensions::ChromeExtensionWebContentsObserver* web_observer =
4903 extensions::ChromeExtensionWebContentsObserver::FromWebContents(
4904 web_contents);
4905
Karan Bhatia91928572018-03-06 01:18:074906 // There is nothing to do if no ChromeExtensionWebContentsObserver is attached
4907 // to the |web_contents|.
4908 if (!web_observer)
4909 return;
4910
Chris Mumfordbae8a742018-03-01 23:02:234911 const Extension* extension =
4912 web_observer->GetExtensionFromFrame(frame_host, false);
4913 if (!extension)
4914 return;
4915
Sam McNally7414eeb72018-09-03 04:05:304916 std::vector<std::string> allowed_webui_hosts;
Chris Mumfordbae8a742018-03-01 23:02:234917 // Support for chrome:// scheme if appropriate.
4918 if ((extension->is_extension() || extension->is_platform_app()) &&
4919 Manifest::IsComponentLocation(extension->location())) {
4920 // Components of chrome that are implemented as extensions or platform apps
4921 // are allowed to use chrome://resources/ and chrome://theme/ URLs.
Sam McNally7414eeb72018-09-03 04:05:304922 allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost);
4923 allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
4924 }
4925 if (extension->is_extension() || extension->is_legacy_packaged_app() ||
4926 (extension->is_platform_app() &&
4927 Manifest::IsComponentLocation(extension->location()))) {
Chris Mumfordbae8a742018-03-01 23:02:234928 // Extensions, legacy packaged apps, and component platform apps are allowed
Lucas Tenório3dd80922019-03-27 03:51:024929 // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon
4930 // URLs. Hosted apps are not allowed because they are served via web servers
4931 // (and are generally never given access to Chrome APIs).
Sam McNally7414eeb72018-09-03 04:05:304932 allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost);
4933 allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost);
Lucas Tenório3dd80922019-03-27 03:51:024934 allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost);
Sam McNally7414eeb72018-09-03 04:05:304935 }
4936 if (!allowed_webui_hosts.empty()) {
Chris Mumfordbae8a742018-03-01 23:02:234937 factories->emplace(
4938 content::kChromeUIScheme,
4939 content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
4940 std::move(allowed_webui_hosts)));
4941 }
Jay Civelli2578ebe2018-06-05 18:44:314942
4943 // Extension with a background page get file access that gets approval from
4944 // ChildProcessSecurityPolicy.
4945 extensions::ExtensionHost* host =
4946 extensions::ProcessManager::Get(web_contents->GetBrowserContext())
4947 ->GetBackgroundHostForExtension(extension->id());
4948 if (host) {
4949 factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>(
4950 render_process_id));
4951 }
Chris Mumfordbae8a742018-03-01 23:02:234952#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Ken Rockot6414c4d92017-11-08 19:58:324953}
4954
Ken Rockota0dfaca12018-02-15 07:26:254955bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
Ken Rockot428b1d62018-06-06 17:12:214956 content::BrowserContext* browser_context,
Ken Rockota0dfaca12018-02-15 07:26:254957 content::RenderFrameHost* frame,
Kenichi Ishibashi09ee5e72018-11-27 07:12:384958 int render_process_id,
Ken Rockota0dfaca12018-02-15 07:26:254959 bool is_navigation,
Ken Rockot1726e182019-02-28 09:48:564960 bool is_download,
Lukasz Anforowicz762733652018-09-28 14:48:264961 const url::Origin& request_initiator,
Dominic Farolino1be897a2019-07-20 08:11:424962 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
Clark DuValla5e25b752018-11-27 22:08:164963 network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
Clark DuVall8dc4e502018-09-07 01:51:124964 bool* bypass_redirect_checks) {
Reilly Grant24bf8332018-08-27 21:55:014965 bool use_proxy = false;
4966
Ken Rockota0dfaca12018-02-15 07:26:254967#if BUILDFLAG(ENABLE_EXTENSIONS)
4968 auto* web_request_api =
4969 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
Ken Rockot428b1d62018-06-06 17:12:214970 browser_context);
Ken Rockota0dfaca12018-02-15 07:26:254971
4972 // NOTE: Some unit test environments do not initialize
4973 // BrowserContextKeyedAPI factories for e.g. WebRequest.
Reilly Grant24bf8332018-08-27 21:55:014974 if (web_request_api) {
Clark DuVall8dc4e502018-09-07 01:51:124975 bool use_proxy_for_web_request =
Kenichi Ishibashi09ee5e72018-11-27 07:12:384976 web_request_api->MaybeProxyURLLoaderFactory(
4977 browser_context, frame, render_process_id, is_navigation,
Dominic Farolino1be897a2019-07-20 08:11:424978 is_download, factory_receiver, header_client);
Clark DuVall8dc4e502018-09-07 01:51:124979 if (bypass_redirect_checks)
4980 *bypass_redirect_checks = use_proxy_for_web_request;
4981 use_proxy |= use_proxy_for_web_request;
Reilly Grant24bf8332018-08-27 21:55:014982 }
Ken Rockota0dfaca12018-02-15 07:26:254983#endif
Reilly Grant24bf8332018-08-27 21:55:014984
Reilly Grantcc22e602018-09-07 15:25:204985 use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest(
Dominic Farolino1be897a2019-07-20 08:11:424986 frame, is_navigation, request_initiator, factory_receiver);
Reilly Grant24bf8332018-08-27 21:55:014987
4988 return use_proxy;
Ken Rockota0dfaca12018-02-15 07:26:254989}
4990
Jian Lide7b43792018-06-01 23:22:134991std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4992ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
4993 content::NavigationUIData* navigation_ui_data,
Ryan Sturm27d93f412019-02-15 21:30:144994 int frame_tree_node_id,
4995 const scoped_refptr<network::SharedURLLoaderFactory>&
4996 network_loader_factory) {
Jian Lide7b43792018-06-01 23:22:134997 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
4998 interceptors;
4999#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
John Abd-El-Malek7577f262019-06-10 21:23:235000 interceptors.push_back(
5001 std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>(
5002 navigation_ui_data, frame_tree_node_id));
Jian Lide7b43792018-06-01 23:22:135003#endif
Ryan Sturmaf523742019-01-16 00:15:455004
Robert Ogden3d5d5b42019-04-22 05:13:115005 ChromeNavigationUIData* chrome_navigation_ui_data =
5006 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5007
Ryan Sturm27d93f412019-02-15 21:30:145008 // TODO(ryansturm): Once this is on the UI thread, stop passing
5009 // |network_loader_factory| and have interceptors create one themselves.
5010 // https://crbug.com/931786
John Abd-El-Malek7577f262019-06-10 21:23:235011 if (base::FeatureList::IsEnabled(
Ryan Sturmaf523742019-01-16 00:15:455012 previews::features::kHTTPSServerPreviewsUsingURLLoader)) {
5013 interceptors.push_back(
5014 std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>(
Robert Ogden3d5d5b42019-04-22 05:13:115015 network_loader_factory,
5016 chrome_navigation_ui_data->data_reduction_proxy_page_id(),
5017 frame_tree_node_id));
Ryan Sturmaf523742019-01-16 00:15:455018 }
5019
Jian Lide7b43792018-06-01 23:22:135020 return interceptors;
5021}
5022
Yutaka Hirano8e0b4d432019-07-04 07:12:385023bool ChromeContentBrowserClient::WillInterceptWebSocket(
5024 content::RenderFrameHost* frame) {
Yutaka Hirano36c94952018-05-30 21:33:335025#if BUILDFLAG(ENABLE_EXTENSIONS)
Yutaka Hirano8e0b4d432019-07-04 07:12:385026 if (!frame) {
5027 return false;
5028 }
5029 const auto* web_request_api =
Yutaka Hirano36c94952018-05-30 21:33:335030 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
5031 frame->GetProcess()->GetBrowserContext());
5032
5033 // NOTE: Some unit test environments do not initialize
5034 // BrowserContextKeyedAPI factories for e.g. WebRequest.
5035 if (!web_request_api)
Yutaka Hirano8e0b4d432019-07-04 07:12:385036 return false;
Yutaka Hirano36c94952018-05-30 21:33:335037
Yutaka Hirano8e0b4d432019-07-04 07:12:385038 return web_request_api->MayHaveProxies();
5039#else
5040 return false;
5041#endif
5042}
5043
5044void ChromeContentBrowserClient::CreateWebSocket(
5045 content::RenderFrameHost* frame,
5046 WebSocketFactory factory,
5047 const GURL& url,
5048 const GURL& site_for_cookies,
5049 const base::Optional<std::string>& user_agent,
5050 network::mojom::WebSocketHandshakeClientPtr handshake_client) {
5051#if BUILDFLAG(ENABLE_EXTENSIONS)
5052 if (!frame) {
5053 return;
5054 }
5055 auto* web_request_api =
5056 extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
5057 frame->GetProcess()->GetBrowserContext());
5058
5059 DCHECK(web_request_api);
5060 web_request_api->ProxyWebSocket(frame, std::move(factory), url,
5061 site_for_cookies, user_agent,
5062 std::move(handshake_client));
Yutaka Hirano36c94952018-05-30 21:33:335063#endif
5064}
5065
Maks Orlovich710d5e32019-07-09 20:16:455066bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager(
Maks Orloviche7db7a22019-07-25 01:47:465067 network::mojom::RestrictedCookieManagerRole role,
Maks Orlovich710d5e32019-07-09 20:16:455068 content::BrowserContext* browser_context,
5069 const url::Origin& origin,
5070 bool is_service_worker,
5071 int process_id,
5072 int routing_id,
5073 network::mojom::RestrictedCookieManagerRequest* request) {
5074 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5075#if BUILDFLAG(ENABLE_EXTENSIONS)
5076 if (origin.scheme() == extensions::kExtensionScheme) {
Maks Orloviche7db7a22019-07-25 01:47:465077 DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role);
Maks Orlovich710d5e32019-07-09 20:16:455078 extensions::ChromeExtensionCookies::Get(browser_context)
5079 ->CreateRestrictedCookieManager(origin, std::move(*request));
5080 return true;
5081 }
5082#endif
5083 return false;
5084}
5085
Matt Menkeae4fdb12018-06-02 06:32:545086void ChromeContentBrowserClient::OnNetworkServiceCreated(
5087 network::mojom::NetworkService* network_service) {
Henrique Nakashima8941aad2018-11-29 23:01:535088 PrefService* local_state;
5089 if (g_browser_process) {
5090 DCHECK(g_browser_process->local_state());
5091 local_state = g_browser_process->local_state();
5092 } else {
Xi Han85079c22019-04-18 21:43:055093 DCHECK(startup_data_->chrome_feature_list_creator()->local_state());
5094 local_state = startup_data_->chrome_feature_list_creator()->local_state();
Henrique Nakashima8941aad2018-11-29 23:01:535095 }
5096
5097 if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance())
5098 data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state);
5099
Henrique Nakashimaa3b1c5d2019-07-03 19:25:495100 // Create SystemNetworkContextManager if it has not been created yet. We need
5101 // to set up global NetworkService state before anything else uses it and this
5102 // is the first opportunity to initialize SystemNetworkContextManager with the
5103 // NetworkService.
5104 if (!SystemNetworkContextManager::HasInstance())
Henrique Nakashima8941aad2018-11-29 23:01:535105 SystemNetworkContextManager::CreateInstance(local_state);
John Abd-El-Malek897374f42019-05-30 03:58:075106
Min Qin8caab1d2018-10-03 17:28:135107 SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated(
Matt Menkeae4fdb12018-06-02 06:32:545108 network_service);
5109}
5110
Ken Rockota0dfaca12018-02-15 07:26:255111network::mojom::NetworkContextPtr
5112ChromeContentBrowserClient::CreateNetworkContext(
5113 content::BrowserContext* context,
5114 bool in_memory,
5115 const base::FilePath& relative_partition_path) {
John Abd-El-Malekcc0b2a62018-03-20 19:32:505116 Profile* profile = Profile::FromBrowserContext(context);
Matt Menked38efd92018-08-14 20:39:455117 return profile->CreateNetworkContext(in_memory, relative_partition_path);
Ken Rockota0dfaca12018-02-15 07:26:255118}
5119
Robert Sesek34f68f312019-01-14 20:25:115120std::vector<base::FilePath>
5121ChromeContentBrowserClient::GetNetworkContextsParentDirectory() {
5122 base::FilePath user_data_dir;
5123 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
5124 DCHECK(!user_data_dir.empty());
5125
5126 base::FilePath cache_dir;
5127 chrome::GetUserCacheDirectory(user_data_dir, &cache_dir);
5128 DCHECK(!cache_dir.empty());
5129
5130 // On some platforms, the cache is a child of the user_data_dir so only
5131 // return the one path.
5132 if (user_data_dir.IsParent(cache_dir))
5133 return {user_data_dir};
5134
5135 return {user_data_dir, cache_dir};
5136}
5137
Min Qin75ed6df2017-12-01 20:39:155138bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp(
Min Qin30a78a12017-12-06 01:29:135139 content::NavigationUIData* navigation_ui_data) {
Min Qin75ed6df2017-12-01 20:39:155140#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5141 // It is OK to load the saved offline copy, in MHTML format.
5142 ChromeNavigationUIData* chrome_navigation_ui_data =
5143 static_cast<ChromeNavigationUIData*>(navigation_ui_data);
5144 if (!chrome_navigation_ui_data)
5145 return false;
5146 offline_pages::OfflinePageNavigationUIData* offline_page_data =
5147 chrome_navigation_ui_data->GetOfflinePageNavigationUIData();
5148 return offline_page_data && offline_page_data->is_offline_page();
5149#else
5150 return false;
5151#endif
5152}
5153
Min Qin30a78a12017-12-06 01:29:135154bool ChromeContentBrowserClient::ShouldForceDownloadResource(
5155 const GURL& url,
5156 const std::string& mime_type) {
5157#if BUILDFLAG(ENABLE_EXTENSIONS)
5158 // Special-case user scripts to get downloaded instead of viewed.
5159 return extensions::UserScript::IsURLUserScript(url, mime_type);
5160#else
5161 return false;
5162#endif
5163}
5164
Donna Wu838ac362018-08-10 10:36:335165void ChromeContentBrowserClient::CreateWebUsbService(
Reilly Grantc31b8192017-12-15 19:54:345166 content::RenderFrameHost* render_frame_host,
Donna Wu838ac362018-08-10 10:36:335167 mojo::InterfaceRequest<blink::mojom::WebUsbService> request) {
Reilly Grantc31b8192017-12-15 19:54:345168 if (!base::FeatureList::IsEnabled(features::kWebUsb))
5169 return;
5170
Reilly Grantc31b8192017-12-15 19:54:345171 WebContents* web_contents =
5172 WebContents::FromRenderFrameHost(render_frame_host);
5173 if (!web_contents) {
5174 NOTREACHED();
5175 return;
5176 }
5177
5178 UsbTabHelper* tab_helper =
5179 UsbTabHelper::GetOrCreateForWebContents(web_contents);
Donna Wu838ac362018-08-10 10:36:335180 tab_helper->CreateWebUsbService(render_frame_host, std::move(request));
Reilly Grantc31b8192017-12-15 19:54:345181}
5182
Reilly Grant0d282322019-01-29 02:42:585183#if !defined(OS_ANDROID)
5184content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() {
5185 if (!serial_delegate_)
5186 serial_delegate_ = std::make_unique<ChromeSerialDelegate>();
5187 return serial_delegate_.get();
5188}
Matt Reynolds93616f9b2019-06-07 01:28:525189
5190content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() {
5191 if (!hid_delegate_)
5192 hid_delegate_ = std::make_unique<ChromeHidDelegate>();
5193 return hid_delegate_.get();
5194}
Reilly Grant0d282322019-01-29 02:42:585195
Balazs Engedya7ff70982018-06-04 18:14:475196std::unique_ptr<content::AuthenticatorRequestClientDelegate>
5197ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate(
Adam Langleyeeac87e2019-04-13 22:58:225198 content::RenderFrameHost* render_frame_host,
5199 const std::string& relying_party_id) {
5200 return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host,
5201 relying_party_id);
Balazs Engedya7ff70982018-06-04 18:14:475202}
Nina Satragno8c832df2019-07-29 15:59:395203#endif
Balazs Engedya7ff70982018-06-04 18:14:475204
Dominic Battréf6f1ec692019-07-27 01:59:265205#if defined(OS_MACOSX)
5206bool ChromeContentBrowserClient::
5207 IsWebAuthenticationTouchIdAuthenticatorSupported() {
5208 return true;
5209}
5210#endif
5211
Jun Cai9409ded2018-01-30 00:19:465212std::unique_ptr<net::ClientCertStore>
5213ChromeContentBrowserClient::CreateClientCertStore(
5214 content::ResourceContext* resource_context) {
5215 if (!resource_context)
5216 return nullptr;
5217 return ProfileIOData::FromResourceContext(resource_context)
5218 ->CreateClientCertStore();
5219}
5220
David Benjamineced01fc2019-02-27 18:29:025221std::unique_ptr<content::LoginDelegate>
Jun Caibc561f412018-02-28 18:41:395222ChromeContentBrowserClient::CreateLoginDelegate(
Emily Starkf2c9bbd2019-04-09 17:08:585223 const net::AuthChallengeInfo& auth_info,
David Benjamineced01fc2019-02-27 18:29:025224 content::WebContents* web_contents,
Ken Rockot5f734e32018-06-13 01:41:035225 const content::GlobalRequestID& request_id,
Jun Cai8e165d22018-05-14 19:21:245226 bool is_request_for_main_frame,
Jun Caibc561f412018-02-28 18:41:395227 const GURL& url,
Ken Rockot5f734e32018-06-13 01:41:035228 scoped_refptr<net::HttpResponseHeaders> response_headers,
Jun Caibc561f412018-02-28 18:41:395229 bool first_auth_attempt,
Mark Pilgrim7cfcd112018-05-08 00:07:565230 LoginAuthRequiredCallback auth_required_callback) {
Ken Rockot5f734e32018-06-13 01:41:035231 return CreateLoginPrompt(
David Benjamineced01fc2019-02-27 18:29:025232 auth_info, web_contents, request_id, is_request_for_main_frame, url,
Emily Starkc5f15792019-05-19 17:24:205233 std::move(response_headers), LoginHandler::PRE_COMMIT,
5234 std::move(auth_required_callback));
Jun Caibc561f412018-02-28 18:41:395235}
5236
John Abd-El-Maleka67add82018-03-09 18:22:015237bool ChromeContentBrowserClient::HandleExternalProtocol(
5238 const GURL& url,
5239 content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
5240 int child_id,
5241 content::NavigationUIData* navigation_data,
5242 bool is_main_frame,
5243 ui::PageTransition page_transition,
Tim Volodineb24393f32018-11-16 18:45:455244 bool has_user_gesture,
Clark DuVallb6042ed32019-07-15 17:20:455245 network::mojom::URLLoaderFactoryPtr* out_factory) {
John Abd-El-Maleka67add82018-03-09 18:22:015246#if BUILDFLAG(ENABLE_EXTENSIONS)
5247 // External protocols are disabled for guests. An exception is made for the
5248 // "mailto" protocol, so that pages that utilize it work properly in a
5249 // WebView.
5250 ChromeNavigationUIData* chrome_data =
5251 static_cast<ChromeNavigationUIData*>(navigation_data);
5252 if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) ||
5253 (chrome_data &&
5254 chrome_data->GetExtensionNavigationUIData()->is_web_view())) &&
5255 !url.SchemeIs(url::kMailToScheme)) {
5256 return false;
5257 }
5258#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5259
5260#if defined(OS_ANDROID)
5261 // Main frame external protocols are handled by
5262 // InterceptNavigationResourceThrottle.
5263 if (is_main_frame)
5264 return false;
5265#endif // defined(ANDROID)
5266
Eric Seckler8652dcd52018-09-20 10:42:285267 base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
5268 base::BindOnce(&LaunchURL, url, web_contents_getter,
5269 page_transition, has_user_gesture));
John Abd-El-Maleka67add82018-03-09 18:22:015270 return true;
5271}
5272
Jennifer Apacible4f854a82018-04-06 22:22:115273std::unique_ptr<content::OverlayWindow>
Jennifer Apacible6010b0232018-04-12 23:35:285274ChromeContentBrowserClient::CreateWindowForPictureInPicture(
5275 content::PictureInPictureWindowController* controller) {
Jennifer Apacible4f854a82018-04-06 22:22:115276 // Note: content::OverlayWindow::Create() is defined by platform-specific
5277 // implementation in chrome/browser/ui/views. This layering hack, which goes
5278 // through //content and ContentBrowserClient, allows us to work around the
5279 // dependency constraints that disallow directly calling
5280 // chrome/browser/ui/views code either from here or from other code in
5281 // chrome/browser.
Jennifer Apacible6010b0232018-04-12 23:35:285282 return content::OverlayWindow::Create(controller);
Jennifer Apacible4f854a82018-04-06 22:22:115283}
5284
Clark DuVallfffa41e2019-06-25 20:27:195285bool ChromeContentBrowserClient::IsSafeRedirectTargetOnIO(
Clark DuVallbf7722f2018-08-03 18:03:335286 const GURL& url,
5287 content::ResourceContext* context) {
Clark DuVallfffa41e2019-06-25 20:27:195288 DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI));
Clark DuVallbf7722f2018-08-03 18:03:335289#if BUILDFLAG(ENABLE_EXTENSIONS)
5290 if (url.SchemeIs(extensions::kExtensionScheme)) {
5291 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
5292 const Extension* extension =
5293 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
5294 if (!extension)
5295 return false;
5296 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5297 extension, url.path());
5298 }
5299#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5300 return true;
5301}
5302
Clark DuVallfffa41e2019-06-25 20:27:195303bool ChromeContentBrowserClient::IsSafeRedirectTarget(
5304 const GURL& url,
5305 content::BrowserContext* context) {
5306#if BUILDFLAG(ENABLE_EXTENSIONS)
5307 if (url.SchemeIs(extensions::kExtensionScheme)) {
5308 const Extension* extension = extensions::ExtensionRegistry::Get(context)
5309 ->enabled_extensions()
5310 .GetByID(url.host());
5311 if (!extension)
5312 return false;
5313 return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
5314 extension, url.path());
5315 }
5316#endif // BUILDFLAG(ENABLE_EXTENSIONS)
5317 return true;
5318}
5319
Kunihiko Sakamoto19aa7082019-02-25 03:14:435320void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher(
Makoto Shimazuc7502932018-08-15 02:12:565321 content::BrowserContext* browser_context,
Leon Hanf4003a162019-01-28 05:31:585322 blink::mojom::RendererPreferenceWatcherPtr watcher) {
Makoto Shimazuc7502932018-08-15 02:12:565323 Profile* profile = Profile::FromBrowserContext(browser_context);
Kunihiko Sakamoto19aa7082019-02-25 03:14:435324 PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher(
5325 std::move(watcher));
Makoto Shimazuc7502932018-08-15 02:12:565326}
5327
dbeam25472e0c2017-06-23 19:02:315328// Static; handles rewriting Web UI URLs.
5329bool ChromeContentBrowserClient::HandleWebUI(
5330 GURL* url,
5331 content::BrowserContext* browser_context) {
5332 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
5333 if (url->SchemeIs(content::kChromeUIScheme) &&
5334 (url->host() == chrome::kChromeUIHelpHost ||
5335 (url->host() == chrome::kChromeUIUberHost &&
5336 (url->path().empty() || url->path() == "/")))) {
5337 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
5338 chrome::kChromeUIHelpHost);
5339 return true; // Return true to update the displayed URL.
5340 }
5341
5342 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
5343 browser_context, *url)) {
5344 return false;
5345 }
5346
5347#if defined(OS_CHROMEOS)
5348 // Special case : in ChromeOS in Guest mode bookmarks and history are
5349 // disabled for security reasons. New tab page explains the reasons, so
5350 // we redirect user to new tab page.
5351 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
5352 if (url->SchemeIs(content::kChromeUIScheme) &&
5353 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
5354 url->DomainIs(chrome::kChromeUIHistoryHost))) {
5355 // Rewrite with new tab URL
5356 *url = GURL(chrome::kChromeUINewTabURL);
5357 }
5358 }
5359#endif
5360
5361 return true;
5362}
5363
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065364bool ChromeContentBrowserClient::ShowPaymentHandlerWindow(
5365 content::BrowserContext* browser_context,
5366 const GURL& url,
Anthony Vallee-Dubois98befeaa2018-01-18 16:31:325367 base::OnceCallback<void(bool, int, int)> callback) {
Anthony Vallee-Dubois8f5e7e12018-01-12 16:14:065368#if defined(OS_ANDROID)
5369 return false;
5370#else
5371 payments::PaymentRequestDisplayManagerFactory::GetInstance()
5372 ->GetForBrowserContext(browser_context)
5373 ->ShowPaymentHandlerWindow(url, std::move(callback));
5374 return true;
5375#endif
5376}
5377
dbeam25472e0c2017-06-23 19:02:315378// Static; reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
5379// "chrome://foo/".
5380bool ChromeContentBrowserClient::HandleWebUIReverse(
5381 GURL* url,
5382 content::BrowserContext* browser_context) {
5383 // No need to actually reverse-rewrite the URL, but return true to update the
5384 // displayed URL when rewriting chrome://help to chrome://settings/help.
5385 return url->SchemeIs(content::kChromeUIScheme) &&
5386 url->host() == chrome::kChromeUISettingsHost;
5387}
5388
Dan Beamf0a7e112019-06-07 18:40:585389const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const {
5390 return ui::NativeTheme::GetInstanceForWeb();
5391}
5392
scottmgde42fb92017-02-10 17:56:035393// static
michaeln10e5fc352017-02-07 02:07:585394void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
5395 const storage::QuotaSettings* settings) {
5396 g_default_quota_settings = settings;
5397}
Yuzhu Shen44094e22017-07-18 22:52:355398
Clark DuVall5497288d2019-07-17 00:17:565399scoped_refptr<safe_browsing::UrlCheckerDelegate>
Yuzhu Shencb3011f62018-02-08 02:51:505400ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate(
5401 content::ResourceContext* resource_context) {
Yuzhu Shen44094e22017-07-18 22:52:355402 DCHECK_CURRENTLY_ON(BrowserThread::IO);
5403
Yuzhu Shencb3011f62018-02-08 02:51:505404 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
5405 if (!io_data->safe_browsing_enabled()->GetValue())
5406 return nullptr;
5407
Yuzhu Shen44094e22017-07-18 22:52:355408 // |safe_browsing_service_| may be unavailable in tests.
5409 if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) {
5410 safe_browsing_url_checker_delegate_ =
Jialiu Lin0de6756c2018-03-22 00:57:435411 base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>(
Yuzhu Shen44094e22017-07-18 22:52:355412 safe_browsing_service_->database_manager(),
Jialiu Lin0de6756c2018-03-22 00:57:435413 safe_browsing_service_->ui_manager());
Yuzhu Shen44094e22017-07-18 22:52:355414 }
5415
Clark DuVall5497288d2019-07-17 00:17:565416 return safe_browsing_url_checker_delegate_;
Yuzhu Shen44094e22017-07-18 22:52:355417}
Daniel Vogelheim6008f572018-09-24 14:35:145418
5419base::Optional<std::string>
5420ChromeContentBrowserClient::GetOriginPolicyErrorPage(
Andy Paicu8b6f8712019-07-16 15:02:265421 network::OriginPolicyState error_reason,
Daniel Vogelheim7badd0d2019-02-04 14:42:185422 content::NavigationHandle* handle) {
5423 return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML(
5424 error_reason, handle);
Daniel Vogelheim6008f572018-09-24 14:35:145425}
Kunihiko Sakamoto73b803d2018-10-05 09:09:525426
Takashi Toyoshima5af383aa2019-07-22 15:24:225427bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
Kunihiko Sakamoto73b803d2018-10-05 09:09:525428 // We require --user-data-dir flag too so that no dangerous changes are made
5429 // in the user's regular profile.
5430 return base::CommandLine::ForCurrentProcess()->HasSwitch(
5431 switches::kUserDataDir);
5432}
rajendrantfeea8592018-10-19 18:26:065433
5434void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate(
5435 int32_t network_traffic_annotation_id_hash,
5436 int64_t recv_bytes,
5437 int64_t sent_bytes) {
Min Qincafb27b2018-10-30 18:02:035438 if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) {
5439 data_use_measurement::ChromeDataUseMeasurement::GetInstance()
5440 ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash,
5441 recv_bytes, sent_bytes);
rajendrantfeea8592018-10-19 18:26:065442 }
5443}
Ryan Sturmaa05092f2018-10-21 03:56:545444
5445content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews(
5446 content::PreviewsState initial_state,
Ryan Sturm647d1d92018-11-07 15:41:395447 content::NavigationHandle* navigation_handle,
5448 const GURL& current_navigation_url) {
Robert Ogden30bbc9d2019-04-30 20:15:135449 content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback(
5450 initial_state, navigation_handle, current_navigation_url);
5451
5452 return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle);
5453}
5454
5455content::PreviewsState
5456ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback(
5457 content::PreviewsState initial_state,
5458 content::NavigationHandle* navigation_handle,
5459 const GURL& current_navigation_url) {
Ryan Sturmaa05092f2018-10-21 03:56:545460 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Tarun Bansalb89c1d52019-01-16 06:56:295461 DCHECK(!navigation_handle->HasCommitted());
Ryan Sturmda2a0e02018-10-25 01:52:215462
Ryan Sturmaa05092f2018-10-21 03:56:545463 // If this is not a main frame, return the initial state. If there are no
5464 // previews in the state, return the state as is.
5465 if (!navigation_handle->IsInMainFrame() ||
5466 navigation_handle->IsSameDocument()) {
5467 return initial_state;
5468 }
5469
Robert Ogdena994eb42019-02-14 19:15:085470 if (!current_navigation_url.SchemeIsHTTPOrHTTPS())
Ryan Sturm647d1d92018-11-07 15:41:395471 return content::PREVIEWS_OFF;
Robert Ogdena994eb42019-02-14 19:15:085472
5473 // Do not allow previews on POST navigations since the primary opt-out
5474 // mechanism is to reload the page. Because POST navigations are not
5475 // idempotent, we do not want to show a preview on a POST navigation where
5476 // opting out would cause another navigation, i.e.: a reload.
5477 if (navigation_handle->IsPost())
5478 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395479
5480 content::WebContents* web_contents = navigation_handle->GetWebContents();
5481 content::WebContentsDelegate* delegate = web_contents->GetDelegate();
5482
Ryan Sturmda2a0e02018-10-25 01:52:215483 auto* browser_context = web_contents->GetBrowserContext();
Ryan Sturmaa05092f2018-10-21 03:56:545484
5485 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile(
5486 Profile::FromBrowserContext(browser_context));
5487 auto* data_reduction_proxy_settings =
5488 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5489 browser_context);
5490 // If the profile does not support previews or Data Saver, do not turn on
5491 // Previews.
5492 if (!previews_service || !previews_service->previews_ui_service() ||
5493 !data_reduction_proxy_settings) {
5494 return content::PREVIEWS_OFF;
5495 }
5496
5497 PreviewsUITabHelper* ui_tab_helper =
Ryan Sturmda2a0e02018-10-25 01:52:215498 PreviewsUITabHelper::FromWebContents(web_contents);
Ryan Sturmaa05092f2018-10-21 03:56:545499 // If this tab does not have a PreviewsUITabHelper, no preview should be
5500 // served.
5501 if (!ui_tab_helper)
5502 return content::PREVIEWS_OFF;
5503
5504 DCHECK(!browser_context->IsOffTheRecord());
5505
5506 // Other previews objects should all exist and be initialized if we have made
5507 // it past earlier checks.
5508 previews::PreviewsDeciderImpl* previews_decider_impl =
5509 previews_service->previews_ui_service()->previews_decider_impl();
5510 DCHECK(previews_decider_impl);
5511
Ryan Sturm647d1d92018-11-07 15:41:395512 // Start with an unspecified state.
Ryan Sturmaa05092f2018-10-21 03:56:545513 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED;
5514
Ryan Sturm647d1d92018-11-07 15:41:395515 previews::PreviewsUserData* previews_data =
5516 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5517
5518 // Certain PreviewsStates are used within URLLoaders (Offline, server
Seanac57e9b92019-04-29 19:19:315519 // previews) and cannot re-evaluate PreviewsState once previews triggering
5520 // logic has already been run, so they should not change. Assume that
5521 // previews triggering logic has run when PreviewsUserData already exists and
5522 // a Lite Page Redirect preview is not being attempted, since it may also
5523 // create a previews_data before this point.
5524 bool previews_triggering_logic_already_ran = false;
Ryan Sturm647d1d92018-11-07 15:41:395525 if (previews_data) {
Seanac57e9b92019-04-29 19:19:315526 previews_triggering_logic_already_ran =
5527 !previews_data->server_lite_page_info();
Ryan Sturm647d1d92018-11-07 15:41:395528 } else {
5529 previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
5530 navigation_handle, previews_decider_impl->GeneratePageId());
5531 }
5532
5533 DCHECK(previews_data);
5534
Robert Ogden01770b362019-05-22 17:36:435535 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
5536 previews::switches::kForceEnablePreviews)) {
5537 previews_decider_impl->LoadPageHints(current_navigation_url);
5538 return content::ALL_SUPPORTED_PREVIEWS;
5539 }
5540
Ryan Sturmaa05092f2018-10-21 03:56:545541 bool is_reload =
5542 navigation_handle->GetReloadType() != content::ReloadType::NONE;
5543
Ryan Sturm647d1d92018-11-07 15:41:395544 content::PreviewsState server_previews_enabled_state =
Robert Ogden54bb4ff2019-06-19 01:31:515545 content::SERVER_LITE_PAGE_ON;
Ryan Sturm647d1d92018-11-07 15:41:395546
5547 // For now, treat server previews types as a single decision, and do not
5548 // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT
5549 // header, nor does the plumbing exist to modify the PreviewsState within the
5550 // URLLoader.
Seanac57e9b92019-04-29 19:19:315551 if (previews_triggering_logic_already_ran) {
Ryan Sturm647d1d92018-11-07 15:41:395552 // Copy the server state that was used before the redirect for the initial
5553 // URL.
Robert Ogden869986f2019-06-20 19:12:055554 previews_state |=
5555 (previews_data->AllowedPreviewsState() & server_previews_enabled_state);
Ryan Sturm647d1d92018-11-07 15:41:395556 } else {
Doug Arnetta3dc71582018-11-08 00:25:105557 if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart(
Ryan Sturm647d1d92018-11-07 15:41:395558 previews_data, current_navigation_url, is_reload,
Doug Arnettd5a60032018-11-12 19:37:305559 previews::PreviewsType::LITE_PAGE)) {
Ryan Sturm647d1d92018-11-07 15:41:395560 previews_state |= server_previews_enabled_state;
5561 }
Ryan Sturmaa05092f2018-10-21 03:56:545562 }
5563
Robert Ogden198d6572019-06-26 15:15:335564 // Evaluate Offline, NoScript, and ResourceBlocking previews.
Ryan Sturmaa05092f2018-10-21 03:56:545565 previews_state |= previews::DetermineAllowedClientPreviewsState(
Seanac57e9b92019-04-29 19:19:315566 previews_data, previews_triggering_logic_already_ran,
Ryan Sturmaa05092f2018-10-21 03:56:545567 data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
Ryan Sturm37b3069e2019-02-22 04:11:245568 previews_decider_impl, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545569
5570 if (previews_state & content::PREVIEWS_OFF) {
Ryan Sturm647d1d92018-11-07 15:41:395571 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545572 return content::PREVIEWS_OFF;
5573 }
5574
5575 if (previews_state & content::PREVIEWS_NO_TRANSFORM) {
Ryan Sturm647d1d92018-11-07 15:41:395576 previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM);
Ryan Sturmaa05092f2018-10-21 03:56:545577 return content::PREVIEWS_NO_TRANSFORM;
5578 }
5579
5580 // At this point, if no Preview is allowed, don't allow previews.
Ryan Sturm647d1d92018-11-07 15:41:395581 if (previews_state == content::PREVIEWS_UNSPECIFIED) {
5582 previews_data->set_allowed_previews_state(content::PREVIEWS_OFF);
Ryan Sturmaa05092f2018-10-21 03:56:545583 return content::PREVIEWS_OFF;
Ryan Sturm647d1d92018-11-07 15:41:395584 }
5585
5586 content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED;
5587 if (delegate) {
5588 delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state);
5589 }
Ryan Sturmaa05092f2018-10-21 03:56:545590
5591 // If the allowed previews are limited by the embedder, ensure previews honors
5592 // those limits.
Ryan Sturm647d1d92018-11-07 15:41:395593 if (embedder_state != content::PREVIEWS_UNSPECIFIED) {
5594 previews_state = previews_state & embedder_state;
Ryan Sturmaa05092f2018-10-21 03:56:545595 // If no valid previews are left, set the state explicitly to PREVIEWS_OFF.
5596 if (previews_state == content::PREVIEWS_UNSPECIFIED)
5597 previews_state = content::PREVIEWS_OFF;
5598 }
Ryan Sturm647d1d92018-11-07 15:41:395599 previews_data->set_allowed_previews_state(previews_state);
Ryan Sturmaa05092f2018-10-21 03:56:545600 return previews_state;
5601}
5602
5603// static
5604content::PreviewsState
5605ChromeContentBrowserClient::DetermineCommittedPreviewsForURL(
5606 const GURL& url,
5607 data_reduction_proxy::DataReductionProxyData* drp_data,
5608 previews::PreviewsUserData* previews_user_data,
5609 const previews::PreviewsDecider* previews_decider,
Ryan Sturm737bd1d2019-02-28 01:38:055610 content::PreviewsState initial_state,
5611 content::NavigationHandle* navigation_handle) {
Ryan Sturmaa05092f2018-10-21 03:56:545612 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5613 if (!previews::HasEnabledPreviews(initial_state))
5614 return content::PREVIEWS_OFF;
5615
5616 // Check if the server sent a preview directive.
5617 content::PreviewsState previews_state =
Clark DuVall0ec52142019-06-06 19:53:555618 previews::DetermineCommittedServerPreviewsState(drp_data, initial_state);
Ryan Sturmaa05092f2018-10-21 03:56:545619
Ryan Sturmaa05092f2018-10-21 03:56:545620 // Check the various other client previews types.
5621 return previews::DetermineCommittedClientPreviewsState(
Ryan Sturm737bd1d2019-02-28 01:38:055622 previews_user_data, url, previews_state, previews_decider,
5623 navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545624}
5625
5626content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews(
5627 content::PreviewsState initial_state,
5628 content::NavigationHandle* navigation_handle,
5629 const net::HttpResponseHeaders* response_headers) {
Robert Ogden30bbc9d2019-04-30 20:15:135630 content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback(
5631 initial_state, navigation_handle, response_headers);
5632
5633 return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle);
5634}
5635
5636content::PreviewsState
5637ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback(
5638 content::PreviewsState initial_state,
5639 content::NavigationHandle* navigation_handle,
5640 const net::HttpResponseHeaders* response_headers) {
Ryan Sturmaa05092f2018-10-21 03:56:545641 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5642 // Only support HTTP and HTTPS.
5643 if (navigation_handle->IsErrorPage() ||
5644 !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) {
5645 return content::PREVIEWS_OFF;
5646 }
5647
5648 // If this is not a main frame, return the initial state. If there are no
5649 // previews in the state, return the state as is.
5650 if (!previews::HasEnabledPreviews(initial_state) ||
5651 !navigation_handle->IsInMainFrame() ||
5652 navigation_handle->IsSameDocument()) {
5653 return initial_state;
5654 }
5655
5656 // WebContents that don't have a PreviewsUITabHelper are not supported.
5657 PreviewsUITabHelper* ui_tab_helper =
5658 PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
5659 if (!ui_tab_helper)
5660 return content::PREVIEWS_OFF;
5661
5662 // If we did not previously create a PreviewsUserData, do not go any further.
5663 previews::PreviewsUserData* previews_user_data =
5664 ui_tab_helper->GetPreviewsUserData(navigation_handle);
5665 if (!previews_user_data)
5666 return content::PREVIEWS_OFF;
5667
5668 PreviewsService* previews_service =
5669 PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext(
5670 navigation_handle->GetWebContents()->GetBrowserContext()));
5671
5672 if (!previews_service || !previews_service->previews_ui_service())
5673 return content::PREVIEWS_OFF;
5674
5675// Check if offline previews are being used and set it in the user data.
5676#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
5677 offline_pages::OfflinePageTabHelper* tab_helper =
5678 offline_pages::OfflinePageTabHelper::FromWebContents(
5679 navigation_handle->GetWebContents());
5680
Ryan Sturmfc7d92f2019-02-12 02:24:235681 bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage();
5682 bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem();
5683
5684 // If this is an offline page, but not a preview, then we should not attempt
5685 // any previews or surface the previews UI.
5686 if (is_offline_page && !is_offline_preview)
5687 return content::PREVIEWS_OFF;
5688
5689 previews_user_data->set_offline_preview_used(is_offline_preview);
Ryan Sturmaa05092f2018-10-21 03:56:545690#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)
5691
5692 // Annotate request if no-transform directive found in response headers.
5693 if (response_headers &&
5694 response_headers->HasHeaderValue("cache-control", "no-transform")) {
Jered Grayba1da122018-10-31 23:06:265695 previews_user_data->set_cache_control_no_transform_directive();
Ryan Sturmaa05092f2018-10-21 03:56:545696 }
5697
5698 previews::PreviewsDeciderImpl* previews_decider_impl =
5699 previews_service->previews_ui_service()->previews_decider_impl();
5700 DCHECK(previews_decider_impl);
5701
Clark DuVall9c5a72cc2018-10-25 01:29:215702 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data;
5703 auto* settings =
5704 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
5705 navigation_handle->GetWebContents()->GetBrowserContext());
5706 if (settings) {
5707 // TODO(898326): |drp_data| may be incomplete because |navigation_handle|
5708 // does not yet have all the response information.
5709 drp_data = settings->CreateDataFromNavigationHandle(navigation_handle,
5710 response_headers);
5711 }
Ryan Sturmaa05092f2018-10-21 03:56:545712
5713 // Determine effective PreviewsState for this committed main frame response.
5714 content::PreviewsState committed_state = DetermineCommittedPreviewsForURL(
Clark DuVall9c5a72cc2018-10-25 01:29:215715 navigation_handle->GetURL(), drp_data.get(), previews_user_data,
Ryan Sturm737bd1d2019-02-28 01:38:055716 previews_decider_impl, initial_state, navigation_handle);
Ryan Sturmaa05092f2018-10-21 03:56:545717
5718 // Double check that we never serve a preview when we have a
5719 // cache-control:no-transform directive.
5720 DCHECK(!previews_user_data->cache_control_no_transform_directive() ||
5721 !previews::HasEnabledPreviews(committed_state));
5722
Robert Ogdended292c6f2019-05-03 22:44:515723 // TODO(robertogden): Consider moving this to after the holdback logic.
Ryan Sturmaa05092f2018-10-21 03:56:545724 previews_user_data->set_committed_previews_state(committed_state);
5725
5726 previews::PreviewsType committed_type =
5727 previews::GetMainFramePreviewsType(committed_state);
5728
5729 // Capture committed previews type, if any, in PreviewsUserData.
5730 // Note: this is for the subset of previews types that are decided upon
5731 // navigation commit. Previews types that are determined prior to
5732 // navigation (such as for offline pages or for redirecting to another
5733 // url), are not set here.
5734 previews_user_data->SetCommittedPreviewsType(committed_type);
5735
5736 // Log the commit decision.
5737 std::vector<previews::PreviewsEligibilityReason> passed_reasons;
5738 previews_decider_impl->LogPreviewDecisionMade(
5739 (previews_user_data->cache_control_no_transform_directive()
5740 ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM
5741 : previews::PreviewsEligibilityReason::COMMITTED),
5742 navigation_handle->GetURL(), base::Time::Now(),
Robert Ogden869986f2019-06-20 19:12:055743 previews_user_data->CommittedPreviewsType(), std::move(passed_reasons),
Robert Ogden33e36312019-05-06 19:17:055744 previews_user_data);
Ryan Sturmaa05092f2018-10-21 03:56:545745
5746 return committed_state;
5747}
Charlie Harrison650e11422018-12-04 00:37:265748
5749void ChromeContentBrowserClient::LogWebFeatureForCurrentPage(
5750 content::RenderFrameHost* render_frame_host,
5751 blink::mojom::WebFeature feature) {
5752 DCHECK_CURRENTLY_ON(BrowserThread::UI);
5753 page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {});
5754 page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
5755 render_frame_host, new_features);
5756}
Yutaka Hirano968d6252018-12-04 05:09:315757
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525758std::string ChromeContentBrowserClient::GetProduct() {
Yutaka Hirano968d6252018-12-04 05:09:315759 return ::GetProduct();
5760}
5761
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525762std::string ChromeContentBrowserClient::GetUserAgent() {
Yutaka Hirano968d6252018-12-04 05:09:315763 return ::GetUserAgent();
5764}
Sam McNallyd54e23f92019-01-16 04:42:395765
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525766blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
Mike West6e4cbb32019-02-13 09:40:175767 return ::GetUserAgentMetadata();
5768}
5769
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525770base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() {
Austin Orione250d012019-05-29 02:56:275771 // This icon is available on Android, but adds 19KiB to the APK. Since it
5772 // isn't used on Android we exclude it to avoid bloat.
5773#if !defined(OS_ANDROID)
5774 return base::Optional<gfx::ImageSkia>(
5775 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
5776 IDR_PRODUCT_LOGO_256));
5777#else
5778 return base::nullopt;
5779#endif
5780}
5781
Sam McNallyd54e23f92019-01-16 04:42:395782bool ChromeContentBrowserClient::IsBuiltinComponent(
5783 content::BrowserContext* browser_context,
5784 const url::Origin& origin) {
5785#if BUILDFLAG(ENABLE_EXTENSIONS)
5786 return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent(
5787 browser_context, origin);
5788#else
5789 return false;
5790#endif
5791}
Oleg Davydov2cc0167b2019-02-05 14:32:485792
5793bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted(
5794 const GURL& url,
5795 content::BrowserContext* context) {
5796 PolicyBlacklistService* service =
5797 PolicyBlacklistFactory::GetForBrowserContext(context);
5798
5799 using URLBlacklistState = policy::URLBlacklist::URLBlacklistState;
5800 URLBlacklistState blacklist_state = service->GetURLBlacklistState(url);
5801 return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST;
5802}
Dominic Mazzoni21fb0282019-02-13 18:32:475803
5804ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
5805 content::BrowserContext* browser_context) {
5806 Profile* profile = Profile::FromBrowserContext(browser_context);
5807 return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode();
5808}
Eric Karld6cd75b2019-03-14 22:01:365809
5810#if defined(OS_ANDROID)
5811content::ContentBrowserClient::WideColorGamutHeuristic
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525812ChromeContentBrowserClient::GetWideColorGamutHeuristic() {
Eric Karld6cd75b2019-03-14 22:01:365813 if (features::UseDisplayWideColorGamut()) {
5814 return WideColorGamutHeuristic::kUseDisplay;
5815 }
5816 return WideColorGamutHeuristic::kNone;
5817}
5818#endif
Ehsan Karamad91413d72019-03-22 16:37:485819
5820base::flat_set<std::string>
Ehsan Karamad466529d2019-05-24 03:24:435821ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
Ehsan Karamad91413d72019-03-22 16:37:485822 content::ResourceContext* resource_context) {
5823 base::flat_set<std::string> mime_types;
5824#if BUILDFLAG(ENABLE_PLUGINS)
5825 auto map = PluginUtils::GetMimeTypeToExtensionIdMap(resource_context);
5826 for (const auto& pair : map)
5827 mime_types.insert(pair.first);
5828#endif
5829 return mime_types;
5830}
Yao Xiaod06607b2019-05-02 23:16:365831
5832void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy(
5833 const content::WebContents* web_contents,
5834 const content::RenderFrameHost* frame_host,
5835 bool user_gesture,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525836 content::NavigationDownloadPolicy* download_policy) {
Yao Xiaod06607b2019-05-02 23:16:365837 const ChromeSubresourceFilterClient* client =
5838 ChromeSubresourceFilterClient::FromWebContents(web_contents);
5839 if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) {
Yao Xiaof60646662019-07-25 07:25:045840 download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame);
Yao Xiaod06607b2019-05-02 23:16:365841 if (!user_gesture) {
5842 if (base::FeatureList::IsEnabled(
5843 blink::features::
5844 kBlockingDownloadsInAdFrameWithoutUserActivation)) {
5845 download_policy->SetDisallowed(
5846 content::NavigationDownloadType::kAdFrameNoGesture);
5847 } else {
5848 download_policy->SetAllowed(
5849 content::NavigationDownloadType::kAdFrameNoGesture);
5850 }
Yao Xiaod06607b2019-05-02 23:16:365851 }
5852 }
5853}
Jun Cai732a05e32019-05-29 19:34:195854
5855bool ChromeContentBrowserClient::IsBluetoothScanningBlocked(
5856 content::BrowserContext* browser_context,
5857 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525858 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195859 const HostContentSettingsMap* const content_settings =
5860 HostContentSettingsMapFactory::GetForProfile(
5861 Profile::FromBrowserContext(browser_context));
5862
5863 if (content_settings->GetContentSetting(
5864 requesting_origin.GetURL(), embedding_origin.GetURL(),
5865 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING,
5866 std::string()) == CONTENT_SETTING_BLOCK) {
5867 return true;
5868 }
5869
5870 return false;
5871}
5872
5873void ChromeContentBrowserClient::BlockBluetoothScanning(
5874 content::BrowserContext* browser_context,
5875 const url::Origin& requesting_origin,
Lucas Furukawa Gadani4909f3c2019-06-18 22:36:525876 const url::Origin& embedding_origin) {
Jun Cai732a05e32019-05-29 19:34:195877 HostContentSettingsMap* const content_settings =
5878 HostContentSettingsMapFactory::GetForProfile(
5879 Profile::FromBrowserContext(browser_context));
5880
5881 content_settings->SetContentSettingDefaultScope(
5882 requesting_origin.GetURL(), embedding_origin.GetURL(),
5883 CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(),
5884 CONTENT_SETTING_BLOCK);
5885}